1 /*
  2  * Copyright (c) 2015, 2021, 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.MethodHandles.Lookup;
 32 import java.lang.invoke.MethodType;
 33 import java.lang.invoke.VarHandle;
 34 import java.lang.reflect.Constructor;
 35 import java.lang.reflect.Method;
 36 import java.lang.reflect.Field;
 37 import java.nio.ByteOrder;
 38 import java.util.List;
 39 import java.util.Map;
 40 import java.util.stream.Stream;
 41 
 42 public interface JavaLangInvokeAccess {
 43     /**
 44      * Create a new MemberName instance. Used by {@code StackFrameInfo}.
 45      */
 46     Object newMemberName();
 47 
 48     /**
 49      * Create a new MemberName instance. Used by {@code StackFrameInfo}.
 50      */
 51     Object newMemberName(Method method);
 52 
 53     /**
 54      * Returns the name for the given MemberName. Used by {@code StackFrameInfo}.
 55      */
 56     String getName(Object mname);
 57 
 58     /**
 59      * Returns the {@code MethodType} for the given MemberName.
 60      * Used by {@code StackFrameInfo}.
 61      */
 62     MethodType getMethodType(Object mname);
 63 
 64     /**
 65      * Returns the descriptor for the given MemberName.
 66      * Used by {@code StackFrameInfo}.
 67      */
 68     String getMethodDescriptor(Object mname);
 69 
 70     /**
 71      * Returns {@code true} if the given MemberName is a native method.
 72      * Used by {@code StackFrameInfo}.
 73      */
 74     boolean isNative(Object mname);
 75 
 76     /**
 77      * Returns the declaring class for the given MemberName.
 78      * Used by {@code StackFrameInfo}.
 79      */
 80     Class<?> getDeclaringClass(Object mname);
 81 
 82     /**
 83      * Returns a map of class name in internal forms to its corresponding
 84      * class bytes per the given stream of LF_RESOLVE and SPECIES_RESOLVE
 85      * trace logs. Used by GenerateJLIClassesPlugin to enable generation
 86      * of such classes during the jlink phase.
 87      */
 88     Map<String, byte[]> generateHolderClasses(Stream<String> traces);
 89 
 90     /**
 91      * Returns a var handle view of a given memory address.
 92      * Used by {@code jdk.internal.foreign.LayoutPath} and
 93      * {@code jdk.incubator.foreign.MemoryHandles}.
 94      */
 95     VarHandle memoryAccessVarHandle(Class<?> carrier, boolean skipAlignmentMaskCheck, long alignmentMask,
 96                                     ByteOrder order);
 97 
 98     /**
 99      * Var handle carrier combinator.
100      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
101      */
102     VarHandle filterValue(VarHandle target, MethodHandle filterToTarget, MethodHandle filterFromTarget);
103 
104     /**
105      * Var handle filter coordinates combinator.
106      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
107      */
108     VarHandle filterCoordinates(VarHandle target, int pos, MethodHandle... filters);
109 
110     /**
111      * Var handle drop coordinates combinator.
112      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
113      */
114     VarHandle dropCoordinates(VarHandle target, int pos, Class<?>... valueTypes);
115 
116     /**
117      * Var handle permute coordinates combinator.
118      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
119      */
120     VarHandle permuteCoordinates(VarHandle target, List<Class<?>> newCoordinates, int... reorder);
121 
122     /**
123      * Var handle collect coordinates combinator.
124      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
125      */
126     VarHandle collectCoordinates(VarHandle target, int pos, MethodHandle filter);
127 
128     /**
129      * Var handle insert coordinates combinator.
130      * Used by {@code jdk.incubator.foreign.MemoryHandles}.
131      */
132     VarHandle insertCoordinates(VarHandle target, int pos, Object... values);
133 
134     /**
135      * Returns a native method handle with given arguments as fallback and steering info.
136      *
137      * Will allow JIT to intrinsify.
138      *
139      * @param nep the native entry point
140      * @param fallback the fallback handle
141      * @return the native method handle
142      */
143     MethodHandle nativeMethodHandle(NativeEntryPoint nep, MethodHandle fallback);
144 
145     /**
146      * Ensure given method handle is customized
147      *
148      * @param mh the method handle
149      */
150     void ensureCustomized(MethodHandle mh);
151 
152     /**
153      * Produces a method handle unreflecting from a {@code Constructor} with
154      * the trusted lookup
155      */
156     MethodHandle unreflectConstructor(Constructor<?> ctor) throws IllegalAccessException;
157 
158     /**
159      * Produces a method handle unreflecting from a {@code Field} with
160      * the trusted lookup
161      */
162     MethodHandle unreflectField(Field field, boolean isSetter) throws IllegalAccessException;
163 
164     /**
165      * Produces a method handle of a virtual method with the trusted lookup.
166      */
167     MethodHandle findVirtual(Class<?> defc, String name, MethodType type) throws IllegalAccessException;
168 
169     /**
170      * Produces a method handle of a static method with the trusted lookup.
171      */
172     MethodHandle findStatic(Class<?> defc, String name, MethodType type) throws IllegalAccessException;
173 
174     /**
175      * Returns a method handle of an invoker class injected for core reflection
176      * implementation with the following signature:
177      *     reflect_invoke_V(MethodHandle mh, Object target, Object[] args)
178      *
179      * The invoker class is a hidden class which has the same
180      * defining class loader, runtime package, and protection domain
181      * as the given caller class.
182      */
183     MethodHandle reflectiveInvoker(Class<?> caller);
184 
185     /**
186      * Defines a hidden class of the given name and bytes with class data.
187      * The given bytes is trusted.
188      */
189     Lookup defineHiddenClassWithClassData(Lookup caller, String name, byte[] bytes, Object classData, boolean initialize);
190 }
--- EOF ---