hotspot/test/runtime/8087223/BadMethodHandles.java
author minqi
Tue, 17 Nov 2015 15:14:29 -0800
changeset 34229 892795cc82fe
permissions -rw-r--r--
8087223: InterfaceMethod CP entry pointing to a class should cause ICCE Summary: Check constantTag for class constant data consistency at method resolution Reviewed-by: coleenp, vlivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34229
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
     1
/*
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
     4
 *
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
     7
 * published by the Free Software Foundation.
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
     8
 *
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    13
 * accompanied this code).
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    14
 *
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    18
 *
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    21
 * questions.
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    22
 */
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    23
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    24
/*
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    25
 * @test
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    26
 * $bug 8087223
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    27
 * @summary Adding constantTag to keep method call consistent with it.
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    28
 * @compile -XDignore.symbol.file BadMethodHandles.java
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    29
 * @run main/othervm BadMethodHandles
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    30
 */
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    31
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    32
import jdk.internal.org.objectweb.asm.*;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    33
import java.io.FileOutputStream;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    34
import java.lang.reflect.InvocationTargetException;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    35
import java.lang.invoke.MethodHandle;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    36
import java.lang.invoke.MethodHandles;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    37
import java.lang.invoke.MethodType;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    38
import static jdk.internal.org.objectweb.asm.Opcodes.*;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    39
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    40
public class BadMethodHandles {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    41
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    42
    static byte[] dumpBadInterfaceMethodref() {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    43
        ClassWriter cw = new ClassWriter(0);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    44
        cw.visit(52, ACC_PUBLIC | ACC_SUPER, "BadInterfaceMethodref", null, "java/lang/Object", null);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    45
        Handle handle1 =
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    46
            new Handle(Opcodes.H_INVOKEINTERFACE, "BadInterfaceMethodref", "m", "()V");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    47
        Handle handle2 =
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    48
            new Handle(Opcodes.H_INVOKEINTERFACE, "BadInterfaceMethodref", "staticM", "()V");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    49
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    50
        {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    51
            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    52
            mv.visitCode();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    53
            mv.visitVarInsn(ALOAD, 0);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    54
            mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    55
            mv.visitInsn(RETURN);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    56
            mv.visitMaxs(1, 1);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    57
            mv.visitEnd();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    58
        }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    59
        {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    60
            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "m", "()V", null, null);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    61
            mv.visitCode();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    62
            mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    63
            mv.visitLdcInsn("hello from m");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    64
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false/*intf*/);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    65
            mv.visitInsn(RETURN);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    66
            mv.visitMaxs(3, 1);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    67
            mv.visitEnd();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    68
        }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    69
        {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    70
            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "staticM", "()V", null, null);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    71
            mv.visitCode();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    72
            mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    73
            mv.visitLdcInsn("hello from staticM");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    74
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false/*intf*/);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    75
            mv.visitInsn(RETURN);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    76
            mv.visitMaxs(3, 1);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    77
            mv.visitEnd();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    78
        }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    79
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    80
        {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    81
            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "runm", "()V", null, null);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    82
            mv.visitCode();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    83
            // REF_invokeStatic
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    84
            mv.visitLdcInsn(handle1);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    85
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invoke", "()V", false);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    86
            mv.visitInsn(RETURN);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    87
            mv.visitMaxs(1, 1);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    88
            mv.visitEnd();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    89
        }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    90
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    91
        {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    92
            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "runStaticM", "()V", null, null);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    93
            mv.visitCode();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    94
            // REF_invokeStatic
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    95
            mv.visitLdcInsn(handle2);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    96
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invoke", "()V", false);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    97
            mv.visitInsn(RETURN);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    98
            mv.visitMaxs(1, 1);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
    99
            mv.visitEnd();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   100
        }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   101
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   102
        cw.visitEnd();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   103
        return cw.toByteArray();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   104
    }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   105
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   106
    static byte[] dumpIBad() {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   107
        ClassWriter cw = new ClassWriter(0);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   108
        cw.visit(52, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "IBad", null, "java/lang/Object", null);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   109
        {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   110
            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "m", "()V", null, null);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   111
            mv.visitCode();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   112
            mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   113
            mv.visitLdcInsn("hello from m");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   114
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false/*intf*/);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   115
            mv.visitInsn(RETURN);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   116
            mv.visitMaxs(3, 1);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   117
            mv.visitEnd();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   118
        }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   119
        {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   120
            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "staticM", "()V", null, null);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   121
            mv.visitCode();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   122
            mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   123
            mv.visitLdcInsn("hello from staticM");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   124
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false/*intf*/);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   125
            mv.visitInsn(RETURN);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   126
            mv.visitMaxs(3, 1);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   127
            mv.visitEnd();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   128
        }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   129
        cw.visitEnd();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   130
        return cw.toByteArray();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   131
    }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   132
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   133
    static byte[] dumpBadMethodref() {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   134
        ClassWriter cw = new ClassWriter(0);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   135
        cw.visit(52, ACC_PUBLIC | ACC_SUPER,  "BadMethodref", null, "java/lang/Object", new String[]{"IBad"});
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   136
        Handle handle1 =
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   137
            new Handle(Opcodes.H_INVOKEINTERFACE, "BadMethodref", "m", "()V");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   138
        Handle handle2 =
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   139
            new Handle(Opcodes.H_INVOKEINTERFACE, "BadMethodref", "staticM", "()V");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   140
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   141
        {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   142
            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   143
            mv.visitCode();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   144
            mv.visitVarInsn(ALOAD, 0);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   145
            mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   146
            mv.visitInsn(RETURN);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   147
            mv.visitMaxs(1, 1);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   148
            mv.visitEnd();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   149
        }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   150
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   151
        {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   152
            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "runm", "()V", null, null);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   153
            mv.visitCode();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   154
            // REF_invokeStatic
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   155
            mv.visitLdcInsn(handle1);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   156
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invoke", "()V", false);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   157
            mv.visitInsn(RETURN);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   158
            mv.visitMaxs(1, 1);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   159
            mv.visitEnd();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   160
        }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   161
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   162
        {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   163
            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "runStaticM", "()V", null, null);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   164
            mv.visitCode();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   165
            // REF_invokeStatic
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   166
            mv.visitLdcInsn(handle2);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   167
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invoke", "()V", false);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   168
            mv.visitInsn(RETURN);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   169
            mv.visitMaxs(1, 1);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   170
            mv.visitEnd();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   171
        }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   172
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   173
        cw.visitEnd();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   174
        return cw.toByteArray();
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   175
    }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   176
    static class CL extends ClassLoader {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   177
        @Override
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   178
        protected Class<?> findClass(String name) throws ClassNotFoundException {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   179
            byte[] classBytes = null;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   180
            switch (name) {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   181
            case "BadInterfaceMethodref": classBytes = dumpBadInterfaceMethodref(); break;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   182
            case "BadMethodref"         : classBytes = dumpBadMethodref(); break;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   183
            case "IBad"                 : classBytes = dumpIBad(); break;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   184
            default                     : throw new ClassNotFoundException(name);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   185
            }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   186
            return defineClass(name, classBytes, 0, classBytes.length);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   187
        }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   188
    }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   189
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   190
    public static void main(String[] args) throws Throwable {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   191
        try (FileOutputStream fos = new FileOutputStream("BadInterfaceMethodref.class")) {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   192
          fos.write(dumpBadInterfaceMethodref());
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   193
        }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   194
        try (FileOutputStream fos = new FileOutputStream("IBad.class")) {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   195
          fos.write(dumpIBad());
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   196
        }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   197
        try (FileOutputStream fos = new FileOutputStream("BadMethodref.class")) {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   198
          fos.write(dumpBadMethodref());
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   199
        }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   200
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   201
        Class<?> cls = (new CL()).loadClass("BadInterfaceMethodref");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   202
        String[] methods = {"runm", "runStaticM"};
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   203
        System.out.println("Test BadInterfaceMethodref:");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   204
        int success = 0;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   205
        for (String name : methods) {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   206
            try {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   207
                System.out.printf("invoke %s: \n", name);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   208
                cls.getMethod(name).invoke(cls.newInstance());
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   209
                System.out.println("FAILED (no exception)"); // ICCE should be thrown
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   210
            } catch (Throwable e) {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   211
                if (e instanceof InvocationTargetException && e.getCause() != null &&
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   212
                    e.getCause() instanceof IncompatibleClassChangeError) {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   213
                    System.out.println("PASSED");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   214
                    success++;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   215
                    continue;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   216
                } else {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   217
                    System.out.println("FAILED with exception");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   218
                    throw e;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   219
                }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   220
            }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   221
        }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   222
        if (success != methods.length) {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   223
           throw new Exception("BadInterfaceMethodRef Failed to catch IncompatibleClassChangeError");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   224
        }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   225
        System.out.println("Test BadMethodref:");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   226
        cls = (new CL()).loadClass("BadMethodref");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   227
        success = 0;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   228
        for (String name : methods) {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   229
            try {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   230
                System.out.printf("invoke %s: \n", name);
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   231
                cls.getMethod(name).invoke(cls.newInstance());
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   232
                System.out.println("FAILED (no exception)"); // ICCE should be thrown
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   233
            } catch (Throwable e) {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   234
                if (e instanceof InvocationTargetException && e.getCause() != null &&
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   235
                    e.getCause() instanceof IncompatibleClassChangeError) {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   236
                    System.out.println("PASSED");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   237
                    success++;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   238
                    continue;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   239
                } else {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   240
                    System.out.println("FAILED with exception");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   241
                    throw e;
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   242
                }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   243
            }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   244
         }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   245
         if (success != methods.length) {
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   246
            throw new Exception("BadMethodRef Failed to catch IncompatibleClassChangeError");
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   247
         }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   248
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   249
    }
892795cc82fe 8087223: InterfaceMethod CP entry pointing to a class should cause ICCE
minqi
parents:
diff changeset
   250
}