Mercurial > hg > truffle
comparison src/share/vm/prims/methodHandles.cpp @ 10283:e484fe2abebd
Merge
author | twisti |
---|---|
date | Thu, 16 May 2013 13:47:55 -0700 |
parents | 39ead0411f07 f0bc60565ba8 |
children | b7fa10a3a69a |
comparison
equal
deleted
inserted
replaced
10272:513a5298c1dd | 10283:e484fe2abebd |
---|---|
1304 java_lang_invoke_CallSite::set_target_volatile(call_site(), target()); | 1304 java_lang_invoke_CallSite::set_target_volatile(call_site(), target()); |
1305 } | 1305 } |
1306 } | 1306 } |
1307 JVM_END | 1307 JVM_END |
1308 | 1308 |
1309 /** | |
1310 * Throws a java/lang/UnsupportedOperationException unconditionally. | |
1311 * This is required by the specification of MethodHandle.invoke if | |
1312 * invoked directly. | |
1313 */ | |
1314 JVM_ENTRY(jobject, MH_invoke_UOE(JNIEnv* env, jobject mh, jobjectArray args)) { | |
1315 THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "MethodHandle.invoke cannot be invoked reflectively"); | |
1316 return NULL; | |
1317 } | |
1318 JVM_END | |
1319 | |
1320 /** | |
1321 * Throws a java/lang/UnsupportedOperationException unconditionally. | |
1322 * This is required by the specification of MethodHandle.invokeExact if | |
1323 * invoked directly. | |
1324 */ | |
1325 JVM_ENTRY(jobject, MH_invokeExact_UOE(JNIEnv* env, jobject mh, jobjectArray args)) { | |
1326 THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "MethodHandle.invokeExact cannot be invoked reflectively"); | |
1327 return NULL; | |
1328 } | |
1329 JVM_END | |
1330 | |
1309 /// JVM_RegisterMethodHandleMethods | 1331 /// JVM_RegisterMethodHandleMethods |
1310 | 1332 |
1311 #undef CS // Solaris builds complain | 1333 #undef CS // Solaris builds complain |
1312 | 1334 |
1313 #define LANG "Ljava/lang/" | 1335 #define LANG "Ljava/lang/" |
1323 | 1345 |
1324 #define CC (char*) /*cast a literal from (const char*)*/ | 1346 #define CC (char*) /*cast a literal from (const char*)*/ |
1325 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) | 1347 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) |
1326 | 1348 |
1327 // These are the native methods on java.lang.invoke.MethodHandleNatives. | 1349 // These are the native methods on java.lang.invoke.MethodHandleNatives. |
1328 static JNINativeMethod required_methods_JDK8[] = { | 1350 static JNINativeMethod MHN_methods[] = { |
1329 {CC"init", CC"("MEM""OBJ")V", FN_PTR(MHN_init_Mem)}, | 1351 {CC"init", CC"("MEM""OBJ")V", FN_PTR(MHN_init_Mem)}, |
1330 {CC"expand", CC"("MEM")V", FN_PTR(MHN_expand_Mem)}, | 1352 {CC"expand", CC"("MEM")V", FN_PTR(MHN_expand_Mem)}, |
1331 {CC"resolve", CC"("MEM""CLS")"MEM, FN_PTR(MHN_resolve_Mem)}, | 1353 {CC"resolve", CC"("MEM""CLS")"MEM, FN_PTR(MHN_resolve_Mem)}, |
1332 {CC"getConstant", CC"(I)I", FN_PTR(MHN_getConstant)}, | 1354 {CC"getConstant", CC"(I)I", FN_PTR(MHN_getConstant)}, |
1333 // static native int getNamedCon(int which, Object[] name) | 1355 // static native int getNamedCon(int which, Object[] name) |
1341 {CC"staticFieldOffset", CC"("MEM")J", FN_PTR(MHN_staticFieldOffset)}, | 1363 {CC"staticFieldOffset", CC"("MEM")J", FN_PTR(MHN_staticFieldOffset)}, |
1342 {CC"staticFieldBase", CC"("MEM")"OBJ, FN_PTR(MHN_staticFieldBase)}, | 1364 {CC"staticFieldBase", CC"("MEM")"OBJ, FN_PTR(MHN_staticFieldBase)}, |
1343 {CC"getMemberVMInfo", CC"("MEM")"OBJ, FN_PTR(MHN_getMemberVMInfo)} | 1365 {CC"getMemberVMInfo", CC"("MEM")"OBJ, FN_PTR(MHN_getMemberVMInfo)} |
1344 }; | 1366 }; |
1345 | 1367 |
1346 // This one function is exported, used by NativeLookup. | 1368 static JNINativeMethod MH_methods[] = { |
1347 | 1369 // UnsupportedOperationException throwers |
1370 {CC"invoke", CC"(["OBJ")"OBJ, FN_PTR(MH_invoke_UOE)}, | |
1371 {CC"invokeExact", CC"(["OBJ")"OBJ, FN_PTR(MH_invokeExact_UOE)} | |
1372 }; | |
1373 | |
1374 /** | |
1375 * Helper method to register native methods. | |
1376 */ | |
1377 static bool register_natives(JNIEnv* env, jclass clazz, const JNINativeMethod* methods, jint nMethods) { | |
1378 int status = env->RegisterNatives(clazz, methods, nMethods); | |
1379 if (status != JNI_OK || env->ExceptionOccurred()) { | |
1380 warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); | |
1381 env->ExceptionClear(); | |
1382 return false; | |
1383 } | |
1384 return true; | |
1385 } | |
1386 | |
1387 /** | |
1388 * This one function is exported, used by NativeLookup. | |
1389 */ | |
1348 JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) { | 1390 JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) { |
1349 if (!EnableInvokeDynamic) { | 1391 if (!EnableInvokeDynamic) { |
1350 warning("JSR 292 is disabled in this JVM. Use -XX:+UnlockDiagnosticVMOptions -XX:+EnableInvokeDynamic to enable."); | 1392 warning("JSR 292 is disabled in this JVM. Use -XX:+UnlockDiagnosticVMOptions -XX:+EnableInvokeDynamic to enable."); |
1351 return; // bind nothing | 1393 return; // bind nothing |
1352 } | 1394 } |
1360 } else { | 1402 } else { |
1361 oop mirror = SystemDictionary::MethodHandle_klass()->java_mirror(); | 1403 oop mirror = SystemDictionary::MethodHandle_klass()->java_mirror(); |
1362 MH_class = (jclass) JNIHandles::make_local(env, mirror); | 1404 MH_class = (jclass) JNIHandles::make_local(env, mirror); |
1363 } | 1405 } |
1364 | 1406 |
1365 int status; | |
1366 | |
1367 if (enable_MH) { | 1407 if (enable_MH) { |
1368 ThreadToNativeFromVM ttnfv(thread); | 1408 ThreadToNativeFromVM ttnfv(thread); |
1369 | 1409 |
1370 status = env->RegisterNatives(MHN_class, required_methods_JDK8, sizeof(required_methods_JDK8)/sizeof(JNINativeMethod)); | 1410 if (enable_MH) { |
1371 if (status != JNI_OK || env->ExceptionOccurred()) { | 1411 enable_MH = register_natives(env, MHN_class, MHN_methods, sizeof(MHN_methods)/sizeof(JNINativeMethod)); |
1372 warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); | 1412 } |
1373 enable_MH = false; | 1413 if (enable_MH) { |
1374 env->ExceptionClear(); | 1414 enable_MH = register_natives(env, MH_class, MH_methods, sizeof(MH_methods)/sizeof(JNINativeMethod)); |
1375 } | 1415 } |
1376 } | 1416 } |
1377 | 1417 |
1378 if (TraceInvokeDynamic) { | 1418 if (TraceInvokeDynamic) { |
1379 tty->print_cr("MethodHandle support loaded (using LambdaForms)"); | 1419 tty->print_cr("MethodHandle support loaded (using LambdaForms)"); |