< prev index next >

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

Print this page




  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang.invoke;
  27 
  28 import java.lang.invoke.MethodHandles.Lookup;
  29 import java.lang.reflect.Field;
  30 import static java.lang.invoke.MethodHandleNatives.Constants.*;
  31 import static java.lang.invoke.MethodHandleStatics.*;
  32 import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
  33 import jdk.internal.ref.Cleaner;
  34 
  35 /**
  36  * The JVM interface for the method handles package is all here.
  37  * This is an interface internal and private to an implementation of JSR 292.
  38  * <em>This class is not part of the JSR 292 standard.</em>
  39  * @author jrose
  40  */
  41 class MethodHandleNatives {
  42 
  43     private MethodHandleNatives() { } // static only
  44 
  45     /// MemberName support
  46 
  47     static native void init(MemberName self, Object ref);
  48     static native void expand(MemberName self);
  49     static native MemberName resolve(MemberName self, Class<?> caller) throws LinkageError;
  50     static native int getMembers(Class<?> defc, String matchName, String matchSig,
  51             int matchFlags, Class<?> caller, int skip, MemberName[] results);
  52 
  53     /// Field layout queries parallel to jdk.internal.misc.Unsafe:
  54     static native long objectFieldOffset(MemberName self);  // e.g., returns vmindex
  55     static native long staticFieldOffset(MemberName self);  // e.g., returns vmindex
  56     static native Object staticFieldBase(MemberName self);  // e.g., returns clazz
  57     static native Object getMemberVMInfo(MemberName self);  // returns {vmindex,vmtarget}
  58 
  59     /// CallSite support
  60 
  61     /** Tell the JVM that we need to change the target of a CallSite. */
  62     static native void setCallSiteTargetNormal(CallSite site, MethodHandle target);
  63     static native void setCallSiteTargetVolatile(CallSite site, MethodHandle target);
  64 
  65     /** Represents a context to track nmethod dependencies on CallSite instance target. */
  66     static class CallSiteContext implements Runnable {
  67         //@Injected JVM_nmethodBucket* vmdependencies;
  68 
  69         static CallSiteContext make(CallSite cs) {
  70             final CallSiteContext newContext = new CallSiteContext();
  71             // Cleaner is attached to CallSite instance and it clears native structures allocated for CallSite context.
  72             // Though the CallSite can become unreachable, its Context is retained by the Cleaner instance (which is
  73             // referenced from Cleaner class) until cleanup is performed.
  74             Cleaner.create(cs, newContext);
  75             return newContext;
  76         }
  77 
  78         @Override
  79         public void run() {
  80             MethodHandleNatives.clearCallSiteContext(this);
  81         }
  82     }
  83 
  84     /** Invalidate all recorded nmethods. */
  85     private static native void clearCallSiteContext(CallSiteContext context);
  86 
  87     private static native void registerNatives();
  88     static {
  89         registerNatives();
  90     }
  91 
  92     /**
  93      * Compile-time constants go here. This collection exists not only for
  94      * reference from clients, but also for ensuring the VM and JDK agree on the




  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang.invoke;
  27 
  28 import java.lang.invoke.MethodHandles.Lookup;
  29 import java.lang.reflect.Field;
  30 import static java.lang.invoke.MethodHandleNatives.Constants.*;
  31 import static java.lang.invoke.MethodHandleStatics.*;
  32 import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
  33 import jdk.internal.ref.CleanerFactory;
  34 
  35 /**
  36  * The JVM interface for the method handles package is all here.
  37  * This is an interface internal and private to an implementation of JSR 292.
  38  * <em>This class is not part of the JSR 292 standard.</em>
  39  * @author jrose
  40  */
  41 class MethodHandleNatives {
  42 
  43     private MethodHandleNatives() { } // static only
  44 
  45     /// MemberName support
  46 
  47     static native void init(MemberName self, Object ref);
  48     static native void expand(MemberName self);
  49     static native MemberName resolve(MemberName self, Class<?> caller) throws LinkageError;
  50     static native int getMembers(Class<?> defc, String matchName, String matchSig,
  51             int matchFlags, Class<?> caller, int skip, MemberName[] results);
  52 
  53     /// Field layout queries parallel to jdk.internal.misc.Unsafe:
  54     static native long objectFieldOffset(MemberName self);  // e.g., returns vmindex
  55     static native long staticFieldOffset(MemberName self);  // e.g., returns vmindex
  56     static native Object staticFieldBase(MemberName self);  // e.g., returns clazz
  57     static native Object getMemberVMInfo(MemberName self);  // returns {vmindex,vmtarget}
  58 
  59     /// CallSite support
  60 
  61     /** Tell the JVM that we need to change the target of a CallSite. */
  62     static native void setCallSiteTargetNormal(CallSite site, MethodHandle target);
  63     static native void setCallSiteTargetVolatile(CallSite site, MethodHandle target);
  64 
  65     /** Represents a context to track nmethod dependencies on CallSite instance target. */
  66     static class CallSiteContext implements Runnable {
  67         //@Injected JVM_nmethodBucket* vmdependencies;
  68 
  69         static CallSiteContext make(CallSite cs) {
  70             final CallSiteContext newContext = new CallSiteContext();
  71             // Cleaner is attached to CallSite instance and it clears native structures allocated for CallSite context.
  72             // Though the CallSite can become unreachable, its Context is retained by the Cleaner instance (which is
  73             // referenced from Cleaner class) until cleanup is performed.
  74             CleanerFactory.cleaner().register(cs, newContext);
  75             return newContext;
  76         }
  77 
  78         @Override
  79         public void run() {
  80             MethodHandleNatives.clearCallSiteContext(this);
  81         }
  82     }
  83 
  84     /** Invalidate all recorded nmethods. */
  85     private static native void clearCallSiteContext(CallSiteContext context);
  86 
  87     private static native void registerNatives();
  88     static {
  89         registerNatives();
  90     }
  91 
  92     /**
  93      * Compile-time constants go here. This collection exists not only for
  94      * reference from clients, but also for ensuring the VM and JDK agree on the


< prev index next >