jdk/test/tools/pack200/InstructionTests.java
author neliasso
Thu, 04 Apr 2013 09:18:47 +0200
changeset 16626 b58a6213631c
parent 16050 1eee624cddb3
child 17490 46864558d068
permissions -rw-r--r--
8006008: Memory leak in hotspot/src/share/vm/adlc/archDesc.cpp Reviewed-by: roland, kvn Contributed-by: niclas.adlertz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15526
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
     1
/*
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
     4
 *
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
     8
 *
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    13
 * accompanied this code).
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    14
 *
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    18
 *
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    21
 * questions.
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    22
 */
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    23
import java.io.File;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    24
import java.nio.charset.Charset;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    25
import java.nio.file.Files;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    26
import java.util.ArrayList;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    27
import java.util.List;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    28
import static java.nio.file.StandardOpenOption.*;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    29
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    30
/*
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    31
 * @test
16050
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
    32
 * @bug 8003549 8007297
15526
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    33
 * @summary tests class files instruction formats introduced in JSR-335
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    34
 * @compile -XDignore.symbol.file Utils.java InstructionTests.java
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    35
 * @run main InstructionTests
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    36
 * @author ksrini
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    37
 */
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    38
public class InstructionTests {
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    39
    public static void main(String... args) throws Exception {
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    40
        testInvokeOpCodes();
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    41
    }
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    42
    /*
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    43
     * the following should produce invokestatic and invokespecial
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    44
     * on InterfaceMethodRefs vs. MethodRefs, packer/unpacker should work
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    45
     */
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    46
    static void testInvokeOpCodes() throws Exception {
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    47
        List<String> scratch = new ArrayList<>();
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    48
        final String fname = "A";
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    49
        String javaFileName = fname + Utils.JAVA_FILE_EXT;
16050
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
    50
        scratch.add("interface I {");
15526
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    51
        scratch.add("    default void forEach(){}");
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    52
        scratch.add("    static void next() {}");
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    53
        scratch.add("}");
16050
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
    54
        scratch.add("class A implements I {");
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
    55
        scratch.add("    public void forEach(Object o){");
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
    56
        scratch.add("        I.super.forEach();");
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
    57
        scratch.add("        I.next();");
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
    58
        scratch.add("    }");
15526
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    59
        scratch.add("}");
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    60
        File cwd = new File(".");
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    61
        File javaFile = new File(cwd, javaFileName);
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    62
        Files.write(javaFile.toPath(), scratch, Charset.defaultCharset(),
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    63
                CREATE, TRUNCATE_EXISTING);
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    64
16050
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
    65
        // -g to compare LVT and LNT entries
15526
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    66
        Utils.compiler("-g", javaFile.getName());
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    67
16050
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
    68
        File propsFile = new File("pack.props");
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
    69
        scratch.clear();
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
    70
        scratch.add("com.sun.java.util.jar.pack.class.format.error=error");
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
    71
        scratch.add("pack.unknown.attribute=error");
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
    72
        Files.write(propsFile.toPath(), scratch, Charset.defaultCharset(),
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
    73
                CREATE, TRUNCATE_EXISTING);
15526
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    74
        // jar the file up
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    75
        File testjarFile = new File(cwd, "test" + Utils.JAR_FILE_EXT);
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    76
        Utils.jar("cvf", testjarFile.getName(), ".");
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    77
16050
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
    78
        Utils.testWithRepack(testjarFile, "--config-file=" + propsFile.getName());
15526
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    79
    }
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents:
diff changeset
    80
}