1 /*
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
89 #endif
90
91 PlaceholderTable* SystemDictionary::_placeholders = NULL;
92 Dictionary* SystemDictionary::_shared_dictionary = NULL;
93 LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL;
94 ResolutionErrorTable* SystemDictionary::_resolution_errors = NULL;
95 SymbolPropertyTable* SystemDictionary::_invoke_method_table = NULL;
96 ProtectionDomainCacheTable* SystemDictionary::_pd_cache_table = NULL;
97
98 int SystemDictionary::_number_of_modifications = 0;
99 oop SystemDictionary::_system_loader_lock_obj = NULL;
100
101 InstanceKlass* SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
102 = { NULL /*, NULL...*/ };
103
104 InstanceKlass* SystemDictionary::_box_klasses[T_VOID+1] = { NULL /*, NULL...*/ };
105
106 oop SystemDictionary::_java_system_loader = NULL;
107 oop SystemDictionary::_java_platform_loader = NULL;
108
109 bool SystemDictionary::_has_loadClassInternal = false;
110 bool SystemDictionary::_has_checkPackageAccess = false;
111
112 // lazily initialized klass variables
113 InstanceKlass* volatile SystemDictionary::_abstract_ownable_synchronizer_klass = NULL;
114
115 // Default ProtectionDomainCacheSize value
116
117 const int defaultProtectionDomainCacheSize = 1009;
118
119
120 // ----------------------------------------------------------------------------
121 // Java-level SystemLoader and PlatformLoader
122
123 oop SystemDictionary::java_system_loader() {
124 return _java_system_loader;
125 }
126
127 oop SystemDictionary::java_platform_loader() {
128 return _java_platform_loader;
129 }
142 JavaCalls::call_static(&result,
143 class_loader_klass,
144 vmSymbols::getPlatformClassLoader_name(),
145 vmSymbols::void_classloader_signature(),
146 CHECK);
147
148 _java_platform_loader = (oop)result.get_jobject();
149
150 CDS_ONLY(SystemDictionaryShared::initialize(CHECK);)
151 }
152
153 ClassLoaderData* SystemDictionary::register_loader(Handle class_loader, TRAPS) {
154 if (class_loader() == NULL) return ClassLoaderData::the_null_class_loader_data();
155 return ClassLoaderDataGraph::find_or_create(class_loader, THREAD);
156 }
157
158 // ----------------------------------------------------------------------------
159 // Parallel class loading check
160
161 bool SystemDictionary::is_parallelCapable(Handle class_loader) {
162 if (UnsyncloadClass || class_loader.is_null()) return true;
163 if (AlwaysLockClassLoader) return false;
164 return java_lang_ClassLoader::parallelCapable(class_loader());
165 }
166 // ----------------------------------------------------------------------------
167 // ParallelDefineClass flag does not apply to bootclass loader
168 bool SystemDictionary::is_parallelDefine(Handle class_loader) {
169 if (class_loader.is_null()) return false;
170 if (AllowParallelDefineClass && java_lang_ClassLoader::parallelCapable(class_loader())) {
171 return true;
172 }
173 return false;
174 }
175
176 // Returns true if the passed class loader is the builtin application class loader
177 // or a custom system class loader. A customer system class loader can be
178 // specified via -Djava.system.class.loader.
179 bool SystemDictionary::is_system_class_loader(oop class_loader) {
180 if (class_loader == NULL) {
181 return false;
182 }
486
487 Symbol* kn = klass->name();
488 unsigned int d_hash = dictionary->compute_hash(kn);
489
490 MutexLocker mu(SystemDictionary_lock, THREAD);
491 int d_index = dictionary->hash_to_index(d_hash);
492 dictionary->add_protection_domain(d_index, d_hash, klass,
493 protection_domain, THREAD);
494 }
495 }
496
497 // We only get here if this thread finds that another thread
498 // has already claimed the placeholder token for the current operation,
499 // but that other thread either never owned or gave up the
500 // object lock
501 // Waits on SystemDictionary_lock to indicate placeholder table updated
502 // On return, caller must recheck placeholder table state
503 //
504 // We only get here if
505 // 1) custom classLoader, i.e. not bootstrap classloader
506 // 2) UnsyncloadClass not set
507 // 3) custom classLoader has broken the class loader objectLock
508 // so another thread got here in parallel
509 //
510 // lockObject must be held.
511 // Complicated dance due to lock ordering:
512 // Must first release the classloader object lock to
513 // allow initial definer to complete the class definition
514 // and to avoid deadlock
515 // Reclaim classloader lock object with same original recursion count
516 // Must release SystemDictionary_lock after notify, since
517 // class loader lock must be claimed before SystemDictionary_lock
518 // to prevent deadlocks
519 //
520 // The notify allows applications that did an untimed wait() on
521 // the classloader object lock to not hang.
522 void SystemDictionary::double_lock_wait(Handle lockObject, TRAPS) {
523 assert_lock_strong(SystemDictionary_lock);
524
525 bool calledholdinglock
526 = ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, lockObject);
527 assert(calledholdinglock,"must hold lock for notify");
577 if (!class_loader.is_null() && is_parallelCapable(class_loader)) {
578 MutexLocker mu(SystemDictionary_lock, THREAD);
579 // Check if classloading completed while we were loading superclass or waiting
580 return find_class(d_hash, name, dictionary);
581 }
582
583 // must loop to both handle other placeholder updates
584 // and spurious notifications
585 bool super_load_in_progress = true;
586 PlaceholderEntry* placeholder;
587 while (super_load_in_progress) {
588 MutexLocker mu(SystemDictionary_lock, THREAD);
589 // Check if classloading completed while we were loading superclass or waiting
590 InstanceKlass* check = find_class(d_hash, name, dictionary);
591 if (check != NULL) {
592 // Klass is already loaded, so just return it
593 return check;
594 } else {
595 placeholder = placeholders()->get_entry(p_index, p_hash, name, loader_data);
596 if (placeholder && placeholder->super_load_in_progress() ){
597 // Before UnsyncloadClass:
598 // We only get here if the application has released the
599 // classloader lock when another thread was in the middle of loading a
600 // superclass/superinterface for this class, and now
601 // this thread is also trying to load this class.
602 // To minimize surprises, the first thread that started to
603 // load a class should be the one to complete the loading
604 // with the classfile it initially expected.
605 // This logic has the current thread wait once it has done
606 // all the superclass/superinterface loading it can, until
607 // the original thread completes the class loading or fails
608 // If it completes we will use the resulting InstanceKlass
609 // which we will find below in the systemDictionary.
610 // We also get here for parallel bootstrap classloader
611 if (class_loader.is_null()) {
612 SystemDictionary_lock->wait();
613 } else {
614 double_lock_wait(lockObject, THREAD);
615 }
616 } else {
617 // If not in SD and not in PH, other thread's load must have failed
670 Dictionary* dictionary = loader_data->dictionary();
671 unsigned int d_hash = dictionary->compute_hash(name);
672
673 // Do lookup to see if class already exist and the protection domain
674 // has the right access
675 // This call uses find which checks protection domain already matches
676 // All subsequent calls use find_class, and set has_loaded_class so that
677 // before we return a result we call out to java to check for valid protection domain
678 // to allow returning the Klass* and add it to the pd_set if it is valid
679 {
680 Klass* probe = dictionary->find(d_hash, name, protection_domain);
681 if (probe != NULL) return probe;
682 }
683
684 // Non-bootstrap class loaders will call out to class loader and
685 // define via jvm/jni_DefineClass which will acquire the
686 // class loader object lock to protect against multiple threads
687 // defining the class in parallel by accident.
688 // This lock must be acquired here so the waiter will find
689 // any successful result in the SystemDictionary and not attempt
690 // the define
691 // ParallelCapable Classloaders and the bootstrap classloader,
692 // or all classloaders with UnsyncloadClass do not acquire lock here
693 bool DoObjectLock = true;
694 if (is_parallelCapable(class_loader)) {
695 DoObjectLock = false;
696 }
697
698 unsigned int p_hash = placeholders()->compute_hash(name);
699 int p_index = placeholders()->hash_to_index(p_hash);
700
701 // Class is not in SystemDictionary so we have to do loading.
702 // Make sure we are synchronized on the class loader before we proceed
703 Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
704 check_loader_lock_contention(lockObject, THREAD);
705 ObjectLocker ol(lockObject, THREAD, DoObjectLock);
706
707 // Check again (after locking) if class already exist in SystemDictionary
708 bool class_has_been_loaded = false;
709 bool super_load_in_progress = false;
710 bool havesupername = false;
711 InstanceKlass* k = NULL;
712 PlaceholderEntry* placeholder;
748
749 bool throw_circularity_error = false;
750 if (!class_has_been_loaded) {
751 bool load_instance_added = false;
752
753 // add placeholder entry to record loading instance class
754 // Five cases:
755 // All cases need to prevent modifying bootclasssearchpath
756 // in parallel with a classload of same classname
757 // Redefineclasses uses existence of the placeholder for the duration
758 // of the class load to prevent concurrent redefinition of not completely
759 // defined classes.
760 // case 1. traditional classloaders that rely on the classloader object lock
761 // - no other need for LOAD_INSTANCE
762 // case 2. traditional classloaders that break the classloader object lock
763 // as a deadlock workaround. Detection of this case requires that
764 // this check is done while holding the classloader object lock,
765 // and that lock is still held when calling classloader's loadClass.
766 // For these classloaders, we ensure that the first requestor
767 // completes the load and other requestors wait for completion.
768 // case 3. UnsyncloadClass - don't use objectLocker
769 // With this flag, we allow parallel classloading of a
770 // class/classloader pair
771 // case4. Bootstrap classloader - don't own objectLocker
772 // This classloader supports parallelism at the classloader level,
773 // but only allows a single load of a class/classloader pair.
774 // No performance benefit and no deadlock issues.
775 // case 5. parallelCapable user level classloaders - without objectLocker
776 // Allow parallel classloading of a class/classloader pair
777
778 {
779 MutexLocker mu(SystemDictionary_lock, THREAD);
780 if (class_loader.is_null() || !is_parallelCapable(class_loader)) {
781 PlaceholderEntry* oldprobe = placeholders()->get_entry(p_index, p_hash, name, loader_data);
782 if (oldprobe) {
783 // only need check_seen_thread once, not on each loop
784 // 6341374 java/lang/Instrument with -Xcomp
785 if (oldprobe->check_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE)) {
786 throw_circularity_error = true;
787 } else {
788 // case 1: traditional: should never see load_in_progress.
789 while (!class_has_been_loaded && oldprobe && oldprobe->instance_load_in_progress()) {
790
791 // case 4: bootstrap classloader: prevent futile classloading,
792 // wait on first requestor
793 if (class_loader.is_null()) {
794 SystemDictionary_lock->wait();
795 } else {
796 // case 2: traditional with broken classloader lock. wait on first
797 // requestor.
798 double_lock_wait(lockObject, THREAD);
799 }
800 // Check if classloading completed while we were waiting
801 InstanceKlass* check = find_class(d_hash, name, dictionary);
802 if (check != NULL) {
803 // Klass is already loaded, so just return it
804 k = check;
805 class_has_been_loaded = true;
806 }
807 // check if other thread failed to load and cleaned up
808 oldprobe = placeholders()->get_entry(p_index, p_hash, name, loader_data);
809 }
810 }
811 }
812 }
813 // All cases: add LOAD_INSTANCE holding SystemDictionary_lock
814 // case 3: UnsyncloadClass || case 5: parallelCapable: allow competing threads to try
815 // LOAD_INSTANCE in parallel
816
817 if (!throw_circularity_error && !class_has_been_loaded) {
818 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, name, loader_data, PlaceholderTable::LOAD_INSTANCE, NULL, THREAD);
819 load_instance_added = true;
820 // For class loaders that do not acquire the classloader object lock,
821 // if they did not catch another thread holding LOAD_INSTANCE,
822 // need a check analogous to the acquire ObjectLocker/find_class
823 // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL
824 // one final check if the load has already completed
825 // class loaders holding the ObjectLock shouldn't find the class here
826 InstanceKlass* check = find_class(d_hash, name, dictionary);
827 if (check != NULL) {
828 // Klass is already loaded, so return it after checking/adding protection domain
829 k = check;
830 class_has_been_loaded = true;
831 }
832 }
833 }
834
835 // must throw error outside of owning lock
836 if (throw_circularity_error) {
837 assert(!HAS_PENDING_EXCEPTION && load_instance_added == false,"circularity error cleanup");
838 ResourceMark rm(THREAD);
839 THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), name->as_C_string());
840 }
841
842 if (!class_has_been_loaded) {
843
844 // Do actual loading
845 k = load_instance_class(name, class_loader, THREAD);
846
847 // For UnsyncloadClass only
848 // If they got a linkageError, check if a parallel class load succeeded.
849 // If it did, then for bytecode resolution the specification requires
850 // that we return the same result we did for the other thread, i.e. the
851 // successfully loaded InstanceKlass
852 // Should not get here for classloaders that support parallelism
853 // with the new cleaner mechanism, even with AllowParallelDefineClass
854 // Bootstrap goes through here to allow for an extra guarantee check
855 if (UnsyncloadClass || (class_loader.is_null())) {
856 if (k == NULL && HAS_PENDING_EXCEPTION
857 && PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
858 MutexLocker mu(SystemDictionary_lock, THREAD);
859 InstanceKlass* check = find_class(d_hash, name, dictionary);
860 if (check != NULL) {
861 // Klass is already loaded, so just use it
862 k = check;
863 CLEAR_PENDING_EXCEPTION;
864 guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?");
865 }
866 }
867 }
868
869 // If everything was OK (no exceptions, no null return value), and
870 // class_loader is NOT the defining loader, do a little more bookkeeping.
871 if (!HAS_PENDING_EXCEPTION && k != NULL &&
872 k->class_loader() != class_loader()) {
873
874 check_constraints(d_hash, k, class_loader, false, THREAD);
875
876 // Need to check for a PENDING_EXCEPTION again; check_constraints
877 // can throw and doesn't use the CHECK macro.
878 if (!HAS_PENDING_EXCEPTION) {
879 { // Grabbing the Compile_lock prevents systemDictionary updates
880 // during compilations.
881 MutexLocker mu(Compile_lock, THREAD);
882 update_dictionary(d_hash, p_index, p_hash,
883 k, class_loader, THREAD);
884 }
885
886 if (JvmtiExport::should_post_class_load()) {
887 Thread *thread = THREAD;
888 assert(thread->is_Java_thread(), "thread->is_Java_thread()");
1080 // the class until we have parsed the stream.
1081
1082 InstanceKlass* SystemDictionary::resolve_from_stream(Symbol* class_name,
1083 Handle class_loader,
1084 Handle protection_domain,
1085 ClassFileStream* st,
1086 TRAPS) {
1087 #if INCLUDE_CDS
1088 ResourceMark rm(THREAD);
1089 if (DumpSharedSpaces && !class_loader.is_null() &&
1090 !UseAppCDS && strcmp(class_name->as_C_string(), "Unnamed") != 0) {
1091 // If AppCDS is not enabled, don't define the class at dump time (except for the "Unnamed"
1092 // class, which is used by MethodHandles).
1093 THROW_MSG_NULL(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string());
1094 }
1095 #endif
1096
1097 HandleMark hm(THREAD);
1098
1099 // Classloaders that support parallelism, e.g. bootstrap classloader,
1100 // or all classloaders with UnsyncloadClass do not acquire lock here
1101 bool DoObjectLock = true;
1102 if (is_parallelCapable(class_loader)) {
1103 DoObjectLock = false;
1104 }
1105
1106 ClassLoaderData* loader_data = register_loader(class_loader, CHECK_NULL);
1107
1108 // Make sure we are synchronized on the class loader before we proceed
1109 Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
1110 check_loader_lock_contention(lockObject, THREAD);
1111 ObjectLocker ol(lockObject, THREAD, DoObjectLock);
1112
1113 assert(st != NULL, "invariant");
1114
1115 // Parse the stream and create a klass.
1116 // Note that we do this even though this klass might
1117 // already be present in the SystemDictionary, otherwise we would not
1118 // throw potential ClassFormatErrors.
1119 InstanceKlass* k = NULL;
1120
1539 ResourceMark rm(THREAD);
1540
1541 assert(THREAD->is_Java_thread(), "must be a JavaThread");
1542 JavaThread* jt = (JavaThread*) THREAD;
1543
1544 PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(),
1545 ClassLoader::perf_app_classload_selftime(),
1546 ClassLoader::perf_app_classload_count(),
1547 jt->get_thread_stat()->perf_recursion_counts_addr(),
1548 jt->get_thread_stat()->perf_timers_addr(),
1549 PerfClassTraceTime::CLASS_LOAD);
1550
1551 Handle s = java_lang_String::create_from_symbol(class_name, CHECK_NULL);
1552 // Translate to external class name format, i.e., convert '/' chars to '.'
1553 Handle string = java_lang_String::externalize_classname(s, CHECK_NULL);
1554
1555 JavaValue result(T_OBJECT);
1556
1557 InstanceKlass* spec_klass = SystemDictionary::ClassLoader_klass();
1558
1559 // Call public unsynchronized loadClass(String) directly for all class loaders
1560 // for parallelCapable class loaders. JDK >=7, loadClass(String, boolean) will
1561 // acquire a class-name based lock rather than the class loader object lock.
1562 // JDK < 7 already acquire the class loader lock in loadClass(String, boolean),
1563 // so the call to loadClassInternal() was not required.
1564 //
1565 // UnsyncloadClass flag means both call loadClass(String) and do
1566 // not acquire the class loader lock even for class loaders that are
1567 // not parallelCapable. This was a risky transitional
1568 // flag for diagnostic purposes only. It is risky to call
1569 // custom class loaders without synchronization.
1570 // WARNING If a custom class loader does NOT synchronizer findClass, or callers of
1571 // findClass, the UnsyncloadClass flag risks unexpected timing bugs in the field.
1572 // Do NOT assume this will be supported in future releases.
1573 //
1574 // Added MustCallLoadClassInternal in case we discover in the field
1575 // a customer that counts on this call
1576 if (MustCallLoadClassInternal && has_loadClassInternal()) {
1577 JavaCalls::call_special(&result,
1578 class_loader,
1579 spec_klass,
1580 vmSymbols::loadClassInternal_name(),
1581 vmSymbols::string_class_signature(),
1582 string,
1583 CHECK_NULL);
1584 } else {
1585 JavaCalls::call_virtual(&result,
1586 class_loader,
1587 spec_klass,
1588 vmSymbols::loadClass_name(),
1589 vmSymbols::string_class_signature(),
1590 string,
1591 CHECK_NULL);
1592 }
1593
1594 assert(result.get_type() == T_OBJECT, "just checking");
1595 oop obj = (oop) result.get_jobject();
1596
1597 // Primitive classes return null since forName() can not be
1598 // used to obtain any of the Class objects representing primitives or void
1599 if ((obj != NULL) && !(java_lang_Class::is_primitive(obj))) {
1600 InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(obj));
1601 // For user defined Java class loaders, check that the name returned is
1602 // the same as that requested. This check is done for the bootstrap
1603 // loader when parsing the class file.
1604 if (class_name == k->name()) {
1605 return k;
1606 }
1607 }
1608 // Class is not found or has the wrong name, return NULL
1609 return NULL;
1610 }
1611 }
1612
1701 // placeholders()->find_and_add(PlaceholderTable::DEFINE_CLASS),
1702 // you need to find_and_remove it before returning.
1703 // So be careful to not exit with a CHECK_ macro betweeen these calls.
1704 InstanceKlass* SystemDictionary::find_or_define_instance_class(Symbol* class_name, Handle class_loader,
1705 InstanceKlass* k, TRAPS) {
1706
1707 Symbol* name_h = k->name(); // passed in class_name may be null
1708 ClassLoaderData* loader_data = class_loader_data(class_loader);
1709 Dictionary* dictionary = loader_data->dictionary();
1710
1711 unsigned int d_hash = dictionary->compute_hash(name_h);
1712
1713 // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS
1714 unsigned int p_hash = placeholders()->compute_hash(name_h);
1715 int p_index = placeholders()->hash_to_index(p_hash);
1716 PlaceholderEntry* probe;
1717
1718 {
1719 MutexLocker mu(SystemDictionary_lock, THREAD);
1720 // First check if class already defined
1721 if (UnsyncloadClass || (is_parallelDefine(class_loader))) {
1722 InstanceKlass* check = find_class(d_hash, name_h, dictionary);
1723 if (check != NULL) {
1724 return check;
1725 }
1726 }
1727
1728 // Acquire define token for this class/classloader
1729 probe = placeholders()->find_and_add(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, NULL, THREAD);
1730 // Wait if another thread defining in parallel
1731 // All threads wait - even those that will throw duplicate class: otherwise
1732 // caller is surprised by LinkageError: duplicate, but findLoadedClass fails
1733 // if other thread has not finished updating dictionary
1734 while (probe->definer() != NULL) {
1735 SystemDictionary_lock->wait();
1736 }
1737 // Only special cases allow parallel defines and can use other thread's results
1738 // Other cases fall through, and may run into duplicate defines
1739 // caught by finding an entry in the SystemDictionary
1740 if ((UnsyncloadClass || is_parallelDefine(class_loader)) && (probe->instance_klass() != NULL)) {
1741 placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD);
1742 SystemDictionary_lock->notify_all();
1743 #ifdef ASSERT
1744 InstanceKlass* check = find_class(d_hash, name_h, dictionary);
1745 assert(check != NULL, "definer missed recording success");
1746 #endif
1747 return probe->instance_klass();
1748 } else {
1749 // This thread will define the class (even if earlier thread tried and had an error)
1750 probe->set_definer(THREAD);
1751 }
1752 }
1753
1754 define_instance_class(k, THREAD);
1755
1756 Handle linkage_exception = Handle(); // null handle
1757
1758 // definer must notify any waiting threads
1759 {
1760 MutexLocker mu(SystemDictionary_lock, THREAD);
2157 InstanceKlass::cast(WK_KLASS(PhantomReference_klass))->set_reference_type(REF_PHANTOM);
2158
2159 // JSR 292 classes
2160 WKID jsr292_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass);
2161 WKID jsr292_group_end = WK_KLASS_ENUM_NAME(VolatileCallSite_klass);
2162 initialize_wk_klasses_until(jsr292_group_start, scan, CHECK);
2163 initialize_wk_klasses_through(jsr292_group_end, scan, CHECK);
2164 initialize_wk_klasses_until(NOT_JVMCI(WKID_LIMIT) JVMCI_ONLY(FIRST_JVMCI_WKID), scan, CHECK);
2165
2166 _box_klasses[T_BOOLEAN] = WK_KLASS(Boolean_klass);
2167 _box_klasses[T_CHAR] = WK_KLASS(Character_klass);
2168 _box_klasses[T_FLOAT] = WK_KLASS(Float_klass);
2169 _box_klasses[T_DOUBLE] = WK_KLASS(Double_klass);
2170 _box_klasses[T_BYTE] = WK_KLASS(Byte_klass);
2171 _box_klasses[T_SHORT] = WK_KLASS(Short_klass);
2172 _box_klasses[T_INT] = WK_KLASS(Integer_klass);
2173 _box_klasses[T_LONG] = WK_KLASS(Long_klass);
2174 //_box_klasses[T_OBJECT] = WK_KLASS(object_klass);
2175 //_box_klasses[T_ARRAY] = WK_KLASS(object_klass);
2176
2177 { // Compute whether we should use loadClass or loadClassInternal when loading classes.
2178 Method* method = InstanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::loadClassInternal_name(), vmSymbols::string_class_signature());
2179 _has_loadClassInternal = (method != NULL);
2180 }
2181 { // Compute whether we should use checkPackageAccess or NOT
2182 Method* method = InstanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature());
2183 _has_checkPackageAccess = (method != NULL);
2184 }
2185 }
2186
2187 // Tells if a given klass is a box (wrapper class, such as java.lang.Integer).
2188 // If so, returns the basic type it holds. If not, returns T_OBJECT.
2189 BasicType SystemDictionary::box_klass_type(Klass* k) {
2190 assert(k != NULL, "");
2191 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
2192 if (_box_klasses[i] == k)
2193 return (BasicType)i;
2194 }
2195 return T_OBJECT;
2196 }
2197
2198 // Constraints on class loaders. The details of the algorithm can be
2199 // found in the OOPSLA'98 paper "Dynamic Class Loading in the Java
2200 // Virtual Machine" by Sheng Liang and Gilad Bracha. The basic idea is
|
1 /*
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
89 #endif
90
91 PlaceholderTable* SystemDictionary::_placeholders = NULL;
92 Dictionary* SystemDictionary::_shared_dictionary = NULL;
93 LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL;
94 ResolutionErrorTable* SystemDictionary::_resolution_errors = NULL;
95 SymbolPropertyTable* SystemDictionary::_invoke_method_table = NULL;
96 ProtectionDomainCacheTable* SystemDictionary::_pd_cache_table = NULL;
97
98 int SystemDictionary::_number_of_modifications = 0;
99 oop SystemDictionary::_system_loader_lock_obj = NULL;
100
101 InstanceKlass* SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
102 = { NULL /*, NULL...*/ };
103
104 InstanceKlass* SystemDictionary::_box_klasses[T_VOID+1] = { NULL /*, NULL...*/ };
105
106 oop SystemDictionary::_java_system_loader = NULL;
107 oop SystemDictionary::_java_platform_loader = NULL;
108
109 bool SystemDictionary::_has_checkPackageAccess = false;
110
111 // lazily initialized klass variables
112 InstanceKlass* volatile SystemDictionary::_abstract_ownable_synchronizer_klass = NULL;
113
114 // Default ProtectionDomainCacheSize value
115
116 const int defaultProtectionDomainCacheSize = 1009;
117
118
119 // ----------------------------------------------------------------------------
120 // Java-level SystemLoader and PlatformLoader
121
122 oop SystemDictionary::java_system_loader() {
123 return _java_system_loader;
124 }
125
126 oop SystemDictionary::java_platform_loader() {
127 return _java_platform_loader;
128 }
141 JavaCalls::call_static(&result,
142 class_loader_klass,
143 vmSymbols::getPlatformClassLoader_name(),
144 vmSymbols::void_classloader_signature(),
145 CHECK);
146
147 _java_platform_loader = (oop)result.get_jobject();
148
149 CDS_ONLY(SystemDictionaryShared::initialize(CHECK);)
150 }
151
152 ClassLoaderData* SystemDictionary::register_loader(Handle class_loader, TRAPS) {
153 if (class_loader() == NULL) return ClassLoaderData::the_null_class_loader_data();
154 return ClassLoaderDataGraph::find_or_create(class_loader, THREAD);
155 }
156
157 // ----------------------------------------------------------------------------
158 // Parallel class loading check
159
160 bool SystemDictionary::is_parallelCapable(Handle class_loader) {
161 if (class_loader.is_null()) return true;
162 if (AlwaysLockClassLoader) return false;
163 return java_lang_ClassLoader::parallelCapable(class_loader());
164 }
165 // ----------------------------------------------------------------------------
166 // ParallelDefineClass flag does not apply to bootclass loader
167 bool SystemDictionary::is_parallelDefine(Handle class_loader) {
168 if (class_loader.is_null()) return false;
169 if (AllowParallelDefineClass && java_lang_ClassLoader::parallelCapable(class_loader())) {
170 return true;
171 }
172 return false;
173 }
174
175 // Returns true if the passed class loader is the builtin application class loader
176 // or a custom system class loader. A customer system class loader can be
177 // specified via -Djava.system.class.loader.
178 bool SystemDictionary::is_system_class_loader(oop class_loader) {
179 if (class_loader == NULL) {
180 return false;
181 }
485
486 Symbol* kn = klass->name();
487 unsigned int d_hash = dictionary->compute_hash(kn);
488
489 MutexLocker mu(SystemDictionary_lock, THREAD);
490 int d_index = dictionary->hash_to_index(d_hash);
491 dictionary->add_protection_domain(d_index, d_hash, klass,
492 protection_domain, THREAD);
493 }
494 }
495
496 // We only get here if this thread finds that another thread
497 // has already claimed the placeholder token for the current operation,
498 // but that other thread either never owned or gave up the
499 // object lock
500 // Waits on SystemDictionary_lock to indicate placeholder table updated
501 // On return, caller must recheck placeholder table state
502 //
503 // We only get here if
504 // 1) custom classLoader, i.e. not bootstrap classloader
505 // 2) custom classLoader has broken the class loader objectLock
506 // so another thread got here in parallel
507 //
508 // lockObject must be held.
509 // Complicated dance due to lock ordering:
510 // Must first release the classloader object lock to
511 // allow initial definer to complete the class definition
512 // and to avoid deadlock
513 // Reclaim classloader lock object with same original recursion count
514 // Must release SystemDictionary_lock after notify, since
515 // class loader lock must be claimed before SystemDictionary_lock
516 // to prevent deadlocks
517 //
518 // The notify allows applications that did an untimed wait() on
519 // the classloader object lock to not hang.
520 void SystemDictionary::double_lock_wait(Handle lockObject, TRAPS) {
521 assert_lock_strong(SystemDictionary_lock);
522
523 bool calledholdinglock
524 = ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, lockObject);
525 assert(calledholdinglock,"must hold lock for notify");
575 if (!class_loader.is_null() && is_parallelCapable(class_loader)) {
576 MutexLocker mu(SystemDictionary_lock, THREAD);
577 // Check if classloading completed while we were loading superclass or waiting
578 return find_class(d_hash, name, dictionary);
579 }
580
581 // must loop to both handle other placeholder updates
582 // and spurious notifications
583 bool super_load_in_progress = true;
584 PlaceholderEntry* placeholder;
585 while (super_load_in_progress) {
586 MutexLocker mu(SystemDictionary_lock, THREAD);
587 // Check if classloading completed while we were loading superclass or waiting
588 InstanceKlass* check = find_class(d_hash, name, dictionary);
589 if (check != NULL) {
590 // Klass is already loaded, so just return it
591 return check;
592 } else {
593 placeholder = placeholders()->get_entry(p_index, p_hash, name, loader_data);
594 if (placeholder && placeholder->super_load_in_progress() ){
595 // We only get here if the application has released the
596 // classloader lock when another thread was in the middle of loading a
597 // superclass/superinterface for this class, and now
598 // this thread is also trying to load this class.
599 // To minimize surprises, the first thread that started to
600 // load a class should be the one to complete the loading
601 // with the classfile it initially expected.
602 // This logic has the current thread wait once it has done
603 // all the superclass/superinterface loading it can, until
604 // the original thread completes the class loading or fails
605 // If it completes we will use the resulting InstanceKlass
606 // which we will find below in the systemDictionary.
607 // We also get here for parallel bootstrap classloader
608 if (class_loader.is_null()) {
609 SystemDictionary_lock->wait();
610 } else {
611 double_lock_wait(lockObject, THREAD);
612 }
613 } else {
614 // If not in SD and not in PH, other thread's load must have failed
667 Dictionary* dictionary = loader_data->dictionary();
668 unsigned int d_hash = dictionary->compute_hash(name);
669
670 // Do lookup to see if class already exist and the protection domain
671 // has the right access
672 // This call uses find which checks protection domain already matches
673 // All subsequent calls use find_class, and set has_loaded_class so that
674 // before we return a result we call out to java to check for valid protection domain
675 // to allow returning the Klass* and add it to the pd_set if it is valid
676 {
677 Klass* probe = dictionary->find(d_hash, name, protection_domain);
678 if (probe != NULL) return probe;
679 }
680
681 // Non-bootstrap class loaders will call out to class loader and
682 // define via jvm/jni_DefineClass which will acquire the
683 // class loader object lock to protect against multiple threads
684 // defining the class in parallel by accident.
685 // This lock must be acquired here so the waiter will find
686 // any successful result in the SystemDictionary and not attempt
687 // the define.
688 // ParallelCapable Classloaders and the bootstrap classloader
689 // do not acquire lock here.
690 bool DoObjectLock = true;
691 if (is_parallelCapable(class_loader)) {
692 DoObjectLock = false;
693 }
694
695 unsigned int p_hash = placeholders()->compute_hash(name);
696 int p_index = placeholders()->hash_to_index(p_hash);
697
698 // Class is not in SystemDictionary so we have to do loading.
699 // Make sure we are synchronized on the class loader before we proceed
700 Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
701 check_loader_lock_contention(lockObject, THREAD);
702 ObjectLocker ol(lockObject, THREAD, DoObjectLock);
703
704 // Check again (after locking) if class already exist in SystemDictionary
705 bool class_has_been_loaded = false;
706 bool super_load_in_progress = false;
707 bool havesupername = false;
708 InstanceKlass* k = NULL;
709 PlaceholderEntry* placeholder;
745
746 bool throw_circularity_error = false;
747 if (!class_has_been_loaded) {
748 bool load_instance_added = false;
749
750 // add placeholder entry to record loading instance class
751 // Five cases:
752 // All cases need to prevent modifying bootclasssearchpath
753 // in parallel with a classload of same classname
754 // Redefineclasses uses existence of the placeholder for the duration
755 // of the class load to prevent concurrent redefinition of not completely
756 // defined classes.
757 // case 1. traditional classloaders that rely on the classloader object lock
758 // - no other need for LOAD_INSTANCE
759 // case 2. traditional classloaders that break the classloader object lock
760 // as a deadlock workaround. Detection of this case requires that
761 // this check is done while holding the classloader object lock,
762 // and that lock is still held when calling classloader's loadClass.
763 // For these classloaders, we ensure that the first requestor
764 // completes the load and other requestors wait for completion.
765 // case 3. Bootstrap classloader - don't own objectLocker
766 // This classloader supports parallelism at the classloader level,
767 // but only allows a single load of a class/classloader pair.
768 // No performance benefit and no deadlock issues.
769 // case 4. parallelCapable user level classloaders - without objectLocker
770 // Allow parallel classloading of a class/classloader pair
771
772 {
773 MutexLocker mu(SystemDictionary_lock, THREAD);
774 if (class_loader.is_null() || !is_parallelCapable(class_loader)) {
775 PlaceholderEntry* oldprobe = placeholders()->get_entry(p_index, p_hash, name, loader_data);
776 if (oldprobe) {
777 // only need check_seen_thread once, not on each loop
778 // 6341374 java/lang/Instrument with -Xcomp
779 if (oldprobe->check_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE)) {
780 throw_circularity_error = true;
781 } else {
782 // case 1: traditional: should never see load_in_progress.
783 while (!class_has_been_loaded && oldprobe && oldprobe->instance_load_in_progress()) {
784
785 // case 3: bootstrap classloader: prevent futile classloading,
786 // wait on first requestor
787 if (class_loader.is_null()) {
788 SystemDictionary_lock->wait();
789 } else {
790 // case 2: traditional with broken classloader lock. wait on first
791 // requestor.
792 double_lock_wait(lockObject, THREAD);
793 }
794 // Check if classloading completed while we were waiting
795 InstanceKlass* check = find_class(d_hash, name, dictionary);
796 if (check != NULL) {
797 // Klass is already loaded, so just return it
798 k = check;
799 class_has_been_loaded = true;
800 }
801 // check if other thread failed to load and cleaned up
802 oldprobe = placeholders()->get_entry(p_index, p_hash, name, loader_data);
803 }
804 }
805 }
806 }
807 // All cases: add LOAD_INSTANCE holding SystemDictionary_lock
808 // case 4: parallelCapable: allow competing threads to try
809 // LOAD_INSTANCE in parallel
810
811 if (!throw_circularity_error && !class_has_been_loaded) {
812 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, name, loader_data, PlaceholderTable::LOAD_INSTANCE, NULL, THREAD);
813 load_instance_added = true;
814 // For class loaders that do not acquire the classloader object lock,
815 // if they did not catch another thread holding LOAD_INSTANCE,
816 // need a check analogous to the acquire ObjectLocker/find_class
817 // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL
818 // one final check if the load has already completed
819 // class loaders holding the ObjectLock shouldn't find the class here
820 InstanceKlass* check = find_class(d_hash, name, dictionary);
821 if (check != NULL) {
822 // Klass is already loaded, so return it after checking/adding protection domain
823 k = check;
824 class_has_been_loaded = true;
825 }
826 }
827 }
828
829 // must throw error outside of owning lock
830 if (throw_circularity_error) {
831 assert(!HAS_PENDING_EXCEPTION && load_instance_added == false,"circularity error cleanup");
832 ResourceMark rm(THREAD);
833 THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), name->as_C_string());
834 }
835
836 if (!class_has_been_loaded) {
837
838 // Do actual loading
839 k = load_instance_class(name, class_loader, THREAD);
840
841 // If everything was OK (no exceptions, no null return value), and
842 // class_loader is NOT the defining loader, do a little more bookkeeping.
843 if (!HAS_PENDING_EXCEPTION && k != NULL &&
844 k->class_loader() != class_loader()) {
845
846 check_constraints(d_hash, k, class_loader, false, THREAD);
847
848 // Need to check for a PENDING_EXCEPTION again; check_constraints
849 // can throw and doesn't use the CHECK macro.
850 if (!HAS_PENDING_EXCEPTION) {
851 { // Grabbing the Compile_lock prevents systemDictionary updates
852 // during compilations.
853 MutexLocker mu(Compile_lock, THREAD);
854 update_dictionary(d_hash, p_index, p_hash,
855 k, class_loader, THREAD);
856 }
857
858 if (JvmtiExport::should_post_class_load()) {
859 Thread *thread = THREAD;
860 assert(thread->is_Java_thread(), "thread->is_Java_thread()");
1052 // the class until we have parsed the stream.
1053
1054 InstanceKlass* SystemDictionary::resolve_from_stream(Symbol* class_name,
1055 Handle class_loader,
1056 Handle protection_domain,
1057 ClassFileStream* st,
1058 TRAPS) {
1059 #if INCLUDE_CDS
1060 ResourceMark rm(THREAD);
1061 if (DumpSharedSpaces && !class_loader.is_null() &&
1062 !UseAppCDS && strcmp(class_name->as_C_string(), "Unnamed") != 0) {
1063 // If AppCDS is not enabled, don't define the class at dump time (except for the "Unnamed"
1064 // class, which is used by MethodHandles).
1065 THROW_MSG_NULL(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string());
1066 }
1067 #endif
1068
1069 HandleMark hm(THREAD);
1070
1071 // Classloaders that support parallelism, e.g. bootstrap classloader,
1072 // do not acquire lock here
1073 bool DoObjectLock = true;
1074 if (is_parallelCapable(class_loader)) {
1075 DoObjectLock = false;
1076 }
1077
1078 ClassLoaderData* loader_data = register_loader(class_loader, CHECK_NULL);
1079
1080 // Make sure we are synchronized on the class loader before we proceed
1081 Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
1082 check_loader_lock_contention(lockObject, THREAD);
1083 ObjectLocker ol(lockObject, THREAD, DoObjectLock);
1084
1085 assert(st != NULL, "invariant");
1086
1087 // Parse the stream and create a klass.
1088 // Note that we do this even though this klass might
1089 // already be present in the SystemDictionary, otherwise we would not
1090 // throw potential ClassFormatErrors.
1091 InstanceKlass* k = NULL;
1092
1511 ResourceMark rm(THREAD);
1512
1513 assert(THREAD->is_Java_thread(), "must be a JavaThread");
1514 JavaThread* jt = (JavaThread*) THREAD;
1515
1516 PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(),
1517 ClassLoader::perf_app_classload_selftime(),
1518 ClassLoader::perf_app_classload_count(),
1519 jt->get_thread_stat()->perf_recursion_counts_addr(),
1520 jt->get_thread_stat()->perf_timers_addr(),
1521 PerfClassTraceTime::CLASS_LOAD);
1522
1523 Handle s = java_lang_String::create_from_symbol(class_name, CHECK_NULL);
1524 // Translate to external class name format, i.e., convert '/' chars to '.'
1525 Handle string = java_lang_String::externalize_classname(s, CHECK_NULL);
1526
1527 JavaValue result(T_OBJECT);
1528
1529 InstanceKlass* spec_klass = SystemDictionary::ClassLoader_klass();
1530
1531 // Call public unsynchronized loadClass(String) directly for all class loaders.
1532 // For parallelCapable class loaders, JDK >=7, loadClass(String, boolean) will
1533 // acquire a class-name based lock rather than the class loader object lock.
1534 // JDK < 7 already acquire the class loader lock in loadClass(String, boolean).
1535 JavaCalls::call_virtual(&result,
1536 class_loader,
1537 spec_klass,
1538 vmSymbols::loadClass_name(),
1539 vmSymbols::string_class_signature(),
1540 string,
1541 CHECK_NULL);
1542
1543 assert(result.get_type() == T_OBJECT, "just checking");
1544 oop obj = (oop) result.get_jobject();
1545
1546 // Primitive classes return null since forName() can not be
1547 // used to obtain any of the Class objects representing primitives or void
1548 if ((obj != NULL) && !(java_lang_Class::is_primitive(obj))) {
1549 InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(obj));
1550 // For user defined Java class loaders, check that the name returned is
1551 // the same as that requested. This check is done for the bootstrap
1552 // loader when parsing the class file.
1553 if (class_name == k->name()) {
1554 return k;
1555 }
1556 }
1557 // Class is not found or has the wrong name, return NULL
1558 return NULL;
1559 }
1560 }
1561
1650 // placeholders()->find_and_add(PlaceholderTable::DEFINE_CLASS),
1651 // you need to find_and_remove it before returning.
1652 // So be careful to not exit with a CHECK_ macro betweeen these calls.
1653 InstanceKlass* SystemDictionary::find_or_define_instance_class(Symbol* class_name, Handle class_loader,
1654 InstanceKlass* k, TRAPS) {
1655
1656 Symbol* name_h = k->name(); // passed in class_name may be null
1657 ClassLoaderData* loader_data = class_loader_data(class_loader);
1658 Dictionary* dictionary = loader_data->dictionary();
1659
1660 unsigned int d_hash = dictionary->compute_hash(name_h);
1661
1662 // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS
1663 unsigned int p_hash = placeholders()->compute_hash(name_h);
1664 int p_index = placeholders()->hash_to_index(p_hash);
1665 PlaceholderEntry* probe;
1666
1667 {
1668 MutexLocker mu(SystemDictionary_lock, THREAD);
1669 // First check if class already defined
1670 if (is_parallelDefine(class_loader)) {
1671 InstanceKlass* check = find_class(d_hash, name_h, dictionary);
1672 if (check != NULL) {
1673 return check;
1674 }
1675 }
1676
1677 // Acquire define token for this class/classloader
1678 probe = placeholders()->find_and_add(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, NULL, THREAD);
1679 // Wait if another thread defining in parallel
1680 // All threads wait - even those that will throw duplicate class: otherwise
1681 // caller is surprised by LinkageError: duplicate, but findLoadedClass fails
1682 // if other thread has not finished updating dictionary
1683 while (probe->definer() != NULL) {
1684 SystemDictionary_lock->wait();
1685 }
1686 // Only special cases allow parallel defines and can use other thread's results
1687 // Other cases fall through, and may run into duplicate defines
1688 // caught by finding an entry in the SystemDictionary
1689 if (is_parallelDefine(class_loader) && (probe->instance_klass() != NULL)) {
1690 placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD);
1691 SystemDictionary_lock->notify_all();
1692 #ifdef ASSERT
1693 InstanceKlass* check = find_class(d_hash, name_h, dictionary);
1694 assert(check != NULL, "definer missed recording success");
1695 #endif
1696 return probe->instance_klass();
1697 } else {
1698 // This thread will define the class (even if earlier thread tried and had an error)
1699 probe->set_definer(THREAD);
1700 }
1701 }
1702
1703 define_instance_class(k, THREAD);
1704
1705 Handle linkage_exception = Handle(); // null handle
1706
1707 // definer must notify any waiting threads
1708 {
1709 MutexLocker mu(SystemDictionary_lock, THREAD);
2106 InstanceKlass::cast(WK_KLASS(PhantomReference_klass))->set_reference_type(REF_PHANTOM);
2107
2108 // JSR 292 classes
2109 WKID jsr292_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass);
2110 WKID jsr292_group_end = WK_KLASS_ENUM_NAME(VolatileCallSite_klass);
2111 initialize_wk_klasses_until(jsr292_group_start, scan, CHECK);
2112 initialize_wk_klasses_through(jsr292_group_end, scan, CHECK);
2113 initialize_wk_klasses_until(NOT_JVMCI(WKID_LIMIT) JVMCI_ONLY(FIRST_JVMCI_WKID), scan, CHECK);
2114
2115 _box_klasses[T_BOOLEAN] = WK_KLASS(Boolean_klass);
2116 _box_klasses[T_CHAR] = WK_KLASS(Character_klass);
2117 _box_klasses[T_FLOAT] = WK_KLASS(Float_klass);
2118 _box_klasses[T_DOUBLE] = WK_KLASS(Double_klass);
2119 _box_klasses[T_BYTE] = WK_KLASS(Byte_klass);
2120 _box_klasses[T_SHORT] = WK_KLASS(Short_klass);
2121 _box_klasses[T_INT] = WK_KLASS(Integer_klass);
2122 _box_klasses[T_LONG] = WK_KLASS(Long_klass);
2123 //_box_klasses[T_OBJECT] = WK_KLASS(object_klass);
2124 //_box_klasses[T_ARRAY] = WK_KLASS(object_klass);
2125
2126 { // Compute whether we should use checkPackageAccess or NOT
2127 Method* method = InstanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature());
2128 _has_checkPackageAccess = (method != NULL);
2129 }
2130 }
2131
2132 // Tells if a given klass is a box (wrapper class, such as java.lang.Integer).
2133 // If so, returns the basic type it holds. If not, returns T_OBJECT.
2134 BasicType SystemDictionary::box_klass_type(Klass* k) {
2135 assert(k != NULL, "");
2136 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
2137 if (_box_klasses[i] == k)
2138 return (BasicType)i;
2139 }
2140 return T_OBJECT;
2141 }
2142
2143 // Constraints on class loaders. The details of the algorithm can be
2144 // found in the OOPSLA'98 paper "Dynamic Class Loading in the Java
2145 // Virtual Machine" by Sheng Liang and Gilad Bracha. The basic idea is
|