< prev index next >

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

Print this page
rev 58565 : 8238358: Implementation of JEP 371: Hidden Classes
Reviewed-by: duke
Contributed-by: mandy.chung@oracle.com, lois.foltan@oracle.com, david.holmes@oracle.com, harold.seigel@oracle.com, serguei.spitsyn@oracle.com, alex.buckley@oracle.com, jamsheed.c.m@oracle.com


   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
  23  * questions.
  24  */
  25 
  26 package java.lang.invoke;
  27 


  28 import jdk.internal.ref.CleanerFactory;
  29 import sun.invoke.util.Wrapper;
  30 
  31 import java.lang.invoke.MethodHandles.Lookup;
  32 import java.lang.reflect.Field;
  33 
  34 import static java.lang.invoke.MethodHandleNatives.Constants.*;
  35 import static java.lang.invoke.MethodHandleStatics.TRACE_METHOD_LINKAGE;
  36 import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
  37 
  38 /**
  39  * The JVM interface for the method handles package is all here.
  40  * This is an interface internal and private to an implementation of JSR 292.
  41  * <em>This class is not part of the JSR 292 standard.</em>
  42  * @author jrose
  43  */
  44 class MethodHandleNatives {
  45 
  46     private MethodHandleNatives() { } // static only
  47 


 120             MN_REFERENCE_KIND_MASK = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
 121             // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:
 122             MN_SEARCH_SUPERCLASSES = 0x00100000,
 123             MN_SEARCH_INTERFACES   = 0x00200000;
 124 
 125         /**
 126          * Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.
 127          */
 128         static final byte
 129             REF_NONE                    = 0,  // null value
 130             REF_getField                = 1,
 131             REF_getStatic               = 2,
 132             REF_putField                = 3,
 133             REF_putStatic               = 4,
 134             REF_invokeVirtual           = 5,
 135             REF_invokeStatic            = 6,
 136             REF_invokeSpecial           = 7,
 137             REF_newInvokeSpecial        = 8,
 138             REF_invokeInterface         = 9,
 139             REF_LIMIT                  = 10;









 140     }
 141 
 142     static boolean refKindIsValid(int refKind) {
 143         return (refKind > REF_NONE && refKind < REF_LIMIT);
 144     }
 145     static boolean refKindIsField(byte refKind) {
 146         assert(refKindIsValid(refKind));
 147         return (refKind <= REF_putStatic);
 148     }
 149     static boolean refKindIsGetter(byte refKind) {
 150         assert(refKindIsValid(refKind));
 151         return (refKind <= REF_getStatic);
 152     }
 153     static boolean refKindIsSetter(byte refKind) {
 154         return refKindIsField(refKind) && !refKindIsGetter(refKind);
 155     }
 156     static boolean refKindIsMethod(byte refKind) {
 157         return !refKindIsField(refKind) && (refKind != REF_newInvokeSpecial);
 158     }
 159     static boolean refKindIsConstructor(byte refKind) {


 642 
 643         return mem.isCallerSensitive() || canBeCalledVirtual(mem);
 644     }
 645 
 646     static boolean canBeCalledVirtual(MemberName mem) {
 647         assert(mem.isInvocable());
 648         switch (mem.getName()) {
 649         case "getContextClassLoader":
 650             return canBeCalledVirtual(mem, java.lang.Thread.class);
 651         }
 652         return false;
 653     }
 654 
 655     static boolean canBeCalledVirtual(MemberName symbolicRef, Class<?> definingClass) {
 656         Class<?> symbolicRefClass = symbolicRef.getDeclaringClass();
 657         if (symbolicRefClass == definingClass)  return true;
 658         if (symbolicRef.isStatic() || symbolicRef.isPrivate())  return false;
 659         return (definingClass.isAssignableFrom(symbolicRefClass) ||  // Msym overrides Mdef
 660                 symbolicRefClass.isInterface());                     // Mdef implements Msym
 661     }









 662 }


   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
  23  * questions.
  24  */
  25 
  26 package java.lang.invoke;
  27 
  28 import jdk.internal.access.JavaLangAccess;
  29 import jdk.internal.access.SharedSecrets;
  30 import jdk.internal.ref.CleanerFactory;
  31 import sun.invoke.util.Wrapper;
  32 
  33 import java.lang.invoke.MethodHandles.Lookup;
  34 import java.lang.reflect.Field;
  35 
  36 import static java.lang.invoke.MethodHandleNatives.Constants.*;
  37 import static java.lang.invoke.MethodHandleStatics.TRACE_METHOD_LINKAGE;
  38 import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
  39 
  40 /**
  41  * The JVM interface for the method handles package is all here.
  42  * This is an interface internal and private to an implementation of JSR 292.
  43  * <em>This class is not part of the JSR 292 standard.</em>
  44  * @author jrose
  45  */
  46 class MethodHandleNatives {
  47 
  48     private MethodHandleNatives() { } // static only
  49 


 122             MN_REFERENCE_KIND_MASK = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
 123             // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:
 124             MN_SEARCH_SUPERCLASSES = 0x00100000,
 125             MN_SEARCH_INTERFACES   = 0x00200000;
 126 
 127         /**
 128          * Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.
 129          */
 130         static final byte
 131             REF_NONE                    = 0,  // null value
 132             REF_getField                = 1,
 133             REF_getStatic               = 2,
 134             REF_putField                = 3,
 135             REF_putStatic               = 4,
 136             REF_invokeVirtual           = 5,
 137             REF_invokeStatic            = 6,
 138             REF_invokeSpecial           = 7,
 139             REF_newInvokeSpecial        = 8,
 140             REF_invokeInterface         = 9,
 141             REF_LIMIT                  = 10;
 142 
 143         /**
 144          * Flags for Lookup.ClassOptions
 145          */
 146         static final int
 147             NESTMATE_CLASS            = 0x00000001,
 148             HIDDEN_CLASS              = 0x00000002,
 149             STRONG_LOADER_LINK        = 0x00000004,
 150             ACCESS_VM_ANNOTATIONS     = 0x00000008;
 151     }
 152 
 153     static boolean refKindIsValid(int refKind) {
 154         return (refKind > REF_NONE && refKind < REF_LIMIT);
 155     }
 156     static boolean refKindIsField(byte refKind) {
 157         assert(refKindIsValid(refKind));
 158         return (refKind <= REF_putStatic);
 159     }
 160     static boolean refKindIsGetter(byte refKind) {
 161         assert(refKindIsValid(refKind));
 162         return (refKind <= REF_getStatic);
 163     }
 164     static boolean refKindIsSetter(byte refKind) {
 165         return refKindIsField(refKind) && !refKindIsGetter(refKind);
 166     }
 167     static boolean refKindIsMethod(byte refKind) {
 168         return !refKindIsField(refKind) && (refKind != REF_newInvokeSpecial);
 169     }
 170     static boolean refKindIsConstructor(byte refKind) {


 653 
 654         return mem.isCallerSensitive() || canBeCalledVirtual(mem);
 655     }
 656 
 657     static boolean canBeCalledVirtual(MemberName mem) {
 658         assert(mem.isInvocable());
 659         switch (mem.getName()) {
 660         case "getContextClassLoader":
 661             return canBeCalledVirtual(mem, java.lang.Thread.class);
 662         }
 663         return false;
 664     }
 665 
 666     static boolean canBeCalledVirtual(MemberName symbolicRef, Class<?> definingClass) {
 667         Class<?> symbolicRefClass = symbolicRef.getDeclaringClass();
 668         if (symbolicRefClass == definingClass)  return true;
 669         if (symbolicRef.isStatic() || symbolicRef.isPrivate())  return false;
 670         return (definingClass.isAssignableFrom(symbolicRefClass) ||  // Msym overrides Mdef
 671                 symbolicRefClass.isInterface());                     // Mdef implements Msym
 672     }
 673 
 674     private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
 675     /*
 676      * A convenient method for LambdaForms to get the class data of a given class.
 677      * LambdaForms cannot use condy via MethodHandles.classData
 678      */
 679     static Object classData(Class<?> c) {
 680         return JLA.classData(c);
 681     }
 682 }
< prev index next >