< prev index next >

src/hotspot/share/prims/methodHandles.cpp

Print this page




1134 //
1135 // Here are the native methods in java.lang.invoke.MethodHandleNatives
1136 // They are the private interface between this JVM and the HotSpot-specific
1137 // Java code that implements JSR 292 method handles.
1138 //
1139 // Note:  We use a JVM_ENTRY macro to define each of these, for this is the way
1140 // that intrinsic (non-JNI) native methods are defined in HotSpot.
1141 //
1142 
1143 #ifndef PRODUCT
1144 #define EACH_NAMED_CON(template, requirement) \
1145     template(java_lang_invoke_MemberName,MN_IS_METHOD) \
1146     template(java_lang_invoke_MemberName,MN_IS_CONSTRUCTOR) \
1147     template(java_lang_invoke_MemberName,MN_IS_FIELD) \
1148     template(java_lang_invoke_MemberName,MN_IS_TYPE) \
1149     template(java_lang_invoke_MemberName,MN_CALLER_SENSITIVE) \
1150     template(java_lang_invoke_MemberName,MN_SEARCH_SUPERCLASSES) \
1151     template(java_lang_invoke_MemberName,MN_SEARCH_INTERFACES) \
1152     template(java_lang_invoke_MemberName,MN_REFERENCE_KIND_SHIFT) \
1153     template(java_lang_invoke_MemberName,MN_REFERENCE_KIND_MASK) \




1154     /*end*/
1155 
1156 #define IGNORE_REQ(req_expr) /* req_expr */
1157 #define ONE_PLUS(scope,value) 1+
1158 static const int con_value_count = EACH_NAMED_CON(ONE_PLUS, IGNORE_REQ) 0;
1159 #define VALUE_COMMA(scope,value) scope::value,
1160 static const int con_values[con_value_count+1] = { EACH_NAMED_CON(VALUE_COMMA, IGNORE_REQ) 0 };
1161 #define STRING_NULL(scope,value) #value "\0"
1162 static const char con_names[] = { EACH_NAMED_CON(STRING_NULL, IGNORE_REQ) };
1163 
1164 static bool advertise_con_value(int which) {
1165   if (which < 0)  return false;
1166   bool ok = true;
1167   int count = 0;
1168 #define INC_COUNT(scope,value) \
1169   ++count;
1170 #define CHECK_REQ(req_expr) \
1171   if (which < count)  return ok; \
1172   ok = (req_expr);
1173   EACH_NAMED_CON(INC_COUNT, CHECK_REQ);


1493   {
1494     // Walk all nmethods depending on this call site.
1495     MutexLocker mu1(Compile_lock, thread);
1496 
1497     int marked = 0;
1498     {
1499       NoSafepointVerifier nsv;
1500       MutexLockerEx mu2(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1501       DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context());
1502       marked = deps.remove_all_dependents();
1503     }
1504     if (marked > 0) {
1505       // At least one nmethod has been marked for deoptimization
1506       VM_Deoptimize op;
1507       VMThread::execute(&op);
1508     }
1509   }
1510 }
1511 JVM_END
1512 











1513 /**
1514  * Throws a java/lang/UnsupportedOperationException unconditionally.
1515  * This is required by the specification of MethodHandle.invoke if
1516  * invoked directly.
1517  */
1518 JVM_ENTRY(jobject, MH_invoke_UOE(JNIEnv* env, jobject mh, jobjectArray args)) {
1519   THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "MethodHandle.invoke cannot be invoked reflectively");
1520   return NULL;
1521 }
1522 JVM_END
1523 
1524 /**
1525  * Throws a java/lang/UnsupportedOperationException unconditionally.
1526  * This is required by the specification of MethodHandle.invokeExact if
1527  * invoked directly.
1528  */
1529 JVM_ENTRY(jobject, MH_invokeExact_UOE(JNIEnv* env, jobject mh, jobjectArray args)) {
1530   THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "MethodHandle.invokeExact cannot be invoked reflectively");
1531   return NULL;
1532 }


1551 #define CC (char*)  /*cast a literal from (const char*)*/
1552 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
1553 
1554 // These are the native methods on java.lang.invoke.MethodHandleNatives.
1555 static JNINativeMethod MHN_methods[] = {
1556   {CC "init",                      CC "(" MEM "" OBJ ")V",                   FN_PTR(MHN_init_Mem)},
1557   {CC "expand",                    CC "(" MEM ")V",                          FN_PTR(MHN_expand_Mem)},
1558   {CC "resolve",                   CC "(" MEM "" CLS "Z)" MEM,               FN_PTR(MHN_resolve_Mem)},
1559   //  static native int getNamedCon(int which, Object[] name)
1560   {CC "getNamedCon",               CC "(I[" OBJ ")I",                        FN_PTR(MHN_getNamedCon)},
1561   //  static native int getMembers(Class<?> defc, String matchName, String matchSig,
1562   //          int matchFlags, Class<?> caller, int skip, MemberName[] results);
1563   {CC "getMembers",                CC "(" CLS "" STRG "" STRG "I" CLS "I[" MEM ")I", FN_PTR(MHN_getMembers)},
1564   {CC "objectFieldOffset",         CC "(" MEM ")J",                          FN_PTR(MHN_objectFieldOffset)},
1565   {CC "setCallSiteTargetNormal",   CC "(" CS "" MH ")V",                     FN_PTR(MHN_setCallSiteTargetNormal)},
1566   {CC "setCallSiteTargetVolatile", CC "(" CS "" MH ")V",                     FN_PTR(MHN_setCallSiteTargetVolatile)},
1567   {CC "copyOutBootstrapArguments", CC "(" CLS "[III[" OBJ "IZ" OBJ ")V",     FN_PTR(MHN_copyOutBootstrapArguments)},
1568   {CC "clearCallSiteContext",      CC "(" CTX ")V",                          FN_PTR(MHN_clearCallSiteContext)},
1569   {CC "staticFieldOffset",         CC "(" MEM ")J",                          FN_PTR(MHN_staticFieldOffset)},
1570   {CC "staticFieldBase",           CC "(" MEM ")" OBJ,                        FN_PTR(MHN_staticFieldBase)},
1571   {CC "getMemberVMInfo",           CC "(" MEM ")" OBJ,                        FN_PTR(MHN_getMemberVMInfo)}

1572 };
1573 
1574 static JNINativeMethod MH_methods[] = {
1575   // UnsupportedOperationException throwers
1576   {CC "invoke",                    CC "([" OBJ ")" OBJ,                       FN_PTR(MH_invoke_UOE)},
1577   {CC "invokeExact",               CC "([" OBJ ")" OBJ,                       FN_PTR(MH_invokeExact_UOE)}
1578 };
1579 
1580 /**
1581  * This one function is exported, used by NativeLookup.
1582  */
1583 JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) {
1584   assert(!MethodHandles::enabled(), "must not be enabled");
1585   assert(SystemDictionary::MethodHandle_klass() != NULL, "should be present");
1586 
1587   oop mirror = SystemDictionary::MethodHandle_klass()->java_mirror();
1588   jclass MH_class = (jclass) JNIHandles::make_local(env, mirror);
1589 
1590   {
1591     ThreadToNativeFromVM ttnfv(thread);


1134 //
1135 // Here are the native methods in java.lang.invoke.MethodHandleNatives
1136 // They are the private interface between this JVM and the HotSpot-specific
1137 // Java code that implements JSR 292 method handles.
1138 //
1139 // Note:  We use a JVM_ENTRY macro to define each of these, for this is the way
1140 // that intrinsic (non-JNI) native methods are defined in HotSpot.
1141 //
1142 
1143 #ifndef PRODUCT
1144 #define EACH_NAMED_CON(template, requirement) \
1145     template(java_lang_invoke_MemberName,MN_IS_METHOD) \
1146     template(java_lang_invoke_MemberName,MN_IS_CONSTRUCTOR) \
1147     template(java_lang_invoke_MemberName,MN_IS_FIELD) \
1148     template(java_lang_invoke_MemberName,MN_IS_TYPE) \
1149     template(java_lang_invoke_MemberName,MN_CALLER_SENSITIVE) \
1150     template(java_lang_invoke_MemberName,MN_SEARCH_SUPERCLASSES) \
1151     template(java_lang_invoke_MemberName,MN_SEARCH_INTERFACES) \
1152     template(java_lang_invoke_MemberName,MN_REFERENCE_KIND_SHIFT) \
1153     template(java_lang_invoke_MemberName,MN_REFERENCE_KIND_MASK) \
1154     template(java_lang_invoke_MemberName,MN_NESTMATE_CLASS) \
1155     template(java_lang_invoke_MemberName,MN_NONFINDABLE_CLASS) \
1156     template(java_lang_invoke_MemberName,MN_WEAK_CLASS) \
1157     template(java_lang_invoke_MemberName,MN_ACCESS_VM_ANNOTATIONS) \
1158     /*end*/
1159 
1160 #define IGNORE_REQ(req_expr) /* req_expr */
1161 #define ONE_PLUS(scope,value) 1+
1162 static const int con_value_count = EACH_NAMED_CON(ONE_PLUS, IGNORE_REQ) 0;
1163 #define VALUE_COMMA(scope,value) scope::value,
1164 static const int con_values[con_value_count+1] = { EACH_NAMED_CON(VALUE_COMMA, IGNORE_REQ) 0 };
1165 #define STRING_NULL(scope,value) #value "\0"
1166 static const char con_names[] = { EACH_NAMED_CON(STRING_NULL, IGNORE_REQ) };
1167 
1168 static bool advertise_con_value(int which) {
1169   if (which < 0)  return false;
1170   bool ok = true;
1171   int count = 0;
1172 #define INC_COUNT(scope,value) \
1173   ++count;
1174 #define CHECK_REQ(req_expr) \
1175   if (which < count)  return ok; \
1176   ok = (req_expr);
1177   EACH_NAMED_CON(INC_COUNT, CHECK_REQ);


1497   {
1498     // Walk all nmethods depending on this call site.
1499     MutexLocker mu1(Compile_lock, thread);
1500 
1501     int marked = 0;
1502     {
1503       NoSafepointVerifier nsv;
1504       MutexLockerEx mu2(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1505       DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context());
1506       marked = deps.remove_all_dependents();
1507     }
1508     if (marked > 0) {
1509       // At least one nmethod has been marked for deoptimization
1510       VM_Deoptimize op;
1511       VMThread::execute(&op);
1512     }
1513   }
1514 }
1515 JVM_END
1516 
1517 /*
1518  * Return the class data from the injected classData field of the given lookup class
1519  */
1520 JVM_ENTRY(jobject, MHN_classData(JNIEnv *env, jobject igcls, jclass lookup))
1521   if (lookup == NULL) {
1522     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Lookup class is null");
1523   }
1524   oop mirror = JNIHandles::resolve_non_null(lookup);
1525   return (jobject) JNIHandles::make_local(env, java_lang_Class::class_data(mirror));
1526 JVM_END
1527 
1528 /**
1529  * Throws a java/lang/UnsupportedOperationException unconditionally.
1530  * This is required by the specification of MethodHandle.invoke if
1531  * invoked directly.
1532  */
1533 JVM_ENTRY(jobject, MH_invoke_UOE(JNIEnv* env, jobject mh, jobjectArray args)) {
1534   THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "MethodHandle.invoke cannot be invoked reflectively");
1535   return NULL;
1536 }
1537 JVM_END
1538 
1539 /**
1540  * Throws a java/lang/UnsupportedOperationException unconditionally.
1541  * This is required by the specification of MethodHandle.invokeExact if
1542  * invoked directly.
1543  */
1544 JVM_ENTRY(jobject, MH_invokeExact_UOE(JNIEnv* env, jobject mh, jobjectArray args)) {
1545   THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "MethodHandle.invokeExact cannot be invoked reflectively");
1546   return NULL;
1547 }


1566 #define CC (char*)  /*cast a literal from (const char*)*/
1567 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
1568 
1569 // These are the native methods on java.lang.invoke.MethodHandleNatives.
1570 static JNINativeMethod MHN_methods[] = {
1571   {CC "init",                      CC "(" MEM "" OBJ ")V",                   FN_PTR(MHN_init_Mem)},
1572   {CC "expand",                    CC "(" MEM ")V",                          FN_PTR(MHN_expand_Mem)},
1573   {CC "resolve",                   CC "(" MEM "" CLS "Z)" MEM,               FN_PTR(MHN_resolve_Mem)},
1574   //  static native int getNamedCon(int which, Object[] name)
1575   {CC "getNamedCon",               CC "(I[" OBJ ")I",                        FN_PTR(MHN_getNamedCon)},
1576   //  static native int getMembers(Class<?> defc, String matchName, String matchSig,
1577   //          int matchFlags, Class<?> caller, int skip, MemberName[] results);
1578   {CC "getMembers",                CC "(" CLS "" STRG "" STRG "I" CLS "I[" MEM ")I", FN_PTR(MHN_getMembers)},
1579   {CC "objectFieldOffset",         CC "(" MEM ")J",                          FN_PTR(MHN_objectFieldOffset)},
1580   {CC "setCallSiteTargetNormal",   CC "(" CS "" MH ")V",                     FN_PTR(MHN_setCallSiteTargetNormal)},
1581   {CC "setCallSiteTargetVolatile", CC "(" CS "" MH ")V",                     FN_PTR(MHN_setCallSiteTargetVolatile)},
1582   {CC "copyOutBootstrapArguments", CC "(" CLS "[III[" OBJ "IZ" OBJ ")V",     FN_PTR(MHN_copyOutBootstrapArguments)},
1583   {CC "clearCallSiteContext",      CC "(" CTX ")V",                          FN_PTR(MHN_clearCallSiteContext)},
1584   {CC "staticFieldOffset",         CC "(" MEM ")J",                          FN_PTR(MHN_staticFieldOffset)},
1585   {CC "staticFieldBase",           CC "(" MEM ")" OBJ,                        FN_PTR(MHN_staticFieldBase)},
1586   {CC "getMemberVMInfo",           CC "(" MEM ")" OBJ,                       FN_PTR(MHN_getMemberVMInfo)},
1587   {CC "classData",                 CC "(" CLS ")" OBJ,                       FN_PTR(MHN_classData)}
1588 };
1589 
1590 static JNINativeMethod MH_methods[] = {
1591   // UnsupportedOperationException throwers
1592   {CC "invoke",                    CC "([" OBJ ")" OBJ,                       FN_PTR(MH_invoke_UOE)},
1593   {CC "invokeExact",               CC "([" OBJ ")" OBJ,                       FN_PTR(MH_invokeExact_UOE)}
1594 };
1595 
1596 /**
1597  * This one function is exported, used by NativeLookup.
1598  */
1599 JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) {
1600   assert(!MethodHandles::enabled(), "must not be enabled");
1601   assert(SystemDictionary::MethodHandle_klass() != NULL, "should be present");
1602 
1603   oop mirror = SystemDictionary::MethodHandle_klass()->java_mirror();
1604   jclass MH_class = (jclass) JNIHandles::make_local(env, mirror);
1605 
1606   {
1607     ThreadToNativeFromVM ttnfv(thread);
< prev index next >