1 /*
   2  * Copyright (c) 2015, 2018, 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
  23  * questions.
  24  */
  25 
  26 package jdk.internal.access;
  27 
  28 import java.lang.invoke.MethodHandle;
  29 import java.lang.invoke.MethodType;
  30 import java.lang.invoke.VarHandle;
  31 import java.nio.ByteOrder;
  32 import java.util.List;
  33 import java.util.Map;
  34 
  35 public interface JavaLangInvokeAccess {
  36     /**
  37      * Create a new MemberName instance. Used by {@code StackFrameInfo}.
  38      */
  39     Object newMemberName();
  40 
  41     /**
  42      * Returns the name for the given MemberName. Used by {@code StackFrameInfo}.
  43      */
  44     String getName(Object mname);
  45 
  46     /**
  47      * Returns the {@code MethodType} for the given MemberName.
  48      * Used by {@code StackFrameInfo}.
  49      */
  50     MethodType getMethodType(Object mname);
  51 
  52     /**
  53      * Returns the descriptor for the given MemberName.
  54      * Used by {@code StackFrameInfo}.
  55      */
  56     String getMethodDescriptor(Object mname);
  57 
  58     /**
  59      * Returns {@code true} if the given MemberName is a native method.
  60      * Used by {@code StackFrameInfo}.
  61      */
  62     boolean isNative(Object mname);
  63 
  64     /**
  65      * Returns the declaring class for the given MemberName.
  66      * Used by {@code StackFrameInfo}.
  67      */
  68     Class<?> getDeclaringClass(Object mname);
  69 
  70     /**
  71      * Returns a {@code byte[]} representation of a class implementing
  72      * DirectMethodHandle of each pairwise combination of {@code MethodType} and
  73      * an {@code int} representing method type.  Used by
  74      * GenerateJLIClassesPlugin to generate such a class during the jlink phase.
  75      */
  76     byte[] generateDirectMethodHandleHolderClassBytes(String className,
  77             MethodType[] methodTypes, int[] types);
  78 
  79     /**
  80      * Returns a {@code byte[]} representation of a class implementing
  81      * DelegatingMethodHandles of each {@code MethodType} kind in the
  82      * {@code methodTypes} argument.  Used by GenerateJLIClassesPlugin to
  83      * generate such a class during the jlink phase.
  84      */
  85     byte[] generateDelegatingMethodHandleHolderClassBytes(String className,
  86             MethodType[] methodTypes);
  87 
  88     /**
  89      * Returns a {@code byte[]} representation of {@code BoundMethodHandle}
  90      * species class implementing the signature defined by {@code types}. Used
  91      * by GenerateJLIClassesPlugin to enable generation of such classes during
  92      * the jlink phase. Should do some added validation since this string may be
  93      * user provided.
  94      */
  95     Map.Entry<String, byte[]> generateConcreteBMHClassBytes(
  96             final String types);
  97 
  98     /**
  99      * Returns a {@code byte[]} representation of a class implementing
 100      * the zero and identity forms of all {@code LambdaForm.BasicType}s.
 101      */
 102     byte[] generateBasicFormsClassBytes(final String className);
 103 
 104     /**
 105      * Returns a {@code byte[]} representation of a class implementing
 106      * the invoker forms for the set of supplied {@code invokerMethodTypes}
 107      * and {@code callSiteMethodTypes}.
 108      */
 109     byte[] generateInvokersHolderClassBytes(String className,
 110             MethodType[] invokerMethodTypes,
 111             MethodType[] callSiteMethodTypes);
 112 
 113     /**
 114      * Returns a var handle view of a given memory address.
 115      * Used by {@code jdk.internal.foreign.LayoutPath} and
 116      * {@code jdk.incubator.foreign.MemoryHandles}.
 117      */
 118     VarHandle memoryAccessVarHandle(Class<?> carrier, long alignmentMask,
 119                                     ByteOrder order, long offset, long[] strides);
 120 
 121     /**
 122      * Is {@code handle} a memory access varhandle?
 123      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 124      */
 125     boolean isMemoryAccessVarHandle(VarHandle handle);
 126 
 127     /**
 128      * Returns the carrier associated with a memory access var handle.
 129      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 130      */
 131     Class<?> memoryAddressCarrier(VarHandle handle);
 132 
 133     /**
 134      * Returns the alignment mask associated with a memory access var handle.
 135      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 136      */
 137     long memoryAddressAlignmentMask(VarHandle handle);
 138 
 139     /**
 140      * Returns the byte order associated with a memory access var handle.
 141      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 142      */
 143     ByteOrder memoryAddressByteOrder(VarHandle handle);
 144 
 145     /**
 146      * Returns the offset associated with a memory access var handle.
 147      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 148      */
 149     long memoryAddressOffset(VarHandle handle);
 150 
 151     /**
 152      * Returns the strides associated with a memory access var handle.
 153      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 154      */
 155     long[] memoryAddressStrides(VarHandle handle);
 156 
 157     /**
 158      * Var handle carrier combinator.
 159      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 160      */
 161     VarHandle filterValue(VarHandle target, MethodHandle filterToTarget, MethodHandle filterFromTarget);
 162 
 163     /**
 164      * Var handle filter coordinates combinator.
 165      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 166      */
 167     VarHandle filterCoordinates(VarHandle target, int pos, MethodHandle... filters);
 168 
 169     /**
 170      * Var handle drop coordinates combinator.
 171      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 172      */
 173     VarHandle dropCoordinates(VarHandle target, int pos, Class<?>... valueTypes);
 174 
 175     /**
 176      * Var handle permute coordinates combinator.
 177      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 178      */
 179     VarHandle permuteCoordinates(VarHandle target, List<Class<?>> newCoordinates, int... reorder);
 180 
 181     /**
 182      * Var handle collect coordinates combinator.
 183      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 184      */
 185     VarHandle collectCoordinates(VarHandle target, int pos, MethodHandle filter);
 186 
 187     /**
 188      * Var handle insert coordinates combinator.
 189      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 190      */
 191     VarHandle insertCoordinates(VarHandle target, int pos, Object... values);
 192 }