hotspot/src/share/vm/oops/instanceKlass.cpp
changeset 33602 16053580a684
parent 33593 60764a78fa5c
child 33611 9abd65805e19
equal deleted inserted replaced
33597:5d42601232b1 33602:16053580a684
   740 void InstanceKlass::initialize_impl(instanceKlassHandle this_k, TRAPS) {
   740 void InstanceKlass::initialize_impl(instanceKlassHandle this_k, TRAPS) {
   741   // Make sure klass is linked (verified) before initialization
   741   // Make sure klass is linked (verified) before initialization
   742   // A class could already be verified, since it has been reflected upon.
   742   // A class could already be verified, since it has been reflected upon.
   743   this_k->link_class(CHECK);
   743   this_k->link_class(CHECK);
   744 
   744 
   745   DTRACE_CLASSINIT_PROBE(required, InstanceKlass::cast(this_k()), -1);
   745   DTRACE_CLASSINIT_PROBE(required, this_k(), -1);
   746 
   746 
   747   bool wait = false;
   747   bool wait = false;
   748 
   748 
   749   // refer to the JVM book page 47 for description of steps
   749   // refer to the JVM book page 47 for description of steps
   750   // Step 1
   750   // Step 1
   763       ol.waitUninterruptibly(CHECK);
   763       ol.waitUninterruptibly(CHECK);
   764     }
   764     }
   765 
   765 
   766     // Step 3
   766     // Step 3
   767     if (this_k->is_being_initialized() && this_k->is_reentrant_initialization(self)) {
   767     if (this_k->is_being_initialized() && this_k->is_reentrant_initialization(self)) {
   768       DTRACE_CLASSINIT_PROBE_WAIT(recursive, InstanceKlass::cast(this_k()), -1,wait);
   768       DTRACE_CLASSINIT_PROBE_WAIT(recursive, this_k(), -1,wait);
   769       return;
   769       return;
   770     }
   770     }
   771 
   771 
   772     // Step 4
   772     // Step 4
   773     if (this_k->is_initialized()) {
   773     if (this_k->is_initialized()) {
   774       DTRACE_CLASSINIT_PROBE_WAIT(concurrent, InstanceKlass::cast(this_k()), -1,wait);
   774       DTRACE_CLASSINIT_PROBE_WAIT(concurrent, this_k(), -1,wait);
   775       return;
   775       return;
   776     }
   776     }
   777 
   777 
   778     // Step 5
   778     // Step 5
   779     if (this_k->is_in_error_state()) {
   779     if (this_k->is_in_error_state()) {
   780       DTRACE_CLASSINIT_PROBE_WAIT(erroneous, InstanceKlass::cast(this_k()), -1,wait);
   780       DTRACE_CLASSINIT_PROBE_WAIT(erroneous, this_k(), -1,wait);
   781       ResourceMark rm(THREAD);
   781       ResourceMark rm(THREAD);
   782       const char* desc = "Could not initialize class ";
   782       const char* desc = "Could not initialize class ";
   783       const char* className = this_k->external_name();
   783       const char* className = this_k->external_name();
   784       size_t msglen = strlen(desc) + strlen(className) + 1;
   784       size_t msglen = strlen(desc) + strlen(className) + 1;
   785       char* message = NEW_RESOURCE_ARRAY(char, msglen);
   785       char* message = NEW_RESOURCE_ARRAY(char, msglen);
   808       {
   808       {
   809         EXCEPTION_MARK;
   809         EXCEPTION_MARK;
   810         this_k->set_initialization_state_and_notify(initialization_error, THREAD); // Locks object, set state, and notify all waiting threads
   810         this_k->set_initialization_state_and_notify(initialization_error, THREAD); // Locks object, set state, and notify all waiting threads
   811         CLEAR_PENDING_EXCEPTION;   // ignore any exception thrown, superclass initialization error is thrown below
   811         CLEAR_PENDING_EXCEPTION;   // ignore any exception thrown, superclass initialization error is thrown below
   812       }
   812       }
   813       DTRACE_CLASSINIT_PROBE_WAIT(super__failed, InstanceKlass::cast(this_k()), -1,wait);
   813       DTRACE_CLASSINIT_PROBE_WAIT(super__failed, this_k(), -1,wait);
   814       THROW_OOP(e());
   814       THROW_OOP(e());
   815     }
   815     }
   816   }
   816   }
   817 
   817 
   818   // Recursively initialize any superinterfaces that declare default methods
   818   // Recursively initialize any superinterfaces that declare default methods
   824 
   824 
   825   // Step 8
   825   // Step 8
   826   {
   826   {
   827     assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl");
   827     assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl");
   828     JavaThread* jt = (JavaThread*)THREAD;
   828     JavaThread* jt = (JavaThread*)THREAD;
   829     DTRACE_CLASSINIT_PROBE_WAIT(clinit, InstanceKlass::cast(this_k()), -1,wait);
   829     DTRACE_CLASSINIT_PROBE_WAIT(clinit, this_k(), -1,wait);
   830     // Timer includes any side effects of class initialization (resolution,
   830     // Timer includes any side effects of class initialization (resolution,
   831     // etc), but not recursive entry into call_class_initializer().
   831     // etc), but not recursive entry into call_class_initializer().
   832     PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
   832     PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
   833                              ClassLoader::perf_class_init_selftime(),
   833                              ClassLoader::perf_class_init_selftime(),
   834                              ClassLoader::perf_classes_inited(),
   834                              ClassLoader::perf_classes_inited(),
   858       CLEAR_PENDING_EXCEPTION;   // ignore any exception thrown, class initialization error is thrown below
   858       CLEAR_PENDING_EXCEPTION;   // ignore any exception thrown, class initialization error is thrown below
   859       // JVMTI has already reported the pending exception
   859       // JVMTI has already reported the pending exception
   860       // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
   860       // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
   861       JvmtiExport::clear_detected_exception((JavaThread*)THREAD);
   861       JvmtiExport::clear_detected_exception((JavaThread*)THREAD);
   862     }
   862     }
   863     DTRACE_CLASSINIT_PROBE_WAIT(error, InstanceKlass::cast(this_k()), -1,wait);
   863     DTRACE_CLASSINIT_PROBE_WAIT(error, this_k(), -1,wait);
   864     if (e->is_a(SystemDictionary::Error_klass())) {
   864     if (e->is_a(SystemDictionary::Error_klass())) {
   865       THROW_OOP(e());
   865       THROW_OOP(e());
   866     } else {
   866     } else {
   867       JavaCallArguments args(e);
   867       JavaCallArguments args(e);
   868       THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),
   868       THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),
   869                 vmSymbols::throwable_void_signature(),
   869                 vmSymbols::throwable_void_signature(),
   870                 &args);
   870                 &args);
   871     }
   871     }
   872   }
   872   }
   873   DTRACE_CLASSINIT_PROBE_WAIT(end, InstanceKlass::cast(this_k()), -1,wait);
   873   DTRACE_CLASSINIT_PROBE_WAIT(end, this_k(), -1,wait);
   874 }
   874 }
   875 
   875 
   876 
   876 
   877 // Note: implementation moved to static method to expose the this pointer.
   877 // Note: implementation moved to static method to expose the this pointer.
   878 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) {
   878 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) {
   905   if (InstanceKlass::cast(k)->is_interface()) return;
   905   if (InstanceKlass::cast(k)->is_interface()) return;
   906 
   906 
   907   // Filter out subclasses whose supers already implement me.
   907   // Filter out subclasses whose supers already implement me.
   908   // (Note: CHA must walk subclasses of direct implementors
   908   // (Note: CHA must walk subclasses of direct implementors
   909   // in order to locate indirect implementors.)
   909   // in order to locate indirect implementors.)
   910   Klass* sk = InstanceKlass::cast(k)->super();
   910   Klass* sk = k->super();
   911   if (sk != NULL && InstanceKlass::cast(sk)->implements_interface(this))
   911   if (sk != NULL && InstanceKlass::cast(sk)->implements_interface(this))
   912     // We only need to check one immediate superclass, since the
   912     // We only need to check one immediate superclass, since the
   913     // implements_interface query looks at transitive_interfaces.
   913     // implements_interface query looks at transitive_interfaces.
   914     // Any supers of the super have the same (or fewer) transitive_interfaces.
   914     // Any supers of the super have the same (or fewer) transitive_interfaces.
   915     return;
   915     return;
   953     return Klass::can_be_primary_super_slow();
   953     return Klass::can_be_primary_super_slow();
   954 }
   954 }
   955 
   955 
   956 GrowableArray<Klass*>* InstanceKlass::compute_secondary_supers(int num_extra_slots) {
   956 GrowableArray<Klass*>* InstanceKlass::compute_secondary_supers(int num_extra_slots) {
   957   // The secondaries are the implemented interfaces.
   957   // The secondaries are the implemented interfaces.
   958   InstanceKlass* ik = InstanceKlass::cast(this);
   958   Array<Klass*>* interfaces = transitive_interfaces();
   959   Array<Klass*>* interfaces = ik->transitive_interfaces();
       
   960   int num_secondaries = num_extra_slots + interfaces->length();
   959   int num_secondaries = num_extra_slots + interfaces->length();
   961   if (num_secondaries == 0) {
   960   if (num_secondaries == 0) {
   962     // Must share this for correct bootstrapping!
   961     // Must share this for correct bootstrapping!
   963     set_secondary_supers(Universe::the_empty_klass_array());
   962     set_secondary_supers(Universe::the_empty_klass_array());
   964     return NULL;
   963     return NULL;
  1530   while (klass != NULL) {
  1529   while (klass != NULL) {
  1531     Method* method = InstanceKlass::cast(klass)->find_method_impl(name, signature, overpass_local_mode, find_static, find_private);
  1530     Method* method = InstanceKlass::cast(klass)->find_method_impl(name, signature, overpass_local_mode, find_static, find_private);
  1532     if (method != NULL) {
  1531     if (method != NULL) {
  1533       return method;
  1532       return method;
  1534     }
  1533     }
  1535     klass = InstanceKlass::cast(klass)->super();
  1534     klass = klass->super();
  1536     overpass_local_mode = skip_overpass;   // Always ignore overpass methods in superclasses
  1535     overpass_local_mode = skip_overpass;   // Always ignore overpass methods in superclasses
  1537   }
  1536   }
  1538   return NULL;
  1537   return NULL;
  1539 }
  1538 }
  1540 
  1539 
  1541 #ifdef ASSERT
  1540 #ifdef ASSERT
  1542 // search through class hierarchy and return true if this class or
  1541 // search through class hierarchy and return true if this class or
  1543 // one of the superclasses was redefined
  1542 // one of the superclasses was redefined
  1544 bool InstanceKlass::has_redefined_this_or_super() const {
  1543 bool InstanceKlass::has_redefined_this_or_super() {
  1545   const InstanceKlass* klass = this;
  1544   Klass* klass = this;
  1546   while (klass != NULL) {
  1545   while (klass != NULL) {
  1547     if (klass->has_been_redefined()) {
  1546     if (InstanceKlass::cast(klass)->has_been_redefined()) {
  1548       return true;
  1547       return true;
  1549     }
  1548     }
  1550     klass = InstanceKlass::cast(klass->super());
  1549     klass = klass->super();
  1551   }
  1550   }
  1552   return false;
  1551   return false;
  1553 }
  1552 }
  1554 #endif
  1553 #endif
  1555 
  1554 
  2323   return dest;
  2322   return dest;
  2324 }
  2323 }
  2325 
  2324 
  2326 // different verisons of is_same_class_package
  2325 // different verisons of is_same_class_package
  2327 bool InstanceKlass::is_same_class_package(Klass* class2) {
  2326 bool InstanceKlass::is_same_class_package(Klass* class2) {
  2328   Klass* class1 = this;
       
  2329   oop classloader1 = InstanceKlass::cast(class1)->class_loader();
       
  2330   Symbol* classname1 = class1->name();
       
  2331 
       
  2332   if (class2->oop_is_objArray()) {
  2327   if (class2->oop_is_objArray()) {
  2333     class2 = ObjArrayKlass::cast(class2)->bottom_klass();
  2328     class2 = ObjArrayKlass::cast(class2)->bottom_klass();
  2334   }
  2329   }
  2335   oop classloader2;
  2330   oop classloader2 = class2->class_loader();
  2336   if (class2->oop_is_instance()) {
       
  2337     classloader2 = InstanceKlass::cast(class2)->class_loader();
       
  2338   } else {
       
  2339     assert(class2->oop_is_typeArray(), "should be type array");
       
  2340     classloader2 = NULL;
       
  2341   }
       
  2342   Symbol* classname2 = class2->name();
  2331   Symbol* classname2 = class2->name();
  2343 
  2332 
  2344   return InstanceKlass::is_same_class_package(classloader1, classname1,
  2333   return InstanceKlass::is_same_class_package(class_loader(), name(),
  2345                                               classloader2, classname2);
  2334                                               classloader2, classname2);
  2346 }
  2335 }
  2347 
  2336 
  2348 bool InstanceKlass::is_same_class_package(oop classloader2, Symbol* classname2) {
  2337 bool InstanceKlass::is_same_class_package(oop classloader2, Symbol* classname2) {
  2349   Klass* class1 = this;
  2338   return InstanceKlass::is_same_class_package(class_loader(), name(),
  2350   oop classloader1 = InstanceKlass::cast(class1)->class_loader();
       
  2351   Symbol* classname1 = class1->name();
       
  2352 
       
  2353   return InstanceKlass::is_same_class_package(classloader1, classname1,
       
  2354                                               classloader2, classname2);
  2339                                               classloader2, classname2);
  2355 }
  2340 }
  2356 
  2341 
  2357 // return true if two classes are in the same package, classloader
  2342 // return true if two classes are in the same package, classloader
  2358 // and classname information is enough to determine a class's package
  2343 // and classname information is enough to determine a class's package
  2908   st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
  2893   st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
  2909   FieldPrinter print_static_field(st);
  2894   FieldPrinter print_static_field(st);
  2910   ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
  2895   ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
  2911   st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
  2896   st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
  2912   FieldPrinter print_nonstatic_field(st);
  2897   FieldPrinter print_nonstatic_field(st);
  2913   ((InstanceKlass*)this)->do_nonstatic_fields(&print_nonstatic_field);
  2898   InstanceKlass* ik = const_cast<InstanceKlass*>(this);
       
  2899   ik->do_nonstatic_fields(&print_nonstatic_field);
  2914 
  2900 
  2915   st->print(BULLET"non-static oop maps: ");
  2901   st->print(BULLET"non-static oop maps: ");
  2916   OopMapBlock* map     = start_of_nonstatic_oop_maps();
  2902   OopMapBlock* map     = start_of_nonstatic_oop_maps();
  2917   OopMapBlock* end_map = map + nonstatic_oop_map_count();
  2903   OopMapBlock* end_map = map + nonstatic_oop_map_count();
  2918   while (map < end_map) {
  2904   while (map < end_map) {