src/hotspot/share/oops/instanceKlass.cpp
changeset 53305 d193d58ae79d
parent 53293 64049c8e7452
child 53384 09909d1356c8
equal deleted inserted replaced
53304:9e968a576dd2 53305:d193d58ae79d
   916 
   916 
   917   DTRACE_CLASSINIT_PROBE(required, -1);
   917   DTRACE_CLASSINIT_PROBE(required, -1);
   918 
   918 
   919   bool wait = false;
   919   bool wait = false;
   920 
   920 
       
   921   assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl");
       
   922   JavaThread* jt = (JavaThread*)THREAD;
       
   923 
   921   // refer to the JVM book page 47 for description of steps
   924   // refer to the JVM book page 47 for description of steps
   922   // Step 1
   925   // Step 1
   923   {
   926   {
   924     Handle h_init_lock(THREAD, init_lock());
   927     Handle h_init_lock(THREAD, init_lock());
   925     ObjectLocker ol(h_init_lock, THREAD, h_init_lock() != NULL);
   928     ObjectLocker ol(h_init_lock, THREAD, h_init_lock() != NULL);
   926 
   929 
   927     Thread *self = THREAD; // it's passed the current thread
       
   928 
       
   929     // Step 2
   930     // Step 2
   930     // If we were to use wait() instead of waitInterruptibly() then
   931     // If we were to use wait() instead of waitInterruptibly() then
   931     // we might end up throwing IE from link/symbol resolution sites
   932     // we might end up throwing IE from link/symbol resolution sites
   932     // that aren't expected to throw.  This would wreak havoc.  See 6320309.
   933     // that aren't expected to throw.  This would wreak havoc.  See 6320309.
   933     while(is_being_initialized() && !is_reentrant_initialization(self)) {
   934     while (is_being_initialized() && !is_reentrant_initialization(jt)) {
   934         wait = true;
   935       wait = true;
   935       ol.waitUninterruptibly(CHECK);
   936       jt->set_class_to_be_initialized(this);
       
   937       ol.waitUninterruptibly(jt);
       
   938       jt->set_class_to_be_initialized(NULL);
   936     }
   939     }
   937 
   940 
   938     // Step 3
   941     // Step 3
   939     if (is_being_initialized() && is_reentrant_initialization(self)) {
   942     if (is_being_initialized() && is_reentrant_initialization(jt)) {
   940       DTRACE_CLASSINIT_PROBE_WAIT(recursive, -1, wait);
   943       DTRACE_CLASSINIT_PROBE_WAIT(recursive, -1, wait);
   941       return;
   944       return;
   942     }
   945     }
   943 
   946 
   944     // Step 4
   947     // Step 4
   964       }
   967       }
   965     }
   968     }
   966 
   969 
   967     // Step 6
   970     // Step 6
   968     set_init_state(being_initialized);
   971     set_init_state(being_initialized);
   969     set_init_thread(self);
   972     set_init_thread(jt);
   970   }
   973   }
   971 
   974 
   972   // Step 7
   975   // Step 7
   973   // Next, if C is a class rather than an interface, initialize it's super class and super
   976   // Next, if C is a class rather than an interface, initialize it's super class and super
   974   // interfaces.
   977   // interfaces.
  1004   // Look for aot compiled methods for this klass, including class initializer.
  1007   // Look for aot compiled methods for this klass, including class initializer.
  1005   AOTLoader::load_for_klass(this, THREAD);
  1008   AOTLoader::load_for_klass(this, THREAD);
  1006 
  1009 
  1007   // Step 8
  1010   // Step 8
  1008   {
  1011   {
  1009     assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl");
       
  1010     JavaThread* jt = (JavaThread*)THREAD;
       
  1011     DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
  1012     DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
  1012     // Timer includes any side effects of class initialization (resolution,
  1013     // Timer includes any side effects of class initialization (resolution,
  1013     // etc), but not recursive entry into call_class_initializer().
  1014     // etc), but not recursive entry into call_class_initializer().
  1014     PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
  1015     PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
  1015                              ClassLoader::perf_class_init_selftime(),
  1016                              ClassLoader::perf_class_init_selftime(),
  1031     // Step 10 and 11
  1032     // Step 10 and 11
  1032     Handle e(THREAD, PENDING_EXCEPTION);
  1033     Handle e(THREAD, PENDING_EXCEPTION);
  1033     CLEAR_PENDING_EXCEPTION;
  1034     CLEAR_PENDING_EXCEPTION;
  1034     // JVMTI has already reported the pending exception
  1035     // JVMTI has already reported the pending exception
  1035     // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
  1036     // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
  1036     JvmtiExport::clear_detected_exception((JavaThread*)THREAD);
  1037     JvmtiExport::clear_detected_exception(jt);
  1037     {
  1038     {
  1038       EXCEPTION_MARK;
  1039       EXCEPTION_MARK;
  1039       set_initialization_state_and_notify(initialization_error, THREAD);
  1040       set_initialization_state_and_notify(initialization_error, THREAD);
  1040       CLEAR_PENDING_EXCEPTION;   // ignore any exception thrown, class initialization error is thrown below
  1041       CLEAR_PENDING_EXCEPTION;   // ignore any exception thrown, class initialization error is thrown below
  1041       // JVMTI has already reported the pending exception
  1042       // JVMTI has already reported the pending exception
  1042       // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
  1043       // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
  1043       JvmtiExport::clear_detected_exception((JavaThread*)THREAD);
  1044       JvmtiExport::clear_detected_exception(jt);
  1044     }
  1045     }
  1045     DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
  1046     DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
  1046     if (e->is_a(SystemDictionary::Error_klass())) {
  1047     if (e->is_a(SystemDictionary::Error_klass())) {
  1047       THROW_OOP(e());
  1048       THROW_OOP(e());
  1048     } else {
  1049     } else {