280
281 // Forwards to resolve_instance_class_or_null
282
283 Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name,
284 Handle class_loader,
285 Handle protection_domain,
286 TRAPS) {
287 assert(FieldType::is_array(class_name), "must be array");
288 Klass* k = NULL;
289 FieldArrayInfo fd;
290 // dimension and object_key in FieldArrayInfo are assigned as a side-effect
291 // of this call
292 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_NULL);
293 if (t == T_OBJECT || t == T_VALUETYPE) {
294 // naked oop "k" is OK here -- we assign back into it
295 k = SystemDictionary::resolve_instance_class_or_null(fd.object_key(),
296 class_loader,
297 protection_domain,
298 CHECK_NULL);
299 if (k != NULL) {
300 k = k->array_klass(fd.dimension(), CHECK_NULL);
301 }
302 } else {
303 k = Universe::typeArrayKlassObj(t);
304 k = TypeArrayKlass::cast(k)->array_klass(fd.dimension(), CHECK_NULL);
305 }
306 return k;
307 }
308
309 // Must be called for any super-class or super-interface resolution
310 // during class definition to allow class circularity checking
311 // super-interface callers:
312 // parse_interfaces - for defineClass & jvmtiRedefineClasses
313 // super-class callers:
314 // ClassFileParser - for defineClass & jvmtiRedefineClasses
315 // load_shared_class - while loading a class from shared archive
316 // resolve_instance_class_or_null:
317 // via: handle_parallel_super_load
318 // when resolving a class that has an existing placeholder with
319 // a saved superclass [i.e. a defineClass is currently in progress]
320 // if another thread is trying to resolve the class, it must do
321 // super-class checks on its own thread to catch class circularity
322 // This last call is critical in class circularity checking for cases
323 // where classloading is delegated to different threads and the
324 // classloader lock is released.
1011 // return NULL in case of error.
1012 Klass* SystemDictionary::find_instance_or_array_klass(Symbol* class_name,
1013 Handle class_loader,
1014 Handle protection_domain,
1015 TRAPS) {
1016 Klass* k = NULL;
1017 assert(class_name != NULL, "class name must be non NULL");
1018
1019 if (FieldType::is_array(class_name)) {
1020 // The name refers to an array. Parse the name.
1021 // dimension and object_key in FieldArrayInfo are assigned as a
1022 // side-effect of this call
1023 FieldArrayInfo fd;
1024 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
1025 if (t != T_OBJECT && t != T_VALUETYPE) {
1026 k = Universe::typeArrayKlassObj(t);
1027 } else {
1028 k = SystemDictionary::find(fd.object_key(), class_loader, protection_domain, THREAD);
1029 }
1030 if (k != NULL) {
1031 k = k->array_klass_or_null(fd.dimension());
1032 }
1033 } else {
1034 k = find(class_name, class_loader, protection_domain, THREAD);
1035 }
1036 return k;
1037 }
1038
1039 // Note: this method is much like resolve_from_stream, but
1040 // does not publish the classes via the SystemDictionary.
1041 // Handles unsafe_DefineAnonymousClass and redefineclasses
1042 // RedefinedClasses do not add to the class hierarchy
1043 InstanceKlass* SystemDictionary::parse_stream(Symbol* class_name,
1044 Handle class_loader,
1045 Handle protection_domain,
1046 ClassFileStream* st,
1047 const InstanceKlass* unsafe_anonymous_host,
1048 GrowableArray<Handle>* cp_patches,
1049 TRAPS) {
1050
1051 EventClassLoad class_load_start_event;
2248 no_protection_domain, CHECK_NULL);
2249 if (klass != NULL)
2250 return klass;
2251
2252 // Now look to see if it has been loaded elsewhere, and is subject to
2253 // a loader constraint that would require this loader to return the
2254 // klass that is already loaded.
2255 if (FieldType::is_array(class_name)) {
2256 // For array classes, their Klass*s are not kept in the
2257 // constraint table. The element Klass*s are.
2258 FieldArrayInfo fd;
2259 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
2260 if (t != T_OBJECT && t != T_VALUETYPE) {
2261 klass = Universe::typeArrayKlassObj(t);
2262 } else {
2263 MutexLocker mu(SystemDictionary_lock, THREAD);
2264 klass = constraints()->find_constrained_klass(fd.object_key(), class_loader);
2265 }
2266 // If element class already loaded, allocate array klass
2267 if (klass != NULL) {
2268 klass = klass->array_klass_or_null(fd.dimension());
2269 }
2270 } else {
2271 MutexLocker mu(SystemDictionary_lock, THREAD);
2272 // Non-array classes are easy: simply check the constraint table.
2273 klass = constraints()->find_constrained_klass(class_name, class_loader);
2274 }
2275
2276 return klass;
2277 }
2278
2279
2280 bool SystemDictionary::add_loader_constraint(Symbol* class_name,
2281 Handle class_loader1,
2282 Handle class_loader2,
2283 Thread* THREAD) {
2284 ClassLoaderData* loader_data1 = class_loader_data(class_loader1);
2285 ClassLoaderData* loader_data2 = class_loader_data(class_loader2);
2286
2287 Symbol* constraint_name = NULL;
2288 // Needs to be in same scope as constraint_name in case a Symbol is created and
|
280
281 // Forwards to resolve_instance_class_or_null
282
283 Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name,
284 Handle class_loader,
285 Handle protection_domain,
286 TRAPS) {
287 assert(FieldType::is_array(class_name), "must be array");
288 Klass* k = NULL;
289 FieldArrayInfo fd;
290 // dimension and object_key in FieldArrayInfo are assigned as a side-effect
291 // of this call
292 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_NULL);
293 if (t == T_OBJECT || t == T_VALUETYPE) {
294 // naked oop "k" is OK here -- we assign back into it
295 k = SystemDictionary::resolve_instance_class_or_null(fd.object_key(),
296 class_loader,
297 protection_domain,
298 CHECK_NULL);
299 if (k != NULL) {
300 k = k->array_klass(fd.storage_props(), fd.dimension(), CHECK_NULL);
301 }
302 } else {
303 k = Universe::typeArrayKlassObj(t);
304 k = TypeArrayKlass::cast(k)->array_klass(fd.storage_props(), fd.dimension(), CHECK_NULL);
305 }
306 return k;
307 }
308
309 // Must be called for any super-class or super-interface resolution
310 // during class definition to allow class circularity checking
311 // super-interface callers:
312 // parse_interfaces - for defineClass & jvmtiRedefineClasses
313 // super-class callers:
314 // ClassFileParser - for defineClass & jvmtiRedefineClasses
315 // load_shared_class - while loading a class from shared archive
316 // resolve_instance_class_or_null:
317 // via: handle_parallel_super_load
318 // when resolving a class that has an existing placeholder with
319 // a saved superclass [i.e. a defineClass is currently in progress]
320 // if another thread is trying to resolve the class, it must do
321 // super-class checks on its own thread to catch class circularity
322 // This last call is critical in class circularity checking for cases
323 // where classloading is delegated to different threads and the
324 // classloader lock is released.
1011 // return NULL in case of error.
1012 Klass* SystemDictionary::find_instance_or_array_klass(Symbol* class_name,
1013 Handle class_loader,
1014 Handle protection_domain,
1015 TRAPS) {
1016 Klass* k = NULL;
1017 assert(class_name != NULL, "class name must be non NULL");
1018
1019 if (FieldType::is_array(class_name)) {
1020 // The name refers to an array. Parse the name.
1021 // dimension and object_key in FieldArrayInfo are assigned as a
1022 // side-effect of this call
1023 FieldArrayInfo fd;
1024 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
1025 if (t != T_OBJECT && t != T_VALUETYPE) {
1026 k = Universe::typeArrayKlassObj(t);
1027 } else {
1028 k = SystemDictionary::find(fd.object_key(), class_loader, protection_domain, THREAD);
1029 }
1030 if (k != NULL) {
1031 k = k->array_klass_or_null(fd.storage_props(), fd.dimension());
1032 }
1033 } else {
1034 k = find(class_name, class_loader, protection_domain, THREAD);
1035 }
1036 return k;
1037 }
1038
1039 // Note: this method is much like resolve_from_stream, but
1040 // does not publish the classes via the SystemDictionary.
1041 // Handles unsafe_DefineAnonymousClass and redefineclasses
1042 // RedefinedClasses do not add to the class hierarchy
1043 InstanceKlass* SystemDictionary::parse_stream(Symbol* class_name,
1044 Handle class_loader,
1045 Handle protection_domain,
1046 ClassFileStream* st,
1047 const InstanceKlass* unsafe_anonymous_host,
1048 GrowableArray<Handle>* cp_patches,
1049 TRAPS) {
1050
1051 EventClassLoad class_load_start_event;
2248 no_protection_domain, CHECK_NULL);
2249 if (klass != NULL)
2250 return klass;
2251
2252 // Now look to see if it has been loaded elsewhere, and is subject to
2253 // a loader constraint that would require this loader to return the
2254 // klass that is already loaded.
2255 if (FieldType::is_array(class_name)) {
2256 // For array classes, their Klass*s are not kept in the
2257 // constraint table. The element Klass*s are.
2258 FieldArrayInfo fd;
2259 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
2260 if (t != T_OBJECT && t != T_VALUETYPE) {
2261 klass = Universe::typeArrayKlassObj(t);
2262 } else {
2263 MutexLocker mu(SystemDictionary_lock, THREAD);
2264 klass = constraints()->find_constrained_klass(fd.object_key(), class_loader);
2265 }
2266 // If element class already loaded, allocate array klass
2267 if (klass != NULL) {
2268 klass = klass->array_klass_or_null(fd.storage_props(), fd.dimension());
2269 }
2270 } else {
2271 MutexLocker mu(SystemDictionary_lock, THREAD);
2272 // Non-array classes are easy: simply check the constraint table.
2273 klass = constraints()->find_constrained_klass(class_name, class_loader);
2274 }
2275
2276 return klass;
2277 }
2278
2279
2280 bool SystemDictionary::add_loader_constraint(Symbol* class_name,
2281 Handle class_loader1,
2282 Handle class_loader2,
2283 Thread* THREAD) {
2284 ClassLoaderData* loader_data1 = class_loader_data(class_loader1);
2285 ClassLoaderData* loader_data2 = class_loader_data(class_loader2);
2286
2287 Symbol* constraint_name = NULL;
2288 // Needs to be in same scope as constraint_name in case a Symbol is created and
|