< prev index next >

src/hotspot/share/oops/instanceKlass.cpp

Print this page


 422 }
 423 
 424 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
 425                                        Array<Method*>* methods) {
 426   if (methods != NULL && methods != Universe::the_empty_method_array() &&
 427       !methods->is_shared()) {
 428     for (int i = 0; i < methods->length(); i++) {
 429       Method* method = methods->at(i);
 430       if (method == NULL) continue;  // maybe null if error processing
 431       // Only want to delete methods that are not executing for RedefineClasses.
 432       // The previous version will point to them so they're not totally dangling
 433       assert (!method->on_stack(), "shouldn't be called with methods on stack");
 434       MetadataFactory::free_metadata(loader_data, method);
 435     }
 436     MetadataFactory::free_array<Method*>(loader_data, methods);
 437   }
 438 }
 439 
 440 void InstanceKlass::deallocate_interfaces(ClassLoaderData* loader_data,
 441                                           const Klass* super_klass,
 442                                           Array<Klass*>* local_interfaces,
 443                                           Array<Klass*>* transitive_interfaces) {
 444   // Only deallocate transitive interfaces if not empty, same as super class
 445   // or same as local interfaces.  See code in parseClassFile.
 446   Array<Klass*>* ti = transitive_interfaces;
 447   if (ti != Universe::the_empty_klass_array() && ti != local_interfaces) {
 448     // check that the interfaces don't come from super class
 449     Array<Klass*>* sti = (super_klass == NULL) ? NULL :
 450                     InstanceKlass::cast(super_klass)->transitive_interfaces();
 451     if (ti != sti && ti != NULL && !ti->is_shared()) {
 452       MetadataFactory::free_array<Klass*>(loader_data, ti);
 453     }
 454   }
 455 
 456   // local interfaces can be empty
 457   if (local_interfaces != Universe::the_empty_klass_array() &&
 458       local_interfaces != NULL && !local_interfaces->is_shared()) {
 459     MetadataFactory::free_array<Klass*>(loader_data, local_interfaces);
 460   }
 461 }
 462 
 463 // This function deallocates the metadata and C heap pointers that the
 464 // InstanceKlass points to.
 465 void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) {
 466 
 467   // Orphan the mirror first, CMS thinks it's still live.
 468   if (java_mirror() != NULL) {
 469     java_lang_Class::set_klass(java_mirror(), NULL);
 470   }
 471 
 472   // Also remove mirror from handles
 473   loader_data->remove_handle(_java_mirror);
 474 
 475   // Need to take this class off the class loader data list.
 476   loader_data->remove_class(this);
 477 
 478   // The array_klass for this class is created later, after error handling.
 479   // For class redefinition, we keep the original class so this scratch class


 500       default_methods() != Universe::the_empty_method_array() &&
 501       !default_methods()->is_shared()) {
 502     MetadataFactory::free_array<Method*>(loader_data, default_methods());
 503   }
 504   // Do NOT deallocate the default methods, they are owned by superinterfaces.
 505   set_default_methods(NULL);
 506 
 507   // default methods vtable indices can be empty
 508   if (default_vtable_indices() != NULL &&
 509       !default_vtable_indices()->is_shared()) {
 510     MetadataFactory::free_array<int>(loader_data, default_vtable_indices());
 511   }
 512   set_default_vtable_indices(NULL);
 513 
 514 
 515   // This array is in Klass, but remove it with the InstanceKlass since
 516   // this place would be the only caller and it can share memory with transitive
 517   // interfaces.
 518   if (secondary_supers() != NULL &&
 519       secondary_supers() != Universe::the_empty_klass_array() &&
 520       secondary_supers() != transitive_interfaces() &&
 521       !secondary_supers()->is_shared()) {
 522     MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
 523   }
 524   set_secondary_supers(NULL);
 525 
 526   deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
 527   set_transitive_interfaces(NULL);
 528   set_local_interfaces(NULL);
 529 
 530   if (fields() != NULL && !fields()->is_shared()) {
 531     MetadataFactory::free_array<jushort>(loader_data, fields());
 532   }
 533   set_fields(NULL, 0);
 534 
 535   // If a method from a redefined class is using this constant pool, don't
 536   // delete it, yet.  The new class's previous version will point to this.
 537   if (constants() != NULL) {
 538     assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
 539     if (!constants()->is_shared()) {
 540       MetadataFactory::free_metadata(loader_data, constants());


 738   // link super class before linking this class
 739   Klass* super_klass = super();
 740   if (super_klass != NULL) {
 741     if (super_klass->is_interface()) {  // check if super class is an interface
 742       ResourceMark rm(THREAD);
 743       Exceptions::fthrow(
 744         THREAD_AND_LOCATION,
 745         vmSymbols::java_lang_IncompatibleClassChangeError(),
 746         "class %s has interface %s as super class",
 747         external_name(),
 748         super_klass->external_name()
 749       );
 750       return false;
 751     }
 752 
 753     InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
 754     ik_super->link_class_impl(throw_verifyerror, CHECK_false);
 755   }
 756 
 757   // link all interfaces implemented by this class before linking this class
 758   Array<Klass*>* interfaces = local_interfaces();
 759   int num_interfaces = interfaces->length();
 760   for (int index = 0; index < num_interfaces; index++) {
 761     InstanceKlass* interk = InstanceKlass::cast(interfaces->at(index));
 762     interk->link_class_impl(throw_verifyerror, CHECK_false);
 763   }
 764 
 765   // in case the class is linked in the process of linking its superclasses
 766   if (is_linked()) {
 767     return true;
 768   }
 769 
 770   // trace only the link time for this klass that includes
 771   // the verification time
 772   PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
 773                              ClassLoader::perf_class_link_selftime(),
 774                              ClassLoader::perf_classes_linked(),
 775                              jt->get_thread_stat()->perf_recursion_counts_addr(),
 776                              jt->get_thread_stat()->perf_timers_addr(),
 777                              PerfClassTraceTime::CLASS_LINK);
 778 
 779   // verification & rewriting
 780   {
 781     HandleMark hm(THREAD);


 855   set_rewritten();
 856 }
 857 
 858 // Now relocate and link method entry points after class is rewritten.
 859 // This is outside is_rewritten flag. In case of an exception, it can be
 860 // executed more than once.
 861 void InstanceKlass::link_methods(TRAPS) {
 862   int len = methods()->length();
 863   for (int i = len-1; i >= 0; i--) {
 864     methodHandle m(THREAD, methods()->at(i));
 865 
 866     // Set up method entry points for compiler and interpreter    .
 867     m->link_method(m, CHECK);
 868   }
 869 }
 870 
 871 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access)
 872 void InstanceKlass::initialize_super_interfaces(TRAPS) {
 873   assert (has_nonstatic_concrete_methods(), "caller should have checked this");
 874   for (int i = 0; i < local_interfaces()->length(); ++i) {
 875     Klass* iface = local_interfaces()->at(i);
 876     InstanceKlass* ik = InstanceKlass::cast(iface);
 877 
 878     // Initialization is depth first search ie. we start with top of the inheritance tree
 879     // has_nonstatic_concrete_methods drives searching superinterfaces since it
 880     // means has_nonstatic_concrete_methods in its superinterface hierarchy
 881     if (ik->has_nonstatic_concrete_methods()) {
 882       ik->initialize_super_interfaces(CHECK);
 883     }
 884 
 885     // Only initialize() interfaces that "declare" concrete methods.
 886     if (ik->should_be_initialized() && ik->declares_nonstatic_concrete_methods()) {
 887       ik->initialize(CHECK);
 888     }
 889   }
 890 }
 891 
 892 void InstanceKlass::initialize_impl(TRAPS) {
 893   HandleMark hm(THREAD);
 894 
 895   // Make sure klass is linked (verified) before initialization
 896   // A class could already be verified, since it has been reflected upon.


1100 
1101 
1102 void InstanceKlass::process_interfaces(Thread *thread) {
1103   // link this class into the implementors list of every interface it implements
1104   for (int i = local_interfaces()->length() - 1; i >= 0; i--) {
1105     assert(local_interfaces()->at(i)->is_klass(), "must be a klass");
1106     InstanceKlass* interf = InstanceKlass::cast(local_interfaces()->at(i));
1107     assert(interf->is_interface(), "expected interface");
1108     interf->add_implementor(this);
1109   }
1110 }
1111 
1112 bool InstanceKlass::can_be_primary_super_slow() const {
1113   if (is_interface())
1114     return false;
1115   else
1116     return Klass::can_be_primary_super_slow();
1117 }
1118 
1119 GrowableArray<Klass*>* InstanceKlass::compute_secondary_supers(int num_extra_slots,
1120                                                                Array<Klass*>* transitive_interfaces) {
1121   // The secondaries are the implemented interfaces.
1122   Array<Klass*>* interfaces = transitive_interfaces;
1123   int num_secondaries = num_extra_slots + interfaces->length();
1124   if (num_secondaries == 0) {
1125     // Must share this for correct bootstrapping!
1126     set_secondary_supers(Universe::the_empty_klass_array());
1127     return NULL;
1128   } else if (num_extra_slots == 0) {
1129     // The secondary super list is exactly the same as the transitive interfaces.

1130     // Redefine classes has to be careful not to delete this!
1131     set_secondary_supers(interfaces);
1132     return NULL;
1133   } else {
1134     // Copy transitive interfaces to a temporary growable array to be constructed
1135     // into the secondary super list with extra slots.
1136     GrowableArray<Klass*>* secondaries = new GrowableArray<Klass*>(interfaces->length());
1137     for (int i = 0; i < interfaces->length(); i++) {
1138       secondaries->push(interfaces->at(i));
1139     }
1140     return secondaries;
1141   }
1142 }
1143 
1144 bool InstanceKlass::compute_is_subtype_of(Klass* k) {
1145   if (k->is_interface()) {
1146     return implements_interface(k);
1147   } else {
1148     return Klass::compute_is_subtype_of(k);
1149   }
1150 }
1151 


1774 // Do NOT return private or static methods
1775 Method* InstanceKlass::lookup_method_in_ordered_interfaces(Symbol* name,
1776                                                          Symbol* signature) const {
1777   Method* m = NULL;
1778   if (default_methods() != NULL) {
1779     m = find_method(default_methods(), name, signature);
1780   }
1781   // Look up interfaces
1782   if (m == NULL) {
1783     m = lookup_method_in_all_interfaces(name, signature, find_defaults);
1784   }
1785   return m;
1786 }
1787 
1788 // lookup a method in all the interfaces that this class implements
1789 // Do NOT return private or static methods, new in JDK8 which are not externally visible
1790 // They should only be found in the initial InterfaceMethodRef
1791 Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name,
1792                                                        Symbol* signature,
1793                                                        DefaultsLookupMode defaults_mode) const {
1794   Array<Klass*>* all_ifs = transitive_interfaces();
1795   int num_ifs = all_ifs->length();
1796   InstanceKlass *ik = NULL;
1797   for (int i = 0; i < num_ifs; i++) {
1798     ik = InstanceKlass::cast(all_ifs->at(i));
1799     Method* m = ik->lookup_method(name, signature);
1800     if (m != NULL && m->is_public() && !m->is_static() &&
1801         ((defaults_mode != skip_defaults) || !m->is_default_method())) {
1802       return m;
1803     }
1804   }
1805   return NULL;
1806 }
1807 
1808 /* jni_id_for_impl for jfieldIds only */
1809 JNIid* InstanceKlass::jni_id_for_impl(int offset) {
1810   MutexLocker ml(JfieldIdCreation_lock);
1811   // Retry lookup after we got the lock
1812   JNIid* probe = jni_ids() == NULL ? NULL : jni_ids()->find(offset);
1813   if (probe == NULL) {
1814     // Slow case, allocate new static field identifier
1815     probe = new JNIid(this, offset, jni_ids());
1816     set_jni_ids(probe);
1817   }
1818   return probe;


2125     }
2126   }
2127 }
2128 
2129 void InstanceKlass::clean_method_data() {
2130   for (int m = 0; m < methods()->length(); m++) {
2131     MethodData* mdo = methods()->at(m)->method_data();
2132     if (mdo != NULL) {
2133       mdo->clean_method_data(/*always_clean*/false);
2134     }
2135   }
2136 }
2137 
2138 bool InstanceKlass::supers_have_passed_fingerprint_checks() {
2139   if (java_super() != NULL && !java_super()->has_passed_fingerprint_check()) {
2140     ResourceMark rm;
2141     log_trace(class, fingerprint)("%s : super %s not fingerprinted", external_name(), java_super()->external_name());
2142     return false;
2143   }
2144 
2145   Array<Klass*>* local_interfaces = this->local_interfaces();
2146   if (local_interfaces != NULL) {
2147     int length = local_interfaces->length();
2148     for (int i = 0; i < length; i++) {
2149       InstanceKlass* intf = InstanceKlass::cast(local_interfaces->at(i));
2150       if (!intf->has_passed_fingerprint_check()) {
2151         ResourceMark rm;
2152         log_trace(class, fingerprint)("%s : interface %s not fingerprinted", external_name(), intf->external_name());
2153         return false;
2154       }
2155     }
2156   }
2157 
2158   return true;
2159 }
2160 
2161 bool InstanceKlass::should_store_fingerprint(bool is_anonymous) {
2162 #if INCLUDE_AOT
2163   // We store the fingerprint into the InstanceKlass only in the following 2 cases:
2164   if (CalculateClassFingerprint) {
2165     // (1) We are running AOT to generate a shared library.
2166     return true;
2167   }
2168   if (DumpSharedSpaces) {
2169     // (2) We are running -Xshare:dump to create a shared archive


2336     // Array classes have null protection domain.
2337     // --> see ArrayKlass::complete_create_array_klass()
2338     array_klasses()->restore_unshareable_info(ClassLoaderData::the_null_class_loader_data(), Handle(), CHECK);
2339   }
2340 }
2341 
2342 // returns true IFF is_in_error_state() has been changed as a result of this call.
2343 bool InstanceKlass::check_sharing_error_state() {
2344   assert(DumpSharedSpaces, "should only be called during dumping");
2345   bool old_state = is_in_error_state();
2346 
2347   if (!is_in_error_state()) {
2348     bool bad = false;
2349     for (InstanceKlass* sup = java_super(); sup; sup = sup->java_super()) {
2350       if (sup->is_in_error_state()) {
2351         bad = true;
2352         break;
2353       }
2354     }
2355     if (!bad) {
2356       Array<Klass*>* interfaces = transitive_interfaces();
2357       for (int i = 0; i < interfaces->length(); i++) {
2358         Klass* iface = interfaces->at(i);
2359         if (InstanceKlass::cast(iface)->is_in_error_state()) {
2360           bad = true;
2361           break;
2362         }
2363       }
2364     }
2365 
2366     if (bad) {
2367       set_in_error_state();
2368     }
2369   }
2370 
2371   return (old_state != is_in_error_state());
2372 }
2373 
2374 #if INCLUDE_JVMTI
2375 static void clear_all_breakpoints(Method* m) {
2376   m->clear_all_breakpoints();
2377 }
2378 #endif
2379 


3237     st->print(BULLET"fake entry for mirror: ");
3238     Metadata::print_value_on_maybe_null(st, mirrored_klass);
3239     st->cr();
3240     Klass* array_klass = java_lang_Class::array_klass_acquire(obj);
3241     st->print(BULLET"fake entry for array: ");
3242     Metadata::print_value_on_maybe_null(st, array_klass);
3243     st->cr();
3244     st->print_cr(BULLET"fake entry for oop_size: %d", java_lang_Class::oop_size(obj));
3245     st->print_cr(BULLET"fake entry for static_oop_field_count: %d", java_lang_Class::static_oop_field_count(obj));
3246     Klass* real_klass = java_lang_Class::as_Klass(obj);
3247     if (real_klass != NULL && real_klass->is_instance_klass()) {
3248       InstanceKlass::cast(real_klass)->do_local_static_fields(&print_field);
3249     }
3250   } else if (this == SystemDictionary::MethodType_klass()) {
3251     st->print(BULLET"signature: ");
3252     java_lang_invoke_MethodType::print_signature(obj, st);
3253     st->cr();
3254   }
3255 }
3256 






3257 #endif //PRODUCT
3258 
3259 void InstanceKlass::oop_print_value_on(oop obj, outputStream* st) {
3260   st->print("a ");
3261   name()->print_value_on(st);
3262   obj->print_address_on(st);
3263   if (this == SystemDictionary::String_klass()
3264       && java_lang_String::value(obj) != NULL) {
3265     ResourceMark rm;
3266     int len = java_lang_String::length(obj);
3267     int plen = (len < 24 ? len : 12);
3268     char* str = java_lang_String::as_utf8_string(obj, 0, plen);
3269     st->print(" = \"%s\"", str);
3270     if (len > plen)
3271       st->print("...[%d]", len);
3272   } else if (this == SystemDictionary::Class_klass()) {
3273     Klass* k = java_lang_Class::as_Klass(obj);
3274     st->print(" = ");
3275     if (k != NULL) {
3276       k->print_value_on(st);


3481   if (sib != NULL) {
3482     if (sib == this) {
3483       fatal("subclass points to itself " PTR_FORMAT, p2i(sib));
3484     }
3485 
3486     guarantee(sib->is_klass(), "should be klass");
3487     guarantee(sib->super() == super, "siblings should have same superklass");
3488   }
3489 
3490   // Verify implementor fields
3491   Klass* im = implementor();
3492   if (im != NULL) {
3493     guarantee(is_interface(), "only interfaces should have implementor set");
3494     guarantee(im->is_klass(), "should be klass");
3495     guarantee(!im->is_interface() || im == this,
3496       "implementors cannot be interfaces");
3497   }
3498 
3499   // Verify local interfaces
3500   if (local_interfaces()) {
3501     Array<Klass*>* local_interfaces = this->local_interfaces();
3502     for (int j = 0; j < local_interfaces->length(); j++) {
3503       Klass* e = local_interfaces->at(j);
3504       guarantee(e->is_klass() && e->is_interface(), "invalid local interface");
3505     }
3506   }
3507 
3508   // Verify transitive interfaces
3509   if (transitive_interfaces() != NULL) {
3510     Array<Klass*>* transitive_interfaces = this->transitive_interfaces();
3511     for (int j = 0; j < transitive_interfaces->length(); j++) {
3512       Klass* e = transitive_interfaces->at(j);
3513       guarantee(e->is_klass() && e->is_interface(), "invalid transitive interface");
3514     }
3515   }
3516 
3517   // Verify methods
3518   if (methods() != NULL) {
3519     Array<Method*>* methods = this->methods();
3520     for (int j = 0; j < methods->length(); j++) {
3521       guarantee(methods->at(j)->is_method(), "non-method in methods array");
3522     }
3523     for (int j = 0; j < methods->length() - 1; j++) {
3524       Method* m1 = methods->at(j);
3525       Method* m2 = methods->at(j + 1);
3526       guarantee(m1->name()->fast_compare(m2->name()) <= 0, "methods not sorted correctly");
3527     }
3528   }
3529 
3530   // Verify method ordering
3531   if (method_ordering() != NULL) {
3532     Array<int>* method_ordering = this->method_ordering();




 422 }
 423 
 424 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
 425                                        Array<Method*>* methods) {
 426   if (methods != NULL && methods != Universe::the_empty_method_array() &&
 427       !methods->is_shared()) {
 428     for (int i = 0; i < methods->length(); i++) {
 429       Method* method = methods->at(i);
 430       if (method == NULL) continue;  // maybe null if error processing
 431       // Only want to delete methods that are not executing for RedefineClasses.
 432       // The previous version will point to them so they're not totally dangling
 433       assert (!method->on_stack(), "shouldn't be called with methods on stack");
 434       MetadataFactory::free_metadata(loader_data, method);
 435     }
 436     MetadataFactory::free_array<Method*>(loader_data, methods);
 437   }
 438 }
 439 
 440 void InstanceKlass::deallocate_interfaces(ClassLoaderData* loader_data,
 441                                           const Klass* super_klass,
 442                                           Array<InstanceKlass*>* local_interfaces,
 443                                           Array<InstanceKlass*>* transitive_interfaces) {
 444   // Only deallocate transitive interfaces if not empty, same as super class
 445   // or same as local interfaces.  See code in parseClassFile.
 446   Array<InstanceKlass*>* ti = transitive_interfaces;
 447   if (ti != Universe::the_empty_instance_klass_array() && ti != local_interfaces) {
 448     // check that the interfaces don't come from super class
 449     Array<InstanceKlass*>* sti = (super_klass == NULL) ? NULL :
 450                     InstanceKlass::cast(super_klass)->transitive_interfaces();
 451     if (ti != sti && ti != NULL && !ti->is_shared()) {
 452       MetadataFactory::free_array<InstanceKlass*>(loader_data, ti);
 453     }
 454   }
 455 
 456   // local interfaces can be empty
 457   if (local_interfaces != Universe::the_empty_instance_klass_array() &&
 458       local_interfaces != NULL && !local_interfaces->is_shared()) {
 459     MetadataFactory::free_array<InstanceKlass*>(loader_data, local_interfaces);
 460   }
 461 }
 462 
 463 // This function deallocates the metadata and C heap pointers that the
 464 // InstanceKlass points to.
 465 void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) {
 466 
 467   // Orphan the mirror first, CMS thinks it's still live.
 468   if (java_mirror() != NULL) {
 469     java_lang_Class::set_klass(java_mirror(), NULL);
 470   }
 471 
 472   // Also remove mirror from handles
 473   loader_data->remove_handle(_java_mirror);
 474 
 475   // Need to take this class off the class loader data list.
 476   loader_data->remove_class(this);
 477 
 478   // The array_klass for this class is created later, after error handling.
 479   // For class redefinition, we keep the original class so this scratch class


 500       default_methods() != Universe::the_empty_method_array() &&
 501       !default_methods()->is_shared()) {
 502     MetadataFactory::free_array<Method*>(loader_data, default_methods());
 503   }
 504   // Do NOT deallocate the default methods, they are owned by superinterfaces.
 505   set_default_methods(NULL);
 506 
 507   // default methods vtable indices can be empty
 508   if (default_vtable_indices() != NULL &&
 509       !default_vtable_indices()->is_shared()) {
 510     MetadataFactory::free_array<int>(loader_data, default_vtable_indices());
 511   }
 512   set_default_vtable_indices(NULL);
 513 
 514 
 515   // This array is in Klass, but remove it with the InstanceKlass since
 516   // this place would be the only caller and it can share memory with transitive
 517   // interfaces.
 518   if (secondary_supers() != NULL &&
 519       secondary_supers() != Universe::the_empty_klass_array() &&
 520       (address)(secondary_supers()) != (address)(transitive_interfaces()) &&
 521       !secondary_supers()->is_shared()) {
 522     MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
 523   }
 524   set_secondary_supers(NULL);
 525 
 526   deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
 527   set_transitive_interfaces(NULL);
 528   set_local_interfaces(NULL);
 529 
 530   if (fields() != NULL && !fields()->is_shared()) {
 531     MetadataFactory::free_array<jushort>(loader_data, fields());
 532   }
 533   set_fields(NULL, 0);
 534 
 535   // If a method from a redefined class is using this constant pool, don't
 536   // delete it, yet.  The new class's previous version will point to this.
 537   if (constants() != NULL) {
 538     assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
 539     if (!constants()->is_shared()) {
 540       MetadataFactory::free_metadata(loader_data, constants());


 738   // link super class before linking this class
 739   Klass* super_klass = super();
 740   if (super_klass != NULL) {
 741     if (super_klass->is_interface()) {  // check if super class is an interface
 742       ResourceMark rm(THREAD);
 743       Exceptions::fthrow(
 744         THREAD_AND_LOCATION,
 745         vmSymbols::java_lang_IncompatibleClassChangeError(),
 746         "class %s has interface %s as super class",
 747         external_name(),
 748         super_klass->external_name()
 749       );
 750       return false;
 751     }
 752 
 753     InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
 754     ik_super->link_class_impl(throw_verifyerror, CHECK_false);
 755   }
 756 
 757   // link all interfaces implemented by this class before linking this class
 758   Array<InstanceKlass*>* interfaces = local_interfaces();
 759   int num_interfaces = interfaces->length();
 760   for (int index = 0; index < num_interfaces; index++) {
 761     InstanceKlass* interk = interfaces->at(index);
 762     interk->link_class_impl(throw_verifyerror, CHECK_false);
 763   }
 764 
 765   // in case the class is linked in the process of linking its superclasses
 766   if (is_linked()) {
 767     return true;
 768   }
 769 
 770   // trace only the link time for this klass that includes
 771   // the verification time
 772   PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
 773                              ClassLoader::perf_class_link_selftime(),
 774                              ClassLoader::perf_classes_linked(),
 775                              jt->get_thread_stat()->perf_recursion_counts_addr(),
 776                              jt->get_thread_stat()->perf_timers_addr(),
 777                              PerfClassTraceTime::CLASS_LINK);
 778 
 779   // verification & rewriting
 780   {
 781     HandleMark hm(THREAD);


 855   set_rewritten();
 856 }
 857 
 858 // Now relocate and link method entry points after class is rewritten.
 859 // This is outside is_rewritten flag. In case of an exception, it can be
 860 // executed more than once.
 861 void InstanceKlass::link_methods(TRAPS) {
 862   int len = methods()->length();
 863   for (int i = len-1; i >= 0; i--) {
 864     methodHandle m(THREAD, methods()->at(i));
 865 
 866     // Set up method entry points for compiler and interpreter    .
 867     m->link_method(m, CHECK);
 868   }
 869 }
 870 
 871 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access)
 872 void InstanceKlass::initialize_super_interfaces(TRAPS) {
 873   assert (has_nonstatic_concrete_methods(), "caller should have checked this");
 874   for (int i = 0; i < local_interfaces()->length(); ++i) {
 875     InstanceKlass* ik = local_interfaces()->at(i);

 876 
 877     // Initialization is depth first search ie. we start with top of the inheritance tree
 878     // has_nonstatic_concrete_methods drives searching superinterfaces since it
 879     // means has_nonstatic_concrete_methods in its superinterface hierarchy
 880     if (ik->has_nonstatic_concrete_methods()) {
 881       ik->initialize_super_interfaces(CHECK);
 882     }
 883 
 884     // Only initialize() interfaces that "declare" concrete methods.
 885     if (ik->should_be_initialized() && ik->declares_nonstatic_concrete_methods()) {
 886       ik->initialize(CHECK);
 887     }
 888   }
 889 }
 890 
 891 void InstanceKlass::initialize_impl(TRAPS) {
 892   HandleMark hm(THREAD);
 893 
 894   // Make sure klass is linked (verified) before initialization
 895   // A class could already be verified, since it has been reflected upon.


1099 
1100 
1101 void InstanceKlass::process_interfaces(Thread *thread) {
1102   // link this class into the implementors list of every interface it implements
1103   for (int i = local_interfaces()->length() - 1; i >= 0; i--) {
1104     assert(local_interfaces()->at(i)->is_klass(), "must be a klass");
1105     InstanceKlass* interf = InstanceKlass::cast(local_interfaces()->at(i));
1106     assert(interf->is_interface(), "expected interface");
1107     interf->add_implementor(this);
1108   }
1109 }
1110 
1111 bool InstanceKlass::can_be_primary_super_slow() const {
1112   if (is_interface())
1113     return false;
1114   else
1115     return Klass::can_be_primary_super_slow();
1116 }
1117 
1118 GrowableArray<Klass*>* InstanceKlass::compute_secondary_supers(int num_extra_slots,
1119                                                                Array<InstanceKlass*>* transitive_interfaces) {
1120   // The secondaries are the implemented interfaces.
1121   Array<InstanceKlass*>* interfaces = transitive_interfaces;
1122   int num_secondaries = num_extra_slots + interfaces->length();
1123   if (num_secondaries == 0) {
1124     // Must share this for correct bootstrapping!
1125     set_secondary_supers(Universe::the_empty_klass_array());
1126     return NULL;
1127   } else if (num_extra_slots == 0) {
1128     // The secondary super list is exactly the same as the transitive interfaces, so
1129     // let's use it instead of making a copy. Just don't write into it!
1130     // Redefine classes has to be careful not to delete this!
1131     set_secondary_supers((Array<Klass*>*)(address)interfaces);
1132     return NULL;
1133   } else {
1134     // Copy transitive interfaces to a temporary growable array to be constructed
1135     // into the secondary super list with extra slots.
1136     GrowableArray<Klass*>* secondaries = new GrowableArray<Klass*>(interfaces->length());
1137     for (int i = 0; i < interfaces->length(); i++) {
1138       secondaries->push(interfaces->at(i));
1139     }
1140     return secondaries;
1141   }
1142 }
1143 
1144 bool InstanceKlass::compute_is_subtype_of(Klass* k) {
1145   if (k->is_interface()) {
1146     return implements_interface(k);
1147   } else {
1148     return Klass::compute_is_subtype_of(k);
1149   }
1150 }
1151 


1774 // Do NOT return private or static methods
1775 Method* InstanceKlass::lookup_method_in_ordered_interfaces(Symbol* name,
1776                                                          Symbol* signature) const {
1777   Method* m = NULL;
1778   if (default_methods() != NULL) {
1779     m = find_method(default_methods(), name, signature);
1780   }
1781   // Look up interfaces
1782   if (m == NULL) {
1783     m = lookup_method_in_all_interfaces(name, signature, find_defaults);
1784   }
1785   return m;
1786 }
1787 
1788 // lookup a method in all the interfaces that this class implements
1789 // Do NOT return private or static methods, new in JDK8 which are not externally visible
1790 // They should only be found in the initial InterfaceMethodRef
1791 Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name,
1792                                                        Symbol* signature,
1793                                                        DefaultsLookupMode defaults_mode) const {
1794   Array<InstanceKlass*>* all_ifs = transitive_interfaces();
1795   int num_ifs = all_ifs->length();
1796   InstanceKlass *ik = NULL;
1797   for (int i = 0; i < num_ifs; i++) {
1798     ik = all_ifs->at(i);
1799     Method* m = ik->lookup_method(name, signature);
1800     if (m != NULL && m->is_public() && !m->is_static() &&
1801         ((defaults_mode != skip_defaults) || !m->is_default_method())) {
1802       return m;
1803     }
1804   }
1805   return NULL;
1806 }
1807 
1808 /* jni_id_for_impl for jfieldIds only */
1809 JNIid* InstanceKlass::jni_id_for_impl(int offset) {
1810   MutexLocker ml(JfieldIdCreation_lock);
1811   // Retry lookup after we got the lock
1812   JNIid* probe = jni_ids() == NULL ? NULL : jni_ids()->find(offset);
1813   if (probe == NULL) {
1814     // Slow case, allocate new static field identifier
1815     probe = new JNIid(this, offset, jni_ids());
1816     set_jni_ids(probe);
1817   }
1818   return probe;


2125     }
2126   }
2127 }
2128 
2129 void InstanceKlass::clean_method_data() {
2130   for (int m = 0; m < methods()->length(); m++) {
2131     MethodData* mdo = methods()->at(m)->method_data();
2132     if (mdo != NULL) {
2133       mdo->clean_method_data(/*always_clean*/false);
2134     }
2135   }
2136 }
2137 
2138 bool InstanceKlass::supers_have_passed_fingerprint_checks() {
2139   if (java_super() != NULL && !java_super()->has_passed_fingerprint_check()) {
2140     ResourceMark rm;
2141     log_trace(class, fingerprint)("%s : super %s not fingerprinted", external_name(), java_super()->external_name());
2142     return false;
2143   }
2144 
2145   Array<InstanceKlass*>* local_interfaces = this->local_interfaces();
2146   if (local_interfaces != NULL) {
2147     int length = local_interfaces->length();
2148     for (int i = 0; i < length; i++) {
2149       InstanceKlass* intf = local_interfaces->at(i);
2150       if (!intf->has_passed_fingerprint_check()) {
2151         ResourceMark rm;
2152         log_trace(class, fingerprint)("%s : interface %s not fingerprinted", external_name(), intf->external_name());
2153         return false;
2154       }
2155     }
2156   }
2157 
2158   return true;
2159 }
2160 
2161 bool InstanceKlass::should_store_fingerprint(bool is_anonymous) {
2162 #if INCLUDE_AOT
2163   // We store the fingerprint into the InstanceKlass only in the following 2 cases:
2164   if (CalculateClassFingerprint) {
2165     // (1) We are running AOT to generate a shared library.
2166     return true;
2167   }
2168   if (DumpSharedSpaces) {
2169     // (2) We are running -Xshare:dump to create a shared archive


2336     // Array classes have null protection domain.
2337     // --> see ArrayKlass::complete_create_array_klass()
2338     array_klasses()->restore_unshareable_info(ClassLoaderData::the_null_class_loader_data(), Handle(), CHECK);
2339   }
2340 }
2341 
2342 // returns true IFF is_in_error_state() has been changed as a result of this call.
2343 bool InstanceKlass::check_sharing_error_state() {
2344   assert(DumpSharedSpaces, "should only be called during dumping");
2345   bool old_state = is_in_error_state();
2346 
2347   if (!is_in_error_state()) {
2348     bool bad = false;
2349     for (InstanceKlass* sup = java_super(); sup; sup = sup->java_super()) {
2350       if (sup->is_in_error_state()) {
2351         bad = true;
2352         break;
2353       }
2354     }
2355     if (!bad) {
2356       Array<InstanceKlass*>* interfaces = transitive_interfaces();
2357       for (int i = 0; i < interfaces->length(); i++) {
2358         InstanceKlass* iface = interfaces->at(i);
2359         if (iface->is_in_error_state()) {
2360           bad = true;
2361           break;
2362         }
2363       }
2364     }
2365 
2366     if (bad) {
2367       set_in_error_state();
2368     }
2369   }
2370 
2371   return (old_state != is_in_error_state());
2372 }
2373 
2374 #if INCLUDE_JVMTI
2375 static void clear_all_breakpoints(Method* m) {
2376   m->clear_all_breakpoints();
2377 }
2378 #endif
2379 


3237     st->print(BULLET"fake entry for mirror: ");
3238     Metadata::print_value_on_maybe_null(st, mirrored_klass);
3239     st->cr();
3240     Klass* array_klass = java_lang_Class::array_klass_acquire(obj);
3241     st->print(BULLET"fake entry for array: ");
3242     Metadata::print_value_on_maybe_null(st, array_klass);
3243     st->cr();
3244     st->print_cr(BULLET"fake entry for oop_size: %d", java_lang_Class::oop_size(obj));
3245     st->print_cr(BULLET"fake entry for static_oop_field_count: %d", java_lang_Class::static_oop_field_count(obj));
3246     Klass* real_klass = java_lang_Class::as_Klass(obj);
3247     if (real_klass != NULL && real_klass->is_instance_klass()) {
3248       InstanceKlass::cast(real_klass)->do_local_static_fields(&print_field);
3249     }
3250   } else if (this == SystemDictionary::MethodType_klass()) {
3251     st->print(BULLET"signature: ");
3252     java_lang_invoke_MethodType::print_signature(obj, st);
3253     st->cr();
3254   }
3255 }
3256 
3257 bool InstanceKlass::verify_itable_index(int i) {
3258   int method_count = klassItable::method_count_for_interface(this);
3259   assert(i >= 0 && i < method_count, "index out of bounds");
3260   return true;
3261 }
3262 
3263 #endif //PRODUCT
3264 
3265 void InstanceKlass::oop_print_value_on(oop obj, outputStream* st) {
3266   st->print("a ");
3267   name()->print_value_on(st);
3268   obj->print_address_on(st);
3269   if (this == SystemDictionary::String_klass()
3270       && java_lang_String::value(obj) != NULL) {
3271     ResourceMark rm;
3272     int len = java_lang_String::length(obj);
3273     int plen = (len < 24 ? len : 12);
3274     char* str = java_lang_String::as_utf8_string(obj, 0, plen);
3275     st->print(" = \"%s\"", str);
3276     if (len > plen)
3277       st->print("...[%d]", len);
3278   } else if (this == SystemDictionary::Class_klass()) {
3279     Klass* k = java_lang_Class::as_Klass(obj);
3280     st->print(" = ");
3281     if (k != NULL) {
3282       k->print_value_on(st);


3487   if (sib != NULL) {
3488     if (sib == this) {
3489       fatal("subclass points to itself " PTR_FORMAT, p2i(sib));
3490     }
3491 
3492     guarantee(sib->is_klass(), "should be klass");
3493     guarantee(sib->super() == super, "siblings should have same superklass");
3494   }
3495 
3496   // Verify implementor fields
3497   Klass* im = implementor();
3498   if (im != NULL) {
3499     guarantee(is_interface(), "only interfaces should have implementor set");
3500     guarantee(im->is_klass(), "should be klass");
3501     guarantee(!im->is_interface() || im == this,
3502       "implementors cannot be interfaces");
3503   }
3504 
3505   // Verify local interfaces
3506   if (local_interfaces()) {
3507     Array<InstanceKlass*>* local_interfaces = this->local_interfaces();
3508     for (int j = 0; j < local_interfaces->length(); j++) {
3509       InstanceKlass* e = local_interfaces->at(j);
3510       guarantee(e->is_klass() && e->is_interface(), "invalid local interface");
3511     }
3512   }
3513 
3514   // Verify transitive interfaces
3515   if (transitive_interfaces() != NULL) {
3516     Array<InstanceKlass*>* transitive_interfaces = this->transitive_interfaces();
3517     for (int j = 0; j < transitive_interfaces->length(); j++) {
3518       InstanceKlass* e = transitive_interfaces->at(j);
3519       guarantee(e->is_klass() && e->is_interface(), "invalid transitive interface");
3520     }
3521   }
3522 
3523   // Verify methods
3524   if (methods() != NULL) {
3525     Array<Method*>* methods = this->methods();
3526     for (int j = 0; j < methods->length(); j++) {
3527       guarantee(methods->at(j)->is_method(), "non-method in methods array");
3528     }
3529     for (int j = 0; j < methods->length() - 1; j++) {
3530       Method* m1 = methods->at(j);
3531       Method* m2 = methods->at(j + 1);
3532       guarantee(m1->name()->fast_compare(m2->name()) <= 0, "methods not sorted correctly");
3533     }
3534   }
3535 
3536   // Verify method ordering
3537   if (method_ordering() != NULL) {
3538     Array<int>* method_ordering = this->method_ordering();


< prev index next >