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 // If a value class is referenced by a class as a method argument type 615 // or return type this value class must be loaded during the linking of 616 // this class because size and properties of the value class must be 617 // known in order to be able to perform value type optimizations. 618 // This is also the moment where 619 620 // Note: 621 // Value class types used for flattenable fields are loaded during 622 // the loading phase (see layout ClassFileParser::layout_fields()). 623 // Value class types used as element types for array creation 624 // are not pre-loaded. Their loading is triggered by either anewarray 625 // or multianewarray bytecodes. 626 627 for (int i = 0; i < constants()->length(); i++) { 628 if (constants()->tag_at(i).is_method()) { 629 Symbol* signature = constants()->uncached_signature_ref_at(i); 630 ResourceMark rm(THREAD); 631 for (SignatureStream ss(signature); !ss.is_done(); ss.next()) { 632 Symbol* sig = ss.as_symbol(THREAD); 633 if (is_declared_value_type(sig)) { 634 // Get current loader and protection domain first. 635 oop loader = class_loader(); 636 oop protection_domain = this->protection_domain(); 637 638 Klass* klass = SystemDictionary::resolve_or_fail(sig, 639 Handle(THREAD, loader), Handle(THREAD, protection_domain), true, 640 CHECK_false); 641 if (klass == NULL) { 642 THROW_(vmSymbols::java_lang_LinkageError(), false); 643 } 644 if (!klass->is_value()) { 645 THROW_(vmSymbols::java_lang_IncompatibleClassChangeError(), false); 646 } 647 } 648 } 649 } 650 } 651 652 // in case the class is linked in the process of linking its superclasses 653 if (is_linked()) { 654 return true; 655 } 656 657 // trace only the link time for this klass that includes 658 // the verification time 659 PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(), 660 ClassLoader::perf_class_link_selftime(), 661 ClassLoader::perf_classes_linked(), 662 jt->get_thread_stat()->perf_recursion_counts_addr(), 663 jt->get_thread_stat()->perf_timers_addr(), 664 PerfClassTraceTime::CLASS_LINK); 665 666 // verification & rewriting 667 { 668 HandleMark hm(THREAD); 669 Handle h_init_lock(THREAD, init_lock()); 670 ObjectLocker ol(h_init_lock, THREAD, h_init_lock() != NULL); 2313 2314 #if INCLUDE_JVMTI 2315 // Deallocate breakpoint records 2316 if (breakpoints() != 0x0) { 2317 methods_do(clear_all_breakpoints); 2318 assert(breakpoints() == 0x0, "should have cleared breakpoints"); 2319 } 2320 2321 // deallocate the cached class file 2322 if (_cached_class_file != NULL && !MetaspaceShared::is_in_shared_metaspace(_cached_class_file)) { 2323 os::free(_cached_class_file); 2324 _cached_class_file = NULL; 2325 } 2326 #endif 2327 2328 // Decrement symbol reference counts associated with the unloaded class. 2329 if (_name != NULL) _name->decrement_refcount(); 2330 // unreference array name derived from this class name (arrays of an unloaded 2331 // class can't be referenced anymore). 2332 if (_array_name != NULL) _array_name->decrement_refcount(); 2333 if (_value_types != NULL) { 2334 for (int i = 0; i < _value_types->length(); i++) { 2335 Symbol* s = _value_types->at(i)._class_name; 2336 if (s != NULL) { 2337 s->decrement_refcount(); 2338 } 2339 } 2340 } 2341 if (_source_debug_extension != NULL) FREE_C_HEAP_ARRAY(char, _source_debug_extension); 2342 } 2343 2344 void InstanceKlass::set_source_debug_extension(const char* array, int length) { 2345 if (array == NULL) { 2346 _source_debug_extension = NULL; 2347 } else { 2348 // Adding one to the attribute length in order to store a null terminator 2349 // character could cause an overflow because the attribute length is 2350 // already coded with an u4 in the classfile, but in practice, it's 2351 // unlikely to happen. 2352 assert((length+1) > length, "Overflow checking"); 2353 char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass); 2354 for (int i = 0; i < length; i++) { 2355 sde[i] = array[i]; 2356 } 2357 sde[length] = '\0'; 2358 _source_debug_extension = sde; 2359 } 2360 } 3198 st->print(" => "); 3199 vmentry->print_value_on(st); 3200 } 3201 } else if (this == SystemDictionary::MemberName_klass()) { 3202 Metadata* vmtarget = java_lang_invoke_MemberName::vmtarget(obj); 3203 if (vmtarget != NULL) { 3204 st->print(" = "); 3205 vmtarget->print_value_on(st); 3206 } else { 3207 java_lang_invoke_MemberName::clazz(obj)->print_value_on(st); 3208 st->print("."); 3209 java_lang_invoke_MemberName::name(obj)->print_value_on(st); 3210 } 3211 } 3212 } 3213 3214 const char* InstanceKlass::internal_name() const { 3215 return external_name(); 3216 } 3217 3218 bool InstanceKlass::is_declared_value_type(int index) { 3219 assert(constants()->is_within_bounds(index) && 3220 constants()->tag_at(index).is_klass_or_reference(), "Invalid index"); 3221 return InstanceKlass::is_declared_value_type(value_types(), index); 3222 } 3223 3224 bool InstanceKlass::is_declared_value_type(Array<ValueTypes>* value_types, int index) { 3225 if (value_types == NULL) return false; // No ValueType attribute in this class file 3226 for(int i = 0; i < value_types->length(); i++) { 3227 if (value_types->at(i)._class_info_index == index) { 3228 return true; 3229 } 3230 } 3231 return false; 3232 } 3233 3234 bool InstanceKlass::is_declared_value_type(Symbol* symbol) { 3235 return InstanceKlass::is_declared_value_type(constants(), value_types(), symbol); 3236 } 3237 3238 bool InstanceKlass::is_declared_value_type(ConstantPool* constants, Array<ValueTypes>* value_types, Symbol* symbol) { 3239 assert(symbol != NULL, "Sanity check"); 3240 if (value_types == NULL) return false; // No ValueType attribute in this class file 3241 for(int i = 0; i < value_types->length(); i++) { 3242 if (value_types->at(i)._class_name == symbol) { 3243 return true; 3244 } 3245 } 3246 // symbol not found, class name symbol might not have been 3247 // updated yet 3248 for(int i = 0; i < value_types->length(); i++) { 3249 if (constants->klass_at_noresolve((int)value_types->at(i)._class_info_index) == symbol) { 3250 value_types->adr_at(i)->_class_name = symbol; 3251 symbol->increment_refcount(); 3252 return true; 3253 } 3254 } 3255 return false; 3256 } 3257 3258 void InstanceKlass::print_class_load_logging(ClassLoaderData* loader_data, 3259 const char* module_name, 3260 const ClassFileStream* cfs) const { 3261 if (!log_is_enabled(Info, class, load)) { 3262 return; 3263 } 3264 3265 ResourceMark rm; 3266 LogMessage(class, load) msg; 3267 stringStream info_stream; 3268 3269 // Name and class hierarchy info 3270 info_stream.print("%s", external_name()); 3271 3272 // Source 3273 if (cfs != NULL) { 3274 if (cfs->source() != NULL) { 3275 if (module_name != NULL) { 3276 if (ClassLoader::is_modules_image(cfs->source())) { 3277 info_stream.print(" source: jrt:/%s", module_name); |