Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/8026365/InvokeSpecialAnonTest.java
32284 views
/*1* Copyright (c) 2013, 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 802636526* @summary Test invokespecial of host class method from an anonymous class27* @author Robert Field28* @library /testlibrary29* @compile -XDignore.symbol.file InvokeSpecialAnonTest.java30* @run main ClassFileInstaller InvokeSpecialAnonTest AnonTester31* @run main/othervm -Xbootclasspath/a:. -Xverify:all InvokeSpecialAnonTest32*/33import jdk.internal.org.objectweb.asm.*;34import java.lang.reflect.Constructor;35import sun.misc.Unsafe;3637public class InvokeSpecialAnonTest implements Opcodes {3839static byte[] anonClassBytes() throws Exception {40ClassWriter cw = new ClassWriter(0);41MethodVisitor mv;4243cw.visit(V1_8, ACC_FINAL + ACC_SUPER, "Anon", null, "java/lang/Object", null);4445{46mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);47mv.visitCode();48mv.visitVarInsn(ALOAD, 0);49mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");50mv.visitInsn(RETURN);51mv.visitMaxs(2, 2);52mv.visitEnd();53}54{55mv = cw.visitMethod(ACC_PUBLIC, "m", "(LInvokeSpecialAnonTest;)I", null, null);56mv.visitCode();57mv.visitVarInsn(ALOAD, 0);58mv.visitVarInsn(ALOAD, 1);59mv.visitMethodInsn(INVOKESPECIAL, "InvokeSpecialAnonTest", "privMethod", "()I");60mv.visitInsn(IRETURN);61mv.visitMaxs(2, 3);62mv.visitEnd();63}64cw.visitEnd();6566return cw.toByteArray();67}6869private int privMethod() { return 1234; }7071public static void main(String[] args) throws Exception {72Class<?> klass = InvokeSpecialAnonTest.class;73try {74Class<?> result = AnonTester.defineTest(klass, anonClassBytes());75System.out.println("Passed.");76} catch (Exception e) {77e.printStackTrace();78throw e;79}80}81}828384class AnonTester {85private static final Unsafe UNSAFE = Unsafe.getUnsafe();8687public static Class<?> defineTest(Class<?> targetClass, byte[] classBytes) throws Exception {88return UNSAFE.defineAnonymousClass(targetClass, classBytes, null);89}90}919293