3079 // TO DO: expand at least some of the MemberNames, to avoid massive callbacks |
3079 // TO DO: expand at least some of the MemberNames, to avoid massive callbacks |
3080 return res; |
3080 return res; |
3081 } |
3081 } |
3082 JVM_END |
3082 JVM_END |
3083 |
3083 |
|
3084 JVM_ENTRY(void, MHN_setCallSiteTargetNormal(JNIEnv* env, jobject igcls, jobject call_site_jh, jobject target_jh)) { |
|
3085 oop call_site = JNIHandles::resolve_non_null(call_site_jh); |
|
3086 oop target = JNIHandles::resolve(target_jh); |
|
3087 { |
|
3088 // Walk all nmethods depending on this call site. |
|
3089 MutexLocker mu(Compile_lock, thread); |
|
3090 Universe::flush_dependents_on(call_site, target); |
|
3091 } |
|
3092 java_lang_invoke_CallSite::set_target(call_site, target); |
|
3093 } |
|
3094 JVM_END |
|
3095 |
|
3096 JVM_ENTRY(void, MHN_setCallSiteTargetVolatile(JNIEnv* env, jobject igcls, jobject call_site_jh, jobject target_jh)) { |
|
3097 oop call_site = JNIHandles::resolve_non_null(call_site_jh); |
|
3098 oop target = JNIHandles::resolve(target_jh); |
|
3099 { |
|
3100 // Walk all nmethods depending on this call site. |
|
3101 MutexLocker mu(Compile_lock, thread); |
|
3102 Universe::flush_dependents_on(call_site, target); |
|
3103 } |
|
3104 java_lang_invoke_CallSite::set_target_volatile(call_site, target); |
|
3105 } |
|
3106 JVM_END |
|
3107 |
3084 methodOop MethodHandles::resolve_raise_exception_method(TRAPS) { |
3108 methodOop MethodHandles::resolve_raise_exception_method(TRAPS) { |
3085 if (_raise_exception_method != NULL) { |
3109 if (_raise_exception_method != NULL) { |
3086 // no need to do it twice |
3110 // no need to do it twice |
3087 return raise_exception_method(); |
3111 return raise_exception_method(); |
3088 } |
3112 } |
3135 JVM_END |
3159 JVM_END |
3136 |
3160 |
3137 |
3161 |
3138 /// JVM_RegisterMethodHandleMethods |
3162 /// JVM_RegisterMethodHandleMethods |
3139 |
3163 |
|
3164 #undef CS // Solaris builds complain |
|
3165 |
3140 #define LANG "Ljava/lang/" |
3166 #define LANG "Ljava/lang/" |
3141 #define JLINV "Ljava/lang/invoke/" |
3167 #define JLINV "Ljava/lang/invoke/" |
3142 |
3168 |
3143 #define OBJ LANG"Object;" |
3169 #define OBJ LANG"Object;" |
3144 #define CLS LANG"Class;" |
3170 #define CLS LANG"Class;" |
3145 #define STRG LANG"String;" |
3171 #define STRG LANG"String;" |
|
3172 #define CS JLINV"CallSite;" |
3146 #define MT JLINV"MethodType;" |
3173 #define MT JLINV"MethodType;" |
3147 #define MH JLINV"MethodHandle;" |
3174 #define MH JLINV"MethodHandle;" |
3148 #define MEM JLINV"MemberName;" |
3175 #define MEM JLINV"MemberName;" |
3149 #define AMH JLINV"AdapterMethodHandle;" |
3176 #define AMH JLINV"AdapterMethodHandle;" |
3150 #define BMH JLINV"BoundMethodHandle;" |
3177 #define BMH JLINV"BoundMethodHandle;" |
3151 #define DMH JLINV"DirectMethodHandle;" |
3178 #define DMH JLINV"DirectMethodHandle;" |
3152 |
3179 |
3153 #define CC (char*) /*cast a literal from (const char*)*/ |
3180 #define CC (char*) /*cast a literal from (const char*)*/ |
3154 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) |
3181 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) |
3155 |
3182 |
3156 // These are the native methods on sun.invoke.MethodHandleNatives. |
3183 // These are the native methods on java.lang.invoke.MethodHandleNatives. |
3157 static JNINativeMethod methods[] = { |
3184 static JNINativeMethod methods[] = { |
3158 // void init(MemberName self, AccessibleObject ref) |
3185 // void init(MemberName self, AccessibleObject ref) |
3159 {CC"init", CC"("AMH""MH"I)V", FN_PTR(MHN_init_AMH)}, |
3186 {CC"init", CC"("AMH""MH"I)V", FN_PTR(MHN_init_AMH)}, |
3160 {CC"init", CC"("BMH""OBJ"I)V", FN_PTR(MHN_init_BMH)}, |
3187 {CC"init", CC"("BMH""OBJ"I)V", FN_PTR(MHN_init_BMH)}, |
3161 {CC"init", CC"("DMH""OBJ"Z"CLS")V", FN_PTR(MHN_init_DMH)}, |
3188 {CC"init", CC"("DMH""OBJ"Z"CLS")V", FN_PTR(MHN_init_DMH)}, |
3162 {CC"init", CC"("MT")V", FN_PTR(MHN_init_MT)}, |
3189 {CC"init", CC"("MT")V", FN_PTR(MHN_init_MT)}, |
3163 {CC"init", CC"("MEM""OBJ")V", FN_PTR(MHN_init_Mem)}, |
3190 {CC"init", CC"("MEM""OBJ")V", FN_PTR(MHN_init_Mem)}, |
3164 {CC"expand", CC"("MEM")V", FN_PTR(MHN_expand_Mem)}, |
3191 {CC"expand", CC"("MEM")V", FN_PTR(MHN_expand_Mem)}, |
3165 {CC"resolve", CC"("MEM""CLS")V", FN_PTR(MHN_resolve_Mem)}, |
3192 {CC"resolve", CC"("MEM""CLS")V", FN_PTR(MHN_resolve_Mem)}, |
3166 {CC"getTarget", CC"("MH"I)"OBJ, FN_PTR(MHN_getTarget)}, |
3193 {CC"getTarget", CC"("MH"I)"OBJ, FN_PTR(MHN_getTarget)}, |
3167 {CC"getConstant", CC"(I)I", FN_PTR(MHN_getConstant)}, |
3194 {CC"getConstant", CC"(I)I", FN_PTR(MHN_getConstant)}, |
3168 // static native int getNamedCon(int which, Object[] name) |
3195 // static native int getNamedCon(int which, Object[] name) |
3169 {CC"getNamedCon", CC"(I["OBJ")I", FN_PTR(MHN_getNamedCon)}, |
3196 {CC"getNamedCon", CC"(I["OBJ")I", FN_PTR(MHN_getNamedCon)}, |
3170 // static native int getMembers(Class<?> defc, String matchName, String matchSig, |
3197 // static native int getMembers(Class<?> defc, String matchName, String matchSig, |
3171 // int matchFlags, Class<?> caller, int skip, MemberName[] results); |
3198 // int matchFlags, Class<?> caller, int skip, MemberName[] results); |
3172 {CC"getMembers", CC"("CLS""STRG""STRG"I"CLS"I["MEM")I", FN_PTR(MHN_getMembers)} |
3199 {CC"getMembers", CC"("CLS""STRG""STRG"I"CLS"I["MEM")I", FN_PTR(MHN_getMembers)} |
|
3200 }; |
|
3201 |
|
3202 static JNINativeMethod call_site_methods[] = { |
|
3203 {CC"setCallSiteTargetNormal", CC"("CS""MH")V", FN_PTR(MHN_setCallSiteTargetNormal)}, |
|
3204 {CC"setCallSiteTargetVolatile", CC"("CS""MH")V", FN_PTR(MHN_setCallSiteTargetVolatile)} |
3173 }; |
3205 }; |
3174 |
3206 |
3175 static JNINativeMethod invoke_methods[] = { |
3207 static JNINativeMethod invoke_methods[] = { |
3176 // void init(MemberName self, AccessibleObject ref) |
3208 // void init(MemberName self, AccessibleObject ref) |
3177 {CC"invoke", CC"(["OBJ")"OBJ, FN_PTR(MH_invoke_UOE)}, |
3209 {CC"invoke", CC"(["OBJ")"OBJ, FN_PTR(MH_invoke_UOE)}, |
3178 {CC"invokeExact", CC"(["OBJ")"OBJ, FN_PTR(MH_invokeExact_UOE)} |
3210 {CC"invokeExact", CC"(["OBJ")"OBJ, FN_PTR(MH_invokeExact_UOE)} |
3179 }; |
3211 }; |
3180 |
3212 |
3181 // This one function is exported, used by NativeLookup. |
3213 // This one function is exported, used by NativeLookup. |
3182 |
3214 |
3183 JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) { |
3215 JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) { |
3186 if (!EnableInvokeDynamic) { |
3218 if (!EnableInvokeDynamic) { |
3187 warning("JSR 292 is disabled in this JVM. Use -XX:+UnlockDiagnosticVMOptions -XX:+EnableInvokeDynamic to enable."); |
3219 warning("JSR 292 is disabled in this JVM. Use -XX:+UnlockDiagnosticVMOptions -XX:+EnableInvokeDynamic to enable."); |
3188 return; // bind nothing |
3220 return; // bind nothing |
3189 } |
3221 } |
3190 |
3222 |
|
3223 assert(!MethodHandles::enabled(), "must not be enabled"); |
3191 bool enable_MH = true; |
3224 bool enable_MH = true; |
3192 |
3225 |
3193 { |
3226 { |
3194 ThreadToNativeFromVM ttnfv(thread); |
3227 ThreadToNativeFromVM ttnfv(thread); |
3195 |
|
3196 int status = env->RegisterNatives(MHN_class, methods, sizeof(methods)/sizeof(JNINativeMethod)); |
3228 int status = env->RegisterNatives(MHN_class, methods, sizeof(methods)/sizeof(JNINativeMethod)); |
3197 if (!env->ExceptionOccurred()) { |
3229 if (!env->ExceptionOccurred()) { |
3198 const char* L_MH_name = (JLINV "MethodHandle"); |
3230 const char* L_MH_name = (JLINV "MethodHandle"); |
3199 const char* MH_name = L_MH_name+1; |
3231 const char* MH_name = L_MH_name+1; |
3200 jclass MH_class = env->FindClass(MH_name); |
3232 jclass MH_class = env->FindClass(MH_name); |
3201 status = env->RegisterNatives(MH_class, invoke_methods, sizeof(invoke_methods)/sizeof(JNINativeMethod)); |
3233 status = env->RegisterNatives(MH_class, invoke_methods, sizeof(invoke_methods)/sizeof(JNINativeMethod)); |
3202 } |
3234 } |
3203 if (env->ExceptionOccurred()) { |
3235 if (env->ExceptionOccurred()) { |
3204 MethodHandles::set_enabled(false); |
|
3205 warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); |
3236 warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); |
3206 enable_MH = false; |
3237 enable_MH = false; |
|
3238 env->ExceptionClear(); |
|
3239 } |
|
3240 |
|
3241 status = env->RegisterNatives(MHN_class, call_site_methods, sizeof(call_site_methods)/sizeof(JNINativeMethod)); |
|
3242 if (env->ExceptionOccurred()) { |
|
3243 // Exception is okay until 7087357 |
3207 env->ExceptionClear(); |
3244 env->ExceptionClear(); |
3208 } |
3245 } |
3209 } |
3246 } |
3210 |
3247 |
3211 if (enable_MH) { |
3248 if (enable_MH) { |