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