Path: blob/master/test/hotspot/jtreg/runtime/InvocationTests/invokevirtualTests.java
64474 views
/*1* Copyright (c) 2019, 2020, 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*22*/2324/*25* @test id=current-int26* @bug 822413727* @summary Run invokevirtual invocation tests28* @library /test/lib29* @modules java.base/jdk.internal.org.objectweb.asm30* java.base/jdk.internal.misc31* @compile invokevirtual/Checker.java invokevirtual/ClassGenerator.java invokevirtual/Generator.java32*33* @run driver/timeout=1800 invokevirtualTests current-int34*/3536/*37* @test id=current-comp38* @bug 822413739* @summary Run invokevirtual invocation tests40* @requires vm.flagless41* @library /test/lib42* @modules java.base/jdk.internal.org.objectweb.asm43* java.base/jdk.internal.misc44* @compile invokevirtual/Checker.java invokevirtual/ClassGenerator.java invokevirtual/Generator.java45*46* @run driver/timeout=1800 invokevirtualTests current-comp47*/4849/*50* @test id=old-int51* @bug 822413752* @summary Run invokevirtual invocation tests53* @requires vm.flagless54* @library /test/lib55* @modules java.base/jdk.internal.org.objectweb.asm56* java.base/jdk.internal.misc57* @compile invokevirtual/Checker.java invokevirtual/ClassGenerator.java invokevirtual/Generator.java58*59* @run driver/timeout=1800 invokevirtualTests old-int60*/6162import jdk.test.lib.process.ProcessTools;63import jdk.test.lib.process.OutputAnalyzer;64import jdk.test.lib.compiler.InMemoryJavaCompiler;6566public class invokevirtualTests {6768public static void runTest(String classFileVersion, String option) throws Throwable {69System.out.println("\ninvokevirtual invocation tests, option: " + option +70", class file version: " + classFileVersion);71ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xmx128M", option,72"--add-exports", "java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED",73"invokevirtual.Generator", "--classfile_version=" + classFileVersion);74OutputAnalyzer output = new OutputAnalyzer(pb.start());75try {76output.shouldContain("EXECUTION STATUS: PASSED");77output.shouldHaveExitValue(0);78} catch (Throwable e) {79System.out.println(80"\nNote that an entry such as 'B.m/C.m' in the failure chart means that" +81" the test case failed because method B.m was invoked but the test " +82"expected method C.m to be invoked. Similarly, a result such as 'AME/C.m'" +83" means that an AbstractMethodError exception was thrown but the test" +84" case expected method C.m to be invoked.");85System.out.println(86"\nAlso note that passing --dump to invokevirtual.Generator will" +87" dump the generated classes (for debugging purposes).\n");8889throw e;90}91}9293public static void main(String args[]) throws Throwable {94if (args.length < 1) {95throw new IllegalArgumentException("Should provide the test name");96}97String testName = args[0];9899// Get current major class file version and test with it.100byte klassbuf[] = InMemoryJavaCompiler.compile("blah", "public class blah { }");101int major_version = klassbuf[6] << 8 | klassbuf[7];102103switch (testName) {104case "current-int":105runTest(String.valueOf(major_version), "-Xint");106break;107case "current-comp":108runTest(String.valueOf(major_version), "-Xcomp");109break;110case "old-int":111// Test old class file version.112runTest("51", "-Xint"); // JDK-7113break;114default:115throw new IllegalArgumentException("Unknown test name: " + testName);116}117}118}119120121