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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classLoaderData.inline.hpp"
27 #include "classfile/dictionary.hpp"
28 #include "classfile/javaClasses.hpp"
29 #include "classfile/loaderConstraints.hpp"
30 #include "classfile/placeholders.hpp"
31 #include "classfile/resolutionErrors.hpp"
32 #include "classfile/stringTable.hpp"
33 #include "classfile/systemDictionary.hpp"
34 #include "classfile/vmSymbols.hpp"
35 #include "compiler/compileBroker.hpp"
36 #include "interpreter/bytecodeStream.hpp"
37 #include "interpreter/interpreter.hpp"
38 #include "memory/gcLocker.hpp"
39 #include "memory/oopFactory.hpp"
40 #include "oops/instanceKlass.hpp"
41 #include "oops/instanceRefKlass.hpp"
42 #include "oops/klass.inline.hpp"
43 #include "oops/methodData.hpp"
44 #include "oops/objArrayKlass.hpp"
45 #include "oops/oop.inline.hpp"
46 #include "oops/oop.inline2.hpp"
47 #include "oops/typeArrayKlass.hpp"
48 #include "prims/jvmtiEnvBase.hpp"
49 #include "prims/methodHandles.hpp"
50 #include "runtime/biasedLocking.hpp"
51 #include "runtime/fieldType.hpp"
52 #include "runtime/handles.inline.hpp"
53 #include "runtime/java.hpp"
54 #include "runtime/javaCalls.hpp"
55 #include "runtime/mutexLocker.hpp"
56 #include "runtime/orderAccess.inline.hpp"
57 #include "runtime/signature.hpp"
93 Klass* volatile SystemDictionary::_abstract_ownable_synchronizer_klass = NULL;
94
95
96 // ----------------------------------------------------------------------------
97 // Java-level SystemLoader
98
99 oop SystemDictionary::java_system_loader() {
100 return _java_system_loader;
101 }
102
103 void SystemDictionary::compute_java_system_loader(TRAPS) {
104 KlassHandle system_klass(THREAD, WK_KLASS(ClassLoader_klass));
105 JavaValue result(T_OBJECT);
106 JavaCalls::call_static(&result,
107 KlassHandle(THREAD, WK_KLASS(ClassLoader_klass)),
108 vmSymbols::getSystemClassLoader_name(),
109 vmSymbols::void_classloader_signature(),
110 CHECK);
111
112 _java_system_loader = (oop)result.get_jobject();
113 }
114
115
116 ClassLoaderData* SystemDictionary::register_loader(Handle class_loader, TRAPS) {
117 if (class_loader() == NULL) return ClassLoaderData::the_null_class_loader_data();
118 return ClassLoaderDataGraph::find_or_create(class_loader, CHECK_NULL);
119 }
120
121 // ----------------------------------------------------------------------------
122 // debugging
123
124 #ifdef ASSERT
125
126 // return true if class_name contains no '.' (internal format is '/')
127 bool SystemDictionary::is_internal_format(Symbol* class_name) {
128 if (class_name != NULL) {
129 ResourceMark rm;
130 char* name = class_name->as_C_string();
131 return strchr(name, '.') == NULL;
132 } else {
957
958 // Note: this method is much like resolve_from_stream, but
959 // updates no supplemental data structures.
960 // TODO consolidate the two methods with a helper routine?
961 Klass* SystemDictionary::parse_stream(Symbol* class_name,
962 Handle class_loader,
963 Handle protection_domain,
964 ClassFileStream* st,
965 KlassHandle host_klass,
966 GrowableArray<Handle>* cp_patches,
967 TRAPS) {
968 TempNewSymbol parsed_name = NULL;
969
970 Ticks class_load_start_time = Ticks::now();
971
972 ClassLoaderData* loader_data;
973 if (host_klass.not_null()) {
974 // Create a new CLD for anonymous class, that uses the same class loader
975 // as the host_klass
976 guarantee(host_klass->class_loader() == class_loader(), "should be the same");
977 loader_data = ClassLoaderData::anonymous_class_loader_data(class_loader(), CHECK_NULL);
978 loader_data->record_dependency(host_klass(), CHECK_NULL);
979 } else {
980 loader_data = ClassLoaderData::class_loader_data(class_loader());
981 }
982
983 // Parse the stream. Note that we do this even though this klass might
984 // already be present in the SystemDictionary, otherwise we would not
985 // throw potential ClassFormatErrors.
986 //
987 // Note: "name" is updated.
988
989 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
990 loader_data,
991 protection_domain,
992 host_klass,
993 cp_patches,
994 parsed_name,
995 true,
996 THREAD);
1117 // Make sure we have an entry in the SystemDictionary on success
1118 debug_only( {
1119 if (!HAS_PENDING_EXCEPTION) {
1120 assert(parsed_name != NULL, "parsed_name is still null?");
1121 Symbol* h_name = k->name();
1122 ClassLoaderData *defining_loader_data = k->class_loader_data();
1123
1124 MutexLocker mu(SystemDictionary_lock, THREAD);
1125
1126 Klass* check = find_class(parsed_name, loader_data);
1127 assert(check == k(), "should be present in the dictionary");
1128
1129 Klass* check2 = find_class(h_name, defining_loader_data);
1130 assert(check == check2, "name inconsistancy in SystemDictionary");
1131 }
1132 } );
1133
1134 return k();
1135 }
1136
1137
1138 void SystemDictionary::set_shared_dictionary(HashtableBucket<mtClass>* t, int length,
1139 int number_of_entries) {
1140 assert(length == _nof_buckets * sizeof(HashtableBucket<mtClass>),
1141 "bad shared dictionary size.");
1142 _shared_dictionary = new Dictionary(_nof_buckets, t, number_of_entries);
1143 }
1144
1145
1146 // If there is a shared dictionary, then find the entry for the
1147 // given shared system class, if any.
1148
1149 Klass* SystemDictionary::find_shared_class(Symbol* class_name) {
1150 if (shared_dictionary() != NULL) {
1151 unsigned int d_hash = shared_dictionary()->compute_hash(class_name, NULL);
1152 int d_index = shared_dictionary()->hash_to_index(d_hash);
1153
1154 return shared_dictionary()->find_shared_class(d_index, d_hash, class_name);
1155 } else {
1156 return NULL;
1157 }
1158 }
1159
1160
1161 // Load a class from the shared spaces (found through the shared system
1162 // dictionary). Force the superclass and all interfaces to be loaded.
1163 // Update the class definition to include sibling classes and no
1164 // subclasses (yet). [Classes in the shared space are not part of the
1165 // object hierarchy until loaded.]
1166
1167 instanceKlassHandle SystemDictionary::load_shared_class(
1168 Symbol* class_name, Handle class_loader, TRAPS) {
1169 instanceKlassHandle ik (THREAD, find_shared_class(class_name));
1170 return load_shared_class(ik, class_loader, THREAD);
1171 }
1172
1173 instanceKlassHandle SystemDictionary::load_shared_class(
1174 instanceKlassHandle ik, Handle class_loader, TRAPS) {
1175 assert(class_loader.is_null(), "non-null classloader for shared class?");
1176 if (ik.not_null()) {
1177 instanceKlassHandle nh = instanceKlassHandle(); // null Handle
1178 Symbol* class_name = ik->name();
1179
1180 // Found the class, now load the superclass and interfaces. If they
1181 // are shared, add them to the main system dictionary and reset
1182 // their hierarchy references (supers, subs, and interfaces).
1183
1184 if (ik->super() != NULL) {
1185 Symbol* cn = ik->super()->name();
1186 resolve_super_or_fail(class_name, cn,
1187 class_loader, Handle(), true, CHECK_(nh));
1188 }
1189
1190 Array<Klass*>* interfaces = ik->local_interfaces();
1191 int num_interfaces = interfaces->length();
1192 for (int index = 0; index < num_interfaces; index++) {
1193 Klass* k = interfaces->at(index);
1194
1195 // Note: can not use InstanceKlass::cast here because
1196 // interfaces' InstanceKlass's C++ vtbls haven't been
1197 // reinitialized yet (they will be once the interface classes
1198 // are loaded)
1199 Symbol* name = k->name();
1200 resolve_super_or_fail(class_name, name, class_loader, Handle(), false, CHECK_(nh));
1201 }
1202
1203 // Adjust methods to recover missing data. They need addresses for
1204 // interpreter entry points and their default native method address
1205 // must be reset.
1206
1207 // Updating methods must be done under a lock so multiple
1208 // threads don't update these in parallel
1209 // Shared classes are all currently loaded by the bootstrap
1210 // classloader, so this will never cause a deadlock on
1211 // a custom class loader lock.
1212
1213 {
1214 Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
1215 check_loader_lock_contention(lockObject, THREAD);
1216 ObjectLocker ol(lockObject, THREAD, true);
1217 ik->restore_unshareable_info(CHECK_(nh));
1218 }
1219
1220 if (TraceClassLoading) {
1221 ResourceMark rm;
1222 tty->print("[Loaded %s", ik->external_name());
1223 tty->print(" from shared objects file");
1224 tty->print_cr("]");
1225 }
1226 // notify a class loaded from shared object
1227 ClassLoadingService::notify_class_loaded(InstanceKlass::cast(ik()),
1228 true /* shared class */);
1229 }
1230 return ik;
1231 }
1232
1233
1234 instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) {
1235 instanceKlassHandle nh = instanceKlassHandle(); // null Handle
1236 if (class_loader.is_null()) {
1237
1238 // Search the shared system dictionary for classes preloaded into the
1239 // shared spaces.
1240 instanceKlassHandle k;
1241 {
1242 PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
1243 k = load_shared_class(class_name, class_loader, THREAD);
1244 }
1245
1246 if (k.is_null()) {
1247 // Use VM class loader
1248 PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
1249 k = ClassLoader::load_classfile(class_name, CHECK_(nh));
1250 }
1251
1252 // find_or_define_instance_class may return a different InstanceKlass
1253 if (!k.is_null()) {
1254 k = find_or_define_instance_class(class_name, class_loader, k, CHECK_(nh));
1255 }
1256 return k;
1257 } else {
1258 // Use user specified class loader to load class. Call loadClass operation on class_loader.
1259 ResourceMark rm(THREAD);
1260
1261 assert(THREAD->is_Java_thread(), "must be a JavaThread");
1262 JavaThread* jt = (JavaThread*) THREAD;
1263
1582 // ----------------------------------------------------------------------------
1583 // Update hierachy. This is done before the new klass has been added to the SystemDictionary. The Recompile_lock
1584 // is held, to ensure that the compiler is not using the class hierachy, and that deoptimization will kick in
1585 // before a new class is used.
1586
1587 void SystemDictionary::add_to_hierarchy(instanceKlassHandle k, TRAPS) {
1588 assert(k.not_null(), "just checking");
1589 assert_locked_or_safepoint(Compile_lock);
1590
1591 // Link into hierachy. Make sure the vtables are initialized before linking into
1592 k->append_to_sibling_list(); // add to superklass/sibling list
1593 k->process_interfaces(THREAD); // handle all "implements" declarations
1594 k->set_init_state(InstanceKlass::loaded);
1595 // Now flush all code that depended on old class hierarchy.
1596 // Note: must be done *after* linking k into the hierarchy (was bug 12/9/97)
1597 // Also, first reinitialize vtable because it may have gotten out of synch
1598 // while the new class wasn't connected to the class hierarchy.
1599 Universe::flush_dependents_on(k);
1600 }
1601
1602
1603 // ----------------------------------------------------------------------------
1604 // GC support
1605
1606 // Following roots during mark-sweep is separated in two phases.
1607 //
1608 // The first phase follows preloaded classes and all other system
1609 // classes, since these will never get unloaded anyway.
1610 //
1611 // The second phase removes (unloads) unreachable classes from the
1612 // system dictionary and follows the remaining classes' contents.
1613
1614 void SystemDictionary::always_strong_oops_do(OopClosure* blk) {
1615 roots_oops_do(blk, NULL);
1616 }
1617
1618 void SystemDictionary::always_strong_classes_do(KlassClosure* closure) {
1619 // Follow all system classes and temporary placeholders in dictionary
1620 dictionary()->always_strong_classes_do(closure);
1621
1622 // Placeholders. These represent classes we're actively loading.
1665 bool unloading_occurred = false;
1666 if (has_dead_loaders) {
1667 unloading_occurred = dictionary()->do_unloading();
1668 constraints()->purge_loader_constraints();
1669 resolution_errors()->purge_resolution_errors();
1670 }
1671 // Oops referenced by the system dictionary may get unreachable independently
1672 // of the class loader (eg. cached protection domain oops). So we need to
1673 // explicitly unlink them here instead of in Dictionary::do_unloading.
1674 dictionary()->unlink(is_alive);
1675 #ifdef ASSERT
1676 VerifySDReachableAndLiveClosure cl(is_alive);
1677 dictionary()->oops_do(&cl);
1678 #endif
1679 return unloading_occurred;
1680 }
1681
1682 void SystemDictionary::roots_oops_do(OopClosure* strong, OopClosure* weak) {
1683 strong->do_oop(&_java_system_loader);
1684 strong->do_oop(&_system_loader_lock_obj);
1685
1686 // Adjust dictionary
1687 dictionary()->roots_oops_do(strong, weak);
1688
1689 // Visit extra methods
1690 invoke_method_table()->oops_do(strong);
1691 }
1692
1693 void SystemDictionary::oops_do(OopClosure* f) {
1694 f->do_oop(&_java_system_loader);
1695 f->do_oop(&_system_loader_lock_obj);
1696
1697 // Adjust dictionary
1698 dictionary()->oops_do(f);
1699
1700 // Visit extra methods
1701 invoke_method_table()->oops_do(f);
1702 }
1703
1704 // Extended Class redefinition support.
1705 // If one of these classes is replaced, we need to replace it in these places.
1706 // KlassClosure::do_klass should take the address of a class but we can
1707 // change that later.
1708 void SystemDictionary::preloaded_classes_do(KlassClosure* f) {
1709 for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
1710 f->do_klass(_well_known_klasses[k]);
1711 }
1712
1713 {
1714 for (int i = 0; i < T_VOID+1; i++) {
1715 if (_box_klasses[i] != NULL) {
1737 // Don't iterate over placeholders
1738 void SystemDictionary::classes_do(void f(Klass*, TRAPS), TRAPS) {
1739 dictionary()->classes_do(f, CHECK);
1740 }
1741
1742 // All classes, and their class loaders
1743 // Don't iterate over placeholders
1744 void SystemDictionary::classes_do(void f(Klass*, ClassLoaderData*)) {
1745 dictionary()->classes_do(f);
1746 }
1747
1748 void SystemDictionary::placeholders_do(void f(Symbol*)) {
1749 placeholders()->entries_do(f);
1750 }
1751
1752 void SystemDictionary::methods_do(void f(Method*)) {
1753 dictionary()->methods_do(f);
1754 invoke_method_table()->methods_do(f);
1755 }
1756
1757 // ----------------------------------------------------------------------------
1758 // Lazily load klasses
1759
1760 void SystemDictionary::load_abstract_ownable_synchronizer_klass(TRAPS) {
1761 // if multiple threads calling this function, only one thread will load
1762 // the class. The other threads will find the loaded version once the
1763 // class is loaded.
1764 Klass* aos = _abstract_ownable_synchronizer_klass;
1765 if (aos == NULL) {
1766 Klass* k = resolve_or_fail(vmSymbols::java_util_concurrent_locks_AbstractOwnableSynchronizer(), true, CHECK);
1767 // Force a fence to prevent any read before the write completes
1768 OrderAccess::fence();
1769 _abstract_ownable_synchronizer_klass = k;
1770 }
1771 }
1772
1773 // ----------------------------------------------------------------------------
1774 // Initialization
1775
1776 void SystemDictionary::initialize(TRAPS) {
2546 void SystemDictionary::copy_buckets(char** top, char* end) {
2547 dictionary()->copy_buckets(top, end);
2548 }
2549
2550
2551 void SystemDictionary::copy_table(char** top, char* end) {
2552 dictionary()->copy_table(top, end);
2553 }
2554
2555
2556 void SystemDictionary::reverse() {
2557 dictionary()->reverse();
2558 }
2559
2560 int SystemDictionary::number_of_classes() {
2561 return dictionary()->number_of_entries();
2562 }
2563
2564
2565 // ----------------------------------------------------------------------------
2566 #ifndef PRODUCT
2567
2568 void SystemDictionary::print() {
2569 dictionary()->print();
2570
2571 // Placeholders
2572 GCMutexLocker mu(SystemDictionary_lock);
2573 placeholders()->print();
2574
2575 // loader constraints - print under SD_lock
2576 constraints()->print();
2577 }
2578
2579 #endif
2580
2581 void SystemDictionary::verify() {
2582 guarantee(dictionary() != NULL, "Verify of system dictionary failed");
2583 guarantee(constraints() != NULL,
2584 "Verify of loader constraints failed");
2585 guarantee(dictionary()->number_of_entries() >= 0 &&
2586 placeholders()->number_of_entries() >= 0,
2587 "Verify of system dictionary failed");
2588
2589 // Verify dictionary
2590 dictionary()->verify();
2591
2592 GCMutexLocker mu(SystemDictionary_lock);
2593 placeholders()->verify();
2594
2595 // Verify constraint table
2596 guarantee(constraints() != NULL, "Verify of loader constraints failed");
2597 constraints()->verify(dictionary(), placeholders());
2598 }
2599
|
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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classLoaderData.inline.hpp"
27 #include "classfile/dictionary.hpp"
28 #include "classfile/javaClasses.hpp"
29 #include "classfile/loaderConstraints.hpp"
30 #include "classfile/placeholders.hpp"
31 #include "classfile/resolutionErrors.hpp"
32 #include "classfile/stringTable.hpp"
33 #include "classfile/systemDictionary.hpp"
34 #if INCLUDE_CDS
35 #include "classfile/sharedClassUtil.hpp"
36 #include "classfile/systemDictionaryShared.hpp"
37 #endif
38 #include "classfile/vmSymbols.hpp"
39 #include "compiler/compileBroker.hpp"
40 #include "interpreter/bytecodeStream.hpp"
41 #include "interpreter/interpreter.hpp"
42 #include "memory/filemap.hpp"
43 #include "memory/gcLocker.hpp"
44 #include "memory/oopFactory.hpp"
45 #include "oops/instanceKlass.hpp"
46 #include "oops/instanceRefKlass.hpp"
47 #include "oops/klass.inline.hpp"
48 #include "oops/methodData.hpp"
49 #include "oops/objArrayKlass.hpp"
50 #include "oops/oop.inline.hpp"
51 #include "oops/oop.inline2.hpp"
52 #include "oops/typeArrayKlass.hpp"
53 #include "prims/jvmtiEnvBase.hpp"
54 #include "prims/methodHandles.hpp"
55 #include "runtime/biasedLocking.hpp"
56 #include "runtime/fieldType.hpp"
57 #include "runtime/handles.inline.hpp"
58 #include "runtime/java.hpp"
59 #include "runtime/javaCalls.hpp"
60 #include "runtime/mutexLocker.hpp"
61 #include "runtime/orderAccess.inline.hpp"
62 #include "runtime/signature.hpp"
98 Klass* volatile SystemDictionary::_abstract_ownable_synchronizer_klass = NULL;
99
100
101 // ----------------------------------------------------------------------------
102 // Java-level SystemLoader
103
104 oop SystemDictionary::java_system_loader() {
105 return _java_system_loader;
106 }
107
108 void SystemDictionary::compute_java_system_loader(TRAPS) {
109 KlassHandle system_klass(THREAD, WK_KLASS(ClassLoader_klass));
110 JavaValue result(T_OBJECT);
111 JavaCalls::call_static(&result,
112 KlassHandle(THREAD, WK_KLASS(ClassLoader_klass)),
113 vmSymbols::getSystemClassLoader_name(),
114 vmSymbols::void_classloader_signature(),
115 CHECK);
116
117 _java_system_loader = (oop)result.get_jobject();
118
119 CDS_ONLY(SystemDictionaryShared::initialize(CHECK);)
120 }
121
122
123 ClassLoaderData* SystemDictionary::register_loader(Handle class_loader, TRAPS) {
124 if (class_loader() == NULL) return ClassLoaderData::the_null_class_loader_data();
125 return ClassLoaderDataGraph::find_or_create(class_loader, CHECK_NULL);
126 }
127
128 // ----------------------------------------------------------------------------
129 // debugging
130
131 #ifdef ASSERT
132
133 // return true if class_name contains no '.' (internal format is '/')
134 bool SystemDictionary::is_internal_format(Symbol* class_name) {
135 if (class_name != NULL) {
136 ResourceMark rm;
137 char* name = class_name->as_C_string();
138 return strchr(name, '.') == NULL;
139 } else {
964
965 // Note: this method is much like resolve_from_stream, but
966 // updates no supplemental data structures.
967 // TODO consolidate the two methods with a helper routine?
968 Klass* SystemDictionary::parse_stream(Symbol* class_name,
969 Handle class_loader,
970 Handle protection_domain,
971 ClassFileStream* st,
972 KlassHandle host_klass,
973 GrowableArray<Handle>* cp_patches,
974 TRAPS) {
975 TempNewSymbol parsed_name = NULL;
976
977 Ticks class_load_start_time = Ticks::now();
978
979 ClassLoaderData* loader_data;
980 if (host_klass.not_null()) {
981 // Create a new CLD for anonymous class, that uses the same class loader
982 // as the host_klass
983 guarantee(host_klass->class_loader() == class_loader(), "should be the same");
984 guarantee(!DumpSharedSpaces, "must not create anonymous classes when dumping");
985 loader_data = ClassLoaderData::anonymous_class_loader_data(class_loader(), CHECK_NULL);
986 loader_data->record_dependency(host_klass(), CHECK_NULL);
987 } else {
988 loader_data = ClassLoaderData::class_loader_data(class_loader());
989 }
990
991 // Parse the stream. Note that we do this even though this klass might
992 // already be present in the SystemDictionary, otherwise we would not
993 // throw potential ClassFormatErrors.
994 //
995 // Note: "name" is updated.
996
997 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
998 loader_data,
999 protection_domain,
1000 host_klass,
1001 cp_patches,
1002 parsed_name,
1003 true,
1004 THREAD);
1125 // Make sure we have an entry in the SystemDictionary on success
1126 debug_only( {
1127 if (!HAS_PENDING_EXCEPTION) {
1128 assert(parsed_name != NULL, "parsed_name is still null?");
1129 Symbol* h_name = k->name();
1130 ClassLoaderData *defining_loader_data = k->class_loader_data();
1131
1132 MutexLocker mu(SystemDictionary_lock, THREAD);
1133
1134 Klass* check = find_class(parsed_name, loader_data);
1135 assert(check == k(), "should be present in the dictionary");
1136
1137 Klass* check2 = find_class(h_name, defining_loader_data);
1138 assert(check == check2, "name inconsistancy in SystemDictionary");
1139 }
1140 } );
1141
1142 return k();
1143 }
1144
1145 #if INCLUDE_CDS
1146 void SystemDictionary::set_shared_dictionary(HashtableBucket<mtClass>* t, int length,
1147 int number_of_entries) {
1148 assert(length == _nof_buckets * sizeof(HashtableBucket<mtClass>),
1149 "bad shared dictionary size.");
1150 _shared_dictionary = new Dictionary(_nof_buckets, t, number_of_entries);
1151 }
1152
1153
1154 // If there is a shared dictionary, then find the entry for the
1155 // given shared system class, if any.
1156
1157 Klass* SystemDictionary::find_shared_class(Symbol* class_name) {
1158 if (shared_dictionary() != NULL) {
1159 unsigned int d_hash = shared_dictionary()->compute_hash(class_name, NULL);
1160 int d_index = shared_dictionary()->hash_to_index(d_hash);
1161
1162 return shared_dictionary()->find_shared_class(d_index, d_hash, class_name);
1163 } else {
1164 return NULL;
1165 }
1166 }
1167
1168
1169 // Load a class from the shared spaces (found through the shared system
1170 // dictionary). Force the superclass and all interfaces to be loaded.
1171 // Update the class definition to include sibling classes and no
1172 // subclasses (yet). [Classes in the shared space are not part of the
1173 // object hierarchy until loaded.]
1174
1175 instanceKlassHandle SystemDictionary::load_shared_class(
1176 Symbol* class_name, Handle class_loader, TRAPS) {
1177 instanceKlassHandle ik (THREAD, find_shared_class(class_name));
1178 // Make sure we only return the boot class for the NULL classloader.
1179 if (ik.not_null() &&
1180 SharedClassUtil::is_shared_boot_class(ik()) && class_loader.is_null()) {
1181 Handle protection_domain;
1182 return load_shared_class(ik, class_loader, protection_domain, THREAD);
1183 }
1184 return instanceKlassHandle();
1185 }
1186
1187 instanceKlassHandle SystemDictionary::load_shared_class(instanceKlassHandle ik,
1188 Handle class_loader,
1189 Handle protection_domain, TRAPS) {
1190 if (ik.not_null()) {
1191 instanceKlassHandle nh = instanceKlassHandle(); // null Handle
1192 Symbol* class_name = ik->name();
1193
1194 // Found the class, now load the superclass and interfaces. If they
1195 // are shared, add them to the main system dictionary and reset
1196 // their hierarchy references (supers, subs, and interfaces).
1197
1198 if (ik->super() != NULL) {
1199 Symbol* cn = ik->super()->name();
1200 resolve_super_or_fail(class_name, cn,
1201 class_loader, protection_domain, true, CHECK_(nh));
1202 }
1203
1204 Array<Klass*>* interfaces = ik->local_interfaces();
1205 int num_interfaces = interfaces->length();
1206 for (int index = 0; index < num_interfaces; index++) {
1207 Klass* k = interfaces->at(index);
1208
1209 // Note: can not use InstanceKlass::cast here because
1210 // interfaces' InstanceKlass's C++ vtbls haven't been
1211 // reinitialized yet (they will be once the interface classes
1212 // are loaded)
1213 Symbol* name = k->name();
1214 resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_(nh));
1215 }
1216
1217 // Adjust methods to recover missing data. They need addresses for
1218 // interpreter entry points and their default native method address
1219 // must be reset.
1220
1221 // Updating methods must be done under a lock so multiple
1222 // threads don't update these in parallel
1223 //
1224 // Shared classes are all currently loaded by either the bootstrap or
1225 // internal parallel class loaders, so this will never cause a deadlock
1226 // on a custom class loader lock.
1227
1228 ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
1229 {
1230 Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
1231 check_loader_lock_contention(lockObject, THREAD);
1232 ObjectLocker ol(lockObject, THREAD, true);
1233 ik->restore_unshareable_info(loader_data, protection_domain, CHECK_(nh));
1234 }
1235
1236 if (TraceClassLoading) {
1237 ResourceMark rm;
1238 tty->print("[Loaded %s", ik->external_name());
1239 tty->print(" from shared objects file");
1240 if (class_loader.not_null()) {
1241 tty->print(" by %s", loader_data->loader_name());
1242 }
1243 tty->print_cr("]");
1244 }
1245
1246 #if INCLUDE_CDS
1247 if (DumpLoadedClassList != NULL && classlist_file->is_open()) {
1248 // Only dump the classes that can be stored into CDS archive
1249 if (SystemDictionaryShared::is_sharing_possible(loader_data)) {
1250 ResourceMark rm(THREAD);
1251 classlist_file->print_cr("%s", ik->name()->as_C_string());
1252 classlist_file->flush();
1253 }
1254 }
1255 #endif
1256
1257 // notify a class loaded from shared object
1258 ClassLoadingService::notify_class_loaded(InstanceKlass::cast(ik()),
1259 true /* shared class */);
1260 }
1261 return ik;
1262 }
1263 #endif
1264
1265 instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) {
1266 instanceKlassHandle nh = instanceKlassHandle(); // null Handle
1267 if (class_loader.is_null()) {
1268
1269 // Search the shared system dictionary for classes preloaded into the
1270 // shared spaces.
1271 instanceKlassHandle k;
1272 {
1273 #if INCLUDE_CDS
1274 PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
1275 k = load_shared_class(class_name, class_loader, THREAD);
1276 #endif
1277 }
1278
1279 if (k.is_null()) {
1280 // Use VM class loader
1281 PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
1282 k = ClassLoader::load_classfile(class_name, CHECK_(nh));
1283 }
1284
1285 // find_or_define_instance_class may return a different InstanceKlass
1286 if (!k.is_null()) {
1287 k = find_or_define_instance_class(class_name, class_loader, k, CHECK_(nh));
1288 }
1289 return k;
1290 } else {
1291 // Use user specified class loader to load class. Call loadClass operation on class_loader.
1292 ResourceMark rm(THREAD);
1293
1294 assert(THREAD->is_Java_thread(), "must be a JavaThread");
1295 JavaThread* jt = (JavaThread*) THREAD;
1296
1615 // ----------------------------------------------------------------------------
1616 // Update hierachy. This is done before the new klass has been added to the SystemDictionary. The Recompile_lock
1617 // is held, to ensure that the compiler is not using the class hierachy, and that deoptimization will kick in
1618 // before a new class is used.
1619
1620 void SystemDictionary::add_to_hierarchy(instanceKlassHandle k, TRAPS) {
1621 assert(k.not_null(), "just checking");
1622 assert_locked_or_safepoint(Compile_lock);
1623
1624 // Link into hierachy. Make sure the vtables are initialized before linking into
1625 k->append_to_sibling_list(); // add to superklass/sibling list
1626 k->process_interfaces(THREAD); // handle all "implements" declarations
1627 k->set_init_state(InstanceKlass::loaded);
1628 // Now flush all code that depended on old class hierarchy.
1629 // Note: must be done *after* linking k into the hierarchy (was bug 12/9/97)
1630 // Also, first reinitialize vtable because it may have gotten out of synch
1631 // while the new class wasn't connected to the class hierarchy.
1632 Universe::flush_dependents_on(k);
1633 }
1634
1635 // ----------------------------------------------------------------------------
1636 // GC support
1637
1638 // Following roots during mark-sweep is separated in two phases.
1639 //
1640 // The first phase follows preloaded classes and all other system
1641 // classes, since these will never get unloaded anyway.
1642 //
1643 // The second phase removes (unloads) unreachable classes from the
1644 // system dictionary and follows the remaining classes' contents.
1645
1646 void SystemDictionary::always_strong_oops_do(OopClosure* blk) {
1647 roots_oops_do(blk, NULL);
1648 }
1649
1650 void SystemDictionary::always_strong_classes_do(KlassClosure* closure) {
1651 // Follow all system classes and temporary placeholders in dictionary
1652 dictionary()->always_strong_classes_do(closure);
1653
1654 // Placeholders. These represent classes we're actively loading.
1697 bool unloading_occurred = false;
1698 if (has_dead_loaders) {
1699 unloading_occurred = dictionary()->do_unloading();
1700 constraints()->purge_loader_constraints();
1701 resolution_errors()->purge_resolution_errors();
1702 }
1703 // Oops referenced by the system dictionary may get unreachable independently
1704 // of the class loader (eg. cached protection domain oops). So we need to
1705 // explicitly unlink them here instead of in Dictionary::do_unloading.
1706 dictionary()->unlink(is_alive);
1707 #ifdef ASSERT
1708 VerifySDReachableAndLiveClosure cl(is_alive);
1709 dictionary()->oops_do(&cl);
1710 #endif
1711 return unloading_occurred;
1712 }
1713
1714 void SystemDictionary::roots_oops_do(OopClosure* strong, OopClosure* weak) {
1715 strong->do_oop(&_java_system_loader);
1716 strong->do_oop(&_system_loader_lock_obj);
1717 CDS_ONLY(SystemDictionaryShared::roots_oops_do(strong);)
1718
1719 // Adjust dictionary
1720 dictionary()->roots_oops_do(strong, weak);
1721
1722 // Visit extra methods
1723 invoke_method_table()->oops_do(strong);
1724 }
1725
1726 void SystemDictionary::oops_do(OopClosure* f) {
1727 f->do_oop(&_java_system_loader);
1728 f->do_oop(&_system_loader_lock_obj);
1729 CDS_ONLY(SystemDictionaryShared::oops_do(f);)
1730
1731 // Adjust dictionary
1732 dictionary()->oops_do(f);
1733
1734 // Visit extra methods
1735 invoke_method_table()->oops_do(f);
1736 }
1737
1738 // Extended Class redefinition support.
1739 // If one of these classes is replaced, we need to replace it in these places.
1740 // KlassClosure::do_klass should take the address of a class but we can
1741 // change that later.
1742 void SystemDictionary::preloaded_classes_do(KlassClosure* f) {
1743 for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
1744 f->do_klass(_well_known_klasses[k]);
1745 }
1746
1747 {
1748 for (int i = 0; i < T_VOID+1; i++) {
1749 if (_box_klasses[i] != NULL) {
1771 // Don't iterate over placeholders
1772 void SystemDictionary::classes_do(void f(Klass*, TRAPS), TRAPS) {
1773 dictionary()->classes_do(f, CHECK);
1774 }
1775
1776 // All classes, and their class loaders
1777 // Don't iterate over placeholders
1778 void SystemDictionary::classes_do(void f(Klass*, ClassLoaderData*)) {
1779 dictionary()->classes_do(f);
1780 }
1781
1782 void SystemDictionary::placeholders_do(void f(Symbol*)) {
1783 placeholders()->entries_do(f);
1784 }
1785
1786 void SystemDictionary::methods_do(void f(Method*)) {
1787 dictionary()->methods_do(f);
1788 invoke_method_table()->methods_do(f);
1789 }
1790
1791 void SystemDictionary::remove_classes_in_error_state() {
1792 dictionary()->remove_classes_in_error_state();
1793 }
1794
1795 // ----------------------------------------------------------------------------
1796 // Lazily load klasses
1797
1798 void SystemDictionary::load_abstract_ownable_synchronizer_klass(TRAPS) {
1799 // if multiple threads calling this function, only one thread will load
1800 // the class. The other threads will find the loaded version once the
1801 // class is loaded.
1802 Klass* aos = _abstract_ownable_synchronizer_klass;
1803 if (aos == NULL) {
1804 Klass* k = resolve_or_fail(vmSymbols::java_util_concurrent_locks_AbstractOwnableSynchronizer(), true, CHECK);
1805 // Force a fence to prevent any read before the write completes
1806 OrderAccess::fence();
1807 _abstract_ownable_synchronizer_klass = k;
1808 }
1809 }
1810
1811 // ----------------------------------------------------------------------------
1812 // Initialization
1813
1814 void SystemDictionary::initialize(TRAPS) {
2584 void SystemDictionary::copy_buckets(char** top, char* end) {
2585 dictionary()->copy_buckets(top, end);
2586 }
2587
2588
2589 void SystemDictionary::copy_table(char** top, char* end) {
2590 dictionary()->copy_table(top, end);
2591 }
2592
2593
2594 void SystemDictionary::reverse() {
2595 dictionary()->reverse();
2596 }
2597
2598 int SystemDictionary::number_of_classes() {
2599 return dictionary()->number_of_entries();
2600 }
2601
2602
2603 // ----------------------------------------------------------------------------
2604 void SystemDictionary::print_shared(bool details) {
2605 shared_dictionary()->print(details);
2606 }
2607
2608 void SystemDictionary::print(bool details) {
2609 dictionary()->print(details);
2610
2611 // Placeholders
2612 GCMutexLocker mu(SystemDictionary_lock);
2613 placeholders()->print();
2614
2615 // loader constraints - print under SD_lock
2616 constraints()->print();
2617 }
2618
2619
2620 void SystemDictionary::verify() {
2621 guarantee(dictionary() != NULL, "Verify of system dictionary failed");
2622 guarantee(constraints() != NULL,
2623 "Verify of loader constraints failed");
2624 guarantee(dictionary()->number_of_entries() >= 0 &&
2625 placeholders()->number_of_entries() >= 0,
2626 "Verify of system dictionary failed");
2627
2628 // Verify dictionary
2629 dictionary()->verify();
2630
2631 GCMutexLocker mu(SystemDictionary_lock);
2632 placeholders()->verify();
2633
2634 // Verify constraint table
2635 guarantee(constraints() != NULL, "Verify of loader constraints failed");
2636 constraints()->verify(dictionary(), placeholders());
2637 }
2638
|