src/java.base/share/classes/java/lang/invoke/MethodHandleNatives.java

Print this page
rev 17771 : 8184777: species logic for BoundMethodHandle doesn't scale, needs refactor


  48     /// MemberName support
  49 
  50     static native void init(MemberName self, Object ref);
  51     static native void expand(MemberName self);
  52     static native MemberName resolve(MemberName self, Class<?> caller) throws LinkageError, ClassNotFoundException;
  53     static native int getMembers(Class<?> defc, String matchName, String matchSig,
  54             int matchFlags, Class<?> caller, int skip, MemberName[] results);
  55 
  56     /// Field layout queries parallel to jdk.internal.misc.Unsafe:
  57     static native long objectFieldOffset(MemberName self);  // e.g., returns vmindex
  58     static native long staticFieldOffset(MemberName self);  // e.g., returns vmindex
  59     static native Object staticFieldBase(MemberName self);  // e.g., returns clazz
  60     static native Object getMemberVMInfo(MemberName self);  // returns {vmindex,vmtarget}
  61 
  62     /// CallSite support
  63 
  64     /** Tell the JVM that we need to change the target of a CallSite. */
  65     static native void setCallSiteTargetNormal(CallSite site, MethodHandle target);
  66     static native void setCallSiteTargetVolatile(CallSite site, MethodHandle target);
  67 















  68     /** Represents a context to track nmethod dependencies on CallSite instance target. */
  69     static class CallSiteContext implements Runnable {
  70         //@Injected JVM_nmethodBucket* vmdependencies;
  71 
  72         static CallSiteContext make(CallSite cs) {
  73             final CallSiteContext newContext = new CallSiteContext();
  74             // CallSite instance is tracked by a Cleanable which clears native
  75             // structures allocated for CallSite context. Though the CallSite can
  76             // become unreachable, its Context is retained by the Cleanable instance
  77             // (which is referenced from Cleaner instance which is referenced from
  78             // CleanerFactory class) until cleanup is performed.
  79             CleanerFactory.cleaner().register(cs, newContext);
  80             return newContext;
  81         }
  82 
  83         @Override
  84         public void run() {
  85             MethodHandleNatives.clearCallSiteContext(this);
  86         }
  87     }




  48     /// MemberName support
  49 
  50     static native void init(MemberName self, Object ref);
  51     static native void expand(MemberName self);
  52     static native MemberName resolve(MemberName self, Class<?> caller) throws LinkageError, ClassNotFoundException;
  53     static native int getMembers(Class<?> defc, String matchName, String matchSig,
  54             int matchFlags, Class<?> caller, int skip, MemberName[] results);
  55 
  56     /// Field layout queries parallel to jdk.internal.misc.Unsafe:
  57     static native long objectFieldOffset(MemberName self);  // e.g., returns vmindex
  58     static native long staticFieldOffset(MemberName self);  // e.g., returns vmindex
  59     static native Object staticFieldBase(MemberName self);  // e.g., returns clazz
  60     static native Object getMemberVMInfo(MemberName self);  // returns {vmindex,vmtarget}
  61 
  62     /// CallSite support
  63 
  64     /** Tell the JVM that we need to change the target of a CallSite. */
  65     static native void setCallSiteTargetNormal(CallSite site, MethodHandle target);
  66     static native void setCallSiteTargetVolatile(CallSite site, MethodHandle target);
  67 
  68     private static boolean MSOK;
  69     static boolean moduleSystemInitialized() {
  70         if (MSOK)  return true;
  71         //if (java.lang.reflect.Layer.boot() == null)  return false;
  72         try {
  73             Class<?> C_Layer = Class.forName("java.lang.reflect.Layer");
  74             if (C_Layer.getDeclaredMethod("boot").invoke(null) == null)
  75                 return false;
  76         } catch (ReflectiveOperationException ex) {
  77             return false;
  78         }
  79         MSOK = true;
  80         return true;
  81     }
  82 
  83     /** Represents a context to track nmethod dependencies on CallSite instance target. */
  84     static class CallSiteContext implements Runnable {
  85         //@Injected JVM_nmethodBucket* vmdependencies;
  86 
  87         static CallSiteContext make(CallSite cs) {
  88             final CallSiteContext newContext = new CallSiteContext();
  89             // CallSite instance is tracked by a Cleanable which clears native
  90             // structures allocated for CallSite context. Though the CallSite can
  91             // become unreachable, its Context is retained by the Cleanable instance
  92             // (which is referenced from Cleaner instance which is referenced from
  93             // CleanerFactory class) until cleanup is performed.
  94             CleanerFactory.cleaner().register(cs, newContext);
  95             return newContext;
  96         }
  97 
  98         @Override
  99         public void run() {
 100             MethodHandleNatives.clearCallSiteContext(this);
 101         }
 102     }