Path: blob/master/src/java.base/share/classes/jdk/internal/invoke/NativeEntryPoint.java
41159 views
/*1* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package jdk.internal.invoke;2627import java.lang.invoke.MethodType;28import java.util.Objects;2930/**31* This class describes a native call, including arguments/return shuffle moves, PC entry point and32* various other info which are relevant when the call will be intrinsified by C2.33*/34public class NativeEntryPoint {35static {36registerNatives();37}3839private final int shadowSpace;4041// encoded as VMRegImpl*42private final long[] argMoves;43private final long[] returnMoves;4445private final boolean needTransition;46private final MethodType methodType; // C2 sees erased version (byte -> int), so need this explicitly47private final String name;4849private NativeEntryPoint(int shadowSpace, long[] argMoves, long[] returnMoves,50boolean needTransition, MethodType methodType, String name) {51this.shadowSpace = shadowSpace;52this.argMoves = Objects.requireNonNull(argMoves);53this.returnMoves = Objects.requireNonNull(returnMoves);54this.needTransition = needTransition;55this.methodType = methodType;56this.name = name;57}5859public static NativeEntryPoint make(String name, ABIDescriptorProxy abi,60VMStorageProxy[] argMoves, VMStorageProxy[] returnMoves,61boolean needTransition, MethodType methodType) {62if (returnMoves.length > 1) {63throw new IllegalArgumentException("Multiple register return not supported");64}6566return new NativeEntryPoint(abi.shadowSpaceBytes(), encodeVMStorages(argMoves), encodeVMStorages(returnMoves),67needTransition, methodType, name);68}6970private static long[] encodeVMStorages(VMStorageProxy[] moves) {71long[] out = new long[moves.length];72for (int i = 0; i < moves.length; i++) {73out[i] = vmStorageToVMReg(moves[i].type(), moves[i].index());74}75return out;76}7778private static native long vmStorageToVMReg(int type, int index);7980public MethodType type() {81return methodType;82}8384private static native void registerNatives();85}868788