1 /* 2 * Copyright (c) 2019, 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 /* 26 * @test 27 * @bug 8224137 28 * @summary Run invokeinterface invocation tests 29 * @library /test/lib 30 * @modules java.base/jdk.internal.org.objectweb.asm 31 * java.base/jdk.internal.misc 32 * @compile shared/AbstractGenerator.java shared/AccessCheck.java shared/AccessType.java 33 * shared/Caller.java shared/ExecutorGenerator.java shared/Utils.java 34 * shared/ByteArrayClassLoader.java shared/Checker.java shared/GenericClassGenerator.java 35 * @compile invokeinterface/Checker.java invokeinterface/ClassGenerator.java 36 * invokeinterface/Generator.java 37 * 38 * @run main/othervm/timeout=1800 invokeinterfaceTests 39 */ 40 41 import jdk.test.lib.process.ProcessTools; 42 import jdk.test.lib.process.OutputAnalyzer; 43 import jdk.test.lib.compiler.InMemoryJavaCompiler; 44 45 public class invokeinterfaceTests { 46 47 public static void runTest(String classFileVersion, String option) throws Exception { 48 System.out.println("\ninvokeinterface invocation tests, option: " + option + 49 ", class file version: " + classFileVersion); 50 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(false, "-Xmx128M", option, 51 "--add-exports", "java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED", 52 "invokeinterface.Generator", "--classfile_version=" + classFileVersion); 53 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 54 try { 55 output.shouldContain("EXECUTION STATUS: PASSED"); 56 output.shouldHaveExitValue(0); 57 } catch (Throwable e) { 58 System.out.println( 59 "\nNote that an entry such as 'B.m/C.m' in the failure chart means that" + 60 " the test case failed because method B.m was invoked but the test " + 61 "expected method C.m to be invoked. Similarly, a result such as 'AME/C.m'" + 62 " means that an AbstractMethodError exception was thrown but the test" + 63 " case expected method C.m to be invoked."); 64 System.out.println( 65 "\nAlso note that passing --dump to invokeinterface.Generator will" + 66 " dump the generated classes (for debugging purposes).\n"); 67 68 System.exit(1); 69 } 70 } 71 72 public static void main(String args[]) throws Throwable { 73 // Get current major class file version and test with it. 74 byte klassbuf[] = InMemoryJavaCompiler.compile("blah", "public class blah { }"); 75 int major_version = klassbuf[6] << 8 | klassbuf[7]; 76 runTest(String.valueOf(major_version), "-Xint"); 77 runTest(String.valueOf(major_version), "-Xcomp"); 78 79 // Test old class file version. 80 runTest("51", "-Xint"); // JDK-7 81 } 82 }