annotate test/runtime/8026365/InvokeSpecialAnonTest.java @ 18408:2c3666f44855

Truffle: initial commit of object API implementation
author Andreas Woess <andreas.woess@jku.at>
date Tue, 18 Nov 2014 23:19:43 +0100
parents e39b138b2518
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13027
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
1 /*
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
4 *
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
7 * published by the Free Software Foundation.
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
8 *
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
13 * accompanied this code).
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
14 *
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
18 *
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
21 * questions.
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
22 */
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
23
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
24 /*
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
25 * @test
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
26 * @bug 8026365
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
27 * @summary Test invokespecial of host class method from an anonymous class
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
28 * @author Robert Field
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
29 * @library /testlibrary
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
30 * @compile -XDignore.symbol.file InvokeSpecialAnonTest.java
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
31 * @run main ClassFileInstaller InvokeSpecialAnonTest AnonTester
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
32 * @run main/othervm -Xbootclasspath/a:. -Xverify:all InvokeSpecialAnonTest
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
33 */
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
34 import jdk.internal.org.objectweb.asm.*;
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
35 import java.lang.reflect.Constructor;
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
36 import sun.misc.Unsafe;
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
37
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
38 public class InvokeSpecialAnonTest implements Opcodes {
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
39
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
40 static byte[] anonClassBytes() throws Exception {
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
41 ClassWriter cw = new ClassWriter(0);
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
42 MethodVisitor mv;
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
43
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
44 cw.visit(V1_8, ACC_FINAL + ACC_SUPER, "Anon", null, "java/lang/Object", null);
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
45
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
46 {
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
47 mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
48 mv.visitCode();
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
49 mv.visitVarInsn(ALOAD, 0);
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
50 mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
51 mv.visitInsn(RETURN);
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
52 mv.visitMaxs(2, 2);
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
53 mv.visitEnd();
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
54 }
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
55 {
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
56 mv = cw.visitMethod(ACC_PUBLIC, "m", "(LInvokeSpecialAnonTest;)I", null, null);
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
57 mv.visitCode();
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
58 mv.visitVarInsn(ALOAD, 0);
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
59 mv.visitVarInsn(ALOAD, 1);
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
60 mv.visitMethodInsn(INVOKESPECIAL, "InvokeSpecialAnonTest", "privMethod", "()I");
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
61 mv.visitInsn(IRETURN);
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
62 mv.visitMaxs(2, 3);
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
63 mv.visitEnd();
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
64 }
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
65 cw.visitEnd();
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
66
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
67 return cw.toByteArray();
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
68 }
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
69
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
70 private int privMethod() { return 1234; }
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
71
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
72 public static void main(String[] args) throws Exception {
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
73 Class<?> klass = InvokeSpecialAnonTest.class;
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
74 try {
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
75 Class<?> result = AnonTester.defineTest(klass, anonClassBytes());
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
76 System.out.println("Passed.");
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
77 } catch (Exception e) {
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
78 e.printStackTrace();
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
79 throw e;
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
80 }
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
81 }
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
82 }
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
83
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
84
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
85 class AnonTester {
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
86 private static final Unsafe UNSAFE = Unsafe.getUnsafe();
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
87
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
88 public static Class<?> defineTest(Class<?> targetClass, byte[] classBytes) throws Exception {
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
89 return UNSAFE.defineAnonymousClass(targetClass, classBytes, null);
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
90 }
e39b138b2518 8026893: Push 8026365 to TL early and add test
acorn
parents:
diff changeset
91 }