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