94 PlaceholderTable* SystemDictionary::_placeholders = NULL;
95 LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL;
96 ResolutionErrorTable* SystemDictionary::_resolution_errors = NULL;
97 SymbolPropertyTable* SystemDictionary::_invoke_method_table = NULL;
98 ProtectionDomainCacheTable* SystemDictionary::_pd_cache_table = NULL;
99
100 oop SystemDictionary::_system_loader_lock_obj = NULL;
101
102 InstanceKlass* SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
103 = { NULL /*, NULL...*/ };
104
105 InstanceKlass* SystemDictionary::_box_klasses[T_VOID+1] = { NULL /*, NULL...*/ };
106
107 oop SystemDictionary::_java_system_loader = NULL;
108 oop SystemDictionary::_java_platform_loader = NULL;
109
110 // Default ProtectionDomainCacheSize value
111
112 const int defaultProtectionDomainCacheSize = 1009;
113
114 // ----------------------------------------------------------------------------
115 // Java-level SystemLoader and PlatformLoader
116
117 oop SystemDictionary::java_system_loader() {
118 return _java_system_loader;
119 }
120
121 oop SystemDictionary::java_platform_loader() {
122 return _java_platform_loader;
123 }
124
125 void SystemDictionary::compute_java_loaders(TRAPS) {
126 JavaValue result(T_OBJECT);
127 InstanceKlass* class_loader_klass = SystemDictionary::ClassLoader_klass();
128 JavaCalls::call_static(&result,
129 class_loader_klass,
130 vmSymbols::getSystemClassLoader_name(),
131 vmSymbols::void_classloader_signature(),
132 CHECK);
133
965 // side-effect of this call
966 SignatureStream ss(class_name, false);
967 int ndims = ss.skip_array_prefix(); // skip all '['s
968 BasicType t = ss.type();
969 if (t != T_OBJECT) {
970 k = Universe::typeArrayKlassObj(t);
971 } else {
972 k = SystemDictionary::find(ss.as_symbol(), class_loader, protection_domain, THREAD);
973 }
974 if (k != NULL) {
975 k = k->array_klass_or_null(ndims);
976 }
977 } else {
978 k = find(class_name, class_loader, protection_domain, THREAD);
979 }
980 return k;
981 }
982
983 // Note: this method is much like resolve_from_stream, but
984 // does not publish the classes via the SystemDictionary.
985 // Handles unsafe_DefineAnonymousClass and redefineclasses
986 // RedefinedClasses do not add to the class hierarchy
987 InstanceKlass* SystemDictionary::parse_stream(Symbol* class_name,
988 Handle class_loader,
989 Handle protection_domain,
990 ClassFileStream* st,
991 const InstanceKlass* unsafe_anonymous_host,
992 GrowableArray<Handle>* cp_patches,
993 TRAPS) {
994
995 EventClassLoad class_load_start_event;
996
997 ClassLoaderData* loader_data;
998 if (unsafe_anonymous_host != NULL) {
999 // Create a new CLD for an unsafe anonymous class, that uses the same class loader
1000 // as the unsafe_anonymous_host
1001 guarantee(unsafe_anonymous_host->class_loader() == class_loader(), "should be the same");
1002 loader_data = ClassLoaderData::unsafe_anonymous_class_loader_data(class_loader);
1003 } else {
1004 loader_data = ClassLoaderData::class_loader_data(class_loader());
1005 }
1006
1007 assert(st != NULL, "invariant");
1008 assert(st->need_verify(), "invariant");
1009
1010 // Parse stream and create a klass.
1011 // Note that we do this even though this klass might
1012 // already be present in the SystemDictionary, otherwise we would not
1013 // throw potential ClassFormatErrors.
1014
1015 InstanceKlass* k = KlassFactory::create_from_stream(st,
1016 class_name,
1017 loader_data,
1018 protection_domain,
1019 unsafe_anonymous_host,
1020 cp_patches,
1021 CHECK_NULL);
1022
1023 if (unsafe_anonymous_host != NULL && k != NULL) {
1024 // Unsafe anonymous classes must update ClassLoaderData holder (was unsafe_anonymous_host loader)
1025 // so that they can be unloaded when the mirror is no longer referenced.
1026 k->class_loader_data()->initialize_holder(Handle(THREAD, k->java_mirror()));
1027
1028 {
1029 MutexLocker mu_r(THREAD, Compile_lock);
1030
1031 // Add to class hierarchy, initialize vtables, and do possible
1032 // deoptimizations.
1033 add_to_hierarchy(k, CHECK_NULL); // No exception, but can block
1034 // But, do not add to dictionary.
1035 }
1036
1037 // Rewrite and patch constant pool here.
1038 k->link_class(CHECK_NULL);
1039 if (cp_patches != NULL) {
1040 k->constants()->patch_resolved_references(cp_patches);
1041 }
1042
1043 // If it's anonymous, initialize it now, since nobody else will.
1044 k->eager_initialize(CHECK_NULL);
1045
1046 // notify jvmti
1047 if (JvmtiExport::should_post_class_load()) {
1048 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
1049 JvmtiExport::post_class_load((JavaThread *) THREAD, k);
1050 }
1051 if (class_load_start_event.should_commit()) {
1052 post_class_load_event(&class_load_start_event, k, loader_data);
1053 }
1054 }
1055 assert(unsafe_anonymous_host != NULL || NULL == cp_patches,
1056 "cp_patches only found with unsafe_anonymous_host");
1057
1058 return k;
1059 }
1060
1061 // Add a klass to the system from a stream (called by jni_DefineClass and
1062 // JVM_DefineClass).
1063 // Note: class_name can be NULL. In that case we do not know the name of
1064 // the class until we have parsed the stream.
1065
1066 InstanceKlass* SystemDictionary::resolve_from_stream(Symbol* class_name,
1067 Handle class_loader,
1068 Handle protection_domain,
1069 ClassFileStream* st,
1070 TRAPS) {
1071
1072 HandleMark hm(THREAD);
1073
1074 // Classloaders that support parallelism, e.g. bootstrap classloader,
1075 // do not acquire lock here
1090 // Parse the stream and create a klass.
1091 // Note that we do this even though this klass might
1092 // already be present in the SystemDictionary, otherwise we would not
1093 // throw potential ClassFormatErrors.
1094 InstanceKlass* k = NULL;
1095
1096 #if INCLUDE_CDS
1097 if (!DumpSharedSpaces) {
1098 k = SystemDictionaryShared::lookup_from_stream(class_name,
1099 class_loader,
1100 protection_domain,
1101 st,
1102 CHECK_NULL);
1103 }
1104 #endif
1105
1106 if (k == NULL) {
1107 if (st->buffer() == NULL) {
1108 return NULL;
1109 }
1110 k = KlassFactory::create_from_stream(st,
1111 class_name,
1112 loader_data,
1113 protection_domain,
1114 NULL, // unsafe_anonymous_host
1115 NULL, // cp_patches
1116 CHECK_NULL);
1117 }
1118
1119 assert(k != NULL, "no klass created");
1120 Symbol* h_name = k->name();
1121 assert(class_name == NULL || class_name == h_name, "name mismatch");
1122
1123 // Add class just loaded
1124 // If a class loader supports parallel classloading handle parallel define requests
1125 // find_or_define_instance_class may return a different InstanceKlass
1126 if (is_parallelCapable(class_loader)) {
1127 InstanceKlass* defined_k = find_or_define_instance_class(h_name, class_loader, k, THREAD);
1128 if (!HAS_PENDING_EXCEPTION && defined_k != k) {
1129 // If a parallel capable class loader already defined this class, register 'k' for cleanup.
1130 assert(defined_k != NULL, "Should have a klass if there's no exception");
1131 loader_data->add_to_deallocate_list(k);
1132 k = defined_k;
1133 }
1134 } else {
1135 define_instance_class(k, THREAD);
1136 }
2308 resolution_errors()->delete_entry(pool);
2309 }
2310
2311 // Lookup resolution error table. Returns error if found, otherwise NULL.
2312 Symbol* SystemDictionary::find_resolution_error(const constantPoolHandle& pool, int which,
2313 Symbol** message) {
2314 unsigned int hash = resolution_errors()->compute_hash(pool, which);
2315 int index = resolution_errors()->hash_to_index(hash);
2316 {
2317 MutexLocker ml(Thread::current(), SystemDictionary_lock);
2318 ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
2319 if (entry != NULL) {
2320 *message = entry->message();
2321 return entry->error();
2322 } else {
2323 return NULL;
2324 }
2325 }
2326 }
2327
2328
2329 // Signature constraints ensure that callers and callees agree about
2330 // the meaning of type names in their signatures. This routine is the
2331 // intake for constraints. It collects them from several places:
2332 //
2333 // * LinkResolver::resolve_method (if check_access is true) requires
2334 // that the resolving class (the caller) and the defining class of
2335 // the resolved method (the callee) agree on each type in the
2336 // method's signature.
2337 //
2338 // * LinkResolver::resolve_interface_method performs exactly the same
2339 // checks.
2340 //
2341 // * LinkResolver::resolve_field requires that the constant pool
2342 // attempting to link to a field agree with the field's defining
2343 // class about the type of the field signature.
2344 //
2345 // * klassVtable::initialize_vtable requires that, when a class
2346 // overrides a vtable entry allocated by a superclass, that the
2347 // overriding method (i.e., the callee) agree with the superclass
|
94 PlaceholderTable* SystemDictionary::_placeholders = NULL;
95 LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL;
96 ResolutionErrorTable* SystemDictionary::_resolution_errors = NULL;
97 SymbolPropertyTable* SystemDictionary::_invoke_method_table = NULL;
98 ProtectionDomainCacheTable* SystemDictionary::_pd_cache_table = NULL;
99
100 oop SystemDictionary::_system_loader_lock_obj = NULL;
101
102 InstanceKlass* SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
103 = { NULL /*, NULL...*/ };
104
105 InstanceKlass* SystemDictionary::_box_klasses[T_VOID+1] = { NULL /*, NULL...*/ };
106
107 oop SystemDictionary::_java_system_loader = NULL;
108 oop SystemDictionary::_java_platform_loader = NULL;
109
110 // Default ProtectionDomainCacheSize value
111
112 const int defaultProtectionDomainCacheSize = 1009;
113
114 ClassLoadInfo::ClassLoadInfo() {
115 _protection_domain = Handle();
116 _unsafe_anonymous_host = NULL;
117 _cp_patches = NULL;
118 _class_hidden_info._dynamic_nest_host = NULL;
119 _class_hidden_info._class_data = Handle();
120 _is_hidden = false;
121 _is_strong_hidden = false;
122 _can_access_vm_annotations = false;
123 }
124
125 ClassLoadInfo::ClassLoadInfo(Handle protection_domain) {
126 _protection_domain = protection_domain;
127 _unsafe_anonymous_host = NULL;
128 _cp_patches = NULL;
129 _class_hidden_info._dynamic_nest_host = NULL;
130 _class_hidden_info._class_data = Handle();
131 _is_hidden = false;
132 _is_strong_hidden = false;
133 _can_access_vm_annotations = false;
134 }
135
136 ClassLoadInfo::ClassLoadInfo(Handle protection_domain,
137 const InstanceKlass* unsafe_anonymous_host,
138 GrowableArray<Handle>* cp_patches,
139 InstanceKlass* dynamic_nest_host,
140 Handle class_data,
141 bool is_hidden,
142 bool is_strong_hidden,
143 bool can_access_vm_annotations) {
144 _protection_domain = protection_domain;
145 _unsafe_anonymous_host = unsafe_anonymous_host;
146 _cp_patches = cp_patches;
147 _class_hidden_info._dynamic_nest_host = dynamic_nest_host;
148 _class_hidden_info._class_data = class_data;
149 _is_hidden = is_hidden;
150 _is_strong_hidden = is_strong_hidden;
151 _can_access_vm_annotations = can_access_vm_annotations;
152 }
153
154 // ----------------------------------------------------------------------------
155 // Java-level SystemLoader and PlatformLoader
156
157 oop SystemDictionary::java_system_loader() {
158 return _java_system_loader;
159 }
160
161 oop SystemDictionary::java_platform_loader() {
162 return _java_platform_loader;
163 }
164
165 void SystemDictionary::compute_java_loaders(TRAPS) {
166 JavaValue result(T_OBJECT);
167 InstanceKlass* class_loader_klass = SystemDictionary::ClassLoader_klass();
168 JavaCalls::call_static(&result,
169 class_loader_klass,
170 vmSymbols::getSystemClassLoader_name(),
171 vmSymbols::void_classloader_signature(),
172 CHECK);
173
1005 // side-effect of this call
1006 SignatureStream ss(class_name, false);
1007 int ndims = ss.skip_array_prefix(); // skip all '['s
1008 BasicType t = ss.type();
1009 if (t != T_OBJECT) {
1010 k = Universe::typeArrayKlassObj(t);
1011 } else {
1012 k = SystemDictionary::find(ss.as_symbol(), class_loader, protection_domain, THREAD);
1013 }
1014 if (k != NULL) {
1015 k = k->array_klass_or_null(ndims);
1016 }
1017 } else {
1018 k = find(class_name, class_loader, protection_domain, THREAD);
1019 }
1020 return k;
1021 }
1022
1023 // Note: this method is much like resolve_from_stream, but
1024 // does not publish the classes via the SystemDictionary.
1025 // Handles Lookup.defineClass hidden, unsafe_DefineAnonymousClass
1026 // and redefineclasses. RedefinedClasses do not add to the class hierarchy.
1027 InstanceKlass* SystemDictionary::parse_stream(Symbol* class_name,
1028 Handle class_loader,
1029 ClassFileStream* st,
1030 const ClassLoadInfo& cl_info,
1031 TRAPS) {
1032
1033 EventClassLoad class_load_start_event;
1034
1035 ClassLoaderData* loader_data;
1036
1037 bool is_unsafe_anon_class = cl_info.unsafe_anonymous_host() != NULL;
1038
1039 if (is_unsafe_anon_class) {
1040 // - for unsafe anonymous class: create a new CLD whith a class holder that uses
1041 // the same class loader as the unsafe_anonymous_host.
1042 guarantee(cl_info.unsafe_anonymous_host()->class_loader() == class_loader(),
1043 "should be the same");
1044 loader_data = ClassLoaderData::has_class_mirror_holder_cld(class_loader);
1045 } else if (cl_info.is_hidden()) {
1046 // - for hidden classes that are not strong: create a new CLD that has a class holder and
1047 // whose loader is the Lookup class' loader.
1048 // - for hidden class: add the class to the Lookup class' loader's CLD.
1049 if (!cl_info.is_strong_hidden()) {
1050 loader_data = ClassLoaderData::has_class_mirror_holder_cld(class_loader);
1051 } else {
1052 // This hidden class goes into the regular CLD pool for this loader.
1053 loader_data = register_loader(class_loader);
1054 }
1055 } else {
1056 loader_data = ClassLoaderData::class_loader_data(class_loader());
1057 }
1058
1059 assert(st != NULL, "invariant");
1060 assert(st->need_verify(), "invariant");
1061
1062 // Parse stream and create a klass.
1063 // Note that we do this even though this klass might
1064 // already be present in the SystemDictionary, otherwise we would not
1065 // throw potential ClassFormatErrors.
1066
1067 InstanceKlass* k = KlassFactory::create_from_stream(st,
1068 class_name,
1069 loader_data,
1070 cl_info,
1071 CHECK_NULL);
1072
1073 if ((cl_info.is_hidden() || is_unsafe_anon_class) && k != NULL) {
1074 // Hidden classes that are not strong and unsafe anonymous classes must update
1075 // ClassLoaderData holder so that they can be unloaded when the mirror is no
1076 // longer referenced.
1077 if (!cl_info.is_strong_hidden() || is_unsafe_anon_class) {
1078 k->class_loader_data()->initialize_holder(Handle(THREAD, k->java_mirror()));
1079 }
1080
1081 {
1082 MutexLocker mu_r(THREAD, Compile_lock);
1083
1084 // Add to class hierarchy, initialize vtables, and do possible
1085 // deoptimizations.
1086 add_to_hierarchy(k, CHECK_NULL); // No exception, but can block
1087 // But, do not add to dictionary.
1088 }
1089
1090 // Rewrite and patch constant pool here.
1091 k->link_class(CHECK_NULL);
1092 if (cl_info.cp_patches() != NULL) {
1093 k->constants()->patch_resolved_references(cl_info.cp_patches());
1094 }
1095
1096 // If it's anonymous, initialize it now, since nobody else will.
1097 if (is_unsafe_anon_class) {
1098 k->eager_initialize(CHECK_NULL);
1099 }
1100
1101 // notify jvmti
1102 if (JvmtiExport::should_post_class_load()) {
1103 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
1104 JvmtiExport::post_class_load((JavaThread *) THREAD, k);
1105 }
1106 if (class_load_start_event.should_commit()) {
1107 post_class_load_event(&class_load_start_event, k, loader_data);
1108 }
1109 }
1110 assert(is_unsafe_anon_class || NULL == cl_info.cp_patches(),
1111 "cp_patches only found with unsafe_anonymous_host");
1112
1113 return k;
1114 }
1115
1116 // Add a klass to the system from a stream (called by jni_DefineClass and
1117 // JVM_DefineClass).
1118 // Note: class_name can be NULL. In that case we do not know the name of
1119 // the class until we have parsed the stream.
1120
1121 InstanceKlass* SystemDictionary::resolve_from_stream(Symbol* class_name,
1122 Handle class_loader,
1123 Handle protection_domain,
1124 ClassFileStream* st,
1125 TRAPS) {
1126
1127 HandleMark hm(THREAD);
1128
1129 // Classloaders that support parallelism, e.g. bootstrap classloader,
1130 // do not acquire lock here
1145 // Parse the stream and create a klass.
1146 // Note that we do this even though this klass might
1147 // already be present in the SystemDictionary, otherwise we would not
1148 // throw potential ClassFormatErrors.
1149 InstanceKlass* k = NULL;
1150
1151 #if INCLUDE_CDS
1152 if (!DumpSharedSpaces) {
1153 k = SystemDictionaryShared::lookup_from_stream(class_name,
1154 class_loader,
1155 protection_domain,
1156 st,
1157 CHECK_NULL);
1158 }
1159 #endif
1160
1161 if (k == NULL) {
1162 if (st->buffer() == NULL) {
1163 return NULL;
1164 }
1165 ClassLoadInfo cl_info(protection_domain);
1166 k = KlassFactory::create_from_stream(st, class_name, loader_data, cl_info, CHECK_NULL);
1167 }
1168
1169 assert(k != NULL, "no klass created");
1170 Symbol* h_name = k->name();
1171 assert(class_name == NULL || class_name == h_name, "name mismatch");
1172
1173 // Add class just loaded
1174 // If a class loader supports parallel classloading handle parallel define requests
1175 // find_or_define_instance_class may return a different InstanceKlass
1176 if (is_parallelCapable(class_loader)) {
1177 InstanceKlass* defined_k = find_or_define_instance_class(h_name, class_loader, k, THREAD);
1178 if (!HAS_PENDING_EXCEPTION && defined_k != k) {
1179 // If a parallel capable class loader already defined this class, register 'k' for cleanup.
1180 assert(defined_k != NULL, "Should have a klass if there's no exception");
1181 loader_data->add_to_deallocate_list(k);
1182 k = defined_k;
1183 }
1184 } else {
1185 define_instance_class(k, THREAD);
1186 }
2358 resolution_errors()->delete_entry(pool);
2359 }
2360
2361 // Lookup resolution error table. Returns error if found, otherwise NULL.
2362 Symbol* SystemDictionary::find_resolution_error(const constantPoolHandle& pool, int which,
2363 Symbol** message) {
2364 unsigned int hash = resolution_errors()->compute_hash(pool, which);
2365 int index = resolution_errors()->hash_to_index(hash);
2366 {
2367 MutexLocker ml(Thread::current(), SystemDictionary_lock);
2368 ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
2369 if (entry != NULL) {
2370 *message = entry->message();
2371 return entry->error();
2372 } else {
2373 return NULL;
2374 }
2375 }
2376 }
2377
2378 // Add an entry to resolution error table to record an error in resolving or
2379 // validating a nest host. This is used to construct informative error
2380 // messages when IllegalAccessError's occur. If an entry already exists it will
2381 // be updated with the nest host error message.
2382 void SystemDictionary::add_nest_host_error(const constantPoolHandle& pool,
2383 int which,
2384 const char* message) {
2385 unsigned int hash = resolution_errors()->compute_hash(pool, which);
2386 int index = resolution_errors()->hash_to_index(hash);
2387 {
2388 MutexLocker ml(Thread::current(), SystemDictionary_lock);
2389 ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
2390 if (entry != NULL) {
2391 assert(entry->nest_host_error() == NULL, "Nest host error message already set!");
2392 entry->set_nest_host_error(message);
2393 } else {
2394 resolution_errors()->add_entry(index, hash, pool, which, message);
2395 }
2396 }
2397 }
2398
2399 // Lookup any nest host error
2400 const char* SystemDictionary::find_nest_host_error(const constantPoolHandle& pool, int which) {
2401 unsigned int hash = resolution_errors()->compute_hash(pool, which);
2402 int index = resolution_errors()->hash_to_index(hash);
2403 {
2404 MutexLocker ml(Thread::current(), SystemDictionary_lock);
2405 ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
2406 if (entry != NULL) {
2407 return entry->nest_host_error();
2408 } else {
2409 return NULL;
2410 }
2411 }
2412 }
2413
2414
2415 // Signature constraints ensure that callers and callees agree about
2416 // the meaning of type names in their signatures. This routine is the
2417 // intake for constraints. It collects them from several places:
2418 //
2419 // * LinkResolver::resolve_method (if check_access is true) requires
2420 // that the resolving class (the caller) and the defining class of
2421 // the resolved method (the callee) agree on each type in the
2422 // method's signature.
2423 //
2424 // * LinkResolver::resolve_interface_method performs exactly the same
2425 // checks.
2426 //
2427 // * LinkResolver::resolve_field requires that the constant pool
2428 // attempting to link to a field agree with the field's defining
2429 // class about the type of the field signature.
2430 //
2431 // * klassVtable::initialize_vtable requires that, when a class
2432 // overrides a vtable entry allocated by a superclass, that the
2433 // overriding method (i.e., the callee) agree with the superclass
|