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