< prev index next >

src/hotspot/share/oops/instanceKlass.cpp

Print this page




 386   // If a method from a redefined class is using this constant pool, don't
 387   // delete it, yet.  The new class's previous version will point to this.
 388   if (constants() != NULL) {
 389     assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
 390     if (!constants()->is_shared()) {
 391       MetadataFactory::free_metadata(loader_data, constants());
 392     }
 393     // Delete any cached resolution errors for the constant pool
 394     SystemDictionary::delete_resolution_error(constants());
 395 
 396     set_constants(NULL);
 397   }
 398 
 399   if (inner_classes() != NULL &&
 400       inner_classes() != Universe::the_empty_short_array() &&
 401       !inner_classes()->is_shared()) {
 402     MetadataFactory::free_array<jushort>(loader_data, inner_classes());
 403   }
 404   set_inner_classes(NULL);
 405 





 406   // We should deallocate the Annotations instance if it's not in shared spaces.
 407   if (annotations() != NULL && !annotations()->is_shared()) {
 408     MetadataFactory::free_metadata(loader_data, annotations());
 409   }
 410   set_annotations(NULL);
 411 }
 412 
 413 bool InstanceKlass::should_be_initialized() const {
 414   return !is_initialized();
 415 }
 416 
 417 klassItable InstanceKlass::itable() const {
 418   return klassItable(const_cast<InstanceKlass*>(this));
 419 }
 420 
 421 void InstanceKlass::eager_initialize(Thread *thread) {
 422   if (!EagerInitialization) return;
 423 
 424   if (this->is_not_initialized()) {
 425     // abort if the the class has a class initializer


 589         vmSymbols::java_lang_IncompatibleClassChangeError(),
 590         "class %s has interface %s as super class",
 591         external_name(),
 592         super_klass->external_name()
 593       );
 594       return false;
 595     }
 596 
 597     InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
 598     ik_super->link_class_impl(throw_verifyerror, CHECK_false);
 599   }
 600 
 601   // link all interfaces implemented by this class before linking this class
 602   Array<Klass*>* interfaces = local_interfaces();
 603   int num_interfaces = interfaces->length();
 604   for (int index = 0; index < num_interfaces; index++) {
 605     InstanceKlass* interk = InstanceKlass::cast(interfaces->at(index));
 606     interk->link_class_impl(throw_verifyerror, CHECK_false);
 607   }
 608 
 609   // If a value type is referenced by a class (either as a field type or a
 610   // method argument or return type) this value type must be loaded during
 611   // the linking of this class because size and properties of the value type
 612   // must be known in order to be able to perform value type optimizations
 613 
 614   // Note: circular dependencies between value types are not handled yet
 615 
 616   // Note: one case is not handled yet: arrays of value types => FixMe
 617 
 618   // Note: the current implementation is not optimized because the search for
 619   // value types is performed on all classes. It would be more efficient to
 620   // detect value types during verification and 'tag' the classes for which
 621   // value type loading is required. However, this optimization won't be
 622   // applicable to classes that are not verified
 623 
 624   // First step: fields
 625   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {





















 626     ResourceMark rm(THREAD);
 627     if (fs.field_descriptor().access_flags().is_flattenable()) {
 628       Symbol* signature = fs.field_descriptor().signature();



 629       // Get current loader and protection domain first.
 630       oop loader = class_loader();
 631       oop prot_domain = protection_domain();
 632       Klass* klass = SystemDictionary::resolve_or_fail(signature,
 633           Handle(THREAD, loader), Handle(THREAD, prot_domain), true,
 634           THREAD);

 635       if (klass == NULL) {
 636         THROW_(vmSymbols::java_lang_LinkageError(), false);
 637       }





 638     }
 639   }
 640 
 641   // Second step: methods arguments and return types
 642   //  for (int i = 0; i < this_k->constants()->length(); i++) {
 643   //    if (this_k->constants()->tag_at(i).is_method()) {
 644   //      Symbol* signature = this_k->constants()->signature_ref_at(i);
 645   //      ResourceMark rm(THREAD);
 646   //      for (SignatureStream ss(signature); !ss.is_done(); ss.next()) {
 647   //        if (ss.type() == T_VALUETYPE) {
 648   //          Symbol* sig = ss.as_symbol(THREAD);
 649   //          // Get current loader and protection domain first.
 650   //          oop loader = this_k->class_loader();
 651   //          oop protection_domain = this_k->protection_domain();
 652   //
 653   //          bool ok = SystemDictionary::resolve_or_fail(sig,
 654   //              Handle(THREAD, loader), Handle(THREAD, protection_domain), true,
 655   //              THREAD);
 656   //          if (!ok) {
 657   //            THROW_(vmSymbols::java_lang_LinkageError(), false);
 658   //          }
 659   //        }
 660   //      }
 661   //    }
 662   //  }
 663 
 664   // in case the class is linked in the process of linking its superclasses
 665   if (is_linked()) {
 666     return true;
 667   }
 668 
 669   // trace only the link time for this klass that includes
 670   // the verification time
 671   PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
 672                              ClassLoader::perf_class_link_selftime(),
 673                              ClassLoader::perf_classes_linked(),
 674                              jt->get_thread_stat()->perf_recursion_counts_addr(),
 675                              jt->get_thread_stat()->perf_timers_addr(),
 676                              PerfClassTraceTime::CLASS_LINK);
 677 
 678   // verification & rewriting
 679   {
 680     HandleMark hm(THREAD);
 681     Handle h_init_lock(THREAD, init_lock());
 682     ObjectLocker ol(h_init_lock, THREAD, h_init_lock() != NULL);


2325 
2326 #if INCLUDE_JVMTI
2327   // Deallocate breakpoint records
2328   if (breakpoints() != 0x0) {
2329     methods_do(clear_all_breakpoints);
2330     assert(breakpoints() == 0x0, "should have cleared breakpoints");
2331   }
2332 
2333   // deallocate the cached class file
2334   if (_cached_class_file != NULL && !MetaspaceShared::is_in_shared_metaspace(_cached_class_file)) {
2335     os::free(_cached_class_file);
2336     _cached_class_file = NULL;
2337   }
2338 #endif
2339 
2340   // Decrement symbol reference counts associated with the unloaded class.
2341   if (_name != NULL) _name->decrement_refcount();
2342   // unreference array name derived from this class name (arrays of an unloaded
2343   // class can't be referenced anymore).
2344   if (_array_name != NULL)  _array_name->decrement_refcount();








2345   if (_source_debug_extension != NULL) FREE_C_HEAP_ARRAY(char, _source_debug_extension);
2346 }
2347 
2348 void InstanceKlass::set_source_debug_extension(const char* array, int length) {
2349   if (array == NULL) {
2350     _source_debug_extension = NULL;
2351   } else {
2352     // Adding one to the attribute length in order to store a null terminator
2353     // character could cause an overflow because the attribute length is
2354     // already coded with an u4 in the classfile, but in practice, it's
2355     // unlikely to happen.
2356     assert((length+1) > length, "Overflow checking");
2357     char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
2358     for (int i = 0; i < length; i++) {
2359       sde[i] = array[i];
2360     }
2361     sde[length] = '\0';
2362     _source_debug_extension = sde;
2363   }
2364 }


3202       st->print(" => ");
3203       vmentry->print_value_on(st);
3204     }
3205   } else if (this == SystemDictionary::MemberName_klass()) {
3206     Metadata* vmtarget = java_lang_invoke_MemberName::vmtarget(obj);
3207     if (vmtarget != NULL) {
3208       st->print(" = ");
3209       vmtarget->print_value_on(st);
3210     } else {
3211       java_lang_invoke_MemberName::clazz(obj)->print_value_on(st);
3212       st->print(".");
3213       java_lang_invoke_MemberName::name(obj)->print_value_on(st);
3214     }
3215   }
3216 }
3217 
3218 const char* InstanceKlass::internal_name() const {
3219   return external_name();
3220 }
3221 








































3222 void InstanceKlass::print_class_load_logging(ClassLoaderData* loader_data,
3223                                              const char* module_name,
3224                                              const ClassFileStream* cfs) const {
3225   if (!log_is_enabled(Info, class, load)) {
3226     return;
3227   }
3228 
3229   ResourceMark rm;
3230   LogMessage(class, load) msg;
3231   stringStream info_stream;
3232 
3233   // Name and class hierarchy info
3234   info_stream.print("%s", external_name());
3235 
3236   // Source
3237   if (cfs != NULL) {
3238     if (cfs->source() != NULL) {
3239       if (module_name != NULL) {
3240         if (ClassLoader::is_modules_image(cfs->source())) {
3241           info_stream.print(" source: jrt:/%s", module_name);




 386   // If a method from a redefined class is using this constant pool, don't
 387   // delete it, yet.  The new class's previous version will point to this.
 388   if (constants() != NULL) {
 389     assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
 390     if (!constants()->is_shared()) {
 391       MetadataFactory::free_metadata(loader_data, constants());
 392     }
 393     // Delete any cached resolution errors for the constant pool
 394     SystemDictionary::delete_resolution_error(constants());
 395 
 396     set_constants(NULL);
 397   }
 398 
 399   if (inner_classes() != NULL &&
 400       inner_classes() != Universe::the_empty_short_array() &&
 401       !inner_classes()->is_shared()) {
 402     MetadataFactory::free_array<jushort>(loader_data, inner_classes());
 403   }
 404   set_inner_classes(NULL);
 405 
 406   if (value_types() != NULL && !value_types()->is_shared()) {
 407     MetadataFactory::free_array<ValueTypes>(loader_data, value_types());
 408   }
 409   set_value_types(NULL);
 410 
 411   // We should deallocate the Annotations instance if it's not in shared spaces.
 412   if (annotations() != NULL && !annotations()->is_shared()) {
 413     MetadataFactory::free_metadata(loader_data, annotations());
 414   }
 415   set_annotations(NULL);
 416 }
 417 
 418 bool InstanceKlass::should_be_initialized() const {
 419   return !is_initialized();
 420 }
 421 
 422 klassItable InstanceKlass::itable() const {
 423   return klassItable(const_cast<InstanceKlass*>(this));
 424 }
 425 
 426 void InstanceKlass::eager_initialize(Thread *thread) {
 427   if (!EagerInitialization) return;
 428 
 429   if (this->is_not_initialized()) {
 430     // abort if the the class has a class initializer


 594         vmSymbols::java_lang_IncompatibleClassChangeError(),
 595         "class %s has interface %s as super class",
 596         external_name(),
 597         super_klass->external_name()
 598       );
 599       return false;
 600     }
 601 
 602     InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
 603     ik_super->link_class_impl(throw_verifyerror, CHECK_false);
 604   }
 605 
 606   // link all interfaces implemented by this class before linking this class
 607   Array<Klass*>* interfaces = local_interfaces();
 608   int num_interfaces = interfaces->length();
 609   for (int index = 0; index < num_interfaces; index++) {
 610     InstanceKlass* interk = InstanceKlass::cast(interfaces->at(index));
 611     interk->link_class_impl(throw_verifyerror, CHECK_false);
 612   }
 613 














 614 
 615   // If a class declares a method that uses a value class as an argument
 616   // type or return value type, this value class must be loaded during the
 617   // linking if this class because size and properties of the value class
 618   // must be known in order to be able to perform value type optimizations.
 619   // The implementation below is an approximation of this rule, the code
 620   // iterates over all methods of the current class (including overridden
 621   // methods), not only the methods declared by this class. This
 622   // approximation makes the code simpler, and doesn't change the semantic
 623   // because classes declaring methods overridden by the current class are
 624   // linked (and have performed their own pre-loading) before the linking
 625   // of the current class.
 626   // This is also the moment where potential mismatch between the
 627   // ValueTypes attribute and the kind of the class effectively loaded.
 628 
 629 
 630   // Note:
 631   // Value class types used for flattenable fields are loaded during
 632   // the loading phase (see layout ClassFileParser::layout_fields()).
 633   // Value class types used as element types for array creation
 634   // are not pre-loaded. Their loading is triggered by either anewarray
 635   // or multianewarray bytecodes.
 636 
 637   {
 638     ResourceMark rm(THREAD);
 639     for (int i = 0; i < methods()->length(); i++) {
 640       Method* m = methods()->at(i);
 641       for (SignatureStream ss(m->signature()); !ss.is_done(); ss.next()) {
 642         Symbol* sig = ss.as_symbol(THREAD);
 643         if (is_declared_value_type(sig)) {
 644           // Get current loader and protection domain first.
 645           oop loader = class_loader();
 646           oop protection_domain = this->protection_domain();
 647 
 648           Klass* klass = SystemDictionary::resolve_or_fail(sig,
 649                                                            Handle(THREAD, loader), Handle(THREAD, protection_domain), true,
 650                                                            CHECK_false);
 651           if (klass == NULL) {
 652             THROW_(vmSymbols::java_lang_LinkageError(), false);
 653           }
 654           if (!klass->is_value()) {
 655             THROW_(vmSymbols::java_lang_IncompatibleClassChangeError(), false);
 656           }
 657         }
 658       }
 659     }
 660   }























 661 
 662   // in case the class is linked in the process of linking its superclasses
 663   if (is_linked()) {
 664     return true;
 665   }
 666 
 667   // trace only the link time for this klass that includes
 668   // the verification time
 669   PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
 670                              ClassLoader::perf_class_link_selftime(),
 671                              ClassLoader::perf_classes_linked(),
 672                              jt->get_thread_stat()->perf_recursion_counts_addr(),
 673                              jt->get_thread_stat()->perf_timers_addr(),
 674                              PerfClassTraceTime::CLASS_LINK);
 675 
 676   // verification & rewriting
 677   {
 678     HandleMark hm(THREAD);
 679     Handle h_init_lock(THREAD, init_lock());
 680     ObjectLocker ol(h_init_lock, THREAD, h_init_lock() != NULL);


2323 
2324 #if INCLUDE_JVMTI
2325   // Deallocate breakpoint records
2326   if (breakpoints() != 0x0) {
2327     methods_do(clear_all_breakpoints);
2328     assert(breakpoints() == 0x0, "should have cleared breakpoints");
2329   }
2330 
2331   // deallocate the cached class file
2332   if (_cached_class_file != NULL && !MetaspaceShared::is_in_shared_metaspace(_cached_class_file)) {
2333     os::free(_cached_class_file);
2334     _cached_class_file = NULL;
2335   }
2336 #endif
2337 
2338   // Decrement symbol reference counts associated with the unloaded class.
2339   if (_name != NULL) _name->decrement_refcount();
2340   // unreference array name derived from this class name (arrays of an unloaded
2341   // class can't be referenced anymore).
2342   if (_array_name != NULL)  _array_name->decrement_refcount();
2343   if (_value_types != NULL) {
2344     for (int i = 0; i < _value_types->length(); i++) {
2345       Symbol* s = _value_types->at(i)._class_name;
2346       if (s != NULL) {
2347         s->decrement_refcount();
2348       }
2349     }
2350   }
2351   if (_source_debug_extension != NULL) FREE_C_HEAP_ARRAY(char, _source_debug_extension);
2352 }
2353 
2354 void InstanceKlass::set_source_debug_extension(const char* array, int length) {
2355   if (array == NULL) {
2356     _source_debug_extension = NULL;
2357   } else {
2358     // Adding one to the attribute length in order to store a null terminator
2359     // character could cause an overflow because the attribute length is
2360     // already coded with an u4 in the classfile, but in practice, it's
2361     // unlikely to happen.
2362     assert((length+1) > length, "Overflow checking");
2363     char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
2364     for (int i = 0; i < length; i++) {
2365       sde[i] = array[i];
2366     }
2367     sde[length] = '\0';
2368     _source_debug_extension = sde;
2369   }
2370 }


3208       st->print(" => ");
3209       vmentry->print_value_on(st);
3210     }
3211   } else if (this == SystemDictionary::MemberName_klass()) {
3212     Metadata* vmtarget = java_lang_invoke_MemberName::vmtarget(obj);
3213     if (vmtarget != NULL) {
3214       st->print(" = ");
3215       vmtarget->print_value_on(st);
3216     } else {
3217       java_lang_invoke_MemberName::clazz(obj)->print_value_on(st);
3218       st->print(".");
3219       java_lang_invoke_MemberName::name(obj)->print_value_on(st);
3220     }
3221   }
3222 }
3223 
3224 const char* InstanceKlass::internal_name() const {
3225   return external_name();
3226 }
3227 
3228 bool InstanceKlass::is_declared_value_type(int index) {
3229   assert(constants()->is_within_bounds(index) &&
3230                constants()->tag_at(index).is_klass_or_reference(), "Invalid index");
3231   return InstanceKlass::is_declared_value_type(value_types(), index);
3232 }
3233 
3234 bool InstanceKlass::is_declared_value_type(Array<ValueTypes>* value_types, int index) {
3235   if (value_types == NULL) return false; // No ValueType attribute in this class file
3236   for(int i = 0; i < value_types->length(); i++) {
3237     if (value_types->at(i)._class_info_index == index) {
3238       return true;
3239     }
3240   }
3241   return false;
3242 }
3243 
3244 bool InstanceKlass::is_declared_value_type(Symbol* symbol) {
3245   return InstanceKlass::is_declared_value_type(constants(), value_types(), symbol);
3246 }
3247 
3248 bool InstanceKlass::is_declared_value_type(ConstantPool* constants, Array<ValueTypes>* value_types, Symbol* symbol) {
3249   assert(symbol != NULL, "Sanity check");
3250   if (value_types == NULL) return false; // No ValueType attribute in this class file
3251   for(int i = 0; i < value_types->length(); i++) {
3252     if (value_types->at(i)._class_name == symbol) {
3253       return true;
3254     }
3255   }
3256   // symbol not found, class name symbol might not have been
3257   // updated yet
3258   for(int i = 0; i < value_types->length(); i++) {
3259     if (constants->klass_at_noresolve((int)value_types->at(i)._class_info_index) == symbol) {
3260       value_types->adr_at(i)->_class_name = symbol;
3261       symbol->increment_refcount();
3262       return true;
3263     }
3264   }
3265   return false;
3266 }
3267 
3268 void InstanceKlass::print_class_load_logging(ClassLoaderData* loader_data,
3269                                              const char* module_name,
3270                                              const ClassFileStream* cfs) const {
3271   if (!log_is_enabled(Info, class, load)) {
3272     return;
3273   }
3274 
3275   ResourceMark rm;
3276   LogMessage(class, load) msg;
3277   stringStream info_stream;
3278 
3279   // Name and class hierarchy info
3280   info_stream.print("%s", external_name());
3281 
3282   // Source
3283   if (cfs != NULL) {
3284     if (cfs->source() != NULL) {
3285       if (module_name != NULL) {
3286         if (ClassLoader::is_modules_image(cfs->source())) {
3287           info_stream.print(" source: jrt:/%s", module_name);


< prev index next >