< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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


  38  * @author jrose
  39  */
  40 class MethodHandleNatives {
  41 
  42     private MethodHandleNatives() { } // static only
  43 
  44     /// MemberName support
  45 
  46     static native void init(MemberName self, Object ref);
  47     static native void expand(MemberName self);
  48     static native MemberName resolve(MemberName self, Class<?> caller) throws LinkageError;
  49     static native int getMembers(Class<?> defc, String matchName, String matchSig,
  50             int matchFlags, Class<?> caller, int skip, MemberName[] results);
  51 
  52     /// Field layout queries parallel to sun.misc.Unsafe:
  53     static native long objectFieldOffset(MemberName self);  // e.g., returns vmindex
  54     static native long staticFieldOffset(MemberName self);  // e.g., returns vmindex
  55     static native Object staticFieldBase(MemberName self);  // e.g., returns clazz
  56     static native Object getMemberVMInfo(MemberName self);  // returns {vmindex,vmtarget}
  57 
  58     /// MethodHandle support
  59 
  60     /** Fetch MH-related JVM parameter.
  61      *  which=0 retrieves MethodHandlePushLimit
  62      *  which=1 retrieves stack slot push size (in address units)
  63      */
  64     static native int getConstant(int which);
  65 
  66     static final boolean COUNT_GWT;
  67 
  68     /// CallSite support
  69 
  70     /** Tell the JVM that we need to change the target of a CallSite. */
  71     static native void setCallSiteTargetNormal(CallSite site, MethodHandle target);
  72     static native void setCallSiteTargetVolatile(CallSite site, MethodHandle target);
  73 
  74     private static native void registerNatives();
  75     static {
  76         registerNatives();
  77         COUNT_GWT                   = getConstant(Constants.GC_COUNT_GWT) != 0;
  78 
  79         // The JVM calls MethodHandleNatives.<clinit>.  Cascade the <clinit> calls as needed:
  80         MethodHandleImpl.initStatics();
  81     }
  82 
  83     // All compile-time constants go here.
  84     // There is an opportunity to check them against the JVM's idea of them.



  85     static class Constants {
  86         Constants() { } // static only
  87         // MethodHandleImpl
  88         static final int // for getConstant
  89                 GC_COUNT_GWT = 4,
  90                 GC_LAMBDA_SUPPORT = 5;
  91 
  92         // MemberName
  93         // The JVM uses values of -2 and above for vtable indexes.
  94         // Field values are simple positive offsets.
  95         // Ref: src/share/vm/oops/methodOop.hpp
  96         // This value is negative enough to avoid such numbers,
  97         // but not too negative.
  98         static final int
  99                 MN_IS_METHOD           = 0x00010000, // method (not constructor)
 100                 MN_IS_CONSTRUCTOR      = 0x00020000, // constructor
 101                 MN_IS_FIELD            = 0x00040000, // field
 102                 MN_IS_TYPE             = 0x00080000, // nested type
 103                 MN_CALLER_SENSITIVE    = 0x00100000, // @CallerSensitive annotation detected
 104                 MN_REFERENCE_KIND_SHIFT = 24, // refKind
 105                 MN_REFERENCE_KIND_MASK = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
 106                 // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:
 107                 MN_SEARCH_SUPERCLASSES = 0x00100000,
 108                 MN_SEARCH_INTERFACES   = 0x00200000;
 109 
 110         /**
 111          * Basic types as encoded in the JVM.  These code values are not
 112          * intended for use outside this class.  They are used as part of


   1 /*
   2  * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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


  38  * @author jrose
  39  */
  40 class MethodHandleNatives {
  41 
  42     private MethodHandleNatives() { } // static only
  43 
  44     /// MemberName support
  45 
  46     static native void init(MemberName self, Object ref);
  47     static native void expand(MemberName self);
  48     static native MemberName resolve(MemberName self, Class<?> caller) throws LinkageError;
  49     static native int getMembers(Class<?> defc, String matchName, String matchSig,
  50             int matchFlags, Class<?> caller, int skip, MemberName[] results);
  51 
  52     /// Field layout queries parallel to sun.misc.Unsafe:
  53     static native long objectFieldOffset(MemberName self);  // e.g., returns vmindex
  54     static native long staticFieldOffset(MemberName self);  // e.g., returns vmindex
  55     static native Object staticFieldBase(MemberName self);  // e.g., returns clazz
  56     static native Object getMemberVMInfo(MemberName self);  // returns {vmindex,vmtarget}
  57 










  58     /// CallSite support
  59 
  60     /** Tell the JVM that we need to change the target of a CallSite. */
  61     static native void setCallSiteTargetNormal(CallSite site, MethodHandle target);
  62     static native void setCallSiteTargetVolatile(CallSite site, MethodHandle target);
  63 
  64     private static native void registerNatives();
  65     static {
  66         registerNatives();

  67 
  68         // The JVM calls MethodHandleNatives.<clinit>.  Cascade the <clinit> calls as needed:
  69         MethodHandleImpl.initStatics();
  70     }
  71 
  72     /**
  73      * Compile-time constants go here. This collection exists not only for
  74      * reference from clients, but also for ensuring the VM and JDK agree on the
  75      * values of these constants (see {@link #verifyConstants()}).
  76      */
  77     static class Constants {
  78         Constants() { } // static only




  79 
  80 
  81         // The JVM uses values of -2 and above for vtable indexes.
  82         // Field values are simple positive offsets.
  83         // Ref: src/share/vm/oops/methodOop.hpp
  84         // This value is negative enough to avoid such numbers,
  85         // but not too negative.
  86         static final int
  87             MN_IS_METHOD           = 0x00010000, // method (not constructor)
  88             MN_IS_CONSTRUCTOR      = 0x00020000, // constructor
  89             MN_IS_FIELD            = 0x00040000, // field
  90             MN_IS_TYPE             = 0x00080000, // nested type
  91             MN_CALLER_SENSITIVE    = 0x00100000, // @CallerSensitive annotation detected
  92             MN_REFERENCE_KIND_SHIFT = 24, // refKind
  93             MN_REFERENCE_KIND_MASK = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
  94             // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:
  95             MN_SEARCH_SUPERCLASSES = 0x00100000,
  96             MN_SEARCH_INTERFACES   = 0x00200000;
  97 
  98         /**
  99          * Basic types as encoded in the JVM.  These code values are not
 100          * intended for use outside this class.  They are used as part of


< prev index next >