Mercurial > hg > graal-compiler
comparison src/share/vm/classfile/systemDictionary.cpp @ 7582:aefb345d3f5e
7199207: NPG: Crash in PlaceholderTable::verify after StackOverflow
Summary: Reduce scope of placeholder table entries to improve cleanup
Reviewed-by: dholmes, coleenp
author | acorn |
---|---|
date | Thu, 10 Jan 2013 17:38:20 -0500 |
parents | 90273fc0a981 |
children | 3ac7d10a6572 8b46b0196eb0 |
comparison
equal
deleted
inserted
replaced
7581:97ee8abd6ab2 | 7582:aefb345d3f5e |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
170 if (throw_error && PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass())) { | 170 if (throw_error && PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass())) { |
171 ResourceMark rm(THREAD); | 171 ResourceMark rm(THREAD); |
172 assert(klass_h() == NULL, "Should not have result with exception pending"); | 172 assert(klass_h() == NULL, "Should not have result with exception pending"); |
173 Handle e(THREAD, PENDING_EXCEPTION); | 173 Handle e(THREAD, PENDING_EXCEPTION); |
174 CLEAR_PENDING_EXCEPTION; | 174 CLEAR_PENDING_EXCEPTION; |
175 THROW_MSG_CAUSE_0(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string(), e); | 175 THROW_MSG_CAUSE_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string(), e); |
176 } else { | 176 } else { |
177 return NULL; | 177 return NULL; |
178 } | 178 } |
179 } | 179 } |
180 // Class not found, throw appropriate error or exception depending on value of throw_error | 180 // Class not found, throw appropriate error or exception depending on value of throw_error |
181 if (klass_h() == NULL) { | 181 if (klass_h() == NULL) { |
182 ResourceMark rm(THREAD); | 182 ResourceMark rm(THREAD); |
183 if (throw_error) { | 183 if (throw_error) { |
184 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string()); | 184 THROW_MSG_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string()); |
185 } else { | 185 } else { |
186 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string()); | 186 THROW_MSG_NULL(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string()); |
187 } | 187 } |
188 } | 188 } |
189 return (Klass*)klass_h(); | 189 return (Klass*)klass_h(); |
190 } | 190 } |
191 | 191 |
341 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, class_name, THREAD); | 341 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, class_name, THREAD); |
342 } | 342 } |
343 } | 343 } |
344 if (throw_circularity_error) { | 344 if (throw_circularity_error) { |
345 ResourceMark rm(THREAD); | 345 ResourceMark rm(THREAD); |
346 THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string()); | 346 THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string()); |
347 } | 347 } |
348 | 348 |
349 // java.lang.Object should have been found above | 349 // java.lang.Object should have been found above |
350 assert(class_name != NULL, "null super class for resolving"); | 350 assert(class_name != NULL, "null super class for resolving"); |
351 // Resolve the super class or interface, check results on return | 351 // Resolve the super class or interface, check results on return |
352 Klass* superk = NULL; | 352 Klass* superk = SystemDictionary::resolve_or_null(class_name, |
353 superk = SystemDictionary::resolve_or_null(class_name, | |
354 class_loader, | 353 class_loader, |
355 protection_domain, | 354 protection_domain, |
356 THREAD); | 355 THREAD); |
357 | 356 |
358 KlassHandle superk_h(THREAD, superk); | 357 KlassHandle superk_h(THREAD, superk); |
359 | 358 |
360 // Note: clean up of placeholders currently in callers of | 359 // Clean up of placeholders moved so that each classloadAction registrar self-cleans up |
361 // resolve_super_or_fail - either at update_dictionary time | 360 // It is no longer necessary to keep the placeholder table alive until update_dictionary |
362 // or on error | 361 // or error. GC used to walk the placeholder table as strong roots. |
362 // The instanceKlass is kept alive because the class loader is on the stack, | |
363 // which keeps the loader_data alive, as well as all instanceKlasses in | |
364 // the loader_data. parseClassFile adds the instanceKlass to loader_data. | |
363 { | 365 { |
364 MutexLocker mu(SystemDictionary_lock, THREAD); | 366 MutexLocker mu(SystemDictionary_lock, THREAD); |
365 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, loader_data); | 367 placeholders()->find_and_remove(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD); |
366 if (probe != NULL) { | 368 SystemDictionary_lock->notify_all(); |
367 probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER); | |
368 } | |
369 } | 369 } |
370 if (HAS_PENDING_EXCEPTION || superk_h() == NULL) { | 370 if (HAS_PENDING_EXCEPTION || superk_h() == NULL) { |
371 // can null superk | 371 // can null superk |
372 superk_h = KlassHandle(THREAD, handle_resolution_exception(class_name, class_loader, protection_domain, true, superk_h, THREAD)); | 372 superk_h = KlassHandle(THREAD, handle_resolution_exception(class_name, class_loader, protection_domain, true, superk_h, THREAD)); |
373 } | 373 } |
428 // Note that we have an entry, and entries can be deleted only during GC, | 428 // Note that we have an entry, and entries can be deleted only during GC, |
429 // so we cannot allow GC to occur while we're holding this entry. | 429 // so we cannot allow GC to occur while we're holding this entry. |
430 | 430 |
431 // We're using a No_Safepoint_Verifier to catch any place where we | 431 // We're using a No_Safepoint_Verifier to catch any place where we |
432 // might potentially do a GC at all. | 432 // might potentially do a GC at all. |
433 // SystemDictionary::do_unloading() asserts that classes are only | 433 // Dictionary::do_unloading() asserts that classes in SD are only |
434 // unloaded at a safepoint. | 434 // unloaded at a safepoint. Anonymous classes are not in SD. |
435 No_Safepoint_Verifier nosafepoint; | 435 No_Safepoint_Verifier nosafepoint; |
436 dictionary()->add_protection_domain(d_index, d_hash, klass, loader_data, | 436 dictionary()->add_protection_domain(d_index, d_hash, klass, loader_data, |
437 protection_domain, THREAD); | 437 protection_domain, THREAD); |
438 } | 438 } |
439 } | 439 } |
484 // is critical to ClassCircularity detection that we try loading | 484 // is critical to ClassCircularity detection that we try loading |
485 // the superclass on the same thread internally, so we do parallel | 485 // the superclass on the same thread internally, so we do parallel |
486 // super class loading here. | 486 // super class loading here. |
487 // This also is critical in cases where the original thread gets stalled | 487 // This also is critical in cases where the original thread gets stalled |
488 // even in non-circularity situations. | 488 // even in non-circularity situations. |
489 // Note: only one thread can define the class, but multiple can resolve | |
490 // Note: must call resolve_super_or_fail even if null super - | 489 // Note: must call resolve_super_or_fail even if null super - |
491 // to force placeholder entry creation for this class for circularity detection | 490 // to force placeholder entry creation for this class for circularity detection |
492 // Caller must check for pending exception | 491 // Caller must check for pending exception |
493 // Returns non-null Klass* if other thread has completed load | 492 // Returns non-null Klass* if other thread has completed load |
494 // and we are done, | 493 // and we are done, |
516 superclassname, | 515 superclassname, |
517 class_loader, | 516 class_loader, |
518 protection_domain, | 517 protection_domain, |
519 true, | 518 true, |
520 CHECK_(nh)); | 519 CHECK_(nh)); |
521 // We don't redefine the class, so we just need to clean up if there | |
522 // was not an error (don't want to modify any system dictionary | |
523 // data structures). | |
524 { | |
525 MutexLocker mu(SystemDictionary_lock, THREAD); | |
526 placeholders()->find_and_remove(p_index, p_hash, name, loader_data, THREAD); | |
527 SystemDictionary_lock->notify_all(); | |
528 } | |
529 | 520 |
530 // parallelCapable class loaders do NOT wait for parallel superclass loads to complete | 521 // parallelCapable class loaders do NOT wait for parallel superclass loads to complete |
531 // Serial class loaders and bootstrap classloader do wait for superclass loads | 522 // Serial class loaders and bootstrap classloader do wait for superclass loads |
532 if (!class_loader.is_null() && is_parallelCapable(class_loader)) { | 523 if (!class_loader.is_null() && is_parallelCapable(class_loader)) { |
533 MutexLocker mu(SystemDictionary_lock, THREAD); | 524 MutexLocker mu(SystemDictionary_lock, THREAD); |
593 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); | 584 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); |
594 ClassLoaderData *loader_data = register_loader(class_loader, CHECK_NULL); | 585 ClassLoaderData *loader_data = register_loader(class_loader, CHECK_NULL); |
595 | 586 |
596 // Do lookup to see if class already exist and the protection domain | 587 // Do lookup to see if class already exist and the protection domain |
597 // has the right access | 588 // has the right access |
589 // This call uses find which checks protection domain already matches | |
590 // All subsequent calls use find_class, and set has_loaded_class so that | |
591 // before we return a result we call out to java to check for valid protection domain | |
592 // to allow returning the Klass* and add it to the pd_set if it is valid | |
598 unsigned int d_hash = dictionary()->compute_hash(name, loader_data); | 593 unsigned int d_hash = dictionary()->compute_hash(name, loader_data); |
599 int d_index = dictionary()->hash_to_index(d_hash); | 594 int d_index = dictionary()->hash_to_index(d_hash); |
600 Klass* probe = dictionary()->find(d_index, d_hash, name, loader_data, | 595 Klass* probe = dictionary()->find(d_index, d_hash, name, loader_data, |
601 protection_domain, THREAD); | 596 protection_domain, THREAD); |
602 if (probe != NULL) return probe; | 597 if (probe != NULL) return probe; |
650 } | 645 } |
651 } | 646 } |
652 } | 647 } |
653 } | 648 } |
654 | 649 |
655 // If the class in is in the placeholder table, class loading is in progress | 650 // If the class is in the placeholder table, class loading is in progress |
656 if (super_load_in_progress && havesupername==true) { | 651 if (super_load_in_progress && havesupername==true) { |
657 k = SystemDictionary::handle_parallel_super_load(name, superclassname, | 652 k = SystemDictionary::handle_parallel_super_load(name, superclassname, |
658 class_loader, protection_domain, lockObject, THREAD); | 653 class_loader, protection_domain, lockObject, THREAD); |
659 if (HAS_PENDING_EXCEPTION) { | 654 if (HAS_PENDING_EXCEPTION) { |
660 return NULL; | 655 return NULL; |
662 if (!k.is_null()) { | 657 if (!k.is_null()) { |
663 class_has_been_loaded = true; | 658 class_has_been_loaded = true; |
664 } | 659 } |
665 } | 660 } |
666 | 661 |
662 bool throw_circularity_error = false; | |
667 if (!class_has_been_loaded) { | 663 if (!class_has_been_loaded) { |
664 bool load_instance_added = false; | |
668 | 665 |
669 // add placeholder entry to record loading instance class | 666 // add placeholder entry to record loading instance class |
670 // Five cases: | 667 // Five cases: |
671 // All cases need to prevent modifying bootclasssearchpath | 668 // All cases need to prevent modifying bootclasssearchpath |
672 // in parallel with a classload of same classname | 669 // in parallel with a classload of same classname |
688 // This classloader supports parallelism at the classloader level, | 685 // This classloader supports parallelism at the classloader level, |
689 // but only allows a single load of a class/classloader pair. | 686 // but only allows a single load of a class/classloader pair. |
690 // No performance benefit and no deadlock issues. | 687 // No performance benefit and no deadlock issues. |
691 // case 5. parallelCapable user level classloaders - without objectLocker | 688 // case 5. parallelCapable user level classloaders - without objectLocker |
692 // Allow parallel classloading of a class/classloader pair | 689 // Allow parallel classloading of a class/classloader pair |
693 bool throw_circularity_error = false; | 690 |
694 { | 691 { |
695 MutexLocker mu(SystemDictionary_lock, THREAD); | 692 MutexLocker mu(SystemDictionary_lock, THREAD); |
696 if (class_loader.is_null() || !is_parallelCapable(class_loader)) { | 693 if (class_loader.is_null() || !is_parallelCapable(class_loader)) { |
697 PlaceholderEntry* oldprobe = placeholders()->get_entry(p_index, p_hash, name, loader_data); | 694 PlaceholderEntry* oldprobe = placeholders()->get_entry(p_index, p_hash, name, loader_data); |
698 if (oldprobe) { | 695 if (oldprobe) { |
724 oldprobe = placeholders()->get_entry(p_index, p_hash, name, loader_data); | 721 oldprobe = placeholders()->get_entry(p_index, p_hash, name, loader_data); |
725 } | 722 } |
726 } | 723 } |
727 } | 724 } |
728 } | 725 } |
729 // All cases: add LOAD_INSTANCE | 726 // All cases: add LOAD_INSTANCE holding SystemDictionary_lock |
730 // case 3: UnsyncloadClass || case 5: parallelCapable: allow competing threads to try | 727 // case 3: UnsyncloadClass || case 5: parallelCapable: allow competing threads to try |
731 // LOAD_INSTANCE in parallel | 728 // LOAD_INSTANCE in parallel |
732 // add placeholder entry even if error - callers will remove on error | 729 |
733 if (!throw_circularity_error && !class_has_been_loaded) { | 730 if (!throw_circularity_error && !class_has_been_loaded) { |
734 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, name, loader_data, PlaceholderTable::LOAD_INSTANCE, NULL, THREAD); | 731 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, name, loader_data, PlaceholderTable::LOAD_INSTANCE, NULL, THREAD); |
732 load_instance_added = true; | |
735 // For class loaders that do not acquire the classloader object lock, | 733 // For class loaders that do not acquire the classloader object lock, |
736 // if they did not catch another thread holding LOAD_INSTANCE, | 734 // if they did not catch another thread holding LOAD_INSTANCE, |
737 // need a check analogous to the acquire ObjectLocker/find_class | 735 // need a check analogous to the acquire ObjectLocker/find_class |
738 // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL | 736 // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL |
739 // one final check if the load has already completed | 737 // one final check if the load has already completed |
740 // class loaders holding the ObjectLock shouldn't find the class here | 738 // class loaders holding the ObjectLock shouldn't find the class here |
741 Klass* check = find_class(d_index, d_hash, name, loader_data); | 739 Klass* check = find_class(d_index, d_hash, name, loader_data); |
742 if (check != NULL) { | 740 if (check != NULL) { |
743 // Klass is already loaded, so just return it | 741 // Klass is already loaded, so return it after checking/adding protection domain |
744 k = instanceKlassHandle(THREAD, check); | 742 k = instanceKlassHandle(THREAD, check); |
745 class_has_been_loaded = true; | 743 class_has_been_loaded = true; |
746 newprobe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE); | |
747 placeholders()->find_and_remove(p_index, p_hash, name, loader_data, THREAD); | |
748 SystemDictionary_lock->notify_all(); | |
749 } | 744 } |
750 } | 745 } |
751 } | 746 } |
747 | |
752 // must throw error outside of owning lock | 748 // must throw error outside of owning lock |
753 if (throw_circularity_error) { | 749 if (throw_circularity_error) { |
750 assert(!HAS_PENDING_EXCEPTION && load_instance_added == false,"circularity error cleanup"); | |
754 ResourceMark rm(THREAD); | 751 ResourceMark rm(THREAD); |
755 THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), name->as_C_string()); | 752 THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), name->as_C_string()); |
756 } | 753 } |
757 | 754 |
758 if (!class_has_been_loaded) { | 755 if (!class_has_been_loaded) { |
759 | 756 |
760 // Do actual loading | 757 // Do actual loading |
780 guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?"); | 777 guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?"); |
781 } | 778 } |
782 } | 779 } |
783 } | 780 } |
784 | 781 |
785 // clean up placeholder entries for success or error | |
786 // This cleans up LOAD_INSTANCE entries | |
787 // It also cleans up LOAD_SUPER entries on errors from | |
788 // calling load_instance_class | |
789 { | |
790 MutexLocker mu(SystemDictionary_lock, THREAD); | |
791 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name, loader_data); | |
792 if (probe != NULL) { | |
793 probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE); | |
794 placeholders()->find_and_remove(p_index, p_hash, name, loader_data, THREAD); | |
795 SystemDictionary_lock->notify_all(); | |
796 } | |
797 } | |
798 | |
799 // If everything was OK (no exceptions, no null return value), and | 782 // If everything was OK (no exceptions, no null return value), and |
800 // class_loader is NOT the defining loader, do a little more bookkeeping. | 783 // class_loader is NOT the defining loader, do a little more bookkeeping. |
801 if (!HAS_PENDING_EXCEPTION && !k.is_null() && | 784 if (!HAS_PENDING_EXCEPTION && !k.is_null() && |
802 k->class_loader() != class_loader()) { | 785 k->class_loader() != class_loader()) { |
803 | 786 |
817 assert(thread->is_Java_thread(), "thread->is_Java_thread()"); | 800 assert(thread->is_Java_thread(), "thread->is_Java_thread()"); |
818 JvmtiExport::post_class_load((JavaThread *) thread, k()); | 801 JvmtiExport::post_class_load((JavaThread *) thread, k()); |
819 } | 802 } |
820 } | 803 } |
821 } | 804 } |
822 if (HAS_PENDING_EXCEPTION || k.is_null()) { | 805 } // load_instance_class loop |
823 // On error, clean up placeholders | 806 |
824 { | 807 if (load_instance_added == true) { |
825 MutexLocker mu(SystemDictionary_lock, THREAD); | 808 // clean up placeholder entries for LOAD_INSTANCE success or error |
826 placeholders()->find_and_remove(p_index, p_hash, name, loader_data, THREAD); | 809 // This brackets the SystemDictionary updates for both defining |
827 SystemDictionary_lock->notify_all(); | 810 // and initiating loaders |
828 } | 811 MutexLocker mu(SystemDictionary_lock, THREAD); |
829 return NULL; | 812 placeholders()->find_and_remove(p_index, p_hash, name, loader_data, PlaceholderTable::LOAD_INSTANCE, THREAD); |
830 } | 813 SystemDictionary_lock->notify_all(); |
831 } | 814 } |
815 } | |
816 | |
817 if (HAS_PENDING_EXCEPTION || k.is_null()) { | |
818 return NULL; | |
832 } | 819 } |
833 | 820 |
834 #ifdef ASSERT | 821 #ifdef ASSERT |
835 { | 822 { |
836 ClassLoaderData* loader_data = k->class_loader_data(); | 823 ClassLoaderData* loader_data = k->class_loader_data(); |
848 MutexLocker mu(SystemDictionary_lock, THREAD); | 835 MutexLocker mu(SystemDictionary_lock, THREAD); |
849 // Note that we have an entry, and entries can be deleted only during GC, | 836 // Note that we have an entry, and entries can be deleted only during GC, |
850 // so we cannot allow GC to occur while we're holding this entry. | 837 // so we cannot allow GC to occur while we're holding this entry. |
851 // We're using a No_Safepoint_Verifier to catch any place where we | 838 // We're using a No_Safepoint_Verifier to catch any place where we |
852 // might potentially do a GC at all. | 839 // might potentially do a GC at all. |
853 // SystemDictionary::do_unloading() asserts that classes are only | 840 // Dictionary::do_unloading() asserts that classes in SD are only |
854 // unloaded at a safepoint. | 841 // unloaded at a safepoint. Anonymous classes are not in SD. |
855 No_Safepoint_Verifier nosafepoint; | 842 No_Safepoint_Verifier nosafepoint; |
856 if (dictionary()->is_valid_protection_domain(d_index, d_hash, name, | 843 if (dictionary()->is_valid_protection_domain(d_index, d_hash, name, |
857 loader_data, | 844 loader_data, |
858 protection_domain)) { | 845 protection_domain)) { |
859 return k(); | 846 return k(); |
896 { | 883 { |
897 // Note that we have an entry, and entries can be deleted only during GC, | 884 // Note that we have an entry, and entries can be deleted only during GC, |
898 // so we cannot allow GC to occur while we're holding this entry. | 885 // so we cannot allow GC to occur while we're holding this entry. |
899 // We're using a No_Safepoint_Verifier to catch any place where we | 886 // We're using a No_Safepoint_Verifier to catch any place where we |
900 // might potentially do a GC at all. | 887 // might potentially do a GC at all. |
901 // SystemDictionary::do_unloading() asserts that classes are only | 888 // Dictionary::do_unloading() asserts that classes in SD are only |
902 // unloaded at a safepoint. | 889 // unloaded at a safepoint. Anonymous classes are not in SD. |
903 No_Safepoint_Verifier nosafepoint; | 890 No_Safepoint_Verifier nosafepoint; |
904 return dictionary()->find(d_index, d_hash, class_name, loader_data, | 891 return dictionary()->find(d_index, d_hash, class_name, loader_data, |
905 protection_domain, THREAD); | 892 protection_domain, THREAD); |
906 } | 893 } |
907 } | 894 } |
963 // Parse the stream. Note that we do this even though this klass might | 950 // Parse the stream. Note that we do this even though this klass might |
964 // already be present in the SystemDictionary, otherwise we would not | 951 // already be present in the SystemDictionary, otherwise we would not |
965 // throw potential ClassFormatErrors. | 952 // throw potential ClassFormatErrors. |
966 // | 953 // |
967 // Note: "name" is updated. | 954 // Note: "name" is updated. |
968 // Further note: a placeholder will be added for this class when | |
969 // super classes are loaded (resolve_super_or_fail). We expect this | |
970 // to be called for all classes but java.lang.Object; and we preload | |
971 // java.lang.Object through resolve_or_fail, not this path. | |
972 | 955 |
973 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name, | 956 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name, |
974 loader_data, | 957 loader_data, |
975 protection_domain, | 958 protection_domain, |
976 host_klass, | 959 host_klass, |
977 cp_patches, | 960 cp_patches, |
978 parsed_name, | 961 parsed_name, |
979 true, | 962 true, |
980 THREAD); | 963 THREAD); |
981 | 964 |
982 // We don't redefine the class, so we just need to clean up whether there | |
983 // was an error or not (don't want to modify any system dictionary | |
984 // data structures). | |
985 // Parsed name could be null if we threw an error before we got far | |
986 // enough along to parse it -- in that case, there is nothing to clean up. | |
987 if (parsed_name != NULL) { | |
988 unsigned int p_hash = placeholders()->compute_hash(parsed_name, | |
989 loader_data); | |
990 int p_index = placeholders()->hash_to_index(p_hash); | |
991 { | |
992 MutexLocker mu(SystemDictionary_lock, THREAD); | |
993 placeholders()->find_and_remove(p_index, p_hash, parsed_name, loader_data, THREAD); | |
994 SystemDictionary_lock->notify_all(); | |
995 } | |
996 } | |
997 | 965 |
998 if (host_klass.not_null() && k.not_null()) { | 966 if (host_klass.not_null() && k.not_null()) { |
999 assert(EnableInvokeDynamic, ""); | 967 assert(EnableInvokeDynamic, ""); |
1000 k->set_host_klass(host_klass()); | 968 k->set_host_klass(host_klass()); |
1001 // If it's anonymous, initialize it now, since nobody else will. | 969 // If it's anonymous, initialize it now, since nobody else will. |
1060 // Parse the stream. Note that we do this even though this klass might | 1028 // Parse the stream. Note that we do this even though this klass might |
1061 // already be present in the SystemDictionary, otherwise we would not | 1029 // already be present in the SystemDictionary, otherwise we would not |
1062 // throw potential ClassFormatErrors. | 1030 // throw potential ClassFormatErrors. |
1063 // | 1031 // |
1064 // Note: "name" is updated. | 1032 // Note: "name" is updated. |
1065 // Further note: a placeholder will be added for this class when | |
1066 // super classes are loaded (resolve_super_or_fail). We expect this | |
1067 // to be called for all classes but java.lang.Object; and we preload | |
1068 // java.lang.Object through resolve_or_fail, not this path. | |
1069 | 1033 |
1070 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name, | 1034 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name, |
1071 loader_data, | 1035 loader_data, |
1072 protection_domain, | 1036 protection_domain, |
1073 parsed_name, | 1037 parsed_name, |
1112 } else { | 1076 } else { |
1113 define_instance_class(k, THREAD); | 1077 define_instance_class(k, THREAD); |
1114 } | 1078 } |
1115 } | 1079 } |
1116 | 1080 |
1117 // If parsing the class file or define_instance_class failed, we | 1081 // Make sure we have an entry in the SystemDictionary on success |
1118 // need to remove the placeholder added on our behalf. But we | |
1119 // must make sure parsed_name is valid first (it won't be if we had | |
1120 // a format error before the class was parsed far enough to | |
1121 // find the name). | |
1122 if (HAS_PENDING_EXCEPTION && parsed_name != NULL) { | |
1123 unsigned int p_hash = placeholders()->compute_hash(parsed_name, | |
1124 loader_data); | |
1125 int p_index = placeholders()->hash_to_index(p_hash); | |
1126 { | |
1127 MutexLocker mu(SystemDictionary_lock, THREAD); | |
1128 placeholders()->find_and_remove(p_index, p_hash, parsed_name, loader_data, THREAD); | |
1129 SystemDictionary_lock->notify_all(); | |
1130 } | |
1131 return NULL; | |
1132 } | |
1133 | |
1134 // Make sure that we didn't leave a place holder in the | |
1135 // SystemDictionary; this is only done on success | |
1136 debug_only( { | 1082 debug_only( { |
1137 if (!HAS_PENDING_EXCEPTION) { | 1083 if (!HAS_PENDING_EXCEPTION) { |
1138 assert(parsed_name != NULL, "parsed_name is still null?"); | 1084 assert(parsed_name != NULL, "parsed_name is still null?"); |
1139 Symbol* h_name = k->name(); | 1085 Symbol* h_name = k->name(); |
1140 ClassLoaderData *defining_loader_data = k->class_loader_data(); | 1086 ClassLoaderData *defining_loader_data = k->class_loader_data(); |
1545 } | 1491 } |
1546 // Only special cases allow parallel defines and can use other thread's results | 1492 // Only special cases allow parallel defines and can use other thread's results |
1547 // Other cases fall through, and may run into duplicate defines | 1493 // Other cases fall through, and may run into duplicate defines |
1548 // caught by finding an entry in the SystemDictionary | 1494 // caught by finding an entry in the SystemDictionary |
1549 if ((UnsyncloadClass || is_parallelDefine(class_loader)) && (probe->instance_klass() != NULL)) { | 1495 if ((UnsyncloadClass || is_parallelDefine(class_loader)) && (probe->instance_klass() != NULL)) { |
1550 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS); | 1496 placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD); |
1551 placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, THREAD); | |
1552 SystemDictionary_lock->notify_all(); | 1497 SystemDictionary_lock->notify_all(); |
1553 #ifdef ASSERT | 1498 #ifdef ASSERT |
1554 Klass* check = find_class(d_index, d_hash, name_h, loader_data); | 1499 Klass* check = find_class(d_index, d_hash, name_h, loader_data); |
1555 assert(check != NULL, "definer missed recording success"); | 1500 assert(check != NULL, "definer missed recording success"); |
1556 #endif | 1501 #endif |
1576 CLEAR_PENDING_EXCEPTION; | 1521 CLEAR_PENDING_EXCEPTION; |
1577 } else { | 1522 } else { |
1578 probe->set_instance_klass(k()); | 1523 probe->set_instance_klass(k()); |
1579 } | 1524 } |
1580 probe->set_definer(NULL); | 1525 probe->set_definer(NULL); |
1581 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS); | 1526 placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD); |
1582 placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, THREAD); | |
1583 SystemDictionary_lock->notify_all(); | 1527 SystemDictionary_lock->notify_all(); |
1584 } | 1528 } |
1585 } | 1529 } |
1586 | 1530 |
1587 // Can't throw exception while holding lock due to rank ordering | 1531 // Can't throw exception while holding lock due to rank ordering |
1734 } | 1678 } |
1735 } | 1679 } |
1736 } | 1680 } |
1737 return newsize; | 1681 return newsize; |
1738 } | 1682 } |
1683 // Assumes classes in the SystemDictionary are only unloaded at a safepoint | |
1684 // Note: anonymous classes are not in the SD. | |
1739 bool SystemDictionary::do_unloading(BoolObjectClosure* is_alive) { | 1685 bool SystemDictionary::do_unloading(BoolObjectClosure* is_alive) { |
1740 // First, mark for unload all ClassLoaderData referencing a dead class loader. | 1686 // First, mark for unload all ClassLoaderData referencing a dead class loader. |
1741 bool has_dead_loaders = ClassLoaderDataGraph::do_unloading(is_alive); | 1687 bool has_dead_loaders = ClassLoaderDataGraph::do_unloading(is_alive); |
1742 bool unloading_occurred = false; | 1688 bool unloading_occurred = false; |
1743 if (has_dead_loaders) { | 1689 if (has_dead_loaders) { |
2103 // counter does not need to be atomically incremented since this | 2049 // counter does not need to be atomically incremented since this |
2104 // is only done while holding the SystemDictionary_lock. | 2050 // is only done while holding the SystemDictionary_lock. |
2105 // All loaded classes get a unique ID. | 2051 // All loaded classes get a unique ID. |
2106 TRACE_INIT_ID(k); | 2052 TRACE_INIT_ID(k); |
2107 | 2053 |
2108 // Check for a placeholder. If there, remove it and make a | 2054 // Make a new system dictionary entry. |
2109 // new system dictionary entry. | |
2110 placeholders()->find_and_remove(p_index, p_hash, name, loader_data, THREAD); | |
2111 Klass* sd_check = find_class(d_index, d_hash, name, loader_data); | 2055 Klass* sd_check = find_class(d_index, d_hash, name, loader_data); |
2112 if (sd_check == NULL) { | 2056 if (sd_check == NULL) { |
2113 dictionary()->add_klass(name, loader_data, k); | 2057 dictionary()->add_klass(name, loader_data, k); |
2114 notice_modification(); | 2058 notice_modification(); |
2115 } | 2059 } |
2116 #ifdef ASSERT | 2060 #ifdef ASSERT |
2117 sd_check = find_class(d_index, d_hash, name, loader_data); | 2061 sd_check = find_class(d_index, d_hash, name, loader_data); |
2118 assert (sd_check != NULL, "should have entry in system dictionary"); | 2062 assert (sd_check != NULL, "should have entry in system dictionary"); |
2119 // Changed to allow PH to remain to complete class circularity checking | 2063 // Note: there may be a placeholder entry: for circularity testing |
2120 // while only one thread can define a class at one time, multiple | 2064 // or for parallel defines |
2121 // classes can resolve the superclass for a class at one time, | |
2122 // and the placeholder is used to track that | |
2123 // Symbol* ph_check = find_placeholder(name, class_loader); | |
2124 // assert (ph_check == NULL, "should not have a placeholder entry"); | |
2125 #endif | 2065 #endif |
2126 SystemDictionary_lock->notify_all(); | 2066 SystemDictionary_lock->notify_all(); |
2127 } | 2067 } |
2128 } | 2068 } |
2129 | 2069 |