1.1 --- a/src/share/vm/prims/methodHandles.cpp Mon Apr 20 14:48:03 2009 -0700 1.2 +++ b/src/share/vm/prims/methodHandles.cpp Tue Apr 21 23:21:04 2009 -0700 1.3 @@ -2279,6 +2279,16 @@ 1.4 JVM_END 1.5 1.6 1.7 +JVM_ENTRY(void, MH_linkCallSite(JNIEnv *env, jobject igcls, jobject site_jh, jobject target_jh)) { 1.8 + // No special action required, yet. 1.9 + oop site_oop = JNIHandles::resolve(site_jh); 1.10 + if (site_oop == NULL || site_oop->klass() != SystemDictionary::CallSiteImpl_klass()) 1.11 + THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "call site"); 1.12 + sun_dyn_CallSiteImpl::set_target(site_oop, JNIHandles::resolve(target_jh)); 1.13 +} 1.14 +JVM_END 1.15 + 1.16 + 1.17 /// JVM_RegisterMethodHandleMethods 1.18 1.19 #define ADR "J" 1.20 @@ -2297,6 +2307,7 @@ 1.21 #define AMH IDYN"AdapterMethodHandle;" 1.22 #define BMH IDYN"BoundMethodHandle;" 1.23 #define DMH IDYN"DirectMethodHandle;" 1.24 +#define CSTI IDYN"CallSiteImpl;" 1.25 1.26 #define CC (char*) /*cast a literal from (const char*)*/ 1.27 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) 1.28 @@ -2320,12 +2331,19 @@ 1.29 {CC"getMembers", CC"("CLS""STRG""STRG"I"CLS"I["MEM")I", FN_PTR(MHI_getMembers)} 1.30 }; 1.31 1.32 +// More entry points specifically for EnableInvokeDynamic. 1.33 +static JNINativeMethod methods2[] = { 1.34 + {CC"linkCallSite", CC"("CSTI MH")V", FN_PTR(MH_linkCallSite)} 1.35 +}; 1.36 + 1.37 1.38 // This one function is exported, used by NativeLookup. 1.39 1.40 JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) { 1.41 assert(MethodHandles::spot_check_entry_names(), "entry enum is OK"); 1.42 1.43 + // note: this explicit warning-producing stuff will be replaced by auto-detection of the JSR 292 classes 1.44 + 1.45 if (!EnableMethodHandles) { 1.46 warning("JSR 292 method handles are disabled in this JVM. Use -XX:+EnableMethodHandles to enable."); 1.47 return; // bind nothing 1.48 @@ -2343,5 +2361,23 @@ 1.49 MethodHandles::set_enabled(true); 1.50 } 1.51 } 1.52 + 1.53 + if (!EnableInvokeDynamic) { 1.54 + warning("JSR 292 invokedynamic is disabled in this JVM. Use -XX:+EnableInvokeDynamic to enable."); 1.55 + return; // bind nothing 1.56 + } 1.57 + 1.58 + { 1.59 + ThreadToNativeFromVM ttnfv(thread); 1.60 + 1.61 + int status = env->RegisterNatives(MHN_class, methods2, sizeof(methods2)/sizeof(JNINativeMethod)); 1.62 + if (env->ExceptionOccurred()) { 1.63 + MethodHandles::set_enabled(false); 1.64 + warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); 1.65 + env->ExceptionClear(); 1.66 + } else { 1.67 + MethodHandles::set_enabled(true); 1.68 + } 1.69 + } 1.70 } 1.71 JVM_END