Path: blob/master/test/hotspot/jtreg/runtime/ConstantPool/IntfMethod.java
40943 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* $bug 808722326* @summary Adding constantTag to keep method call consistent with it.27* @modules java.base/jdk.internal.org.objectweb.asm28* java.base/jdk.internal.misc29* java.management30* @compile -XDignore.symbol.file IntfMethod.java31* @run main/othervm IntfMethod32* @run main/othervm -Xint IntfMethod33* @run main/othervm -Xcomp IntfMethod34*/353637import jdk.internal.org.objectweb.asm.*;38import java.io.FileOutputStream;39import java.lang.reflect.InvocationTargetException;40import static jdk.internal.org.objectweb.asm.Opcodes.*;4142public class IntfMethod {43static byte[] dumpC() {44ClassWriter cw = new ClassWriter(0);45cw.visit(52, ACC_PUBLIC | ACC_SUPER, "C", null, "java/lang/Object", new String[]{"I"});46{47MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);48mv.visitCode();49mv.visitVarInsn(ALOAD, 0);50mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);51mv.visitInsn(RETURN);52mv.visitMaxs(1, 1);53mv.visitEnd();54}55{56MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "testSpecialIntf", "()V", null, null);57mv.visitCode();58mv.visitVarInsn(ALOAD, 0);59mv.visitMethodInsn(INVOKESPECIAL, "I", "f1", "()V", /*itf=*/false);60mv.visitInsn(RETURN);61mv.visitMaxs(1, 1);62mv.visitEnd();63}64{65MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "testStaticIntf", "()V", null, null);66mv.visitCode();67mv.visitMethodInsn(INVOKESTATIC, "I", "f2", "()V", /*itf=*/false);68mv.visitInsn(RETURN);69mv.visitMaxs(1, 1);70mv.visitEnd();71}72{73MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "testSpecialClass", "()V", null, null);74mv.visitCode();75mv.visitVarInsn(ALOAD, 0);76mv.visitMethodInsn(INVOKESPECIAL, "C", "f1", "()V", /*itf=*/true);77mv.visitInsn(RETURN);78mv.visitMaxs(1, 1);79mv.visitEnd();80}8182{83MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "f2", "()V", null, null);84mv.visitCode();85mv.visitInsn(RETURN);86mv.visitMaxs(0, 1);87mv.visitEnd();88}89{90MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "testStaticClass", "()V", null, null);91mv.visitCode();92mv.visitMethodInsn(INVOKESTATIC, "C", "f2", "()V", /*itf=*/true);93mv.visitInsn(RETURN);94mv.visitMaxs(1, 1);95mv.visitEnd();96}97cw.visitEnd();98return cw.toByteArray();99}100101static byte[] dumpI() {102ClassWriter cw = new ClassWriter(0);103cw.visit(52, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "I", null, "java/lang/Object", null);104{105MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "f1", "()V", null, null);106mv.visitCode();107mv.visitInsn(RETURN);108mv.visitMaxs(0, 1);109mv.visitEnd();110}111{112MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "f2", "()V", null, null);113mv.visitCode();114mv.visitInsn(RETURN);115mv.visitMaxs(0, 1);116mv.visitEnd();117}118cw.visitEnd();119return cw.toByteArray();120}121122static class CL extends ClassLoader {123@Override124protected Class<?> findClass(String name) throws ClassNotFoundException {125byte[] classFile;126switch (name) {127case "I": classFile = dumpI(); break;128case "C": classFile = dumpC(); break;129default:130throw new ClassNotFoundException(name);131}132return defineClass(name, classFile, 0, classFile.length);133}134}135136public static void main(String[] args) throws Throwable {137Class<?> cls = (new CL()).loadClass("C");138try (FileOutputStream fos = new FileOutputStream("I.class")) { fos.write(dumpI()); }139try (FileOutputStream fos = new FileOutputStream("C.class")) { fos.write(dumpC()); }140141int success = 0;142for (String name : new String[] { "testSpecialIntf", "testStaticIntf", "testSpecialClass", "testStaticClass"}) {143System.out.printf("%s: ", name);144try {145cls.getMethod(name).invoke(cls.newInstance());146System.out.println("FAILED - ICCE not thrown");147} catch (Throwable e) {148if (e instanceof InvocationTargetException &&149e.getCause() != null && e.getCause() instanceof IncompatibleClassChangeError) {150System.out.println("PASSED - expected ICCE thrown");151success++;152continue;153}154}155}156if (success != 4) throw new Exception("Failed to catch ICCE");157}158}159160161