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 {@code Map<String, byte[]>} represent holder class vs class bytes
 115      * @param lines input as TRACE_LF_RESOLVE
 116      */
 117     Map<String, byte[]> generateMethodHandleHolderClasses(String... lines);
 118     /**
 119      * Returns a var handle view of a given memory address.
 120      * Used by {@code jdk.internal.foreign.LayoutPath} and
 121      * {@code jdk.incubator.foreign.MemoryHandles}.
 122      */
 123     VarHandle memoryAccessVarHandle(Class<?> carrier, long alignmentMask,
 124                                     ByteOrder order, long offset, long[] strides);
 125 
 126     /**
 127      * Is {@code handle} a memory access varhandle?
 128      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 129      */
 130     boolean isMemoryAccessVarHandle(VarHandle handle);
 131 
 132     /**
 133      * Returns the carrier associated with a memory access var handle.
 134      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 135      */
 136     Class<?> memoryAddressCarrier(VarHandle handle);
 137 
 138     /**
 139      * Returns the alignment mask associated with a memory access var handle.
 140      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 141      */
 142     long memoryAddressAlignmentMask(VarHandle handle);
 143 
 144     /**
 145      * Returns the byte order associated with a memory access var handle.
 146      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 147      */
 148     ByteOrder memoryAddressByteOrder(VarHandle handle);
 149 
 150     /**
 151      * Returns the offset associated with a memory access var handle.
 152      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 153      */
 154     long memoryAddressOffset(VarHandle handle);
 155 
 156     /**
 157      * Returns the strides associated with a memory access var handle.
 158      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 159      */
 160     long[] memoryAddressStrides(VarHandle handle);
 161 
 162     /**
 163      * Var handle carrier combinator.
 164      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 165      */
 166     VarHandle filterValue(VarHandle target, MethodHandle filterToTarget, MethodHandle filterFromTarget);
 167 
 168     /**
 169      * Var handle filter coordinates combinator.
 170      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 171      */
 172     VarHandle filterCoordinates(VarHandle target, int pos, MethodHandle... filters);
 173 
 174     /**
 175      * Var handle drop coordinates combinator.
 176      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 177      */
 178     VarHandle dropCoordinates(VarHandle target, int pos, Class<?>... valueTypes);
 179 
 180     /**
 181      * Var handle permute coordinates combinator.
 182      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 183      */
 184     VarHandle permuteCoordinates(VarHandle target, List<Class<?>> newCoordinates, int... reorder);
 185 
 186     /**
 187      * Var handle collect coordinates combinator.
 188      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 189      */
 190     VarHandle collectCoordinates(VarHandle target, int pos, MethodHandle filter);
 191 
 192     /**
 193      * Var handle insert coordinates combinator.
 194      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 195      */
 196     VarHandle insertCoordinates(VarHandle target, int pos, Object... values);
 197 }