118 oop SystemDictionary::java_system_loader() { |
118 oop SystemDictionary::java_system_loader() { |
119 return _java_system_loader; |
119 return _java_system_loader; |
120 } |
120 } |
121 |
121 |
122 void SystemDictionary::compute_java_system_loader(TRAPS) { |
122 void SystemDictionary::compute_java_system_loader(TRAPS) { |
123 KlassHandle system_klass(THREAD, WK_KLASS(ClassLoader_klass)); |
123 Klass* system_klass = WK_KLASS(ClassLoader_klass); |
124 JavaValue result(T_OBJECT); |
124 JavaValue result(T_OBJECT); |
125 JavaCalls::call_static(&result, |
125 JavaCalls::call_static(&result, |
126 KlassHandle(THREAD, WK_KLASS(ClassLoader_klass)), |
126 WK_KLASS(ClassLoader_klass), |
127 vmSymbols::getSystemClassLoader_name(), |
127 vmSymbols::getSystemClassLoader_name(), |
128 vmSymbols::void_classloader_signature(), |
128 vmSymbols::void_classloader_signature(), |
129 CHECK); |
129 CHECK); |
130 |
130 |
131 _java_system_loader = (oop)result.get_jobject(); |
131 _java_system_loader = (oop)result.get_jobject(); |
182 // Forwards to resolve_or_null |
182 // Forwards to resolve_or_null |
183 |
183 |
184 Klass* SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) { |
184 Klass* SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) { |
185 Klass* klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD); |
185 Klass* klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD); |
186 if (HAS_PENDING_EXCEPTION || klass == NULL) { |
186 if (HAS_PENDING_EXCEPTION || klass == NULL) { |
187 KlassHandle k_h(THREAD, klass); |
|
188 // can return a null klass |
187 // can return a null klass |
189 klass = handle_resolution_exception(class_name, throw_error, k_h, THREAD); |
188 klass = handle_resolution_exception(class_name, throw_error, klass, THREAD); |
190 } |
189 } |
191 return klass; |
190 return klass; |
192 } |
191 } |
193 |
192 |
194 Klass* SystemDictionary::handle_resolution_exception(Symbol* class_name, |
193 Klass* SystemDictionary::handle_resolution_exception(Symbol* class_name, |
195 bool throw_error, |
194 bool throw_error, |
196 KlassHandle klass_h, TRAPS) { |
195 Klass* klass, TRAPS) { |
197 if (HAS_PENDING_EXCEPTION) { |
196 if (HAS_PENDING_EXCEPTION) { |
198 // If we have a pending exception we forward it to the caller, unless throw_error is true, |
197 // If we have a pending exception we forward it to the caller, unless throw_error is true, |
199 // in which case we have to check whether the pending exception is a ClassNotFoundException, |
198 // in which case we have to check whether the pending exception is a ClassNotFoundException, |
200 // and if so convert it to a NoClassDefFoundError |
199 // and if so convert it to a NoClassDefFoundError |
201 // And chain the original ClassNotFoundException |
200 // And chain the original ClassNotFoundException |
202 if (throw_error && PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass())) { |
201 if (throw_error && PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass())) { |
203 ResourceMark rm(THREAD); |
202 ResourceMark rm(THREAD); |
204 assert(klass_h() == NULL, "Should not have result with exception pending"); |
203 assert(klass == NULL, "Should not have result with exception pending"); |
205 Handle e(THREAD, PENDING_EXCEPTION); |
204 Handle e(THREAD, PENDING_EXCEPTION); |
206 CLEAR_PENDING_EXCEPTION; |
205 CLEAR_PENDING_EXCEPTION; |
207 THROW_MSG_CAUSE_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string(), e); |
206 THROW_MSG_CAUSE_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string(), e); |
208 } else { |
207 } else { |
209 return NULL; |
208 return NULL; |
210 } |
209 } |
211 } |
210 } |
212 // Class not found, throw appropriate error or exception depending on value of throw_error |
211 // Class not found, throw appropriate error or exception depending on value of throw_error |
213 if (klass_h() == NULL) { |
212 if (klass == NULL) { |
214 ResourceMark rm(THREAD); |
213 ResourceMark rm(THREAD); |
215 if (throw_error) { |
214 if (throw_error) { |
216 THROW_MSG_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string()); |
215 THROW_MSG_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string()); |
217 } else { |
216 } else { |
218 THROW_MSG_NULL(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string()); |
217 THROW_MSG_NULL(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string()); |
219 } |
218 } |
220 } |
219 } |
221 return (Klass*)klass_h(); |
220 return klass; |
222 } |
221 } |
223 |
222 |
224 |
223 |
225 Klass* SystemDictionary::resolve_or_fail(Symbol* class_name, |
224 Klass* SystemDictionary::resolve_or_fail(Symbol* class_name, |
226 bool throw_error, TRAPS) |
225 bool throw_error, TRAPS) |
396 |
395 |
397 // java.lang.Object should have been found above |
396 // java.lang.Object should have been found above |
398 assert(class_name != NULL, "null super class for resolving"); |
397 assert(class_name != NULL, "null super class for resolving"); |
399 // Resolve the super class or interface, check results on return |
398 // Resolve the super class or interface, check results on return |
400 Klass* superk = SystemDictionary::resolve_or_null(class_name, |
399 Klass* superk = SystemDictionary::resolve_or_null(class_name, |
401 class_loader, |
400 class_loader, |
402 protection_domain, |
401 protection_domain, |
403 THREAD); |
402 THREAD); |
404 |
|
405 KlassHandle superk_h(THREAD, superk); |
|
406 |
403 |
407 // Clean up of placeholders moved so that each classloadAction registrar self-cleans up |
404 // Clean up of placeholders moved so that each classloadAction registrar self-cleans up |
408 // It is no longer necessary to keep the placeholder table alive until update_dictionary |
405 // It is no longer necessary to keep the placeholder table alive until update_dictionary |
409 // or error. GC used to walk the placeholder table as strong roots. |
406 // or error. GC used to walk the placeholder table as strong roots. |
410 // The instanceKlass is kept alive because the class loader is on the stack, |
407 // The instanceKlass is kept alive because the class loader is on the stack, |
413 { |
410 { |
414 MutexLocker mu(SystemDictionary_lock, THREAD); |
411 MutexLocker mu(SystemDictionary_lock, THREAD); |
415 placeholders()->find_and_remove(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD); |
412 placeholders()->find_and_remove(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD); |
416 SystemDictionary_lock->notify_all(); |
413 SystemDictionary_lock->notify_all(); |
417 } |
414 } |
418 if (HAS_PENDING_EXCEPTION || superk_h() == NULL) { |
415 if (HAS_PENDING_EXCEPTION || superk == NULL) { |
419 // can null superk |
416 // can null superk |
420 superk_h = KlassHandle(THREAD, handle_resolution_exception(class_name, true, superk_h, THREAD)); |
417 superk = handle_resolution_exception(class_name, true, superk, THREAD); |
421 } |
418 } |
422 |
419 |
423 return superk_h(); |
420 return superk; |
424 } |
421 } |
425 |
422 |
426 void SystemDictionary::validate_protection_domain(instanceKlassHandle klass, |
423 void SystemDictionary::validate_protection_domain(InstanceKlass* klass, |
427 Handle class_loader, |
424 Handle class_loader, |
428 Handle protection_domain, |
425 Handle protection_domain, |
429 TRAPS) { |
426 TRAPS) { |
430 if(!has_checkPackageAccess()) return; |
427 if(!has_checkPackageAccess()) return; |
431 |
428 |
436 // Print out trace information |
433 // Print out trace information |
437 outputStream* log = Log(protectiondomain)::debug_stream(); |
434 outputStream* log = Log(protectiondomain)::debug_stream(); |
438 log->print_cr("Checking package access"); |
435 log->print_cr("Checking package access"); |
439 log->print("class loader: "); class_loader()->print_value_on(log); |
436 log->print("class loader: "); class_loader()->print_value_on(log); |
440 log->print(" protection domain: "); protection_domain()->print_value_on(log); |
437 log->print(" protection domain: "); protection_domain()->print_value_on(log); |
441 log->print(" loading: "); klass()->print_value_on(log); |
438 log->print(" loading: "); klass->print_value_on(log); |
442 log->cr(); |
439 log->cr(); |
443 } |
440 } |
444 |
441 |
445 KlassHandle system_loader(THREAD, SystemDictionary::ClassLoader_klass()); |
442 InstanceKlass* system_loader = SystemDictionary::ClassLoader_klass(); |
446 JavaCalls::call_special(&result, |
443 JavaCalls::call_special(&result, |
447 class_loader, |
444 class_loader, |
448 system_loader, |
445 system_loader, |
449 vmSymbols::checkPackageAccess_name(), |
446 vmSymbols::checkPackageAccess_name(), |
450 vmSymbols::class_protectiondomain_signature(), |
447 vmSymbols::class_protectiondomain_signature(), |
538 // to force placeholder entry creation for this class for circularity detection |
535 // to force placeholder entry creation for this class for circularity detection |
539 // Caller must check for pending exception |
536 // Caller must check for pending exception |
540 // Returns non-null Klass* if other thread has completed load |
537 // Returns non-null Klass* if other thread has completed load |
541 // and we are done, |
538 // and we are done, |
542 // If return null Klass* and no pending exception, the caller must load the class |
539 // If return null Klass* and no pending exception, the caller must load the class |
543 instanceKlassHandle SystemDictionary::handle_parallel_super_load( |
540 InstanceKlass* SystemDictionary::handle_parallel_super_load( |
544 Symbol* name, Symbol* superclassname, Handle class_loader, |
541 Symbol* name, Symbol* superclassname, Handle class_loader, |
545 Handle protection_domain, Handle lockObject, TRAPS) { |
542 Handle protection_domain, Handle lockObject, TRAPS) { |
546 |
543 |
547 instanceKlassHandle nh = instanceKlassHandle(); // null Handle |
|
548 ClassLoaderData* loader_data = class_loader_data(class_loader); |
544 ClassLoaderData* loader_data = class_loader_data(class_loader); |
549 unsigned int d_hash = dictionary()->compute_hash(name, loader_data); |
545 unsigned int d_hash = dictionary()->compute_hash(name, loader_data); |
550 int d_index = dictionary()->hash_to_index(d_hash); |
546 int d_index = dictionary()->hash_to_index(d_hash); |
551 unsigned int p_hash = placeholders()->compute_hash(name, loader_data); |
547 unsigned int p_hash = placeholders()->compute_hash(name, loader_data); |
552 int p_index = placeholders()->hash_to_index(p_hash); |
548 int p_index = placeholders()->hash_to_index(p_hash); |
562 Klass* superk = SystemDictionary::resolve_super_or_fail(name, |
558 Klass* superk = SystemDictionary::resolve_super_or_fail(name, |
563 superclassname, |
559 superclassname, |
564 class_loader, |
560 class_loader, |
565 protection_domain, |
561 protection_domain, |
566 true, |
562 true, |
567 CHECK_(nh)); |
563 CHECK_NULL); |
568 |
564 |
569 // parallelCapable class loaders do NOT wait for parallel superclass loads to complete |
565 // parallelCapable class loaders do NOT wait for parallel superclass loads to complete |
570 // Serial class loaders and bootstrap classloader do wait for superclass loads |
566 // Serial class loaders and bootstrap classloader do wait for superclass loads |
571 if (!class_loader.is_null() && is_parallelCapable(class_loader)) { |
567 if (!class_loader.is_null() && is_parallelCapable(class_loader)) { |
572 MutexLocker mu(SystemDictionary_lock, THREAD); |
568 MutexLocker mu(SystemDictionary_lock, THREAD); |
573 // Check if classloading completed while we were loading superclass or waiting |
569 // Check if classloading completed while we were loading superclass or waiting |
574 Klass* check = find_class(d_index, d_hash, name, loader_data); |
570 return find_class(d_index, d_hash, name, loader_data); |
575 if (check != NULL) { |
|
576 // Klass is already loaded, so just return it |
|
577 return(instanceKlassHandle(THREAD, check)); |
|
578 } else { |
|
579 return nh; |
|
580 } |
|
581 } |
571 } |
582 |
572 |
583 // must loop to both handle other placeholder updates |
573 // must loop to both handle other placeholder updates |
584 // and spurious notifications |
574 // and spurious notifications |
585 bool super_load_in_progress = true; |
575 bool super_load_in_progress = true; |
586 PlaceholderEntry* placeholder; |
576 PlaceholderEntry* placeholder; |
587 while (super_load_in_progress) { |
577 while (super_load_in_progress) { |
588 MutexLocker mu(SystemDictionary_lock, THREAD); |
578 MutexLocker mu(SystemDictionary_lock, THREAD); |
589 // Check if classloading completed while we were loading superclass or waiting |
579 // Check if classloading completed while we were loading superclass or waiting |
590 Klass* check = find_class(d_index, d_hash, name, loader_data); |
580 InstanceKlass* check = find_class(d_index, d_hash, name, loader_data); |
591 if (check != NULL) { |
581 if (check != NULL) { |
592 // Klass is already loaded, so just return it |
582 // Klass is already loaded, so just return it |
593 return(instanceKlassHandle(THREAD, check)); |
583 return check; |
594 } else { |
584 } else { |
595 placeholder = placeholders()->get_entry(p_index, p_hash, name, loader_data); |
585 placeholder = placeholders()->get_entry(p_index, p_hash, name, loader_data); |
596 if (placeholder && placeholder->super_load_in_progress() ){ |
586 if (placeholder && placeholder->super_load_in_progress() ){ |
597 // Before UnsyncloadClass: |
587 // Before UnsyncloadClass: |
598 // We only get here if the application has released the |
588 // We only get here if the application has released the |
617 // If not in SD and not in PH, other thread's load must have failed |
607 // If not in SD and not in PH, other thread's load must have failed |
618 super_load_in_progress = false; |
608 super_load_in_progress = false; |
619 } |
609 } |
620 } |
610 } |
621 } |
611 } |
622 return (nh); |
612 return NULL; |
623 } |
613 } |
624 |
614 |
625 static void post_class_load_event(const Ticks& start_time, |
615 static void post_class_load_event(const Ticks& start_time, |
626 instanceKlassHandle k, |
616 InstanceKlass* k, |
627 const ClassLoaderData* init_cld) { |
617 const ClassLoaderData* init_cld) { |
628 #if INCLUDE_TRACE |
618 #if INCLUDE_TRACE |
629 EventClassLoad event(UNTIMED); |
619 EventClassLoad event(UNTIMED); |
630 if (event.should_commit()) { |
620 if (event.should_commit()) { |
631 event.set_starttime(start_time); |
621 event.set_starttime(start_time); |
632 event.set_loadedClass(k()); |
622 event.set_loadedClass(k); |
633 event.set_definingClassLoader(k->class_loader_data()); |
623 event.set_definingClassLoader(k->class_loader_data()); |
634 event.set_initiatingClassLoader(init_cld); |
624 event.set_initiatingClassLoader(init_cld); |
635 event.commit(); |
625 event.commit(); |
636 } |
626 } |
637 #endif // INCLUDE_TRACE |
627 #endif // INCLUDE_TRACE |
638 } |
628 } |
639 |
629 |
640 static void class_define_event(instanceKlassHandle k, |
630 static void class_define_event(InstanceKlass* k, |
641 const ClassLoaderData* def_cld) { |
631 const ClassLoaderData* def_cld) { |
642 #if INCLUDE_TRACE |
632 #if INCLUDE_TRACE |
643 EventClassDefine event; |
633 EventClassDefine event; |
644 if (event.should_commit()) { |
634 if (event.should_commit()) { |
645 event.set_definedClass(k()); |
635 event.set_definedClass(k); |
646 event.set_definingClassLoader(def_cld); |
636 event.set_definingClassLoader(def_cld); |
647 event.commit(); |
637 event.commit(); |
648 } |
638 } |
649 #endif // INCLUDE_TRACE |
639 #endif // INCLUDE_TRACE |
650 } |
640 } |
706 |
696 |
707 // Check again (after locking) if class already exist in SystemDictionary |
697 // Check again (after locking) if class already exist in SystemDictionary |
708 bool class_has_been_loaded = false; |
698 bool class_has_been_loaded = false; |
709 bool super_load_in_progress = false; |
699 bool super_load_in_progress = false; |
710 bool havesupername = false; |
700 bool havesupername = false; |
711 instanceKlassHandle k; |
701 InstanceKlass* k = NULL; |
712 PlaceholderEntry* placeholder; |
702 PlaceholderEntry* placeholder; |
713 Symbol* superclassname = NULL; |
703 Symbol* superclassname = NULL; |
714 |
704 |
715 { |
705 { |
716 MutexLocker mu(SystemDictionary_lock, THREAD); |
706 MutexLocker mu(SystemDictionary_lock, THREAD); |
717 Klass* check = find_class(d_index, d_hash, name, loader_data); |
707 InstanceKlass* check = find_class(d_index, d_hash, name, loader_data); |
718 if (check != NULL) { |
708 if (check != NULL) { |
719 // Klass is already loaded, so just return it |
709 // Klass is already loaded, so just return it |
720 class_has_been_loaded = true; |
710 class_has_been_loaded = true; |
721 k = instanceKlassHandle(THREAD, check); |
711 k = check; |
722 } else { |
712 } else { |
723 placeholder = placeholders()->get_entry(p_index, p_hash, name, loader_data); |
713 placeholder = placeholders()->get_entry(p_index, p_hash, name, loader_data); |
724 if (placeholder && placeholder->super_load_in_progress()) { |
714 if (placeholder && placeholder->super_load_in_progress()) { |
725 super_load_in_progress = true; |
715 super_load_in_progress = true; |
726 if (placeholder->havesupername() == true) { |
716 if (placeholder->havesupername() == true) { |
731 } |
721 } |
732 } |
722 } |
733 |
723 |
734 // If the class is in the placeholder table, class loading is in progress |
724 // If the class is in the placeholder table, class loading is in progress |
735 if (super_load_in_progress && havesupername==true) { |
725 if (super_load_in_progress && havesupername==true) { |
736 k = SystemDictionary::handle_parallel_super_load(name, superclassname, |
726 k = handle_parallel_super_load(name, |
737 class_loader, protection_domain, lockObject, THREAD); |
727 superclassname, |
|
728 class_loader, |
|
729 protection_domain, |
|
730 lockObject, THREAD); |
738 if (HAS_PENDING_EXCEPTION) { |
731 if (HAS_PENDING_EXCEPTION) { |
739 return NULL; |
732 return NULL; |
740 } |
733 } |
741 if (!k.is_null()) { |
734 if (k != NULL) { |
742 class_has_been_loaded = true; |
735 class_has_been_loaded = true; |
743 } |
736 } |
744 } |
737 } |
745 |
738 |
746 bool throw_circularity_error = false; |
739 bool throw_circularity_error = false; |
793 // case 2: traditional with broken classloader lock. wait on first |
786 // case 2: traditional with broken classloader lock. wait on first |
794 // requestor. |
787 // requestor. |
795 double_lock_wait(lockObject, THREAD); |
788 double_lock_wait(lockObject, THREAD); |
796 } |
789 } |
797 // Check if classloading completed while we were waiting |
790 // Check if classloading completed while we were waiting |
798 Klass* check = find_class(d_index, d_hash, name, loader_data); |
791 InstanceKlass* check = find_class(d_index, d_hash, name, loader_data); |
799 if (check != NULL) { |
792 if (check != NULL) { |
800 // Klass is already loaded, so just return it |
793 // Klass is already loaded, so just return it |
801 k = instanceKlassHandle(THREAD, check); |
794 k = check; |
802 class_has_been_loaded = true; |
795 class_has_been_loaded = true; |
803 } |
796 } |
804 // check if other thread failed to load and cleaned up |
797 // check if other thread failed to load and cleaned up |
805 oldprobe = placeholders()->get_entry(p_index, p_hash, name, loader_data); |
798 oldprobe = placeholders()->get_entry(p_index, p_hash, name, loader_data); |
806 } |
799 } |
818 // if they did not catch another thread holding LOAD_INSTANCE, |
811 // if they did not catch another thread holding LOAD_INSTANCE, |
819 // need a check analogous to the acquire ObjectLocker/find_class |
812 // need a check analogous to the acquire ObjectLocker/find_class |
820 // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL |
813 // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL |
821 // one final check if the load has already completed |
814 // one final check if the load has already completed |
822 // class loaders holding the ObjectLock shouldn't find the class here |
815 // class loaders holding the ObjectLock shouldn't find the class here |
823 Klass* check = find_class(d_index, d_hash, name, loader_data); |
816 InstanceKlass* check = find_class(d_index, d_hash, name, loader_data); |
824 if (check != NULL) { |
817 if (check != NULL) { |
825 // Klass is already loaded, so return it after checking/adding protection domain |
818 // Klass is already loaded, so return it after checking/adding protection domain |
826 k = instanceKlassHandle(THREAD, check); |
819 k = check; |
827 class_has_been_loaded = true; |
820 class_has_been_loaded = true; |
828 } |
821 } |
829 } |
822 } |
830 } |
823 } |
831 |
824 |
848 // successfully loaded InstanceKlass |
841 // successfully loaded InstanceKlass |
849 // Should not get here for classloaders that support parallelism |
842 // Should not get here for classloaders that support parallelism |
850 // with the new cleaner mechanism, even with AllowParallelDefineClass |
843 // with the new cleaner mechanism, even with AllowParallelDefineClass |
851 // Bootstrap goes through here to allow for an extra guarantee check |
844 // Bootstrap goes through here to allow for an extra guarantee check |
852 if (UnsyncloadClass || (class_loader.is_null())) { |
845 if (UnsyncloadClass || (class_loader.is_null())) { |
853 if (k.is_null() && HAS_PENDING_EXCEPTION |
846 if (k == NULL && HAS_PENDING_EXCEPTION |
854 && PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) { |
847 && PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) { |
855 MutexLocker mu(SystemDictionary_lock, THREAD); |
848 MutexLocker mu(SystemDictionary_lock, THREAD); |
856 Klass* check = find_class(d_index, d_hash, name, loader_data); |
849 InstanceKlass* check = find_class(d_index, d_hash, name, loader_data); |
857 if (check != NULL) { |
850 if (check != NULL) { |
858 // Klass is already loaded, so just use it |
851 // Klass is already loaded, so just use it |
859 k = instanceKlassHandle(THREAD, check); |
852 k = check; |
860 CLEAR_PENDING_EXCEPTION; |
853 CLEAR_PENDING_EXCEPTION; |
861 guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?"); |
854 guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?"); |
862 } |
855 } |
863 } |
856 } |
864 } |
857 } |
865 |
858 |
866 // If everything was OK (no exceptions, no null return value), and |
859 // If everything was OK (no exceptions, no null return value), and |
867 // class_loader is NOT the defining loader, do a little more bookkeeping. |
860 // class_loader is NOT the defining loader, do a little more bookkeeping. |
868 if (!HAS_PENDING_EXCEPTION && !k.is_null() && |
861 if (!HAS_PENDING_EXCEPTION && k != NULL && |
869 k->class_loader() != class_loader()) { |
862 k->class_loader() != class_loader()) { |
870 |
863 |
871 check_constraints(d_index, d_hash, k, class_loader, false, THREAD); |
864 check_constraints(d_index, d_hash, k, class_loader, false, THREAD); |
872 |
865 |
873 // Need to check for a PENDING_EXCEPTION again; check_constraints |
866 // Need to check for a PENDING_EXCEPTION again; check_constraints |
897 placeholders()->find_and_remove(p_index, p_hash, name, loader_data, PlaceholderTable::LOAD_INSTANCE, THREAD); |
890 placeholders()->find_and_remove(p_index, p_hash, name, loader_data, PlaceholderTable::LOAD_INSTANCE, THREAD); |
898 SystemDictionary_lock->notify_all(); |
891 SystemDictionary_lock->notify_all(); |
899 } |
892 } |
900 } |
893 } |
901 |
894 |
902 if (HAS_PENDING_EXCEPTION || k.is_null()) { |
895 if (HAS_PENDING_EXCEPTION || k == NULL) { |
903 return NULL; |
896 return NULL; |
904 } |
897 } |
905 |
898 |
906 post_class_load_event(class_load_start_time, k, loader_data); |
899 post_class_load_event(class_load_start_time, k, loader_data); |
907 |
900 |
908 #ifdef ASSERT |
901 #ifdef ASSERT |
909 { |
902 { |
910 ClassLoaderData* loader_data = k->class_loader_data(); |
903 ClassLoaderData* loader_data = k->class_loader_data(); |
911 MutexLocker mu(SystemDictionary_lock, THREAD); |
904 MutexLocker mu(SystemDictionary_lock, THREAD); |
912 Klass* kk = find_class(name, loader_data); |
905 Klass* kk = find_class(name, loader_data); |
913 assert(kk == k(), "should be present in dictionary"); |
906 assert(kk == k, "should be present in dictionary"); |
914 } |
907 } |
915 #endif |
908 #endif |
916 |
909 |
917 // return if the protection domain in NULL |
910 // return if the protection domain in NULL |
918 if (protection_domain() == NULL) return k(); |
911 if (protection_domain() == NULL) return k; |
919 |
912 |
920 // Check the protection domain has the right access |
913 // Check the protection domain has the right access |
921 { |
914 { |
922 MutexLocker mu(SystemDictionary_lock, THREAD); |
915 MutexLocker mu(SystemDictionary_lock, THREAD); |
923 // Note that we have an entry, and entries can be deleted only during GC, |
916 // Note that we have an entry, and entries can be deleted only during GC, |
928 // unloaded at a safepoint. Anonymous classes are not in SD. |
921 // unloaded at a safepoint. Anonymous classes are not in SD. |
929 NoSafepointVerifier nosafepoint; |
922 NoSafepointVerifier nosafepoint; |
930 if (dictionary()->is_valid_protection_domain(d_index, d_hash, name, |
923 if (dictionary()->is_valid_protection_domain(d_index, d_hash, name, |
931 loader_data, |
924 loader_data, |
932 protection_domain)) { |
925 protection_domain)) { |
933 return k(); |
926 return k; |
934 } |
927 } |
935 } |
928 } |
936 |
929 |
937 // Verify protection domain. If it fails an exception is thrown |
930 // Verify protection domain. If it fails an exception is thrown |
938 validate_protection_domain(k, class_loader, protection_domain, CHECK_NULL); |
931 validate_protection_domain(k, class_loader, protection_domain, CHECK_NULL); |
939 |
932 |
940 return k(); |
933 return k; |
941 } |
934 } |
942 |
935 |
943 |
936 |
944 // This routine does not lock the system dictionary. |
937 // This routine does not lock the system dictionary. |
945 // |
938 // |
1017 |
1010 |
1018 // Note: this method is much like resolve_from_stream, but |
1011 // Note: this method is much like resolve_from_stream, but |
1019 // does not publish the classes via the SystemDictionary. |
1012 // does not publish the classes via the SystemDictionary. |
1020 // Handles unsafe_DefineAnonymousClass and redefineclasses |
1013 // Handles unsafe_DefineAnonymousClass and redefineclasses |
1021 // RedefinedClasses do not add to the class hierarchy |
1014 // RedefinedClasses do not add to the class hierarchy |
1022 Klass* SystemDictionary::parse_stream(Symbol* class_name, |
1015 InstanceKlass* SystemDictionary::parse_stream(Symbol* class_name, |
1023 Handle class_loader, |
1016 Handle class_loader, |
1024 Handle protection_domain, |
1017 Handle protection_domain, |
1025 ClassFileStream* st, |
1018 ClassFileStream* st, |
1026 const InstanceKlass* host_klass, |
1019 const InstanceKlass* host_klass, |
1027 GrowableArray<Handle>* cp_patches, |
1020 GrowableArray<Handle>* cp_patches, |
1028 TRAPS) { |
1021 TRAPS) { |
1029 |
1022 |
1030 Ticks class_load_start_time = Ticks::now(); |
1023 Ticks class_load_start_time = Ticks::now(); |
1031 |
1024 |
1032 ClassLoaderData* loader_data; |
1025 ClassLoaderData* loader_data; |
1033 if (host_klass != NULL) { |
1026 if (host_klass != NULL) { |
1047 // Parse stream and create a klass. |
1040 // Parse stream and create a klass. |
1048 // Note that we do this even though this klass might |
1041 // Note that we do this even though this klass might |
1049 // already be present in the SystemDictionary, otherwise we would not |
1042 // already be present in the SystemDictionary, otherwise we would not |
1050 // throw potential ClassFormatErrors. |
1043 // throw potential ClassFormatErrors. |
1051 |
1044 |
1052 instanceKlassHandle k = KlassFactory::create_from_stream(st, |
1045 InstanceKlass* k = KlassFactory::create_from_stream(st, |
1053 class_name, |
1046 class_name, |
1054 loader_data, |
1047 loader_data, |
1055 protection_domain, |
1048 protection_domain, |
1056 host_klass, |
1049 host_klass, |
1057 cp_patches, |
1050 cp_patches, |
1058 CHECK_NULL); |
1051 CHECK_NULL); |
1059 |
1052 |
1060 if (host_klass != NULL && k.not_null()) { |
1053 if (host_klass != NULL && k != NULL) { |
1061 // If it's anonymous, initialize it now, since nobody else will. |
1054 // If it's anonymous, initialize it now, since nobody else will. |
1062 |
1055 |
1063 { |
1056 { |
1064 MutexLocker mu_r(Compile_lock, THREAD); |
1057 MutexLocker mu_r(Compile_lock, THREAD); |
1065 |
1058 |
1081 k->eager_initialize(CHECK_NULL); |
1074 k->eager_initialize(CHECK_NULL); |
1082 |
1075 |
1083 // notify jvmti |
1076 // notify jvmti |
1084 if (JvmtiExport::should_post_class_load()) { |
1077 if (JvmtiExport::should_post_class_load()) { |
1085 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); |
1078 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); |
1086 JvmtiExport::post_class_load((JavaThread *) THREAD, k()); |
1079 JvmtiExport::post_class_load((JavaThread *) THREAD, k); |
1087 } |
1080 } |
1088 |
1081 |
1089 post_class_load_event(class_load_start_time, k, loader_data); |
1082 post_class_load_event(class_load_start_time, k, loader_data); |
1090 } |
1083 } |
1091 assert(host_klass != NULL || NULL == cp_patches, |
1084 assert(host_klass != NULL || NULL == cp_patches, |
1092 "cp_patches only found with host_klass"); |
1085 "cp_patches only found with host_klass"); |
1093 |
1086 |
1094 return k(); |
1087 return k; |
1095 } |
1088 } |
1096 |
1089 |
1097 // Add a klass to the system from a stream (called by jni_DefineClass and |
1090 // Add a klass to the system from a stream (called by jni_DefineClass and |
1098 // JVM_DefineClass). |
1091 // JVM_DefineClass). |
1099 // Note: class_name can be NULL. In that case we do not know the name of |
1092 // Note: class_name can be NULL. In that case we do not know the name of |
1100 // the class until we have parsed the stream. |
1093 // the class until we have parsed the stream. |
1101 |
1094 |
1102 Klass* SystemDictionary::resolve_from_stream(Symbol* class_name, |
1095 InstanceKlass* SystemDictionary::resolve_from_stream(Symbol* class_name, |
1103 Handle class_loader, |
1096 Handle class_loader, |
1104 Handle protection_domain, |
1097 Handle protection_domain, |
1105 ClassFileStream* st, |
1098 ClassFileStream* st, |
1106 TRAPS) { |
1099 TRAPS) { |
1107 |
1100 |
1108 HandleMark hm(THREAD); |
1101 HandleMark hm(THREAD); |
1109 |
1102 |
1110 // Classloaders that support parallelism, e.g. bootstrap classloader, |
1103 // Classloaders that support parallelism, e.g. bootstrap classloader, |
1111 // or all classloaders with UnsyncloadClass do not acquire lock here |
1104 // or all classloaders with UnsyncloadClass do not acquire lock here |
1125 |
1118 |
1126 // Parse the stream and create a klass. |
1119 // Parse the stream and create a klass. |
1127 // Note that we do this even though this klass might |
1120 // Note that we do this even though this klass might |
1128 // already be present in the SystemDictionary, otherwise we would not |
1121 // already be present in the SystemDictionary, otherwise we would not |
1129 // throw potential ClassFormatErrors. |
1122 // throw potential ClassFormatErrors. |
1130 // |
1123 InstanceKlass* k = NULL; |
1131 |
|
1132 instanceKlassHandle k; |
|
1133 |
1124 |
1134 #if INCLUDE_CDS |
1125 #if INCLUDE_CDS |
1135 k = SystemDictionaryShared::lookup_from_stream(class_name, |
1126 k = SystemDictionaryShared::lookup_from_stream(class_name, |
1136 class_loader, |
1127 class_loader, |
1137 protection_domain, |
1128 protection_domain, |
1138 st, |
1129 st, |
1139 CHECK_NULL); |
1130 CHECK_NULL); |
1140 #endif |
1131 #endif |
1141 |
1132 |
1142 if (k.is_null()) { |
1133 if (k == NULL) { |
1143 if (st->buffer() == NULL) { |
1134 if (st->buffer() == NULL) { |
1144 return NULL; |
1135 return NULL; |
1145 } |
1136 } |
1146 k = KlassFactory::create_from_stream(st, |
1137 k = KlassFactory::create_from_stream(st, |
1147 class_name, |
1138 class_name, |
1150 NULL, // host_klass |
1141 NULL, // host_klass |
1151 NULL, // cp_patches |
1142 NULL, // cp_patches |
1152 CHECK_NULL); |
1143 CHECK_NULL); |
1153 } |
1144 } |
1154 |
1145 |
1155 assert(k.not_null(), "no klass created"); |
1146 assert(k != NULL, "no klass created"); |
1156 Symbol* h_name = k->name(); |
1147 Symbol* h_name = k->name(); |
1157 assert(class_name == NULL || class_name == h_name, "name mismatch"); |
1148 assert(class_name == NULL || class_name == h_name, "name mismatch"); |
1158 |
1149 |
1159 // Add class just loaded |
1150 // Add class just loaded |
1160 // If a class loader supports parallel classloading handle parallel define requests |
1151 // If a class loader supports parallel classloading handle parallel define requests |
1161 // find_or_define_instance_class may return a different InstanceKlass |
1152 // find_or_define_instance_class may return a different InstanceKlass |
1162 if (is_parallelCapable(class_loader)) { |
1153 if (is_parallelCapable(class_loader)) { |
1163 instanceKlassHandle defined_k = find_or_define_instance_class(h_name, class_loader, k, THREAD); |
1154 InstanceKlass* defined_k = find_or_define_instance_class(h_name, class_loader, k, THREAD); |
1164 if (!HAS_PENDING_EXCEPTION && defined_k() != k()) { |
1155 if (!HAS_PENDING_EXCEPTION && defined_k != k) { |
1165 // If a parallel capable class loader already defined this class, register 'k' for cleanup. |
1156 // If a parallel capable class loader already defined this class, register 'k' for cleanup. |
1166 assert(defined_k.not_null(), "Should have a klass if there's no exception"); |
1157 assert(defined_k != NULL, "Should have a klass if there's no exception"); |
1167 loader_data->add_to_deallocate_list(k()); |
1158 loader_data->add_to_deallocate_list(k); |
1168 k = defined_k; |
1159 k = defined_k; |
1169 } |
1160 } |
1170 } else { |
1161 } else { |
1171 define_instance_class(k, THREAD); |
1162 define_instance_class(k, THREAD); |
1172 } |
1163 } |
1173 |
1164 |
1174 // If defining the class throws an exception register 'k' for cleanup. |
1165 // If defining the class throws an exception register 'k' for cleanup. |
1175 if (HAS_PENDING_EXCEPTION) { |
1166 if (HAS_PENDING_EXCEPTION) { |
1176 assert(k.not_null(), "Must have an instance klass here!"); |
1167 assert(k != NULL, "Must have an instance klass here!"); |
1177 loader_data->add_to_deallocate_list(k()); |
1168 loader_data->add_to_deallocate_list(k); |
1178 return NULL; |
1169 return NULL; |
1179 } |
1170 } |
1180 |
1171 |
1181 // Make sure we have an entry in the SystemDictionary on success |
1172 // Make sure we have an entry in the SystemDictionary on success |
1182 debug_only( { |
1173 debug_only( { |
1183 MutexLocker mu(SystemDictionary_lock, THREAD); |
1174 MutexLocker mu(SystemDictionary_lock, THREAD); |
1184 |
1175 |
1185 Klass* check = find_class(h_name, k->class_loader_data()); |
1176 Klass* check = find_class(h_name, k->class_loader_data()); |
1186 assert(check == k(), "should be present in the dictionary"); |
1177 assert(check == k, "should be present in the dictionary"); |
1187 } ); |
1178 } ); |
1188 |
1179 |
1189 return k(); |
1180 return k; |
1190 } |
1181 } |
1191 |
1182 |
1192 #if INCLUDE_CDS |
1183 #if INCLUDE_CDS |
1193 void SystemDictionary::set_shared_dictionary(HashtableBucket<mtClass>* t, int length, |
1184 void SystemDictionary::set_shared_dictionary(HashtableBucket<mtClass>* t, int length, |
1194 int number_of_entries) { |
1185 int number_of_entries) { |
1199 |
1190 |
1200 |
1191 |
1201 // If there is a shared dictionary, then find the entry for the |
1192 // If there is a shared dictionary, then find the entry for the |
1202 // given shared system class, if any. |
1193 // given shared system class, if any. |
1203 |
1194 |
1204 Klass* SystemDictionary::find_shared_class(Symbol* class_name) { |
1195 InstanceKlass* SystemDictionary::find_shared_class(Symbol* class_name) { |
1205 if (shared_dictionary() != NULL) { |
1196 if (shared_dictionary() != NULL) { |
1206 unsigned int d_hash = shared_dictionary()->compute_hash(class_name, NULL); |
1197 unsigned int d_hash = shared_dictionary()->compute_hash(class_name, NULL); |
1207 int d_index = shared_dictionary()->hash_to_index(d_hash); |
1198 int d_index = shared_dictionary()->hash_to_index(d_hash); |
1208 |
1199 |
1209 return shared_dictionary()->find_shared_class(d_index, d_hash, class_name); |
1200 return shared_dictionary()->find_shared_class(d_index, d_hash, class_name); |
1217 // dictionary). Force the superclass and all interfaces to be loaded. |
1208 // dictionary). Force the superclass and all interfaces to be loaded. |
1218 // Update the class definition to include sibling classes and no |
1209 // Update the class definition to include sibling classes and no |
1219 // subclasses (yet). [Classes in the shared space are not part of the |
1210 // subclasses (yet). [Classes in the shared space are not part of the |
1220 // object hierarchy until loaded.] |
1211 // object hierarchy until loaded.] |
1221 |
1212 |
1222 instanceKlassHandle SystemDictionary::load_shared_class( |
1213 InstanceKlass* SystemDictionary::load_shared_class( |
1223 Symbol* class_name, Handle class_loader, TRAPS) { |
1214 Symbol* class_name, Handle class_loader, TRAPS) { |
1224 instanceKlassHandle ik (THREAD, find_shared_class(class_name)); |
1215 InstanceKlass* ik = find_shared_class(class_name); |
1225 // Make sure we only return the boot class for the NULL classloader. |
1216 // Make sure we only return the boot class for the NULL classloader. |
1226 if (ik.not_null() && |
1217 if (ik != NULL && |
1227 ik->is_shared_boot_class() && class_loader.is_null()) { |
1218 ik->is_shared_boot_class() && class_loader.is_null()) { |
1228 Handle protection_domain; |
1219 Handle protection_domain; |
1229 return load_shared_class(ik, class_loader, protection_domain, THREAD); |
1220 return load_shared_class(ik, class_loader, protection_domain, THREAD); |
1230 } |
1221 } |
1231 return instanceKlassHandle(); |
1222 return NULL; |
1232 } |
1223 } |
1233 |
1224 |
1234 // Check if a shared class can be loaded by the specific classloader: |
1225 // Check if a shared class can be loaded by the specific classloader: |
1235 // |
1226 // |
1236 // NULL classloader: |
1227 // NULL classloader: |
1237 // - Module class from "modules" jimage. ModuleEntry must be defined in the classloader. |
1228 // - Module class from "modules" jimage. ModuleEntry must be defined in the classloader. |
1238 // - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must |
1229 // - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must |
1239 // be defined in an unnamed module. |
1230 // be defined in an unnamed module. |
1240 bool SystemDictionary::is_shared_class_visible(Symbol* class_name, |
1231 bool SystemDictionary::is_shared_class_visible(Symbol* class_name, |
1241 instanceKlassHandle ik, |
1232 InstanceKlass* ik, |
1242 Handle class_loader, TRAPS) { |
1233 Handle class_loader, TRAPS) { |
1243 assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(), |
1234 assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(), |
1244 "Cannot use sharing if java.base is patched"); |
1235 "Cannot use sharing if java.base is patched"); |
1245 ResourceMark rm; |
1236 ResourceMark rm; |
1246 int path_index = ik->shared_classpath_index(); |
1237 int path_index = ik->shared_classpath_index(); |
1313 pkg_entry, mod_entry, CHECK_(false)); |
1304 pkg_entry, mod_entry, CHECK_(false)); |
1314 return res; |
1305 return res; |
1315 } |
1306 } |
1316 } |
1307 } |
1317 |
1308 |
1318 instanceKlassHandle SystemDictionary::load_shared_class(instanceKlassHandle ik, |
1309 InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik, |
1319 Handle class_loader, |
1310 Handle class_loader, |
1320 Handle protection_domain, TRAPS) { |
1311 Handle protection_domain, TRAPS) { |
1321 instanceKlassHandle nh = instanceKlassHandle(); // null Handle |
1312 |
1322 |
1313 if (ik != NULL) { |
1323 if (ik.not_null()) { |
|
1324 Symbol* class_name = ik->name(); |
1314 Symbol* class_name = ik->name(); |
1325 |
1315 |
1326 bool visible = is_shared_class_visible( |
1316 bool visible = is_shared_class_visible( |
1327 class_name, ik, class_loader, CHECK_(nh)); |
1317 class_name, ik, class_loader, CHECK_NULL); |
1328 if (!visible) { |
1318 if (!visible) { |
1329 return nh; |
1319 return NULL; |
1330 } |
1320 } |
1331 |
1321 |
1332 // Resolve the superclass and interfaces. They must be the same |
1322 // Resolve the superclass and interfaces. They must be the same |
1333 // as in dump time, because the layout of <ik> depends on |
1323 // as in dump time, because the layout of <ik> depends on |
1334 // the specific layout of ik->super() and ik->local_interfaces(). |
1324 // the specific layout of ik->super() and ik->local_interfaces(). |
1337 // load <ik> from the shared archive. |
1327 // load <ik> from the shared archive. |
1338 |
1328 |
1339 if (ik->super() != NULL) { |
1329 if (ik->super() != NULL) { |
1340 Symbol* cn = ik->super()->name(); |
1330 Symbol* cn = ik->super()->name(); |
1341 Klass *s = resolve_super_or_fail(class_name, cn, |
1331 Klass *s = resolve_super_or_fail(class_name, cn, |
1342 class_loader, protection_domain, true, CHECK_(nh)); |
1332 class_loader, protection_domain, true, CHECK_NULL); |
1343 if (s != ik->super()) { |
1333 if (s != ik->super()) { |
1344 // The dynamically resolved super class is not the same as the one we used during dump time, |
1334 // The dynamically resolved super class is not the same as the one we used during dump time, |
1345 // so we cannot use ik. |
1335 // so we cannot use ik. |
1346 return nh; |
1336 return NULL; |
1347 } else { |
1337 } else { |
1348 assert(s->is_shared(), "must be"); |
1338 assert(s->is_shared(), "must be"); |
1349 } |
1339 } |
1350 } |
1340 } |
1351 |
1341 |
1352 Array<Klass*>* interfaces = ik->local_interfaces(); |
1342 Array<Klass*>* interfaces = ik->local_interfaces(); |
1353 int num_interfaces = interfaces->length(); |
1343 int num_interfaces = interfaces->length(); |
1354 for (int index = 0; index < num_interfaces; index++) { |
1344 for (int index = 0; index < num_interfaces; index++) { |
1355 Klass* k = interfaces->at(index); |
1345 Klass* k = interfaces->at(index); |
1356 Symbol* name = k->name(); |
1346 Symbol* name = k->name(); |
1357 Klass* i = resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_(nh)); |
1347 Klass* i = resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_NULL); |
1358 if (k != i) { |
1348 if (k != i) { |
1359 // The dynamically resolved interface class is not the same as the one we used during dump time, |
1349 // The dynamically resolved interface class is not the same as the one we used during dump time, |
1360 // so we cannot use ik. |
1350 // so we cannot use ik. |
1361 return nh; |
1351 return NULL; |
1362 } else { |
1352 } else { |
1363 assert(i->is_shared(), "must be"); |
1353 assert(i->is_shared(), "must be"); |
1364 } |
1354 } |
1365 } |
1355 } |
1366 |
1356 |
1367 instanceKlassHandle new_ik = KlassFactory::check_shared_class_file_load_hook( |
1357 InstanceKlass* new_ik = KlassFactory::check_shared_class_file_load_hook( |
1368 ik, class_name, class_loader, protection_domain, CHECK_(nh)); |
1358 ik, class_name, class_loader, protection_domain, CHECK_NULL); |
1369 if (new_ik.not_null()) { |
1359 if (new_ik != NULL) { |
1370 // The class is changed by CFLH. Return the new class. The shared class is |
1360 // The class is changed by CFLH. Return the new class. The shared class is |
1371 // not used. |
1361 // not used. |
1372 return new_ik; |
1362 return new_ik; |
1373 } |
1363 } |
1374 |
1364 |
1389 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); |
1379 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); |
1390 check_loader_lock_contention(lockObject, THREAD); |
1380 check_loader_lock_contention(lockObject, THREAD); |
1391 ObjectLocker ol(lockObject, THREAD, true); |
1381 ObjectLocker ol(lockObject, THREAD, true); |
1392 // prohibited package check assumes all classes loaded from archive call |
1382 // prohibited package check assumes all classes loaded from archive call |
1393 // restore_unshareable_info which calls ik->set_package() |
1383 // restore_unshareable_info which calls ik->set_package() |
1394 ik->restore_unshareable_info(loader_data, protection_domain, CHECK_(nh)); |
1384 ik->restore_unshareable_info(loader_data, protection_domain, CHECK_NULL); |
1395 } |
1385 } |
1396 |
1386 |
1397 if (log_is_enabled(Info, class, load)) { |
1387 if (log_is_enabled(Info, class, load)) { |
1398 ik()->print_loading_log(LogLevel::Info, loader_data, NULL, NULL); |
1388 ik->print_loading_log(LogLevel::Info, loader_data, NULL, NULL); |
1399 } |
1389 } |
1400 // No 'else' here as logging levels are not mutually exclusive |
1390 // No 'else' here as logging levels are not mutually exclusive |
1401 |
1391 |
1402 if (log_is_enabled(Debug, class, load)) { |
1392 if (log_is_enabled(Debug, class, load)) { |
1403 ik()->print_loading_log(LogLevel::Debug, loader_data, NULL, NULL); |
1393 ik->print_loading_log(LogLevel::Debug, loader_data, NULL, NULL); |
1404 } |
1394 } |
1405 |
1395 |
1406 // For boot loader, ensure that GetSystemPackage knows that a class in this |
1396 // For boot loader, ensure that GetSystemPackage knows that a class in this |
1407 // package was loaded. |
1397 // package was loaded. |
1408 if (class_loader.is_null()) { |
1398 if (class_loader.is_null()) { |
1419 classlist_file->flush(); |
1409 classlist_file->flush(); |
1420 } |
1410 } |
1421 } |
1411 } |
1422 |
1412 |
1423 // notify a class loaded from shared object |
1413 // notify a class loaded from shared object |
1424 ClassLoadingService::notify_class_loaded(ik(), true /* shared class */); |
1414 ClassLoadingService::notify_class_loaded(ik, true /* shared class */); |
1425 } |
1415 } |
1426 |
1416 |
1427 ik->set_has_passed_fingerprint_check(false); |
1417 ik->set_has_passed_fingerprint_check(false); |
1428 if (UseAOT && ik->supers_have_passed_fingerprint_checks()) { |
1418 if (UseAOT && ik->supers_have_passed_fingerprint_checks()) { |
1429 uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik()); |
1419 uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik); |
1430 uint64_t cds_fp = ik->get_stored_fingerprint(); |
1420 uint64_t cds_fp = ik->get_stored_fingerprint(); |
1431 if (aot_fp != 0 && aot_fp == cds_fp) { |
1421 if (aot_fp != 0 && aot_fp == cds_fp) { |
1432 // This class matches with a class saved in an AOT library |
1422 // This class matches with a class saved in an AOT library |
1433 ik->set_has_passed_fingerprint_check(true); |
1423 ik->set_has_passed_fingerprint_check(true); |
1434 } else { |
1424 } else { |
1471 // load the class post java.base definition. If |
1460 // load the class post java.base definition. If |
1472 // java.base has not been defined, let the class load |
1461 // java.base has not been defined, let the class load |
1473 // and its package will be checked later by |
1462 // and its package will be checked later by |
1474 // ModuleEntryTable::verify_javabase_packages. |
1463 // ModuleEntryTable::verify_javabase_packages. |
1475 if (ModuleEntryTable::javabase_defined()) { |
1464 if (ModuleEntryTable::javabase_defined()) { |
1476 return nh; |
1465 return NULL; |
1477 } |
1466 } |
1478 } else { |
1467 } else { |
1479 // Check that the class' package is defined within java.base. |
1468 // Check that the class' package is defined within java.base. |
1480 ModuleEntry* mod_entry = pkg_entry->module(); |
1469 ModuleEntry* mod_entry = pkg_entry->module(); |
1481 Symbol* mod_entry_name = mod_entry->name(); |
1470 Symbol* mod_entry_name = mod_entry->name(); |
1482 if (mod_entry_name->fast_compare(vmSymbols::java_base()) != 0) { |
1471 if (mod_entry_name->fast_compare(vmSymbols::java_base()) != 0) { |
1483 return nh; |
1472 return NULL; |
1484 } |
1473 } |
1485 } |
1474 } |
1486 } |
1475 } |
1487 } else { |
1476 } else { |
1488 assert(!DumpSharedSpaces, "Archive dumped after module system initialization"); |
1477 assert(!DumpSharedSpaces, "Archive dumped after module system initialization"); |
1504 !search_only_bootloader_append, |
1493 !search_only_bootloader_append, |
1505 "Attempt to load a class outside of boot loader's module path"); |
1494 "Attempt to load a class outside of boot loader's module path"); |
1506 |
1495 |
1507 // Search the shared system dictionary for classes preloaded into the |
1496 // Search the shared system dictionary for classes preloaded into the |
1508 // shared spaces. |
1497 // shared spaces. |
1509 instanceKlassHandle k; |
1498 InstanceKlass* k = NULL; |
1510 { |
1499 { |
1511 #if INCLUDE_CDS |
1500 #if INCLUDE_CDS |
1512 PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time()); |
1501 PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time()); |
1513 k = load_shared_class(class_name, class_loader, THREAD); |
1502 k = load_shared_class(class_name, class_loader, THREAD); |
1514 #endif |
1503 #endif |
1515 } |
1504 } |
1516 |
1505 |
1517 if (k.is_null()) { |
1506 if (k == NULL) { |
1518 // Use VM class loader |
1507 // Use VM class loader |
1519 PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time()); |
1508 PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time()); |
1520 k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_(nh)); |
1509 k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL); |
1521 } |
1510 } |
1522 |
1511 |
1523 // find_or_define_instance_class may return a different InstanceKlass |
1512 // find_or_define_instance_class may return a different InstanceKlass |
1524 if (!k.is_null()) { |
1513 if (k != NULL) { |
1525 instanceKlassHandle defined_k = |
1514 InstanceKlass* defined_k = |
1526 find_or_define_instance_class(class_name, class_loader, k, THREAD); |
1515 find_or_define_instance_class(class_name, class_loader, k, THREAD); |
1527 if (!HAS_PENDING_EXCEPTION && defined_k() != k()) { |
1516 if (!HAS_PENDING_EXCEPTION && defined_k != k) { |
1528 // If a parallel capable class loader already defined this class, register 'k' for cleanup. |
1517 // If a parallel capable class loader already defined this class, register 'k' for cleanup. |
1529 assert(defined_k.not_null(), "Should have a klass if there's no exception"); |
1518 assert(defined_k != NULL, "Should have a klass if there's no exception"); |
1530 loader_data->add_to_deallocate_list(k()); |
1519 loader_data->add_to_deallocate_list(k); |
1531 k = defined_k; |
1520 k = defined_k; |
1532 } else if (HAS_PENDING_EXCEPTION) { |
1521 } else if (HAS_PENDING_EXCEPTION) { |
1533 loader_data->add_to_deallocate_list(k()); |
1522 loader_data->add_to_deallocate_list(k); |
1534 return nh; |
1523 return NULL; |
1535 } |
1524 } |
1536 } |
1525 } |
1537 return k; |
1526 return k; |
1538 } else { |
1527 } else { |
1539 // Use user specified class loader to load class. Call loadClass operation on class_loader. |
1528 // Use user specified class loader to load class. Call loadClass operation on class_loader. |
1547 ClassLoader::perf_app_classload_count(), |
1536 ClassLoader::perf_app_classload_count(), |
1548 jt->get_thread_stat()->perf_recursion_counts_addr(), |
1537 jt->get_thread_stat()->perf_recursion_counts_addr(), |
1549 jt->get_thread_stat()->perf_timers_addr(), |
1538 jt->get_thread_stat()->perf_timers_addr(), |
1550 PerfClassTraceTime::CLASS_LOAD); |
1539 PerfClassTraceTime::CLASS_LOAD); |
1551 |
1540 |
1552 Handle s = java_lang_String::create_from_symbol(class_name, CHECK_(nh)); |
1541 Handle s = java_lang_String::create_from_symbol(class_name, CHECK_NULL); |
1553 // Translate to external class name format, i.e., convert '/' chars to '.' |
1542 // Translate to external class name format, i.e., convert '/' chars to '.' |
1554 Handle string = java_lang_String::externalize_classname(s, CHECK_(nh)); |
1543 Handle string = java_lang_String::externalize_classname(s, CHECK_NULL); |
1555 |
1544 |
1556 JavaValue result(T_OBJECT); |
1545 JavaValue result(T_OBJECT); |
1557 |
1546 |
1558 KlassHandle spec_klass (THREAD, SystemDictionary::ClassLoader_klass()); |
1547 InstanceKlass* spec_klass = SystemDictionary::ClassLoader_klass(); |
1559 |
1548 |
1560 // Call public unsynchronized loadClass(String) directly for all class loaders |
1549 // Call public unsynchronized loadClass(String) directly for all class loaders |
1561 // for parallelCapable class loaders. JDK >=7, loadClass(String, boolean) will |
1550 // for parallelCapable class loaders. JDK >=7, loadClass(String, boolean) will |
1562 // acquire a class-name based lock rather than the class loader object lock. |
1551 // acquire a class-name based lock rather than the class loader object lock. |
1563 // JDK < 7 already acquire the class loader lock in loadClass(String, boolean), |
1552 // JDK < 7 already acquire the class loader lock in loadClass(String, boolean), |
1579 class_loader, |
1568 class_loader, |
1580 spec_klass, |
1569 spec_klass, |
1581 vmSymbols::loadClassInternal_name(), |
1570 vmSymbols::loadClassInternal_name(), |
1582 vmSymbols::string_class_signature(), |
1571 vmSymbols::string_class_signature(), |
1583 string, |
1572 string, |
1584 CHECK_(nh)); |
1573 CHECK_NULL); |
1585 } else { |
1574 } else { |
1586 JavaCalls::call_virtual(&result, |
1575 JavaCalls::call_virtual(&result, |
1587 class_loader, |
1576 class_loader, |
1588 spec_klass, |
1577 spec_klass, |
1589 vmSymbols::loadClass_name(), |
1578 vmSymbols::loadClass_name(), |
1590 vmSymbols::string_class_signature(), |
1579 vmSymbols::string_class_signature(), |
1591 string, |
1580 string, |
1592 CHECK_(nh)); |
1581 CHECK_NULL); |
1593 } |
1582 } |
1594 |
1583 |
1595 assert(result.get_type() == T_OBJECT, "just checking"); |
1584 assert(result.get_type() == T_OBJECT, "just checking"); |
1596 oop obj = (oop) result.get_jobject(); |
1585 oop obj = (oop) result.get_jobject(); |
1597 |
1586 |
1598 // Primitive classes return null since forName() can not be |
1587 // Primitive classes return null since forName() can not be |
1599 // used to obtain any of the Class objects representing primitives or void |
1588 // used to obtain any of the Class objects representing primitives or void |
1600 if ((obj != NULL) && !(java_lang_Class::is_primitive(obj))) { |
1589 if ((obj != NULL) && !(java_lang_Class::is_primitive(obj))) { |
1601 instanceKlassHandle k = |
1590 InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(obj)); |
1602 instanceKlassHandle(THREAD, java_lang_Class::as_Klass(obj)); |
|
1603 // For user defined Java class loaders, check that the name returned is |
1591 // For user defined Java class loaders, check that the name returned is |
1604 // the same as that requested. This check is done for the bootstrap |
1592 // the same as that requested. This check is done for the bootstrap |
1605 // loader when parsing the class file. |
1593 // loader when parsing the class file. |
1606 if (class_name == k->name()) { |
1594 if (class_name == k->name()) { |
1607 return k; |
1595 return k; |
1608 } |
1596 } |
1609 } |
1597 } |
1610 // Class is not found or has the wrong name, return NULL |
1598 // Class is not found or has the wrong name, return NULL |
1611 return nh; |
1599 return NULL; |
1612 } |
1600 } |
1613 } |
1601 } |
1614 |
1602 |
1615 void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) { |
1603 void SystemDictionary::define_instance_class(InstanceKlass* k, TRAPS) { |
1616 |
1604 |
1617 HandleMark hm(THREAD); |
1605 HandleMark hm(THREAD); |
1618 ClassLoaderData* loader_data = k->class_loader_data(); |
1606 ClassLoaderData* loader_data = k->class_loader_data(); |
1619 Handle class_loader_h(THREAD, loader_data->class_loader()); |
1607 Handle class_loader_h(THREAD, loader_data->class_loader()); |
1620 |
1608 |
1701 // Note: VM callers should ensure consistency of k/class_name,class_loader |
1689 // Note: VM callers should ensure consistency of k/class_name,class_loader |
1702 // Be careful when modifying this code: once you have run |
1690 // Be careful when modifying this code: once you have run |
1703 // placeholders()->find_and_add(PlaceholderTable::DEFINE_CLASS), |
1691 // placeholders()->find_and_add(PlaceholderTable::DEFINE_CLASS), |
1704 // you need to find_and_remove it before returning. |
1692 // you need to find_and_remove it before returning. |
1705 // So be careful to not exit with a CHECK_ macro betweeen these calls. |
1693 // So be careful to not exit with a CHECK_ macro betweeen these calls. |
1706 instanceKlassHandle SystemDictionary::find_or_define_instance_class(Symbol* class_name, Handle class_loader, instanceKlassHandle k, TRAPS) { |
1694 InstanceKlass* SystemDictionary::find_or_define_instance_class(Symbol* class_name, Handle class_loader, |
1707 |
1695 InstanceKlass* k, TRAPS) { |
1708 instanceKlassHandle nh = instanceKlassHandle(); // null Handle |
1696 |
1709 Symbol* name_h = k->name(); // passed in class_name may be null |
1697 Symbol* name_h = k->name(); // passed in class_name may be null |
1710 ClassLoaderData* loader_data = class_loader_data(class_loader); |
1698 ClassLoaderData* loader_data = class_loader_data(class_loader); |
1711 |
1699 |
1712 unsigned int d_hash = dictionary()->compute_hash(name_h, loader_data); |
1700 unsigned int d_hash = dictionary()->compute_hash(name_h, loader_data); |
1713 int d_index = dictionary()->hash_to_index(d_hash); |
1701 int d_index = dictionary()->hash_to_index(d_hash); |
1714 |
1702 |
1715 // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS |
1703 // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS |
1716 unsigned int p_hash = placeholders()->compute_hash(name_h, loader_data); |
1704 unsigned int p_hash = placeholders()->compute_hash(name_h, loader_data); |
1717 int p_index = placeholders()->hash_to_index(p_hash); |
1705 int p_index = placeholders()->hash_to_index(p_hash); |
1718 PlaceholderEntry* probe; |
1706 PlaceholderEntry* probe; |
1719 |
1707 |
1720 { |
1708 { |
1721 MutexLocker mu(SystemDictionary_lock, THREAD); |
1709 MutexLocker mu(SystemDictionary_lock, THREAD); |
1722 // First check if class already defined |
1710 // First check if class already defined |
1723 if (UnsyncloadClass || (is_parallelDefine(class_loader))) { |
1711 if (UnsyncloadClass || (is_parallelDefine(class_loader))) { |
1724 Klass* check = find_class(d_index, d_hash, name_h, loader_data); |
1712 InstanceKlass* check = find_class(d_index, d_hash, name_h, loader_data); |
1725 if (check != NULL) { |
1713 if (check != NULL) { |
1726 return(instanceKlassHandle(THREAD, check)); |
1714 return check; |
1727 } |
1715 } |
1728 } |
1716 } |
1729 |
1717 |
1730 // Acquire define token for this class/classloader |
1718 // Acquire define token for this class/classloader |
1731 probe = placeholders()->find_and_add(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, NULL, THREAD); |
1719 probe = placeholders()->find_and_add(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, NULL, THREAD); |
1741 // caught by finding an entry in the SystemDictionary |
1729 // caught by finding an entry in the SystemDictionary |
1742 if ((UnsyncloadClass || is_parallelDefine(class_loader)) && (probe->instance_klass() != NULL)) { |
1730 if ((UnsyncloadClass || is_parallelDefine(class_loader)) && (probe->instance_klass() != NULL)) { |
1743 placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD); |
1731 placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD); |
1744 SystemDictionary_lock->notify_all(); |
1732 SystemDictionary_lock->notify_all(); |
1745 #ifdef ASSERT |
1733 #ifdef ASSERT |
1746 Klass* check = find_class(d_index, d_hash, name_h, loader_data); |
1734 InstanceKlass* check = find_class(d_index, d_hash, name_h, loader_data); |
1747 assert(check != NULL, "definer missed recording success"); |
1735 assert(check != NULL, "definer missed recording success"); |
1748 #endif |
1736 #endif |
1749 return(instanceKlassHandle(THREAD, probe->instance_klass())); |
1737 return probe->instance_klass(); |
1750 } else { |
1738 } else { |
1751 // This thread will define the class (even if earlier thread tried and had an error) |
1739 // This thread will define the class (even if earlier thread tried and had an error) |
1752 probe->set_definer(THREAD); |
1740 probe->set_definer(THREAD); |
1753 } |
1741 } |
1754 } |
1742 } |
1765 if (probe != NULL) { |
1753 if (probe != NULL) { |
1766 if (HAS_PENDING_EXCEPTION) { |
1754 if (HAS_PENDING_EXCEPTION) { |
1767 linkage_exception = Handle(THREAD,PENDING_EXCEPTION); |
1755 linkage_exception = Handle(THREAD,PENDING_EXCEPTION); |
1768 CLEAR_PENDING_EXCEPTION; |
1756 CLEAR_PENDING_EXCEPTION; |
1769 } else { |
1757 } else { |
1770 probe->set_instance_klass(k()); |
1758 probe->set_instance_klass(k); |
1771 } |
1759 } |
1772 probe->set_definer(NULL); |
1760 probe->set_definer(NULL); |
1773 placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD); |
1761 placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD); |
1774 SystemDictionary_lock->notify_all(); |
1762 SystemDictionary_lock->notify_all(); |
1775 } |
1763 } |
1776 } |
1764 } |
1777 |
1765 |
1778 // Can't throw exception while holding lock due to rank ordering |
1766 // Can't throw exception while holding lock due to rank ordering |
1779 if (linkage_exception() != NULL) { |
1767 if (linkage_exception() != NULL) { |
1780 THROW_OOP_(linkage_exception(), nh); // throws exception and returns |
1768 THROW_OOP_(linkage_exception(), NULL); // throws exception and returns |
1781 } |
1769 } |
1782 |
1770 |
1783 return k; |
1771 return k; |
1784 } |
1772 } |
1785 Handle SystemDictionary::compute_loader_lock_object(Handle class_loader, TRAPS) { |
1773 Handle SystemDictionary::compute_loader_lock_object(Handle class_loader, TRAPS) { |
1815 } |
1803 } |
1816 |
1804 |
1817 // ---------------------------------------------------------------------------- |
1805 // ---------------------------------------------------------------------------- |
1818 // Lookup |
1806 // Lookup |
1819 |
1807 |
1820 Klass* SystemDictionary::find_class(int index, unsigned int hash, |
1808 InstanceKlass* SystemDictionary::find_class(int index, unsigned int hash, |
1821 Symbol* class_name, |
1809 Symbol* class_name, |
1822 ClassLoaderData* loader_data) { |
1810 ClassLoaderData* loader_data) { |
1823 assert_locked_or_safepoint(SystemDictionary_lock); |
1811 assert_locked_or_safepoint(SystemDictionary_lock); |
1824 assert (index == dictionary()->index_for(class_name, loader_data), |
1812 assert (index == dictionary()->index_for(class_name, loader_data), |
1825 "incorrect index?"); |
1813 "incorrect index?"); |
1826 |
1814 |
1827 Klass* k = dictionary()->find_class(index, hash, class_name, loader_data); |
1815 return dictionary()->find_class(index, hash, class_name, loader_data); |
1828 return k; |
|
1829 } |
1816 } |
1830 |
1817 |
1831 |
1818 |
1832 // Basic find on classes in the midst of being loaded |
1819 // Basic find on classes in the midst of being loaded |
1833 Symbol* SystemDictionary::find_placeholder(Symbol* class_name, |
1820 Symbol* SystemDictionary::find_placeholder(Symbol* class_name, |
1866 // ---------------------------------------------------------------------------- |
1853 // ---------------------------------------------------------------------------- |
1867 // Update hierachy. This is done before the new klass has been added to the SystemDictionary. The Recompile_lock |
1854 // Update hierachy. This is done before the new klass has been added to the SystemDictionary. The Recompile_lock |
1868 // is held, to ensure that the compiler is not using the class hierachy, and that deoptimization will kick in |
1855 // is held, to ensure that the compiler is not using the class hierachy, and that deoptimization will kick in |
1869 // before a new class is used. |
1856 // before a new class is used. |
1870 |
1857 |
1871 void SystemDictionary::add_to_hierarchy(instanceKlassHandle k, TRAPS) { |
1858 void SystemDictionary::add_to_hierarchy(InstanceKlass* k, TRAPS) { |
1872 assert(k.not_null(), "just checking"); |
1859 assert(k != NULL, "just checking"); |
1873 assert_locked_or_safepoint(Compile_lock); |
1860 assert_locked_or_safepoint(Compile_lock); |
1874 |
1861 |
1875 // Link into hierachy. Make sure the vtables are initialized before linking into |
1862 // Link into hierachy. Make sure the vtables are initialized before linking into |
1876 k->append_to_sibling_list(); // add to superklass/sibling list |
1863 k->append_to_sibling_list(); // add to superklass/sibling list |
1877 k->process_interfaces(THREAD); // handle all "implements" declarations |
1864 k->process_interfaces(THREAD); // handle all "implements" declarations |
2148 WKID scan = FIRST_WKID; |
2135 WKID scan = FIRST_WKID; |
2149 // first do Object, then String, Class |
2136 // first do Object, then String, Class |
2150 if (UseSharedSpaces) { |
2137 if (UseSharedSpaces) { |
2151 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Object_klass), scan, CHECK); |
2138 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Object_klass), scan, CHECK); |
2152 // Initialize the constant pool for the Object_class |
2139 // Initialize the constant pool for the Object_class |
2153 InstanceKlass* ik = InstanceKlass::cast(Object_klass()); |
2140 Object_klass()->constants()->restore_unshareable_info(CHECK); |
2154 ik->constants()->restore_unshareable_info(CHECK); |
|
2155 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK); |
2141 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK); |
2156 } else { |
2142 } else { |
2157 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK); |
2143 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK); |
2158 } |
2144 } |
2159 |
2145 |
2229 // must be satisfied by all classes in the dictionary. |
2215 // must be satisfied by all classes in the dictionary. |
2230 // if defining is true, then LinkageError if already in systemDictionary |
2216 // if defining is true, then LinkageError if already in systemDictionary |
2231 // if initiating loader, then ok if InstanceKlass matches existing entry |
2217 // if initiating loader, then ok if InstanceKlass matches existing entry |
2232 |
2218 |
2233 void SystemDictionary::check_constraints(int d_index, unsigned int d_hash, |
2219 void SystemDictionary::check_constraints(int d_index, unsigned int d_hash, |
2234 instanceKlassHandle k, |
2220 InstanceKlass* k, |
2235 Handle class_loader, bool defining, |
2221 Handle class_loader, bool defining, |
2236 TRAPS) { |
2222 TRAPS) { |
2237 const char *linkage_error1 = NULL; |
2223 const char *linkage_error1 = NULL; |
2238 const char *linkage_error2 = NULL; |
2224 const char *linkage_error2 = NULL; |
2239 { |
2225 { |
2240 Symbol* name = k->name(); |
2226 Symbol* name = k->name(); |
2241 ClassLoaderData *loader_data = class_loader_data(class_loader); |
2227 ClassLoaderData *loader_data = class_loader_data(class_loader); |
2242 |
2228 |
2243 MutexLocker mu(SystemDictionary_lock, THREAD); |
2229 MutexLocker mu(SystemDictionary_lock, THREAD); |
2244 |
2230 |
2245 Klass* check = find_class(d_index, d_hash, name, loader_data); |
2231 InstanceKlass* check = find_class(d_index, d_hash, name, loader_data); |
2246 if (check != (Klass*)NULL) { |
2232 if (check != NULL) { |
2247 // if different InstanceKlass - duplicate class definition, |
2233 // if different InstanceKlass - duplicate class definition, |
2248 // else - ok, class loaded by a different thread in parallel, |
2234 // else - ok, class loaded by a different thread in parallel, |
2249 // we should only have found it if it was done loading and ok to use |
2235 // we should only have found it if it was done loading and ok to use |
2250 // system dictionary only holds instance classes, placeholders |
2236 // system dictionary only holds instance classes, placeholders |
2251 // also holds array classes |
2237 // also holds array classes |
2252 |
2238 |
2253 assert(check->is_instance_klass(), "noninstance in systemdictionary"); |
2239 assert(check->is_instance_klass(), "noninstance in systemdictionary"); |
2254 if ((defining == true) || (k() != check)) { |
2240 if ((defining == true) || (k != check)) { |
2255 linkage_error1 = "loader (instance of "; |
2241 linkage_error1 = "loader (instance of "; |
2256 linkage_error2 = "): attempted duplicate class definition for name: \""; |
2242 linkage_error2 = "): attempted duplicate class definition for name: \""; |
2257 } else { |
2243 } else { |
2258 return; |
2244 return; |
2259 } |
2245 } |
2260 } |
2246 } |
2261 |
2247 |
2290 |
2276 |
2291 // Update system dictionary - done after check_constraint and add_to_hierachy |
2277 // Update system dictionary - done after check_constraint and add_to_hierachy |
2292 // have been called. |
2278 // have been called. |
2293 void SystemDictionary::update_dictionary(int d_index, unsigned int d_hash, |
2279 void SystemDictionary::update_dictionary(int d_index, unsigned int d_hash, |
2294 int p_index, unsigned int p_hash, |
2280 int p_index, unsigned int p_hash, |
2295 instanceKlassHandle k, |
2281 InstanceKlass* k, |
2296 Handle class_loader, |
2282 Handle class_loader, |
2297 TRAPS) { |
2283 TRAPS) { |
2298 // Compile_lock prevents systemDictionary updates during compilations |
2284 // Compile_lock prevents systemDictionary updates during compilations |
2299 assert_locked_or_safepoint(Compile_lock); |
2285 assert_locked_or_safepoint(Compile_lock); |
2300 Symbol* name = k->name(); |
2286 Symbol* name = k->name(); |
2413 MutexLocker mu_s(SystemDictionary_lock, THREAD); |
2399 MutexLocker mu_s(SystemDictionary_lock, THREAD); |
2414 |
2400 |
2415 // Better never do a GC while we're holding these oops |
2401 // Better never do a GC while we're holding these oops |
2416 NoSafepointVerifier nosafepoint; |
2402 NoSafepointVerifier nosafepoint; |
2417 |
2403 |
2418 Klass* klass1 = find_class(d_index1, d_hash1, constraint_name, loader_data1); |
2404 InstanceKlass* klass1 = find_class(d_index1, d_hash1, constraint_name, loader_data1); |
2419 Klass* klass2 = find_class(d_index2, d_hash2, constraint_name, loader_data2); |
2405 InstanceKlass* klass2 = find_class(d_index2, d_hash2, constraint_name, loader_data2); |
2420 return constraints()->add_entry(constraint_name, klass1, class_loader1, |
2406 return constraints()->add_entry(constraint_name, klass1, class_loader1, |
2421 klass2, class_loader2); |
2407 klass2, class_loader2); |
2422 } |
2408 } |
2423 } |
2409 } |
2424 |
2410 |
2574 return spe->method(); |
2560 return spe->method(); |
2575 } |
2561 } |
2576 |
2562 |
2577 // Helper for unpacking the return value from linkMethod and linkCallSite. |
2563 // Helper for unpacking the return value from linkMethod and linkCallSite. |
2578 static methodHandle unpack_method_and_appendix(Handle mname, |
2564 static methodHandle unpack_method_and_appendix(Handle mname, |
2579 KlassHandle accessing_klass, |
2565 Klass* accessing_klass, |
2580 objArrayHandle appendix_box, |
2566 objArrayHandle appendix_box, |
2581 Handle* appendix_result, |
2567 Handle* appendix_result, |
2582 TRAPS) { |
2568 TRAPS) { |
2583 methodHandle empty; |
2569 methodHandle empty; |
2584 if (mname.not_null()) { |
2570 if (mname.not_null()) { |
2598 (*appendix_result) = Handle(THREAD, appendix); |
2584 (*appendix_result) = Handle(THREAD, appendix); |
2599 // the target is stored in the cpCache and if a reference to this |
2585 // the target is stored in the cpCache and if a reference to this |
2600 // MethodName is dropped we need a way to make sure the |
2586 // MethodName is dropped we need a way to make sure the |
2601 // class_loader containing this method is kept alive. |
2587 // class_loader containing this method is kept alive. |
2602 // FIXME: the appendix might also preserve this dependency. |
2588 // FIXME: the appendix might also preserve this dependency. |
2603 ClassLoaderData* this_key = InstanceKlass::cast(accessing_klass())->class_loader_data(); |
2589 ClassLoaderData* this_key = accessing_klass->class_loader_data(); |
2604 this_key->record_dependency(m->method_holder(), CHECK_NULL); // Can throw OOM |
2590 this_key->record_dependency(m->method_holder(), CHECK_NULL); // Can throw OOM |
2605 return methodHandle(THREAD, m); |
2591 return methodHandle(THREAD, m); |
2606 } |
2592 } |
2607 } |
2593 } |
2608 THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad value from MethodHandleNatives", empty); |
2594 THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad value from MethodHandleNatives", empty); |
2609 return empty; |
2595 return empty; |
2610 } |
2596 } |
2611 |
2597 |
2612 methodHandle SystemDictionary::find_method_handle_invoker(KlassHandle klass, |
2598 methodHandle SystemDictionary::find_method_handle_invoker(Klass* klass, |
2613 Symbol* name, |
2599 Symbol* name, |
2614 Symbol* signature, |
2600 Symbol* signature, |
2615 KlassHandle accessing_klass, |
2601 Klass* accessing_klass, |
2616 Handle *appendix_result, |
2602 Handle *appendix_result, |
2617 Handle *method_type_result, |
2603 Handle *method_type_result, |
2618 TRAPS) { |
2604 TRAPS) { |
2619 methodHandle empty; |
2605 methodHandle empty; |
2620 assert(THREAD->can_call_java() ,""); |
2606 assert(THREAD->can_call_java() ,""); |
2626 Handle name_str (THREAD, name_oop); |
2612 Handle name_str (THREAD, name_oop); |
2627 objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_(empty)); |
2613 objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_(empty)); |
2628 assert(appendix_box->obj_at(0) == NULL, ""); |
2614 assert(appendix_box->obj_at(0) == NULL, ""); |
2629 |
2615 |
2630 // This should not happen. JDK code should take care of that. |
2616 // This should not happen. JDK code should take care of that. |
2631 if (accessing_klass.is_null() || method_type.is_null()) { |
2617 if (accessing_klass == NULL || method_type.is_null()) { |
2632 THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokehandle", empty); |
2618 THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokehandle", empty); |
2633 } |
2619 } |
2634 |
2620 |
2635 // call java.lang.invoke.MethodHandleNatives::linkMethod(... String, MethodType) -> MemberName |
2621 // call java.lang.invoke.MethodHandleNatives::linkMethod(... String, MethodType) -> MemberName |
2636 JavaCallArguments args; |
2622 JavaCallArguments args; |
2637 args.push_oop(Handle(THREAD, accessing_klass()->java_mirror())); |
2623 args.push_oop(Handle(THREAD, accessing_klass->java_mirror())); |
2638 args.push_int(ref_kind); |
2624 args.push_int(ref_kind); |
2639 args.push_oop(Handle(THREAD, klass()->java_mirror())); |
2625 args.push_oop(Handle(THREAD, klass->java_mirror())); |
2640 args.push_oop(name_str); |
2626 args.push_oop(name_str); |
2641 args.push_oop(method_type); |
2627 args.push_oop(method_type); |
2642 args.push_oop(appendix_box); |
2628 args.push_oop(appendix_box); |
2643 JavaValue result(T_OBJECT); |
2629 JavaValue result(T_OBJECT); |
2644 JavaCalls::call_static(&result, |
2630 JavaCalls::call_static(&result, |
2673 // Ask Java code to find or construct a java.lang.invoke.MethodType for the given |
2659 // Ask Java code to find or construct a java.lang.invoke.MethodType for the given |
2674 // signature, as interpreted relative to the given class loader. |
2660 // signature, as interpreted relative to the given class loader. |
2675 // Because of class loader constraints, all method handle usage must be |
2661 // Because of class loader constraints, all method handle usage must be |
2676 // consistent with this loader. |
2662 // consistent with this loader. |
2677 Handle SystemDictionary::find_method_handle_type(Symbol* signature, |
2663 Handle SystemDictionary::find_method_handle_type(Symbol* signature, |
2678 KlassHandle accessing_klass, |
2664 Klass* accessing_klass, |
2679 TRAPS) { |
2665 TRAPS) { |
2680 Handle empty; |
2666 Handle empty; |
2681 vmIntrinsics::ID null_iid = vmIntrinsics::_none; // distinct from all method handle invoker intrinsics |
2667 vmIntrinsics::ID null_iid = vmIntrinsics::_none; // distinct from all method handle invoker intrinsics |
2682 unsigned int hash = invoke_method_table()->compute_hash(signature, null_iid); |
2668 unsigned int hash = invoke_method_table()->compute_hash(signature, null_iid); |
2683 int index = invoke_method_table()->hash_to_index(hash); |
2669 int index = invoke_method_table()->hash_to_index(hash); |
2689 warning("SystemDictionary::find_method_handle_type called from compiler thread"); // FIXME |
2675 warning("SystemDictionary::find_method_handle_type called from compiler thread"); // FIXME |
2690 return Handle(); // do not attempt from within compiler, unless it was cached |
2676 return Handle(); // do not attempt from within compiler, unless it was cached |
2691 } |
2677 } |
2692 |
2678 |
2693 Handle class_loader, protection_domain; |
2679 Handle class_loader, protection_domain; |
2694 if (accessing_klass.not_null()) { |
2680 if (accessing_klass != NULL) { |
2695 class_loader = Handle(THREAD, InstanceKlass::cast(accessing_klass())->class_loader()); |
2681 class_loader = Handle(THREAD, accessing_klass->class_loader()); |
2696 protection_domain = Handle(THREAD, InstanceKlass::cast(accessing_klass())->protection_domain()); |
2682 protection_domain = Handle(THREAD, accessing_klass->protection_domain()); |
2697 } |
2683 } |
2698 bool can_be_cached = true; |
2684 bool can_be_cached = true; |
2699 int npts = ArgumentCount(signature).size(); |
2685 int npts = ArgumentCount(signature).size(); |
2700 objArrayHandle pts = oopFactory::new_objArray_handle(SystemDictionary::Class_klass(), npts, CHECK_(empty)); |
2686 objArrayHandle pts = oopFactory::new_objArray_handle(SystemDictionary::Class_klass(), npts, CHECK_(empty)); |
2701 int arg = 0; |
2687 int arg = 0; |
2722 rt = Handle(THREAD, mirror); |
2708 rt = Handle(THREAD, mirror); |
2723 else |
2709 else |
2724 pts->obj_at_put(arg++, mirror); |
2710 pts->obj_at_put(arg++, mirror); |
2725 |
2711 |
2726 // Check accessibility. |
2712 // Check accessibility. |
2727 if (ss.is_object() && accessing_klass.not_null()) { |
2713 if (ss.is_object() && accessing_klass != NULL) { |
2728 Klass* sel_klass = java_lang_Class::as_Klass(mirror); |
2714 Klass* sel_klass = java_lang_Class::as_Klass(mirror); |
2729 mirror = NULL; // safety |
2715 mirror = NULL; // safety |
2730 // Emulate ConstantPool::verify_constant_pool_resolve. |
2716 // Emulate ConstantPool::verify_constant_pool_resolve. |
2731 if (sel_klass->is_objArray_klass()) |
2717 if (sel_klass->is_objArray_klass()) |
2732 sel_klass = ObjArrayKlass::cast(sel_klass)->bottom_klass(); |
2718 sel_klass = ObjArrayKlass::cast(sel_klass)->bottom_klass(); |
2733 if (sel_klass->is_instance_klass()) { |
2719 if (sel_klass->is_instance_klass()) { |
2734 KlassHandle sel_kh(THREAD, sel_klass); |
2720 LinkResolver::check_klass_accessability(accessing_klass, sel_klass, CHECK_(empty)); |
2735 LinkResolver::check_klass_accessability(accessing_klass, sel_kh, CHECK_(empty)); |
|
2736 } |
2721 } |
2737 } |
2722 } |
2738 } |
2723 } |
2739 assert(arg == npts, ""); |
2724 assert(arg == npts, ""); |
2740 |
2725 |
2763 // report back to the caller with the MethodType |
2748 // report back to the caller with the MethodType |
2764 return method_type; |
2749 return method_type; |
2765 } |
2750 } |
2766 |
2751 |
2767 // Ask Java code to find or construct a method handle constant. |
2752 // Ask Java code to find or construct a method handle constant. |
2768 Handle SystemDictionary::link_method_handle_constant(KlassHandle caller, |
2753 Handle SystemDictionary::link_method_handle_constant(Klass* caller, |
2769 int ref_kind, //e.g., JVM_REF_invokeVirtual |
2754 int ref_kind, //e.g., JVM_REF_invokeVirtual |
2770 KlassHandle callee, |
2755 Klass* callee, |
2771 Symbol* name_sym, |
2756 Symbol* name_sym, |
2772 Symbol* signature, |
2757 Symbol* signature, |
2773 TRAPS) { |
2758 TRAPS) { |
2774 Handle empty; |
2759 Handle empty; |
2775 Handle name = java_lang_String::create_from_symbol(name_sym, CHECK_(empty)); |
2760 Handle name = java_lang_String::create_from_symbol(name_sym, CHECK_(empty)); |
2776 Handle type; |
2761 Handle type; |
2777 if (signature->utf8_length() > 0 && signature->byte_at(0) == '(') { |
2762 if (signature->utf8_length() > 0 && signature->byte_at(0) == '(') { |
2778 type = find_method_handle_type(signature, caller, CHECK_(empty)); |
2763 type = find_method_handle_type(signature, caller, CHECK_(empty)); |
2779 } else if (caller.is_null()) { |
2764 } else if (caller == NULL) { |
2780 // This should not happen. JDK code should take care of that. |
2765 // This should not happen. JDK code should take care of that. |
2781 THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad MH constant", empty); |
2766 THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad MH constant", empty); |
2782 } else { |
2767 } else { |
2783 ResourceMark rm(THREAD); |
2768 ResourceMark rm(THREAD); |
2784 SignatureStream ss(signature, false); |
2769 SignatureStream ss(signature, false); |
2811 return Handle(THREAD, (oop) result.get_jobject()); |
2796 return Handle(THREAD, (oop) result.get_jobject()); |
2812 } |
2797 } |
2813 |
2798 |
2814 // Ask Java code to find or construct a java.lang.invoke.CallSite for the given |
2799 // Ask Java code to find or construct a java.lang.invoke.CallSite for the given |
2815 // name and signature, as interpreted relative to the given class loader. |
2800 // name and signature, as interpreted relative to the given class loader. |
2816 methodHandle SystemDictionary::find_dynamic_call_site_invoker(KlassHandle caller, |
2801 methodHandle SystemDictionary::find_dynamic_call_site_invoker(Klass* caller, |
2817 Handle bootstrap_specifier, |
2802 Handle bootstrap_specifier, |
2818 Symbol* name, |
2803 Symbol* name, |
2819 Symbol* type, |
2804 Symbol* type, |
2820 Handle *appendix_result, |
2805 Handle *appendix_result, |
2821 Handle *method_type_result, |
2806 Handle *method_type_result, |
2842 |
2827 |
2843 Handle method_name = java_lang_String::create_from_symbol(name, CHECK_(empty)); |
2828 Handle method_name = java_lang_String::create_from_symbol(name, CHECK_(empty)); |
2844 Handle method_type = find_method_handle_type(type, caller, CHECK_(empty)); |
2829 Handle method_type = find_method_handle_type(type, caller, CHECK_(empty)); |
2845 |
2830 |
2846 // This should not happen. JDK code should take care of that. |
2831 // This should not happen. JDK code should take care of that. |
2847 if (caller.is_null() || method_type.is_null()) { |
2832 if (caller == NULL || method_type.is_null()) { |
2848 THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokedynamic", empty); |
2833 THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokedynamic", empty); |
2849 } |
2834 } |
2850 |
2835 |
2851 objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_(empty)); |
2836 objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_(empty)); |
2852 assert(appendix_box->obj_at(0) == NULL, ""); |
2837 assert(appendix_box->obj_at(0) == NULL, ""); |