1 /* 2 * Copyright (c) 2013, 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 import java.io.File; 24 import java.nio.charset.Charset; 25 import java.nio.file.Files; 26 import java.util.ArrayList; 27 import java.util.List; 28 import static java.nio.file.StandardOpenOption.*; 29 30 /* 31 * @test 32 * @bug 8003549 8007297 33 * @summary tests class files instruction formats introduced in JSR-335 34 * @compile -XDignore.symbol.file Utils.java InstructionTests.java 35 * @run main InstructionTests 36 * @author ksrini 37 */ 38 public class InstructionTests { 39 public static void main(String... args) throws Exception { 40 testInvokeOpCodes(); 41 } 42 /* 43 * the following should produce invokestatic and invokespecial 44 * on InterfaceMethodRefs vs. MethodRefs, packer/unpacker should work 45 */ 46 static void testInvokeOpCodes() throws Exception { 47 List<String> scratch = new ArrayList<>(); 48 final String fname = "A"; 49 String javaFileName = fname + Utils.JAVA_FILE_EXT; 50 scratch.add("interface I {"); 51 scratch.add(" default void forEach(){}"); 52 scratch.add(" static void next() {}"); 53 scratch.add("}"); 54 scratch.add("class A implements I {"); 55 scratch.add(" public void forEach(Object o){"); 56 scratch.add(" I.super.forEach();"); 57 scratch.add(" I.next();"); 58 scratch.add(" }"); 59 scratch.add("}"); 60 File cwd = new File("."); 61 File javaFile = new File(cwd, javaFileName); 62 Files.write(javaFile.toPath(), scratch, Charset.defaultCharset(), 63 CREATE, TRUNCATE_EXISTING); 64 65 // -g to compare LVT and LNT entries 66 Utils.compiler("-g", javaFile.getName()); 67 68 File propsFile = new File("pack.props"); 69 scratch.clear(); 70 scratch.add("com.sun.java.util.jar.pack.class.format.error=error"); 71 scratch.add("pack.unknown.attribute=error"); 72 Files.write(propsFile.toPath(), scratch, Charset.defaultCharset(), 73 CREATE, TRUNCATE_EXISTING); 74 // jar the file up 75 File testjarFile = new File(cwd, "test" + Utils.JAR_FILE_EXT); 76 Utils.jar("cvf", testjarFile.getName(), "."); 77 78 Utils.testWithRepack(testjarFile, "--config-file=" + propsFile.getName()); 79 } 80 }