src/hotspot/share/classfile/systemDictionary.cpp
changeset 59056 15936b142f86
parent 58783 d55b62dbe688
child 59156 14fa9e70ae71
equal deleted inserted replaced
59055:57ad70bcf06c 59056:15936b142f86
  2336   }
  2336   }
  2337   return NULL;
  2337   return NULL;
  2338 }
  2338 }
  2339 
  2339 
  2340 
  2340 
  2341 methodHandle SystemDictionary::find_method_handle_intrinsic(vmIntrinsics::ID iid,
  2341 Method* SystemDictionary::find_method_handle_intrinsic(vmIntrinsics::ID iid,
  2342                                                             Symbol* signature,
  2342                                                        Symbol* signature,
  2343                                                             TRAPS) {
  2343                                                        TRAPS) {
  2344   methodHandle empty;
  2344   methodHandle empty;
  2345   assert(MethodHandles::is_signature_polymorphic(iid) &&
  2345   assert(MethodHandles::is_signature_polymorphic(iid) &&
  2346          MethodHandles::is_signature_polymorphic_intrinsic(iid) &&
  2346          MethodHandles::is_signature_polymorphic_intrinsic(iid) &&
  2347          iid != vmIntrinsics::_invokeGeneric,
  2347          iid != vmIntrinsics::_invokeGeneric,
  2348          "must be a known MH intrinsic iid=%d: %s", iid, vmIntrinsics::name_at(iid));
  2348          "must be a known MH intrinsic iid=%d: %s", iid, vmIntrinsics::name_at(iid));
  2352   SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, iid);
  2352   SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, iid);
  2353   methodHandle m;
  2353   methodHandle m;
  2354   if (spe == NULL || spe->method() == NULL) {
  2354   if (spe == NULL || spe->method() == NULL) {
  2355     spe = NULL;
  2355     spe = NULL;
  2356     // Must create lots of stuff here, but outside of the SystemDictionary lock.
  2356     // Must create lots of stuff here, but outside of the SystemDictionary lock.
  2357     m = Method::make_method_handle_intrinsic(iid, signature, CHECK_(empty));
  2357     m = Method::make_method_handle_intrinsic(iid, signature, CHECK_NULL);
  2358     if (!Arguments::is_interpreter_only()) {
  2358     if (!Arguments::is_interpreter_only()) {
  2359       // Generate a compiled form of the MH intrinsic.
  2359       // Generate a compiled form of the MH intrinsic.
  2360       AdapterHandlerLibrary::create_native_wrapper(m);
  2360       AdapterHandlerLibrary::create_native_wrapper(m);
  2361       // Check if have the compiled code.
  2361       // Check if have the compiled code.
  2362       if (!m->has_compiled_code()) {
  2362       if (!m->has_compiled_code()) {
  2363         THROW_MSG_(vmSymbols::java_lang_VirtualMachineError(),
  2363         THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(),
  2364                    "Out of space in CodeCache for method handle intrinsic", empty);
  2364                        "Out of space in CodeCache for method handle intrinsic");
  2365       }
  2365       }
  2366     }
  2366     }
  2367     // Now grab the lock.  We might have to throw away the new method,
  2367     // Now grab the lock.  We might have to throw away the new method,
  2368     // if a racing thread has managed to install one at the same time.
  2368     // if a racing thread has managed to install one at the same time.
  2369     {
  2369     {
  2382          "MH intrinsic invariant");
  2382          "MH intrinsic invariant");
  2383   return spe->method();
  2383   return spe->method();
  2384 }
  2384 }
  2385 
  2385 
  2386 // Helper for unpacking the return value from linkMethod and linkCallSite.
  2386 // Helper for unpacking the return value from linkMethod and linkCallSite.
  2387 static methodHandle unpack_method_and_appendix(Handle mname,
  2387 static Method* unpack_method_and_appendix(Handle mname,
  2388                                                Klass* accessing_klass,
  2388                                           Klass* accessing_klass,
  2389                                                objArrayHandle appendix_box,
  2389                                           objArrayHandle appendix_box,
  2390                                                Handle* appendix_result,
  2390                                           Handle* appendix_result,
  2391                                                TRAPS) {
  2391                                           TRAPS) {
  2392   methodHandle empty;
       
  2393   if (mname.not_null()) {
  2392   if (mname.not_null()) {
  2394     Method* m = java_lang_invoke_MemberName::vmtarget(mname());
  2393     Method* m = java_lang_invoke_MemberName::vmtarget(mname());
  2395     if (m != NULL) {
  2394     if (m != NULL) {
  2396       oop appendix = appendix_box->obj_at(0);
  2395       oop appendix = appendix_box->obj_at(0);
  2397       if (TraceMethodHandles) {
  2396       if (TraceMethodHandles) {
  2405       }
  2404       }
  2406       (*appendix_result) = Handle(THREAD, appendix);
  2405       (*appendix_result) = Handle(THREAD, appendix);
  2407       // the target is stored in the cpCache and if a reference to this
  2406       // the target is stored in the cpCache and if a reference to this
  2408       // MemberName is dropped we need a way to make sure the
  2407       // MemberName is dropped we need a way to make sure the
  2409       // class_loader containing this method is kept alive.
  2408       // class_loader containing this method is kept alive.
       
  2409       methodHandle mh(THREAD, m); // record_dependency can safepoint.
  2410       ClassLoaderData* this_key = accessing_klass->class_loader_data();
  2410       ClassLoaderData* this_key = accessing_klass->class_loader_data();
  2411       this_key->record_dependency(m->method_holder());
  2411       this_key->record_dependency(m->method_holder());
  2412       return methodHandle(THREAD, m);
  2412       return mh();
  2413     }
  2413     }
  2414   }
  2414   }
  2415   THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad value from MethodHandleNatives", empty);
  2415   THROW_MSG_NULL(vmSymbols::java_lang_LinkageError(), "bad value from MethodHandleNatives");
  2416   return empty;
  2416 }
  2417 }
  2417 
  2418 
  2418 Method* SystemDictionary::find_method_handle_invoker(Klass* klass,
  2419 methodHandle SystemDictionary::find_method_handle_invoker(Klass* klass,
  2419                                                      Symbol* name,
  2420                                                           Symbol* name,
  2420                                                      Symbol* signature,
  2421                                                           Symbol* signature,
  2421                                                      Klass* accessing_klass,
  2422                                                           Klass* accessing_klass,
  2422                                                      Handle *appendix_result,
  2423                                                           Handle *appendix_result,
  2423                                                      TRAPS) {
  2424                                                           TRAPS) {
       
  2425   methodHandle empty;
       
  2426   assert(THREAD->can_call_java() ,"");
  2424   assert(THREAD->can_call_java() ,"");
  2427   Handle method_type =
  2425   Handle method_type =
  2428     SystemDictionary::find_method_handle_type(signature, accessing_klass, CHECK_(empty));
  2426     SystemDictionary::find_method_handle_type(signature, accessing_klass, CHECK_NULL);
  2429 
  2427 
  2430   int ref_kind = JVM_REF_invokeVirtual;
  2428   int ref_kind = JVM_REF_invokeVirtual;
  2431   oop name_oop = StringTable::intern(name, CHECK_(empty));
  2429   oop name_oop = StringTable::intern(name, CHECK_NULL);
  2432   Handle name_str (THREAD, name_oop);
  2430   Handle name_str (THREAD, name_oop);
  2433   objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_(empty));
  2431   objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_NULL);
  2434   assert(appendix_box->obj_at(0) == NULL, "");
  2432   assert(appendix_box->obj_at(0) == NULL, "");
  2435 
  2433 
  2436   // This should not happen.  JDK code should take care of that.
  2434   // This should not happen.  JDK code should take care of that.
  2437   if (accessing_klass == NULL || method_type.is_null()) {
  2435   if (accessing_klass == NULL || method_type.is_null()) {
  2438     THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokehandle", empty);
  2436     THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "bad invokehandle");
  2439   }
  2437   }
  2440 
  2438 
  2441   // call java.lang.invoke.MethodHandleNatives::linkMethod(... String, MethodType) -> MemberName
  2439   // call java.lang.invoke.MethodHandleNatives::linkMethod(... String, MethodType) -> MemberName
  2442   JavaCallArguments args;
  2440   JavaCallArguments args;
  2443   args.push_oop(Handle(THREAD, accessing_klass->java_mirror()));
  2441   args.push_oop(Handle(THREAD, accessing_klass->java_mirror()));
  2449   JavaValue result(T_OBJECT);
  2447   JavaValue result(T_OBJECT);
  2450   JavaCalls::call_static(&result,
  2448   JavaCalls::call_static(&result,
  2451                          SystemDictionary::MethodHandleNatives_klass(),
  2449                          SystemDictionary::MethodHandleNatives_klass(),
  2452                          vmSymbols::linkMethod_name(),
  2450                          vmSymbols::linkMethod_name(),
  2453                          vmSymbols::linkMethod_signature(),
  2451                          vmSymbols::linkMethod_signature(),
  2454                          &args, CHECK_(empty));
  2452                          &args, CHECK_NULL);
  2455   Handle mname(THREAD, (oop) result.get_jobject());
  2453   Handle mname(THREAD, (oop) result.get_jobject());
  2456   return unpack_method_and_appendix(mname, accessing_klass, appendix_box, appendix_result, THREAD);
  2454   return unpack_method_and_appendix(mname, accessing_klass, appendix_box, appendix_result, THREAD);
  2457 }
  2455 }
  2458 
  2456 
  2459 // Decide if we can globally cache a lookup of this class, to be returned to any client that asks.
  2457 // Decide if we can globally cache a lookup of this class, to be returned to any client that asks.
  2753                          &args, CHECK);
  2751                          &args, CHECK);
  2754 
  2752 
  2755   Handle value(THREAD, (oop) result.get_jobject());
  2753   Handle value(THREAD, (oop) result.get_jobject());
  2756   if (is_indy) {
  2754   if (is_indy) {
  2757     Handle appendix;
  2755     Handle appendix;
  2758     methodHandle method = unpack_method_and_appendix(value,
  2756     Method* method = unpack_method_and_appendix(value,
  2759                                                      bootstrap_specifier.caller(),
  2757                                                 bootstrap_specifier.caller(),
  2760                                                      appendix_box,
  2758                                                 appendix_box,
  2761                                                      &appendix, CHECK);
  2759                                                 &appendix, CHECK);
  2762     bootstrap_specifier.set_resolved_method(method, appendix);
  2760     methodHandle mh(THREAD, method);
       
  2761     bootstrap_specifier.set_resolved_method(mh, appendix);
  2763   } else {
  2762   } else {
  2764     bootstrap_specifier.set_resolved_value(value);
  2763     bootstrap_specifier.set_resolved_value(value);
  2765   }
  2764   }
  2766 
  2765 
  2767   // sanity check
  2766   // sanity check