< prev index next >

src/share/vm/classfile/systemDictionary.cpp

Print this page




 212       THROW_MSG_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string());
 213     } else {
 214       THROW_MSG_NULL(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string());
 215     }
 216   }
 217   return (Klass*)klass_h();
 218 }
 219 
 220 
 221 Klass* SystemDictionary::resolve_or_fail(Symbol* class_name,
 222                                            bool throw_error, TRAPS)
 223 {
 224   return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
 225 }
 226 
 227 
 228 // Forwards to resolve_instance_class_or_null
 229 
 230 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
 231   assert(!THREAD->is_Compiler_thread(),
 232          err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
 233                  class_name->as_C_string(),
 234                  class_loader.is_null() ? "null" : class_loader->klass()->name()->as_C_string()));
 235   if (FieldType::is_array(class_name)) {
 236     return resolve_array_class_or_null(class_name, class_loader, protection_domain, THREAD);
 237   } else if (FieldType::is_obj(class_name)) {
 238     ResourceMark rm(THREAD);
 239     // Ignore wrapping L and ;.
 240     TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
 241                                    class_name->utf8_length() - 2, CHECK_NULL);
 242     return resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
 243   } else {
 244     return resolve_instance_class_or_null(class_name, class_loader, protection_domain, THREAD);
 245   }
 246 }
 247 
 248 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, TRAPS) {
 249   return resolve_or_null(class_name, Handle(), Handle(), THREAD);
 250 }
 251 
 252 // Forwards to resolve_instance_class_or_null
 253 
 254 Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name,


2247   while (!sig_strm.is_done()) {
2248     if (sig_strm.is_object()) {
2249       Symbol* sig = sig_strm.as_symbol(CHECK_NULL);
2250       if (!add_loader_constraint(sig, loader1, loader2, THREAD)) {
2251         return sig;
2252       }
2253     }
2254     sig_strm.next();
2255   }
2256   return NULL;
2257 }
2258 
2259 
2260 methodHandle SystemDictionary::find_method_handle_intrinsic(vmIntrinsics::ID iid,
2261                                                             Symbol* signature,
2262                                                             TRAPS) {
2263   methodHandle empty;
2264   assert(MethodHandles::is_signature_polymorphic(iid) &&
2265          MethodHandles::is_signature_polymorphic_intrinsic(iid) &&
2266          iid != vmIntrinsics::_invokeGeneric,
2267          err_msg("must be a known MH intrinsic iid=%d: %s", iid, vmIntrinsics::name_at(iid)));
2268 
2269   unsigned int hash  = invoke_method_table()->compute_hash(signature, iid);
2270   int          index = invoke_method_table()->hash_to_index(hash);
2271   SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, iid);
2272   methodHandle m;
2273   if (spe == NULL || spe->method() == NULL) {
2274     spe = NULL;
2275     // Must create lots of stuff here, but outside of the SystemDictionary lock.
2276     m = Method::make_method_handle_intrinsic(iid, signature, CHECK_(empty));
2277     if (!Arguments::is_interpreter_only()) {
2278       // Generate a compiled form of the MH intrinsic.
2279       AdapterHandlerLibrary::create_native_wrapper(m);
2280       // Check if have the compiled code.
2281       if (!m->has_compiled_code()) {
2282         THROW_MSG_(vmSymbols::java_lang_VirtualMachineError(),
2283                    "out of space in CodeCache for method handle intrinsic", empty);
2284       }
2285     }
2286     // Now grab the lock.  We might have to throw away the new method,
2287     // if a racing thread has managed to install one at the same time.


2373                          vmSymbols::linkMethod_signature(),
2374                          &args, CHECK_(empty));
2375   Handle mname(THREAD, (oop) result.get_jobject());
2376   (*method_type_result) = method_type;
2377   return unpack_method_and_appendix(mname, accessing_klass, appendix_box, appendix_result, THREAD);
2378 }
2379 
2380 // Decide if we can globally cache a lookup of this class, to be returned to any client that asks.
2381 // We must ensure that all class loaders everywhere will reach this class, for any client.
2382 // This is a safe bet for public classes in java.lang, such as Object and String.
2383 // We also include public classes in java.lang.invoke, because they appear frequently in system-level method types.
2384 // Out of an abundance of caution, we do not include any other classes, not even for packages like java.util.
2385 static bool is_always_visible_class(oop mirror) {
2386   Klass* klass = java_lang_Class::as_Klass(mirror);
2387   if (klass->oop_is_objArray()) {
2388     klass = ObjArrayKlass::cast(klass)->bottom_klass(); // check element type
2389   }
2390   if (klass->oop_is_typeArray()) {
2391     return true; // primitive array
2392   }
2393   assert(klass->oop_is_instance(), klass->external_name());
2394   return klass->is_public() &&
2395          (InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::Object_klass()) ||       // java.lang
2396           InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::MethodHandle_klass()));  // java.lang.invoke
2397 }
2398 
2399 // Ask Java code to find or construct a java.lang.invoke.MethodType for the given
2400 // signature, as interpreted relative to the given class loader.
2401 // Because of class loader constraints, all method handle usage must be
2402 // consistent with this loader.
2403 Handle SystemDictionary::find_method_handle_type(Symbol* signature,
2404                                                  KlassHandle accessing_klass,
2405                                                  TRAPS) {
2406   Handle empty;
2407   vmIntrinsics::ID null_iid = vmIntrinsics::_none;  // distinct from all method handle invoker intrinsics
2408   unsigned int hash  = invoke_method_table()->compute_hash(signature, null_iid);
2409   int          index = invoke_method_table()->hash_to_index(hash);
2410   SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, null_iid);
2411   if (spe != NULL && spe->method_type() != NULL) {
2412     assert(java_lang_invoke_MethodType::is_instance(spe->method_type()), "");
2413     return Handle(THREAD, spe->method_type());


2426   objArrayHandle pts = oopFactory::new_objArray(SystemDictionary::Class_klass(), npts, CHECK_(empty));
2427   int arg = 0;
2428   Handle rt; // the return type from the signature
2429   ResourceMark rm(THREAD);
2430   for (SignatureStream ss(signature); !ss.is_done(); ss.next()) {
2431     oop mirror = NULL;
2432     if (can_be_cached) {
2433       // Use neutral class loader to lookup candidate classes to be placed in the cache.
2434       mirror = ss.as_java_mirror(Handle(), Handle(),
2435                                  SignatureStream::ReturnNull, CHECK_(empty));
2436       if (mirror == NULL || (ss.is_object() && !is_always_visible_class(mirror))) {
2437         // Fall back to accessing_klass context.
2438         can_be_cached = false;
2439       }
2440     }
2441     if (!can_be_cached) {
2442       // Resolve, throwing a real error if it doesn't work.
2443       mirror = ss.as_java_mirror(class_loader, protection_domain,
2444                                  SignatureStream::NCDFError, CHECK_(empty));
2445     }
2446     assert(!oopDesc::is_null(mirror), ss.as_symbol(THREAD)->as_C_string());
2447     if (ss.at_return_type())
2448       rt = Handle(THREAD, mirror);
2449     else
2450       pts->obj_at_put(arg++, mirror);
2451 
2452     // Check accessibility.
2453     if (ss.is_object() && accessing_klass.not_null()) {
2454       Klass* sel_klass = java_lang_Class::as_Klass(mirror);
2455       mirror = NULL;  // safety
2456       // Emulate ConstantPool::verify_constant_pool_resolve.
2457       if (sel_klass->oop_is_objArray())
2458         sel_klass = ObjArrayKlass::cast(sel_klass)->bottom_klass();
2459       if (sel_klass->oop_is_instance()) {
2460         KlassHandle sel_kh(THREAD, sel_klass);
2461         LinkResolver::check_klass_accessability(accessing_klass, sel_kh, CHECK_(empty));
2462       }
2463     }
2464   }
2465   assert(arg == npts, "");
2466 




 212       THROW_MSG_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string());
 213     } else {
 214       THROW_MSG_NULL(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string());
 215     }
 216   }
 217   return (Klass*)klass_h();
 218 }
 219 
 220 
 221 Klass* SystemDictionary::resolve_or_fail(Symbol* class_name,
 222                                            bool throw_error, TRAPS)
 223 {
 224   return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
 225 }
 226 
 227 
 228 // Forwards to resolve_instance_class_or_null
 229 
 230 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
 231   assert(!THREAD->is_Compiler_thread(),
 232          "can not load classes with compiler thread: class=%s, classloader=%s",
 233          class_name->as_C_string(),
 234          class_loader.is_null() ? "null" : class_loader->klass()->name()->as_C_string());
 235   if (FieldType::is_array(class_name)) {
 236     return resolve_array_class_or_null(class_name, class_loader, protection_domain, THREAD);
 237   } else if (FieldType::is_obj(class_name)) {
 238     ResourceMark rm(THREAD);
 239     // Ignore wrapping L and ;.
 240     TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
 241                                    class_name->utf8_length() - 2, CHECK_NULL);
 242     return resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
 243   } else {
 244     return resolve_instance_class_or_null(class_name, class_loader, protection_domain, THREAD);
 245   }
 246 }
 247 
 248 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, TRAPS) {
 249   return resolve_or_null(class_name, Handle(), Handle(), THREAD);
 250 }
 251 
 252 // Forwards to resolve_instance_class_or_null
 253 
 254 Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name,


2247   while (!sig_strm.is_done()) {
2248     if (sig_strm.is_object()) {
2249       Symbol* sig = sig_strm.as_symbol(CHECK_NULL);
2250       if (!add_loader_constraint(sig, loader1, loader2, THREAD)) {
2251         return sig;
2252       }
2253     }
2254     sig_strm.next();
2255   }
2256   return NULL;
2257 }
2258 
2259 
2260 methodHandle SystemDictionary::find_method_handle_intrinsic(vmIntrinsics::ID iid,
2261                                                             Symbol* signature,
2262                                                             TRAPS) {
2263   methodHandle empty;
2264   assert(MethodHandles::is_signature_polymorphic(iid) &&
2265          MethodHandles::is_signature_polymorphic_intrinsic(iid) &&
2266          iid != vmIntrinsics::_invokeGeneric,
2267          "must be a known MH intrinsic iid=%d: %s", iid, vmIntrinsics::name_at(iid));
2268 
2269   unsigned int hash  = invoke_method_table()->compute_hash(signature, iid);
2270   int          index = invoke_method_table()->hash_to_index(hash);
2271   SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, iid);
2272   methodHandle m;
2273   if (spe == NULL || spe->method() == NULL) {
2274     spe = NULL;
2275     // Must create lots of stuff here, but outside of the SystemDictionary lock.
2276     m = Method::make_method_handle_intrinsic(iid, signature, CHECK_(empty));
2277     if (!Arguments::is_interpreter_only()) {
2278       // Generate a compiled form of the MH intrinsic.
2279       AdapterHandlerLibrary::create_native_wrapper(m);
2280       // Check if have the compiled code.
2281       if (!m->has_compiled_code()) {
2282         THROW_MSG_(vmSymbols::java_lang_VirtualMachineError(),
2283                    "out of space in CodeCache for method handle intrinsic", empty);
2284       }
2285     }
2286     // Now grab the lock.  We might have to throw away the new method,
2287     // if a racing thread has managed to install one at the same time.


2373                          vmSymbols::linkMethod_signature(),
2374                          &args, CHECK_(empty));
2375   Handle mname(THREAD, (oop) result.get_jobject());
2376   (*method_type_result) = method_type;
2377   return unpack_method_and_appendix(mname, accessing_klass, appendix_box, appendix_result, THREAD);
2378 }
2379 
2380 // Decide if we can globally cache a lookup of this class, to be returned to any client that asks.
2381 // We must ensure that all class loaders everywhere will reach this class, for any client.
2382 // This is a safe bet for public classes in java.lang, such as Object and String.
2383 // We also include public classes in java.lang.invoke, because they appear frequently in system-level method types.
2384 // Out of an abundance of caution, we do not include any other classes, not even for packages like java.util.
2385 static bool is_always_visible_class(oop mirror) {
2386   Klass* klass = java_lang_Class::as_Klass(mirror);
2387   if (klass->oop_is_objArray()) {
2388     klass = ObjArrayKlass::cast(klass)->bottom_klass(); // check element type
2389   }
2390   if (klass->oop_is_typeArray()) {
2391     return true; // primitive array
2392   }
2393   assert(klass->oop_is_instance(), "%s", klass->external_name());
2394   return klass->is_public() &&
2395          (InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::Object_klass()) ||       // java.lang
2396           InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::MethodHandle_klass()));  // java.lang.invoke
2397 }
2398 
2399 // Ask Java code to find or construct a java.lang.invoke.MethodType for the given
2400 // signature, as interpreted relative to the given class loader.
2401 // Because of class loader constraints, all method handle usage must be
2402 // consistent with this loader.
2403 Handle SystemDictionary::find_method_handle_type(Symbol* signature,
2404                                                  KlassHandle accessing_klass,
2405                                                  TRAPS) {
2406   Handle empty;
2407   vmIntrinsics::ID null_iid = vmIntrinsics::_none;  // distinct from all method handle invoker intrinsics
2408   unsigned int hash  = invoke_method_table()->compute_hash(signature, null_iid);
2409   int          index = invoke_method_table()->hash_to_index(hash);
2410   SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, null_iid);
2411   if (spe != NULL && spe->method_type() != NULL) {
2412     assert(java_lang_invoke_MethodType::is_instance(spe->method_type()), "");
2413     return Handle(THREAD, spe->method_type());


2426   objArrayHandle pts = oopFactory::new_objArray(SystemDictionary::Class_klass(), npts, CHECK_(empty));
2427   int arg = 0;
2428   Handle rt; // the return type from the signature
2429   ResourceMark rm(THREAD);
2430   for (SignatureStream ss(signature); !ss.is_done(); ss.next()) {
2431     oop mirror = NULL;
2432     if (can_be_cached) {
2433       // Use neutral class loader to lookup candidate classes to be placed in the cache.
2434       mirror = ss.as_java_mirror(Handle(), Handle(),
2435                                  SignatureStream::ReturnNull, CHECK_(empty));
2436       if (mirror == NULL || (ss.is_object() && !is_always_visible_class(mirror))) {
2437         // Fall back to accessing_klass context.
2438         can_be_cached = false;
2439       }
2440     }
2441     if (!can_be_cached) {
2442       // Resolve, throwing a real error if it doesn't work.
2443       mirror = ss.as_java_mirror(class_loader, protection_domain,
2444                                  SignatureStream::NCDFError, CHECK_(empty));
2445     }
2446     assert(!oopDesc::is_null(mirror), "%s", ss.as_symbol(THREAD)->as_C_string());
2447     if (ss.at_return_type())
2448       rt = Handle(THREAD, mirror);
2449     else
2450       pts->obj_at_put(arg++, mirror);
2451 
2452     // Check accessibility.
2453     if (ss.is_object() && accessing_klass.not_null()) {
2454       Klass* sel_klass = java_lang_Class::as_Klass(mirror);
2455       mirror = NULL;  // safety
2456       // Emulate ConstantPool::verify_constant_pool_resolve.
2457       if (sel_klass->oop_is_objArray())
2458         sel_klass = ObjArrayKlass::cast(sel_klass)->bottom_klass();
2459       if (sel_klass->oop_is_instance()) {
2460         KlassHandle sel_kh(THREAD, sel_klass);
2461         LinkResolver::check_klass_accessability(accessing_klass, sel_kh, CHECK_(empty));
2462       }
2463     }
2464   }
2465   assert(arg == npts, "");
2466 


< prev index next >