< 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


 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


 614   // If a value type is referenced by a class (either as a field type or a
 615   // method argument or return type) this value type must be loaded during
 616   // the linking of this class because size and properties of the value type
 617   // must be known in order to be able to perform value type optimizations
 618 
 619   // Note: circular dependencies between value types are not handled yet
 620 
 621   // Note: one case is not handled yet: arrays of value types => FixMe
 622 
 623   // Note: the current implementation is not optimized because the search for
 624   // value types is performed on all classes. It would be more efficient to
 625   // detect value types during verification and 'tag' the classes for which
 626   // value type loading is required. However, this optimization won't be
 627   // applicable to classes that are not verified
 628 
 629   // First step: fields
 630   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
 631     ResourceMark rm(THREAD);
 632     if (fs.field_descriptor().access_flags().is_flattenable()) {
 633       Symbol* signature = fs.field_descriptor().signature();
 634       ResourceMark rm;
 635       Symbol* name = SymbolTable::lookup(signature->as_C_string() + 1,
 636                                          signature->utf8_length() - 2, CHECK_false);
 637       assert(this->is_declared_value_type(name), "Verifying consistency with ValueTypes attribute");
 638       name->decrement_refcount();
 639       name = NULL;
 640       // Get current loader and protection domain first.
 641       oop loader = class_loader();
 642       oop prot_domain = protection_domain();
 643       Klass* klass = SystemDictionary::resolve_or_fail(signature,
 644           Handle(THREAD, loader), Handle(THREAD, prot_domain), true,
 645           CHECK_false);
 646       if (klass == NULL) {
 647         THROW_(vmSymbols::java_lang_LinkageError(), false);
 648       }
 649     }
 650   }
 651 
 652    // Second step: methods arguments and return types
 653   for (int i = 0; i < constants()->length(); i++) {
 654     if (constants()->tag_at(i).is_method()) {
 655       Symbol* signature = constants()->uncached_signature_ref_at(i);
 656       ResourceMark rm(THREAD);
 657       for (SignatureStream ss(signature); !ss.is_done(); ss.next()) {
 658         Symbol* sig = ss.as_symbol(THREAD);
 659         if (is_declared_value_type(sig)) {
 660           // Get current loader and protection domain first.
 661           oop loader = class_loader();
 662           oop protection_domain = this->protection_domain();
 663 
 664           bool ok = SystemDictionary::resolve_or_fail(sig,
 665                                                       Handle(THREAD, loader), Handle(THREAD, protection_domain), true,
 666                                                       CHECK_false);
 667           if (!ok) {
 668             THROW_(vmSymbols::java_lang_LinkageError(), false);
 669           }
 670         }
 671       }
 672     }
 673   }
 674 
 675   // in case the class is linked in the process of linking its superclasses
 676   if (is_linked()) {
 677     return true;
 678   }
 679 
 680   // trace only the link time for this klass that includes
 681   // the verification time
 682   PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
 683                              ClassLoader::perf_class_link_selftime(),
 684                              ClassLoader::perf_classes_linked(),
 685                              jt->get_thread_stat()->perf_recursion_counts_addr(),
 686                              jt->get_thread_stat()->perf_timers_addr(),
 687                              PerfClassTraceTime::CLASS_LINK);
 688 
 689   // verification & rewriting
 690   {
 691     HandleMark hm(THREAD);
 692     Handle h_init_lock(THREAD, init_lock());
 693     ObjectLocker ol(h_init_lock, THREAD, h_init_lock() != NULL);


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


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


< prev index next >