Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/share/Arguments.java
41162 views
/*1* Copyright (c) 2011, 2018, 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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package vm.mlvm.meth.share;2425import java.lang.invoke.MethodType;26import java.util.ArrayList;27import java.util.Arrays;28import java.util.List;2930public final class Arguments {3132public static List<Argument> listFromArray(Object[][] a) {33ArrayList<Argument> result = new ArrayList<Argument>(a.length);3435for (Object[] elem : a) {36result.add(Argument.fromArray(elem));37}3839return result;40}4142public static Argument[] fromArray(Object[][] a) {43return listFromArray(a).toArray(new Argument[a.length]);44}4546public static Class<?>[] typesArray(List<Argument> vts) {47return typesArray(vts.toArray(new Argument[vts.size()]));48}4950public static Class<?>[] typesArray(Argument[] vts) {51Class<?>[] result = new Class<?>[vts.length];52for (int i = 0; i < vts.length; i++)53result[i] = vts[i].getType();54return result;55}5657public static Object[] valuesArray(List<Argument> vts) {58return valuesArray(vts.toArray(new Argument[vts.size()]));59}6061public static Object[] valuesArray(Argument[] vts) {62Object[] result = new Object[vts.length];63for (int i = 0; i < vts.length; i++)64result[i] = vts[i].getValue();65return result;66}6768public static Argument[] fromMethodType(boolean isVirtual, MethodType t, MethodParameterValueProvider vp) {69int virtualOffset = isVirtual ? 1 : 0;70Class<?>[] paramTypes = t.parameterArray();71Argument[] result = new Argument[paramTypes.length - virtualOffset];72for (int i = virtualOffset; i < paramTypes.length; i++) {73result[i - virtualOffset] = new Argument(paramTypes[i], vp.getValue(t, i));74}75return result;76}7778public static int[] findTag(List<Argument> args, String tag) {79return findTag(args.toArray(new Argument[args.size()]), tag);80}8182public static int[] findTag(Argument[] args, String tag) {83int[] result = new int[args.length];84int resCount = 0;85for ( int i = 0; i < args.length; i++ ) {86if ( args[i].getTag().equals(tag) )87result[resCount++] = i;88}8990return Arrays.copyOf(result, resCount);91}9293}949596