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.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.Field;
 36 import java.nio.ByteOrder;
 37 import java.util.List;
 38 import java.util.Map;
 39 import java.util.stream.Stream;
 40 
 41 public interface JavaLangInvokeAccess {
 42     /**
 43      * Create a new MemberName instance. Used by {@code StackFrameInfo}.
 44      */
 45     Object newMemberName();
 46 





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