Mercurial > hg > truffle
comparison src/share/vm/prims/methodHandles.cpp @ 10276:f0bc60565ba8
7196277: JSR 292: Two jck/runtime tests crash on java.lang.invoke.MethodHandle.invokeExact
Reviewed-by: jrose, kvn
author | twisti |
---|---|
date | Mon, 06 May 2013 13:53:13 -0700 |
parents | 746b070f5022 |
children | e484fe2abebd |
comparison
equal
deleted
inserted
replaced
10275:d73c88e524ff | 10276:f0bc60565ba8 |
---|---|
1296 java_lang_invoke_CallSite::set_target_volatile(call_site(), target()); | 1296 java_lang_invoke_CallSite::set_target_volatile(call_site(), target()); |
1297 } | 1297 } |
1298 } | 1298 } |
1299 JVM_END | 1299 JVM_END |
1300 | 1300 |
1301 /** | |
1302 * Throws a java/lang/UnsupportedOperationException unconditionally. | |
1303 * This is required by the specification of MethodHandle.invoke if | |
1304 * invoked directly. | |
1305 */ | |
1306 JVM_ENTRY(jobject, MH_invoke_UOE(JNIEnv* env, jobject mh, jobjectArray args)) { | |
1307 THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "MethodHandle.invoke cannot be invoked reflectively"); | |
1308 return NULL; | |
1309 } | |
1310 JVM_END | |
1311 | |
1312 /** | |
1313 * Throws a java/lang/UnsupportedOperationException unconditionally. | |
1314 * This is required by the specification of MethodHandle.invokeExact if | |
1315 * invoked directly. | |
1316 */ | |
1317 JVM_ENTRY(jobject, MH_invokeExact_UOE(JNIEnv* env, jobject mh, jobjectArray args)) { | |
1318 THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "MethodHandle.invokeExact cannot be invoked reflectively"); | |
1319 return NULL; | |
1320 } | |
1321 JVM_END | |
1322 | |
1301 /// JVM_RegisterMethodHandleMethods | 1323 /// JVM_RegisterMethodHandleMethods |
1302 | 1324 |
1303 #undef CS // Solaris builds complain | 1325 #undef CS // Solaris builds complain |
1304 | 1326 |
1305 #define LANG "Ljava/lang/" | 1327 #define LANG "Ljava/lang/" |
1315 | 1337 |
1316 #define CC (char*) /*cast a literal from (const char*)*/ | 1338 #define CC (char*) /*cast a literal from (const char*)*/ |
1317 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) | 1339 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) |
1318 | 1340 |
1319 // These are the native methods on java.lang.invoke.MethodHandleNatives. | 1341 // These are the native methods on java.lang.invoke.MethodHandleNatives. |
1320 static JNINativeMethod required_methods_JDK8[] = { | 1342 static JNINativeMethod MHN_methods[] = { |
1321 {CC"init", CC"("MEM""OBJ")V", FN_PTR(MHN_init_Mem)}, | 1343 {CC"init", CC"("MEM""OBJ")V", FN_PTR(MHN_init_Mem)}, |
1322 {CC"expand", CC"("MEM")V", FN_PTR(MHN_expand_Mem)}, | 1344 {CC"expand", CC"("MEM")V", FN_PTR(MHN_expand_Mem)}, |
1323 {CC"resolve", CC"("MEM""CLS")"MEM, FN_PTR(MHN_resolve_Mem)}, | 1345 {CC"resolve", CC"("MEM""CLS")"MEM, FN_PTR(MHN_resolve_Mem)}, |
1324 {CC"getConstant", CC"(I)I", FN_PTR(MHN_getConstant)}, | 1346 {CC"getConstant", CC"(I)I", FN_PTR(MHN_getConstant)}, |
1325 // static native int getNamedCon(int which, Object[] name) | 1347 // static native int getNamedCon(int which, Object[] name) |
1333 {CC"staticFieldOffset", CC"("MEM")J", FN_PTR(MHN_staticFieldOffset)}, | 1355 {CC"staticFieldOffset", CC"("MEM")J", FN_PTR(MHN_staticFieldOffset)}, |
1334 {CC"staticFieldBase", CC"("MEM")"OBJ, FN_PTR(MHN_staticFieldBase)}, | 1356 {CC"staticFieldBase", CC"("MEM")"OBJ, FN_PTR(MHN_staticFieldBase)}, |
1335 {CC"getMemberVMInfo", CC"("MEM")"OBJ, FN_PTR(MHN_getMemberVMInfo)} | 1357 {CC"getMemberVMInfo", CC"("MEM")"OBJ, FN_PTR(MHN_getMemberVMInfo)} |
1336 }; | 1358 }; |
1337 | 1359 |
1338 // This one function is exported, used by NativeLookup. | 1360 static JNINativeMethod MH_methods[] = { |
1339 | 1361 // UnsupportedOperationException throwers |
1362 {CC"invoke", CC"(["OBJ")"OBJ, FN_PTR(MH_invoke_UOE)}, | |
1363 {CC"invokeExact", CC"(["OBJ")"OBJ, FN_PTR(MH_invokeExact_UOE)} | |
1364 }; | |
1365 | |
1366 /** | |
1367 * Helper method to register native methods. | |
1368 */ | |
1369 static bool register_natives(JNIEnv* env, jclass clazz, const JNINativeMethod* methods, jint nMethods) { | |
1370 int status = env->RegisterNatives(clazz, methods, nMethods); | |
1371 if (status != JNI_OK || env->ExceptionOccurred()) { | |
1372 warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); | |
1373 env->ExceptionClear(); | |
1374 return false; | |
1375 } | |
1376 return true; | |
1377 } | |
1378 | |
1379 /** | |
1380 * This one function is exported, used by NativeLookup. | |
1381 */ | |
1340 JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) { | 1382 JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) { |
1341 if (!EnableInvokeDynamic) { | 1383 if (!EnableInvokeDynamic) { |
1342 warning("JSR 292 is disabled in this JVM. Use -XX:+UnlockDiagnosticVMOptions -XX:+EnableInvokeDynamic to enable."); | 1384 warning("JSR 292 is disabled in this JVM. Use -XX:+UnlockDiagnosticVMOptions -XX:+EnableInvokeDynamic to enable."); |
1343 return; // bind nothing | 1385 return; // bind nothing |
1344 } | 1386 } |
1352 } else { | 1394 } else { |
1353 oop mirror = SystemDictionary::MethodHandle_klass()->java_mirror(); | 1395 oop mirror = SystemDictionary::MethodHandle_klass()->java_mirror(); |
1354 MH_class = (jclass) JNIHandles::make_local(env, mirror); | 1396 MH_class = (jclass) JNIHandles::make_local(env, mirror); |
1355 } | 1397 } |
1356 | 1398 |
1357 int status; | |
1358 | |
1359 if (enable_MH) { | 1399 if (enable_MH) { |
1360 ThreadToNativeFromVM ttnfv(thread); | 1400 ThreadToNativeFromVM ttnfv(thread); |
1361 | 1401 |
1362 status = env->RegisterNatives(MHN_class, required_methods_JDK8, sizeof(required_methods_JDK8)/sizeof(JNINativeMethod)); | 1402 if (enable_MH) { |
1363 if (status != JNI_OK || env->ExceptionOccurred()) { | 1403 enable_MH = register_natives(env, MHN_class, MHN_methods, sizeof(MHN_methods)/sizeof(JNINativeMethod)); |
1364 warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); | 1404 } |
1365 enable_MH = false; | 1405 if (enable_MH) { |
1366 env->ExceptionClear(); | 1406 enable_MH = register_natives(env, MH_class, MH_methods, sizeof(MH_methods)/sizeof(JNINativeMethod)); |
1367 } | 1407 } |
1368 } | 1408 } |
1369 | 1409 |
1370 if (TraceInvokeDynamic) { | 1410 if (TraceInvokeDynamic) { |
1371 tty->print_cr("MethodHandle support loaded (using LambdaForms)"); | 1411 tty->print_cr("MethodHandle support loaded (using LambdaForms)"); |