예제 #1
0
 @Override
 protected WeakReference<Thread> computeValue(Class<?> type) {
   UNSAFE.ensureClassInitialized(type);
   if (UNSAFE.shouldBeInitialized(type))
     // If the previous call didn't block, this can happen.
     // We are executing inside <clinit>.
     return new WeakReference<>(Thread.currentThread());
   return null;
 }
예제 #2
0
 private static boolean checkInitialized(MemberName member) {
   Class<?> defc = member.getDeclaringClass();
   WeakReference<Thread> ref = EnsureInitialized.INSTANCE.get(defc);
   if (ref == null) {
     return true; // the final state
   }
   Thread clinitThread = ref.get();
   // Somebody may still be running defc.<clinit>.
   if (clinitThread == Thread.currentThread()) {
     // If anybody is running defc.<clinit>, it is this thread.
     if (UNSAFE.shouldBeInitialized(defc))
       // Yes, we are running it; keep the barrier for now.
       return false;
   } else {
     // We are in a random thread.  Block.
     UNSAFE.ensureClassInitialized(defc);
   }
   assert (!UNSAFE.shouldBeInitialized(defc));
   // put it into the final state
   EnsureInitialized.INSTANCE.remove(defc);
   return true;
 }