src/share/vm/prims/methodHandles.cpp

changeset 3131
b0efc7ee3b31
parent 3105
c26de9aef2ed
child 3137
e6b1331a51d2
     1.1 --- a/src/share/vm/prims/methodHandles.cpp	Thu Sep 08 10:12:25 2011 +0200
     1.2 +++ b/src/share/vm/prims/methodHandles.cpp	Thu Sep 08 05:11:31 2011 -0700
     1.3 @@ -3081,6 +3081,30 @@
     1.4  }
     1.5  JVM_END
     1.6  
     1.7 +JVM_ENTRY(void, MHN_setCallSiteTargetNormal(JNIEnv* env, jobject igcls, jobject call_site_jh, jobject target_jh)) {
     1.8 +  oop call_site = JNIHandles::resolve_non_null(call_site_jh);
     1.9 +  oop target    = JNIHandles::resolve(target_jh);
    1.10 +  {
    1.11 +    // Walk all nmethods depending on this call site.
    1.12 +    MutexLocker mu(Compile_lock, thread);
    1.13 +    Universe::flush_dependents_on(call_site, target);
    1.14 +  }
    1.15 +  java_lang_invoke_CallSite::set_target(call_site, target);
    1.16 +}
    1.17 +JVM_END
    1.18 +
    1.19 +JVM_ENTRY(void, MHN_setCallSiteTargetVolatile(JNIEnv* env, jobject igcls, jobject call_site_jh, jobject target_jh)) {
    1.20 +  oop call_site = JNIHandles::resolve_non_null(call_site_jh);
    1.21 +  oop target    = JNIHandles::resolve(target_jh);
    1.22 +  {
    1.23 +    // Walk all nmethods depending on this call site.
    1.24 +    MutexLocker mu(Compile_lock, thread);
    1.25 +    Universe::flush_dependents_on(call_site, target);
    1.26 +  }
    1.27 +  java_lang_invoke_CallSite::set_target_volatile(call_site, target);
    1.28 +}
    1.29 +JVM_END
    1.30 +
    1.31  methodOop MethodHandles::resolve_raise_exception_method(TRAPS) {
    1.32    if (_raise_exception_method != NULL) {
    1.33      // no need to do it twice
    1.34 @@ -3137,12 +3161,15 @@
    1.35  
    1.36  /// JVM_RegisterMethodHandleMethods
    1.37  
    1.38 +#undef CS  // Solaris builds complain
    1.39 +
    1.40  #define LANG "Ljava/lang/"
    1.41  #define JLINV "Ljava/lang/invoke/"
    1.42  
    1.43  #define OBJ   LANG"Object;"
    1.44  #define CLS   LANG"Class;"
    1.45  #define STRG  LANG"String;"
    1.46 +#define CS    JLINV"CallSite;"
    1.47  #define MT    JLINV"MethodType;"
    1.48  #define MH    JLINV"MethodHandle;"
    1.49  #define MEM   JLINV"MemberName;"
    1.50 @@ -3153,29 +3180,34 @@
    1.51  #define CC (char*)  /*cast a literal from (const char*)*/
    1.52  #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
    1.53  
    1.54 -// These are the native methods on sun.invoke.MethodHandleNatives.
    1.55 +// These are the native methods on java.lang.invoke.MethodHandleNatives.
    1.56  static JNINativeMethod methods[] = {
    1.57    // void init(MemberName self, AccessibleObject ref)
    1.58 -  {CC"init",                    CC"("AMH""MH"I)V",              FN_PTR(MHN_init_AMH)},
    1.59 -  {CC"init",                    CC"("BMH""OBJ"I)V",             FN_PTR(MHN_init_BMH)},
    1.60 -  {CC"init",                    CC"("DMH""OBJ"Z"CLS")V",        FN_PTR(MHN_init_DMH)},
    1.61 -  {CC"init",                    CC"("MT")V",                    FN_PTR(MHN_init_MT)},
    1.62 -  {CC"init",                    CC"("MEM""OBJ")V",              FN_PTR(MHN_init_Mem)},
    1.63 -  {CC"expand",                  CC"("MEM")V",                   FN_PTR(MHN_expand_Mem)},
    1.64 -  {CC"resolve",                 CC"("MEM""CLS")V",              FN_PTR(MHN_resolve_Mem)},
    1.65 -  {CC"getTarget",               CC"("MH"I)"OBJ,                 FN_PTR(MHN_getTarget)},
    1.66 -  {CC"getConstant",             CC"(I)I",                       FN_PTR(MHN_getConstant)},
    1.67 +  {CC"init",                      CC"("AMH""MH"I)V",                     FN_PTR(MHN_init_AMH)},
    1.68 +  {CC"init",                      CC"("BMH""OBJ"I)V",                    FN_PTR(MHN_init_BMH)},
    1.69 +  {CC"init",                      CC"("DMH""OBJ"Z"CLS")V",               FN_PTR(MHN_init_DMH)},
    1.70 +  {CC"init",                      CC"("MT")V",                           FN_PTR(MHN_init_MT)},
    1.71 +  {CC"init",                      CC"("MEM""OBJ")V",                     FN_PTR(MHN_init_Mem)},
    1.72 +  {CC"expand",                    CC"("MEM")V",                          FN_PTR(MHN_expand_Mem)},
    1.73 +  {CC"resolve",                   CC"("MEM""CLS")V",                     FN_PTR(MHN_resolve_Mem)},
    1.74 +  {CC"getTarget",                 CC"("MH"I)"OBJ,                        FN_PTR(MHN_getTarget)},
    1.75 +  {CC"getConstant",               CC"(I)I",                              FN_PTR(MHN_getConstant)},
    1.76    //  static native int getNamedCon(int which, Object[] name)
    1.77 -  {CC"getNamedCon",             CC"(I["OBJ")I",                 FN_PTR(MHN_getNamedCon)},
    1.78 +  {CC"getNamedCon",               CC"(I["OBJ")I",                        FN_PTR(MHN_getNamedCon)},
    1.79    //  static native int getMembers(Class<?> defc, String matchName, String matchSig,
    1.80    //          int matchFlags, Class<?> caller, int skip, MemberName[] results);
    1.81 -  {CC"getMembers",              CC"("CLS""STRG""STRG"I"CLS"I["MEM")I",  FN_PTR(MHN_getMembers)}
    1.82 +  {CC"getMembers",                CC"("CLS""STRG""STRG"I"CLS"I["MEM")I", FN_PTR(MHN_getMembers)}
    1.83 +};
    1.84 +
    1.85 +static JNINativeMethod call_site_methods[] = {
    1.86 +  {CC"setCallSiteTargetNormal",   CC"("CS""MH")V",                       FN_PTR(MHN_setCallSiteTargetNormal)},
    1.87 +  {CC"setCallSiteTargetVolatile", CC"("CS""MH")V",                       FN_PTR(MHN_setCallSiteTargetVolatile)}
    1.88  };
    1.89  
    1.90  static JNINativeMethod invoke_methods[] = {
    1.91    // void init(MemberName self, AccessibleObject ref)
    1.92 -  {CC"invoke",                  CC"(["OBJ")"OBJ,                FN_PTR(MH_invoke_UOE)},
    1.93 -  {CC"invokeExact",             CC"(["OBJ")"OBJ,                FN_PTR(MH_invokeExact_UOE)}
    1.94 +  {CC"invoke",                    CC"(["OBJ")"OBJ,                       FN_PTR(MH_invoke_UOE)},
    1.95 +  {CC"invokeExact",               CC"(["OBJ")"OBJ,                       FN_PTR(MH_invokeExact_UOE)}
    1.96  };
    1.97  
    1.98  // This one function is exported, used by NativeLookup.
    1.99 @@ -3188,11 +3220,11 @@
   1.100      return;  // bind nothing
   1.101    }
   1.102  
   1.103 +  assert(!MethodHandles::enabled(), "must not be enabled");
   1.104    bool enable_MH = true;
   1.105  
   1.106    {
   1.107      ThreadToNativeFromVM ttnfv(thread);
   1.108 -
   1.109      int status = env->RegisterNatives(MHN_class, methods, sizeof(methods)/sizeof(JNINativeMethod));
   1.110      if (!env->ExceptionOccurred()) {
   1.111        const char* L_MH_name = (JLINV "MethodHandle");
   1.112 @@ -3201,11 +3233,16 @@
   1.113        status = env->RegisterNatives(MH_class, invoke_methods, sizeof(invoke_methods)/sizeof(JNINativeMethod));
   1.114      }
   1.115      if (env->ExceptionOccurred()) {
   1.116 -      MethodHandles::set_enabled(false);
   1.117        warning("JSR 292 method handle code is mismatched to this JVM.  Disabling support.");
   1.118        enable_MH = false;
   1.119        env->ExceptionClear();
   1.120      }
   1.121 +
   1.122 +    status = env->RegisterNatives(MHN_class, call_site_methods, sizeof(call_site_methods)/sizeof(JNINativeMethod));
   1.123 +    if (env->ExceptionOccurred()) {
   1.124 +      // Exception is okay until 7087357
   1.125 +      env->ExceptionClear();
   1.126 +    }
   1.127    }
   1.128  
   1.129    if (enable_MH) {

mercurial