jdk/test/java/lang/invoke/lambda/LambdaAsm.java
author shurailine
Tue, 27 Oct 2015 20:06:02 -0700
changeset 33402 1156d495a525
parent 30820 0d4717a011d3
child 35315 67dcc46f8241
permissions -rw-r--r--
8140336: Add @modules for exported dependencies to jdk_core tests Reviewed-by: alanb, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21618
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
     1
/*
33402
1156d495a525 8140336: Add @modules for exported dependencies to jdk_core tests
shurailine
parents: 30820
diff changeset
     2
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
21618
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
     4
 *
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
     8
 *
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    13
 * accompanied this code).
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    14
 *
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    18
 *
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    21
 * questions.
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    22
 */
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    23
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    24
/*
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    25
 * @test
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    26
 * @bug 8027232
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    27
 * @summary ensures that j.l.i.InvokerByteCodeGenerator and ASM visitMethodInsn
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    28
 * generate  bytecodes with correct constant pool references
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 21618
diff changeset
    29
 * @modules java.base/jdk.internal.org.objectweb.asm
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 21618
diff changeset
    30
 *          jdk.compiler/com.sun.tools.classfile
21618
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    31
 * @compile -XDignore.symbol.file LambdaAsm.java LUtils.java
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    32
 * @run main/othervm LambdaAsm
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    33
 */
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    34
import com.sun.tools.classfile.Attribute;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    35
import com.sun.tools.classfile.ClassFile;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    36
import com.sun.tools.classfile.Code_attribute;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    37
import com.sun.tools.classfile.ConstantPool;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    38
import com.sun.tools.classfile.ConstantPool.CPInfo;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    39
import com.sun.tools.classfile.Instruction;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    40
import com.sun.tools.classfile.Method;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    41
import java.io.ByteArrayInputStream;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    42
import java.io.File;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    43
import java.util.ArrayList;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    44
import java.nio.file.DirectoryStream;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    45
import java.nio.file.Path;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    46
import jdk.internal.org.objectweb.asm.ClassWriter;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    47
import jdk.internal.org.objectweb.asm.MethodVisitor;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    48
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    49
import static java.nio.file.Files.*;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    50
import static jdk.internal.org.objectweb.asm.Opcodes.*;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    51
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    52
public class LambdaAsm {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    53
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    54
    static final File TestFile = new File("A.java");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    55
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    56
    static void init() {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    57
        emitCode();
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    58
        LUtils.compile(TestFile.getName());
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    59
        LUtils.TestResult tr = LUtils.doExec(LUtils.JAVA_CMD.getAbsolutePath(),
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    60
                "-Djdk.internal.lambda.dumpProxyClasses=.",
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    61
                "-cp", ".", "A");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    62
        if (tr.exitValue != 0) {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    63
            System.out.println("Error: " + tr.toString());
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    64
            throw new RuntimeException("could not create proxy classes");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    65
        }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    66
    }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    67
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    68
    static void emitCode() {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    69
        ArrayList<String> scratch = new ArrayList<>();
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    70
        scratch.add("import java.util.function.*;");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    71
        scratch.add("class A {");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    72
        scratch.add("   interface I {");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    73
        scratch.add("       default Supplier<Integer> a() { return () -> 1; }");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    74
        scratch.add("       default Supplier<Integer> b(int i) { return () -> i; }");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    75
        scratch.add("       default Supplier<Integer> c(int i) { return () -> m(i); }");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    76
        scratch.add("       int m(int i);");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    77
        scratch.add("       static Integer d() { return 0; }");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    78
        scratch.add("   }");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    79
        scratch.add("   static class C implements I {");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    80
        scratch.add("       public int m(int i) { return i;}");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    81
        scratch.add("   }");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    82
        scratch.add("   public static void main(String[] args) {");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    83
        scratch.add("       I i = new C();");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    84
        scratch.add("       i.a();");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    85
        scratch.add("       i.b(1);");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    86
        scratch.add("       i.c(1);");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    87
        scratch.add("       I.d();");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    88
        scratch.add("   }");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    89
        scratch.add("}");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    90
        LUtils.createFile(TestFile, scratch);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    91
    }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    92
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    93
    static void checkMethod(String cname, String mname, ConstantPool cp,
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    94
            Code_attribute code) throws ConstantPool.InvalidIndex {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    95
        for (Instruction i : code.getInstructions()) {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    96
            String iname = i.getMnemonic();
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    97
            if ("invokespecial".equals(iname)
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    98
                    || "invokestatic".equals(iname)) {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
    99
                int idx = i.getByte(2);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   100
                System.out.println("Verifying " + cname + ":" + mname +
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   101
                        " instruction:" + iname + " index @" + idx);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   102
                CPInfo cpinfo = cp.get(idx);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   103
                if (cpinfo instanceof ConstantPool.CONSTANT_Methodref_info) {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   104
                    throw new RuntimeException("unexpected CP type expected "
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   105
                            + "InterfaceMethodRef, got MethodRef, " + cname
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   106
                            + ", " + mname);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   107
                }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   108
            }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   109
        }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   110
    }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   111
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   112
    static int checkMethod(ClassFile cf, String mthd) throws Exception {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   113
        if (cf.major_version < 52) {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   114
            throw new RuntimeException("unexpected class file version, in "
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   115
                    + cf.getName() + "expected 52, got " + cf.major_version);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   116
        }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   117
        int count = 0;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   118
        for (Method m : cf.methods) {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   119
            String mname = m.getName(cf.constant_pool);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   120
            if (mname.equals(mthd)) {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   121
                for (Attribute a : m.attributes) {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   122
                    if ("Code".equals(a.getName(cf.constant_pool))) {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   123
                        count++;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   124
                        checkMethod(cf.getName(), mname, cf.constant_pool,
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   125
                                (Code_attribute) a);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   126
                    }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   127
                }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   128
            }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   129
        }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   130
        return count;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   131
    }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   132
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   133
    static void verifyInvokerBytecodeGenerator() throws Exception {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   134
        int count = 0;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   135
        int mcount = 0;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   136
        try (DirectoryStream<Path> ds = newDirectoryStream(new File(".").toPath(),
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   137
                // filter in lambda proxy classes
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 21618
diff changeset
   138
                "A$I$$Lambda$*.class")) {
21618
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   139
            for (Path p : ds) {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   140
                System.out.println(p.toFile());
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   141
                ClassFile cf = ClassFile.read(p.toFile());
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   142
                // Check those methods implementing Supplier.get
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   143
                mcount += checkMethod(cf, "get");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   144
                count++;
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   145
            }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   146
        }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   147
        if (count < 3) {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   148
            throw new RuntimeException("unexpected number of files, "
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   149
                    + "expected atleast 3 files, but got only " + count);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   150
        }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   151
        if (mcount < 3) {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   152
            throw new RuntimeException("unexpected number of methods, "
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   153
                    + "expected atleast 3 methods, but got only " + mcount);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   154
        }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   155
    }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   156
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   157
    static void verifyASM() throws Exception {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   158
        ClassWriter cw = new ClassWriter(0);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   159
        cw.visit(V1_8, ACC_PUBLIC, "X", null, "java/lang/Object", null);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   160
        MethodVisitor mv = cw.visitMethod(ACC_STATIC, "foo",
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   161
                "()V", null, null);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   162
        mv.visitMaxs(2, 1);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   163
        mv.visitMethodInsn(INVOKESTATIC,
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   164
                "java/util/function/Function.class",
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   165
                "identity", "()Ljava/util/function/Function;", true);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   166
        mv.visitInsn(RETURN);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   167
        cw.visitEnd();
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   168
        byte[] carray = cw.toByteArray();
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   169
        // for debugging
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   170
        // write((new File("X.class")).toPath(), carray, CREATE, TRUNCATE_EXISTING);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   171
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   172
        // verify using javap/classfile reader
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   173
        ClassFile cf = ClassFile.read(new ByteArrayInputStream(carray));
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   174
        int mcount = checkMethod(cf, "foo");
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   175
        if (mcount < 1) {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   176
            throw new RuntimeException("unexpected method count, expected 1" +
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   177
                    "but got " + mcount);
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   178
        }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   179
    }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   180
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   181
    public static void main(String... args) throws Exception {
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   182
        init();
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   183
        verifyInvokerBytecodeGenerator();
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   184
        verifyASM();
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   185
    }
6632680b0683 8027232: Update j.l.invoke code generating class files to use ASM enhancements for invocation of non-abstract methods on ifaces
ksrini
parents:
diff changeset
   186
}