1 /*
  2  * Copyright (c) 2015, 2020, 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 jdk.internal.invoke.NativeEntryPoint;
 29 
 30 import java.lang.invoke.MethodHandle;
 31 import java.lang.invoke.MethodType;
 32 import java.lang.invoke.VarHandle;
 33 import java.nio.ByteOrder;
 34 import java.util.List;
 35 import java.util.Map;
 36 import java.util.stream.Stream;
 37 
 38 public interface JavaLangInvokeAccess {
 39     /**
 40      * Create a new MemberName instance. Used by {@code StackFrameInfo}.
 41      */
 42     Object newMemberName();
 43 
 44     /**
 45      * Returns the name for the given MemberName. Used by {@code StackFrameInfo}.
 46      */
 47     String getName(Object mname);
 48 
 49     /**
 50      * Returns the {@code MethodType} for the given MemberName.
 51      * Used by {@code StackFrameInfo}.
 52      */
 53     MethodType getMethodType(Object mname);
 54 
 55     /**
 56      * Returns the descriptor for the given MemberName.
 57      * Used by {@code StackFrameInfo}.
 58      */
 59     String getMethodDescriptor(Object mname);
 60 
 61     /**
 62      * Returns {@code true} if the given MemberName is a native method.
 63      * Used by {@code StackFrameInfo}.
 64      */
 65     boolean isNative(Object mname);
 66 
 67     /**
 68      * Returns the declaring class for the given MemberName.
 69      * Used by {@code StackFrameInfo}.
 70      */
 71     Class<?> getDeclaringClass(Object mname);
 72 
 73     /**
 74      * Returns a map of class name in internal forms to its corresponding
 75      * class bytes per the given stream of LF_RESOLVE and SPECIES_RESOLVE
 76      * trace logs. Used by GenerateJLIClassesPlugin to enable generation
 77      * of such classes during the jlink phase.
 78      */
 79     Map<String, byte[]> generateHolderClasses(Stream<String> traces);
 80 
 81     /**
 82      * Returns a var handle view of a given memory address.
 83      * Used by {@code jdk.internal.foreign.LayoutPath} and
 84      * {@code jdk.incubator.foreign.MemoryHandles}.
 85      */
 86     VarHandle memoryAccessVarHandle(Class<?> carrier, boolean skipAlignmentMaskCheck, long alignmentMask,
 87                                     ByteOrder order);
 88 
 89     /**
 90      * Var handle carrier combinator.
 91      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 92      */
 93     VarHandle filterValue(VarHandle target, MethodHandle filterToTarget, MethodHandle filterFromTarget);
 94 
 95     /**
 96      * Var handle filter coordinates combinator.
 97      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
 98      */
 99     VarHandle filterCoordinates(VarHandle target, int pos, MethodHandle... filters);
100 
101     /**
102      * Var handle drop coordinates combinator.
103      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
104      */
105     VarHandle dropCoordinates(VarHandle target, int pos, Class<?>... valueTypes);
106 
107     /**
108      * Var handle permute coordinates combinator.
109      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
110      */
111     VarHandle permuteCoordinates(VarHandle target, List<Class<?>> newCoordinates, int... reorder);
112 
113     /**
114      * Var handle collect coordinates combinator.
115      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
116      */
117     VarHandle collectCoordinates(VarHandle target, int pos, MethodHandle filter);
118 
119     /**
120      * Var handle insert coordinates combinator.
121      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
122      */
123     VarHandle insertCoordinates(VarHandle target, int pos, Object... values);
124 
125     /**
126      * Returns a native method handle with given arguments as fallback and steering info.
127      *
128      * Will allow JIT to intrinsify.
129      *
130      * @param nep the native entry point
131      * @param fallback the fallback handle
132      * @return the native method handle
133      */
134     MethodHandle nativeMethodHandle(NativeEntryPoint nep, MethodHandle fallback);
135 
136     /**
137      * Ensure given method handle is customized
138      *
139      * @param mh the method handle
140      */
141     void ensureCustomized(MethodHandle mh);
142 }