Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/ExecuteInstalledCodeTest.java
41153 views
/*1* Copyright (c) 2015, 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.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*/2223/*24* @test25* @bug 813642126* @requires vm.jvmci27* @library /test/lib /28* @library ../common/patches29* @ignore 824962130* @modules java.base/jdk.internal.misc31* @modules java.base/jdk.internal.org.objectweb.asm32* java.base/jdk.internal.org.objectweb.asm.tree33* jdk.internal.vm.ci/jdk.vm.ci.hotspot34* jdk.internal.vm.ci/jdk.vm.ci.code35* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox36* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox37* @run main/othervm -Xbootclasspath/a:.38* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI39* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI40* -XX:-BackgroundCompilation41* compiler.jvmci.compilerToVM.ExecuteInstalledCodeTest42*/4344package compiler.jvmci.compilerToVM;4546import jdk.test.lib.Asserts;47import jdk.test.lib.util.Pair;48import jdk.test.lib.Utils;49import jdk.vm.ci.code.InstalledCode;50import jdk.vm.ci.code.InvalidInstalledCodeException;51import jdk.vm.ci.hotspot.CompilerToVMHelper;52import sun.hotspot.code.NMethod;5354import java.lang.reflect.Constructor;55import java.lang.reflect.Modifier;56import java.util.ArrayList;57import java.util.List;5859public class ExecuteInstalledCodeTest {6061public static void main(String[] args) {62ExecuteInstalledCodeTest test = new ExecuteInstalledCodeTest();63List<CompileCodeTestCase> testCases = new ArrayList<>();64testCases.addAll(CompileCodeTestCase.generate(/* bci = */ -1));65testCases .stream()66// ignore <init> of abstract class -- 813879367.filter(e -> !(e.executable instanceof Constructor68&& Modifier.isAbstract(69e.executable.getDeclaringClass()70.getModifiers())))71.forEach(test::checkSanity);72}7374private void checkSanity(CompileCodeTestCase testCase) {75System.out.println(testCase);76// to have a clean state77testCase.deoptimize();78Pair<Object, ? extends Throwable> reflectionResult;79Object[] args = Utils.getNullValues(80testCase.executable.getParameterTypes());81reflectionResult = testCase.invoke(args);82NMethod nMethod = testCase.compile();83if (nMethod == null) {84throw new Error(testCase + " : nmethod is null");85}86InstalledCode installedCode = testCase.toInstalledCode();87Object result = null;88Throwable expectedException = reflectionResult.second;89boolean gotException = true;90try {91args = addReceiver(testCase, args);92result = CompilerToVMHelper.executeInstalledCode(93args, installedCode);94if (testCase.executable instanceof Constructor) {95// <init> doesn't have return value, it changes receiver96result = args[0];97}98gotException = false;99} catch (InvalidInstalledCodeException e) {100throw new AssertionError(101testCase + " : unexpected InvalidInstalledCodeException", e);102} catch (Throwable t) {103if (expectedException == null) {104throw new AssertionError(testCase105+ " : got unexpected execption : " + t.getMessage(), t);106}107108if (expectedException.getClass() != t.getClass()) {109System.err.println("exception from CompilerToVM:");110t.printStackTrace();111System.err.println("exception from reflection:");112expectedException.printStackTrace();113throw new AssertionError(String.format(114"%s : got unexpected different exceptions : %s != %s",115testCase, expectedException.getClass(), t.getClass()));116}117}118119Asserts.assertEQ(reflectionResult.first, result, testCase120+ " : different return value");121if (!gotException) {122Asserts.assertNull(expectedException, testCase123+ " : expected exception hasn't been thrown");124}125}126127private Object[] addReceiver(CompileCodeTestCase testCase, Object[] args) {128if (!Modifier.isStatic(testCase.executable.getModifiers())) {129// add instance as 0th arg130Object[] newArgs = new Object[args.length + 1];131newArgs[0] = testCase.receiver;132System.arraycopy(args, 0, newArgs, 1, args.length);133args = newArgs;134}135return args;136}137}138139140