238 return klass;
239 }
240
241
242 Klass* SystemDictionary::resolve_or_fail(Symbol* class_name,
243 bool throw_error, TRAPS)
244 {
245 return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
246 }
247
248
249 // Forwards to resolve_instance_class_or_null
250
251 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
252 assert(THREAD->can_call_java(),
253 "can not load classes with compiler thread: class=%s, classloader=%s",
254 class_name->as_C_string(),
255 class_loader.is_null() ? "null" : class_loader->klass()->name()->as_C_string());
256 if (FieldType::is_array(class_name)) {
257 return resolve_array_class_or_null(class_name, class_loader, protection_domain, THREAD);
258 } else if (FieldType::is_obj(class_name) || FieldType::is_valuetype(class_name)) {
259 ResourceMark rm(THREAD);
260 // Ignore wrapping L and ;. (and Q and ; for value types);
261 TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
262 class_name->utf8_length() - 2, CHECK_NULL);
263 return resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
264 } else {
265 return resolve_instance_class_or_null(class_name, class_loader, protection_domain, THREAD);
266 }
267 }
268
269 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, TRAPS) {
270 return resolve_or_null(class_name, Handle(), Handle(), THREAD);
271 }
272
273 // Forwards to resolve_instance_class_or_null
274
275 Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name,
276 Handle class_loader,
277 Handle protection_domain,
278 TRAPS) {
281 FieldArrayInfo fd;
282 // dimension and object_key in FieldArrayInfo are assigned as a side-effect
283 // of this call
284 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_NULL);
285 if (t == T_OBJECT || t == T_VALUETYPE) {
286 // naked oop "k" is OK here -- we assign back into it
287 k = SystemDictionary::resolve_instance_class_or_null(fd.object_key(),
288 class_loader,
289 protection_domain,
290 CHECK_NULL);
291 if (k != NULL) {
292 k = k->array_klass(fd.dimension(), CHECK_NULL);
293 }
294 } else {
295 k = Universe::typeArrayKlassObj(t);
296 k = TypeArrayKlass::cast(k)->array_klass(fd.dimension(), CHECK_NULL);
297 }
298 return k;
299 }
300
301 // Temporary Minimal Value Type support code. Attempt to load VCC for DVT descriptor
302 Klass* SystemDictionary::resolve_dvt_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
303 assert(EnableMVT && FieldType::is_dvt_postfix(class_name), "Invariant");
304
305 ResourceMark rm(THREAD);
306 // Given a "Q-type" descriptor and EnableMVT, original exception is not so interesting
307 CLEAR_PENDING_EXCEPTION;
308
309 TempNewSymbol vcc_name = SymbolTable::new_symbol(FieldType::dvt_unmangle_vcc(class_name), CHECK_NULL);
310 Klass* vcc = do_resolve_instance_class_or_null(vcc_name, class_loader, protection_domain, CHECK_NULL);
311 if (vcc == NULL) {
312 return NULL;
313 }
314 Klass* dvt = do_resolve_instance_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL);
315 if ((dvt !=NULL) && dvt->is_value() && (ValueKlass::cast(dvt)->get_vcc_klass() == vcc)) {
316 return dvt;
317 }
318 if (vcc->is_instance_klass() && (!InstanceKlass::cast(vcc)->has_vcc_annotation())) {
319 static const char not_vcc_msg[] =
320 "Failed to resolve %s, found possible ValueCapableClass name mangle match is not ValueCapableClass annotated: %s";
321 size_t buflen = strlen(not_vcc_msg) + class_name->utf8_length() + vcc_name->utf8_length();
322 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
323 jio_snprintf(buf, buflen, not_vcc_msg, class_name->as_C_string(), vcc_name->as_C_string());
324 THROW_MSG_NULL(vmSymbols::java_lang_NoClassDefFoundError(), buf);
325 }
326 return NULL;
327 }
328
329
330 // Must be called for any super-class or super-interface resolution
331 // during class definition to allow class circularity checking
332 // super-interface callers:
333 // parse_interfaces - for defineClass & jvmtiRedefineClasses
334 // super-class callers:
335 // ClassFileParser - for defineClass & jvmtiRedefineClasses
336 // load_shared_class - while loading a class from shared archive
337 // resolve_instance_class_or_null:
338 // via: handle_parallel_super_load
339 // when resolving a class that has an existing placeholder with
340 // a saved superclass [i.e. a defineClass is currently in progress]
341 // if another thread is trying to resolve the class, it must do
342 // super-class checks on its own thread to catch class circularity
343 // This last call is critical in class circularity checking for cases
344 // where classloading is delegated to different threads and the
345 // classloader lock is released.
346 // Take the case: Base->Super->Base
347 // 1. If thread T1 tries to do a defineClass of class Base
348 // resolve_super_or_fail creates placeholder: T1, Base (super Super)
349 // 2. resolve_instance_class_or_null does not find SD or placeholder for Super
667 #endif // INCLUDE_TRACE
668 }
669
670 static void class_define_event(InstanceKlass* k,
671 const ClassLoaderData* def_cld) {
672 #if INCLUDE_TRACE
673 EventClassDefine event;
674 if (event.should_commit()) {
675 event.set_definedClass(k);
676 event.set_definingClassLoader(def_cld);
677 event.commit();
678 }
679 #endif // INCLUDE_TRACE
680 }
681
682 Klass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
683 Handle class_loader,
684 Handle protection_domain,
685 TRAPS) {
686 Klass* k = do_resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
687 if (EnableMVT && (k == NULL) && FieldType::is_dvt_postfix(name)) {
688 k = resolve_dvt_or_null(name, class_loader, protection_domain, THREAD);
689 }
690 return k;
691 }
692
693 // Be careful when modifying this code: once you have run
694 // placeholders()->find_and_add(PlaceholderTable::LOAD_INSTANCE),
695 // you need to find_and_remove it before returning.
696 // So be careful to not exit with a CHECK_ macro betweeen these calls.
697 Klass* SystemDictionary::do_resolve_instance_class_or_null(Symbol* name,
698 Handle class_loader,
699 Handle protection_domain,
700 TRAPS) {
701 assert(name != NULL && !FieldType::is_array(name) &&
702 !FieldType::is_obj(name) && !FieldType::is_valuetype(name), "invalid class name");
703
704 EventClassLoad class_load_start_event;
705
706 HandleMark hm(THREAD);
707
708 // Fix for 4474172; see evaluation for more details
709 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
710 ClassLoaderData *loader_data = register_loader(class_loader, CHECK_NULL);
711 Dictionary* dictionary = loader_data->dictionary();
712 unsigned int d_hash = dictionary->compute_hash(name);
713
714 // Do lookup to see if class already exist and the protection domain
715 // has the right access
716 // This call uses find which checks protection domain already matches
717 // All subsequent calls use find_class, and set has_loaded_class so that
718 // before we return a result we call out to java to check for valid protection domain
719 // to allow returning the Klass* and add it to the pd_set if it is valid
720 {
721 Klass* probe = dictionary->find(d_hash, name, protection_domain);
722 if (probe != NULL) return probe;
|
238 return klass;
239 }
240
241
242 Klass* SystemDictionary::resolve_or_fail(Symbol* class_name,
243 bool throw_error, TRAPS)
244 {
245 return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
246 }
247
248
249 // Forwards to resolve_instance_class_or_null
250
251 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
252 assert(THREAD->can_call_java(),
253 "can not load classes with compiler thread: class=%s, classloader=%s",
254 class_name->as_C_string(),
255 class_loader.is_null() ? "null" : class_loader->klass()->name()->as_C_string());
256 if (FieldType::is_array(class_name)) {
257 return resolve_array_class_or_null(class_name, class_loader, protection_domain, THREAD);
258 } else if (FieldType::is_obj(class_name)) {
259 ResourceMark rm(THREAD);
260 // Ignore wrapping L and ;. (and Q and ; for value types);
261 TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
262 class_name->utf8_length() - 2, CHECK_NULL);
263 return resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
264 } else {
265 return resolve_instance_class_or_null(class_name, class_loader, protection_domain, THREAD);
266 }
267 }
268
269 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, TRAPS) {
270 return resolve_or_null(class_name, Handle(), Handle(), THREAD);
271 }
272
273 // Forwards to resolve_instance_class_or_null
274
275 Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name,
276 Handle class_loader,
277 Handle protection_domain,
278 TRAPS) {
281 FieldArrayInfo fd;
282 // dimension and object_key in FieldArrayInfo are assigned as a side-effect
283 // of this call
284 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_NULL);
285 if (t == T_OBJECT || t == T_VALUETYPE) {
286 // naked oop "k" is OK here -- we assign back into it
287 k = SystemDictionary::resolve_instance_class_or_null(fd.object_key(),
288 class_loader,
289 protection_domain,
290 CHECK_NULL);
291 if (k != NULL) {
292 k = k->array_klass(fd.dimension(), CHECK_NULL);
293 }
294 } else {
295 k = Universe::typeArrayKlassObj(t);
296 k = TypeArrayKlass::cast(k)->array_klass(fd.dimension(), CHECK_NULL);
297 }
298 return k;
299 }
300
301 // Must be called for any super-class or super-interface resolution
302 // during class definition to allow class circularity checking
303 // super-interface callers:
304 // parse_interfaces - for defineClass & jvmtiRedefineClasses
305 // super-class callers:
306 // ClassFileParser - for defineClass & jvmtiRedefineClasses
307 // load_shared_class - while loading a class from shared archive
308 // resolve_instance_class_or_null:
309 // via: handle_parallel_super_load
310 // when resolving a class that has an existing placeholder with
311 // a saved superclass [i.e. a defineClass is currently in progress]
312 // if another thread is trying to resolve the class, it must do
313 // super-class checks on its own thread to catch class circularity
314 // This last call is critical in class circularity checking for cases
315 // where classloading is delegated to different threads and the
316 // classloader lock is released.
317 // Take the case: Base->Super->Base
318 // 1. If thread T1 tries to do a defineClass of class Base
319 // resolve_super_or_fail creates placeholder: T1, Base (super Super)
320 // 2. resolve_instance_class_or_null does not find SD or placeholder for Super
638 #endif // INCLUDE_TRACE
639 }
640
641 static void class_define_event(InstanceKlass* k,
642 const ClassLoaderData* def_cld) {
643 #if INCLUDE_TRACE
644 EventClassDefine event;
645 if (event.should_commit()) {
646 event.set_definedClass(k);
647 event.set_definingClassLoader(def_cld);
648 event.commit();
649 }
650 #endif // INCLUDE_TRACE
651 }
652
653 Klass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
654 Handle class_loader,
655 Handle protection_domain,
656 TRAPS) {
657 Klass* k = do_resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
658 return k;
659 }
660
661 // Be careful when modifying this code: once you have run
662 // placeholders()->find_and_add(PlaceholderTable::LOAD_INSTANCE),
663 // you need to find_and_remove it before returning.
664 // So be careful to not exit with a CHECK_ macro betweeen these calls.
665 Klass* SystemDictionary::do_resolve_instance_class_or_null(Symbol* name,
666 Handle class_loader,
667 Handle protection_domain,
668 TRAPS) {
669 assert(name != NULL && !FieldType::is_array(name) &&
670 !FieldType::is_obj(name), "invalid class name");
671
672 EventClassLoad class_load_start_event;
673
674 HandleMark hm(THREAD);
675
676 // Fix for 4474172; see evaluation for more details
677 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
678 ClassLoaderData *loader_data = register_loader(class_loader, CHECK_NULL);
679 Dictionary* dictionary = loader_data->dictionary();
680 unsigned int d_hash = dictionary->compute_hash(name);
681
682 // Do lookup to see if class already exist and the protection domain
683 // has the right access
684 // This call uses find which checks protection domain already matches
685 // All subsequent calls use find_class, and set has_loaded_class so that
686 // before we return a result we call out to java to check for valid protection domain
687 // to allow returning the Klass* and add it to the pd_set if it is valid
688 {
689 Klass* probe = dictionary->find(d_hash, name, protection_domain);
690 if (probe != NULL) return probe;
|