src/share/vm/prims/methodHandles.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 7196120 Sdiff src/share/vm/prims

src/share/vm/prims/methodHandles.cpp

Print this page




1177     // Walk all nmethods depending on this call site.
1178     MutexLocker mu(Compile_lock, thread);
1179     Universe::flush_dependents_on(call_site, target);
1180   }
1181   java_lang_invoke_CallSite::set_target(call_site(), target());
1182 }
1183 JVM_END
1184 
1185 JVM_ENTRY(void, MHN_setCallSiteTargetVolatile(JNIEnv* env, jobject igcls, jobject call_site_jh, jobject target_jh)) {
1186   Handle call_site(THREAD, JNIHandles::resolve_non_null(call_site_jh));
1187   Handle target   (THREAD, JNIHandles::resolve(target_jh));
1188   {
1189     // Walk all nmethods depending on this call site.
1190     MutexLocker mu(Compile_lock, thread);
1191     Universe::flush_dependents_on(call_site, target);
1192   }
1193   java_lang_invoke_CallSite::set_target_volatile(call_site(), target());
1194 }
1195 JVM_END
1196 
1197 JVM_ENTRY(jobject, MH_invoke_UOE(JNIEnv *env, jobject igmh, jobjectArray igargs)) {
1198     TempNewSymbol UOE_name = SymbolTable::new_symbol("java/lang/UnsupportedOperationException", CHECK_NULL);
1199     THROW_MSG_NULL(UOE_name, "MethodHandle.invoke cannot be invoked reflectively");
1200     return NULL;
1201 }
1202 JVM_END
1203 
1204 JVM_ENTRY(jobject, MH_invokeExact_UOE(JNIEnv *env, jobject igmh, jobjectArray igargs)) {
1205     TempNewSymbol UOE_name = SymbolTable::new_symbol("java/lang/UnsupportedOperationException", CHECK_NULL);
1206     THROW_MSG_NULL(UOE_name, "MethodHandle.invokeExact cannot be invoked reflectively");
1207     return NULL;
1208 }
1209 JVM_END
1210 
1211 /// JVM_RegisterMethodHandleMethods
1212 
1213 #undef CS  // Solaris builds complain
1214 
1215 #define LANG "Ljava/lang/"
1216 #define JLINV "Ljava/lang/invoke/"
1217 
1218 #define OBJ   LANG"Object;"
1219 #define CLS   LANG"Class;"
1220 #define STRG  LANG"String;"
1221 #define CS    JLINV"CallSite;"
1222 #define MT    JLINV"MethodType;"
1223 #define MH    JLINV"MethodHandle;"
1224 #define MEM   JLINV"MemberName;"
1225 
1226 #define CC (char*)  /*cast a literal from (const char*)*/
1227 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
1228 
1229 // These are the native methods on java.lang.invoke.MethodHandleNatives.
1230 static JNINativeMethod required_methods_JDK8[] = {
1231   {CC"init",                      CC"("MEM""OBJ")V",                     FN_PTR(MHN_init_Mem)},
1232   {CC"expand",                    CC"("MEM")V",                          FN_PTR(MHN_expand_Mem)},
1233   {CC"resolve",                   CC"("MEM""CLS")"MEM,                   FN_PTR(MHN_resolve_Mem)},
1234   {CC"getConstant",               CC"(I)I",                              FN_PTR(MHN_getConstant)},
1235   //  static native int getNamedCon(int which, Object[] name)
1236   {CC"getNamedCon",               CC"(I["OBJ")I",                        FN_PTR(MHN_getNamedCon)},
1237   //  static native int getMembers(Class<?> defc, String matchName, String matchSig,
1238   //          int matchFlags, Class<?> caller, int skip, MemberName[] results);
1239   {CC"getMembers",                CC"("CLS""STRG""STRG"I"CLS"I["MEM")I", FN_PTR(MHN_getMembers)},
1240   {CC"objectFieldOffset",         CC"("MEM")J",                          FN_PTR(MHN_objectFieldOffset)},
1241   {CC"setCallSiteTargetNormal",   CC"("CS""MH")V",                       FN_PTR(MHN_setCallSiteTargetNormal)},
1242   {CC"setCallSiteTargetVolatile", CC"("CS""MH")V",                       FN_PTR(MHN_setCallSiteTargetVolatile)},
1243   {CC"staticFieldOffset",         CC"("MEM")J",                          FN_PTR(MHN_staticFieldOffset)},
1244   {CC"staticFieldBase",           CC"("MEM")"OBJ,                        FN_PTR(MHN_staticFieldBase)},
1245   {CC"getMemberVMInfo",           CC"("MEM")"OBJ,                        FN_PTR(MHN_getMemberVMInfo)}
1246 };
1247 
1248 static JNINativeMethod invoke_methods[] = {
1249   {CC"invoke",                    CC"(["OBJ")"OBJ,                       FN_PTR(MH_invoke_UOE)},
1250   {CC"invokeExact",               CC"(["OBJ")"OBJ,                       FN_PTR(MH_invokeExact_UOE)}
1251 };
1252 
1253 // This one function is exported, used by NativeLookup.
1254 
1255 JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) {
1256   if (!EnableInvokeDynamic) {
1257     warning("JSR 292 is disabled in this JVM.  Use -XX:+UnlockDiagnosticVMOptions -XX:+EnableInvokeDynamic to enable.");
1258     return;  // bind nothing
1259   }
1260 
1261   assert(!MethodHandles::enabled(), "must not be enabled");
1262   bool enable_MH = true;
1263 
1264   jclass MH_class = NULL;
1265   if (SystemDictionary::MethodHandle_klass() == NULL) {
1266     enable_MH = false;
1267   } else {
1268     oop mirror = Klass::cast(SystemDictionary::MethodHandle_klass())->java_mirror();
1269     MH_class = (jclass) JNIHandles::make_local(env, mirror);
1270   }
1271 
1272   int status;
1273 
1274   if (enable_MH) {
1275     ThreadToNativeFromVM ttnfv(thread);
1276 
1277     status = env->RegisterNatives(MHN_class, required_methods_JDK8, sizeof(required_methods_JDK8)/sizeof(JNINativeMethod));
1278     if (status == JNI_OK && !env->ExceptionOccurred()) {
1279       status = env->RegisterNatives(MH_class, invoke_methods, sizeof(invoke_methods)/sizeof(JNINativeMethod));
1280     }
1281     if (status != JNI_OK || env->ExceptionOccurred()) {
1282       warning("JSR 292 method handle code is mismatched to this JVM.  Disabling support.");
1283       enable_MH = false;
1284       env->ExceptionClear();
1285     }
1286   }
1287 
1288   if (TraceInvokeDynamic) {
1289     tty->print_cr("MethodHandle support loaded (using LambdaForms)");
1290   }
1291 
1292   if (enable_MH) {
1293     MethodHandles::generate_adapters();
1294     MethodHandles::set_enabled(true);
1295   }
1296 }
1297 JVM_END


1177     // Walk all nmethods depending on this call site.
1178     MutexLocker mu(Compile_lock, thread);
1179     Universe::flush_dependents_on(call_site, target);
1180   }
1181   java_lang_invoke_CallSite::set_target(call_site(), target());
1182 }
1183 JVM_END
1184 
1185 JVM_ENTRY(void, MHN_setCallSiteTargetVolatile(JNIEnv* env, jobject igcls, jobject call_site_jh, jobject target_jh)) {
1186   Handle call_site(THREAD, JNIHandles::resolve_non_null(call_site_jh));
1187   Handle target   (THREAD, JNIHandles::resolve(target_jh));
1188   {
1189     // Walk all nmethods depending on this call site.
1190     MutexLocker mu(Compile_lock, thread);
1191     Universe::flush_dependents_on(call_site, target);
1192   }
1193   java_lang_invoke_CallSite::set_target_volatile(call_site(), target());
1194 }
1195 JVM_END
1196 














1197 /// JVM_RegisterMethodHandleMethods
1198 
1199 #undef CS  // Solaris builds complain
1200 
1201 #define LANG "Ljava/lang/"
1202 #define JLINV "Ljava/lang/invoke/"
1203 
1204 #define OBJ   LANG"Object;"
1205 #define CLS   LANG"Class;"
1206 #define STRG  LANG"String;"
1207 #define CS    JLINV"CallSite;"
1208 #define MT    JLINV"MethodType;"
1209 #define MH    JLINV"MethodHandle;"
1210 #define MEM   JLINV"MemberName;"
1211 
1212 #define CC (char*)  /*cast a literal from (const char*)*/
1213 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
1214 
1215 // These are the native methods on java.lang.invoke.MethodHandleNatives.
1216 static JNINativeMethod required_methods_JDK8[] = {
1217   {CC"init",                      CC"("MEM""OBJ")V",                     FN_PTR(MHN_init_Mem)},
1218   {CC"expand",                    CC"("MEM")V",                          FN_PTR(MHN_expand_Mem)},
1219   {CC"resolve",                   CC"("MEM""CLS")"MEM,                   FN_PTR(MHN_resolve_Mem)},
1220   {CC"getConstant",               CC"(I)I",                              FN_PTR(MHN_getConstant)},
1221   //  static native int getNamedCon(int which, Object[] name)
1222   {CC"getNamedCon",               CC"(I["OBJ")I",                        FN_PTR(MHN_getNamedCon)},
1223   //  static native int getMembers(Class<?> defc, String matchName, String matchSig,
1224   //          int matchFlags, Class<?> caller, int skip, MemberName[] results);
1225   {CC"getMembers",                CC"("CLS""STRG""STRG"I"CLS"I["MEM")I", FN_PTR(MHN_getMembers)},
1226   {CC"objectFieldOffset",         CC"("MEM")J",                          FN_PTR(MHN_objectFieldOffset)},
1227   {CC"setCallSiteTargetNormal",   CC"("CS""MH")V",                       FN_PTR(MHN_setCallSiteTargetNormal)},
1228   {CC"setCallSiteTargetVolatile", CC"("CS""MH")V",                       FN_PTR(MHN_setCallSiteTargetVolatile)},
1229   {CC"staticFieldOffset",         CC"("MEM")J",                          FN_PTR(MHN_staticFieldOffset)},
1230   {CC"staticFieldBase",           CC"("MEM")"OBJ,                        FN_PTR(MHN_staticFieldBase)},
1231   {CC"getMemberVMInfo",           CC"("MEM")"OBJ,                        FN_PTR(MHN_getMemberVMInfo)}
1232 };
1233 





1234 // This one function is exported, used by NativeLookup.
1235 
1236 JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) {
1237   if (!EnableInvokeDynamic) {
1238     warning("JSR 292 is disabled in this JVM.  Use -XX:+UnlockDiagnosticVMOptions -XX:+EnableInvokeDynamic to enable.");
1239     return;  // bind nothing
1240   }
1241 
1242   assert(!MethodHandles::enabled(), "must not be enabled");
1243   bool enable_MH = true;
1244 
1245   jclass MH_class = NULL;
1246   if (SystemDictionary::MethodHandle_klass() == NULL) {
1247     enable_MH = false;
1248   } else {
1249     oop mirror = Klass::cast(SystemDictionary::MethodHandle_klass())->java_mirror();
1250     MH_class = (jclass) JNIHandles::make_local(env, mirror);
1251   }
1252 
1253   int status;
1254 
1255   if (enable_MH) {
1256     ThreadToNativeFromVM ttnfv(thread);
1257 
1258     status = env->RegisterNatives(MHN_class, required_methods_JDK8, sizeof(required_methods_JDK8)/sizeof(JNINativeMethod));



1259     if (status != JNI_OK || env->ExceptionOccurred()) {
1260       warning("JSR 292 method handle code is mismatched to this JVM.  Disabling support.");
1261       enable_MH = false;
1262       env->ExceptionClear();
1263     }
1264   }
1265 
1266   if (TraceInvokeDynamic) {
1267     tty->print_cr("MethodHandle support loaded (using LambdaForms)");
1268   }
1269 
1270   if (enable_MH) {
1271     MethodHandles::generate_adapters();
1272     MethodHandles::set_enabled(true);
1273   }
1274 }
1275 JVM_END
src/share/vm/prims/methodHandles.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File