Mercurial > hg > graal-compiler
annotate test/compiler/jsr292/VMAnonymousClasses.java @ 21451:24dd9af9ac26
SPARCArithmetic: add register hint for Unary2Op.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Thu, 21 May 2015 15:00:11 +0200 |
parents | 9dc314de223d |
children |
rev | line source |
---|---|
20574
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
1 /* |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
4 * |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
8 * |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
13 * accompanied this code). |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
14 * |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
18 * |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
21 * questions. |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
22 */ |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
23 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
24 /** |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
25 * @test |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
26 * @bug 8058828 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
27 * @run main/bootclasspath -Xbatch VMAnonymousClasses |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
28 */ |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
29 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
30 import jdk.internal.org.objectweb.asm.ClassWriter; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
31 import jdk.internal.org.objectweb.asm.MethodVisitor; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
32 import jdk.internal.org.objectweb.asm.Opcodes; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
33 import sun.misc.Unsafe; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
34 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
35 import java.lang.invoke.ConstantCallSite; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
36 import java.lang.invoke.MethodHandle; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
37 import java.lang.invoke.MethodHandles; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
38 import java.lang.invoke.MethodType; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
39 import java.lang.invoke.MutableCallSite; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
40 import java.lang.invoke.VolatileCallSite; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
41 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
42 public class VMAnonymousClasses { |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
43 static final String TEST_METHOD_NAME = "constant"; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
44 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
45 static final Unsafe UNSAFE = Unsafe.getUnsafe(); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
46 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
47 static int getConstantPoolSize(byte[] classFile) { |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
48 // The first few bytes: |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
49 // u4 magic; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
50 // u2 minor_version; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
51 // u2 major_version; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
52 // u2 constant_pool_count; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
53 return ((classFile[8] & 0xFF) << 8) | (classFile[9] & 0xFF); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
54 } |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
55 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
56 static void test(Object value) throws ReflectiveOperationException { |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
57 System.out.printf("Test: %s", value != null ? value.getClass() : "null"); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
58 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
59 ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
60 cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, "Test", null, "java/lang/Object", null); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
61 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
62 MethodVisitor mv = cw.visitMethod(Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC, TEST_METHOD_NAME, "()Ljava/lang/Object;", null, null); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
63 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
64 String placeholder = "CONSTANT"; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
65 int index = cw.newConst(placeholder); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
66 mv.visitLdcInsn(placeholder); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
67 mv.visitInsn(Opcodes.ARETURN); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
68 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
69 mv.visitMaxs(0, 0); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
70 mv.visitEnd(); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
71 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
72 byte[] classFile = cw.toByteArray(); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
73 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
74 Object[] cpPatches = new Object[getConstantPoolSize(classFile)]; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
75 cpPatches[index] = value; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
76 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
77 Class<?> test = UNSAFE.defineAnonymousClass(VMAnonymousClasses.class, classFile, cpPatches); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
78 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
79 Object expectedResult = (value != null) ? value : placeholder; |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
80 for (int i = 0; i<15000; i++) { |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
81 Object result = test.getMethod(TEST_METHOD_NAME).invoke(null); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
82 if (result != expectedResult) { |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
83 throw new AssertionError(String.format("Wrong value returned: %s != %s", value, result)); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
84 } |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
85 } |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
86 System.out.println(" PASSED"); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
87 } |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
88 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
89 public static void main(String[] args) throws ReflectiveOperationException { |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
90 // Objects |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
91 test(new Object()); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
92 test("TEST"); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
93 test(new VMAnonymousClasses()); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
94 test(null); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
95 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
96 // Class |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
97 test(String.class); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
98 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
99 // Arrays |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
100 test(new boolean[0]); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
101 test(new byte[0]); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
102 test(new char[0]); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
103 test(new short[0]); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
104 test(new int[0]); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
105 test(new long[0]); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
106 test(new float[0]); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
107 test(new double[0]); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
108 test(new Object[0]); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
109 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
110 // Multi-dimensional arrays |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
111 test(new byte[0][0]); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
112 test(new Object[0][0]); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
113 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
114 // MethodHandle-related |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
115 MethodType mt = MethodType.methodType(void.class, String[].class); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
116 MethodHandle mh = MethodHandles.lookup().findStatic(VMAnonymousClasses.class, "main", mt); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
117 test(mt); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
118 test(mh); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
119 test(new ConstantCallSite(mh)); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
120 test(new MutableCallSite(MethodType.methodType(void.class))); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
121 test(new VolatileCallSite(MethodType.methodType(void.class))); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
122 |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
123 System.out.println("TEST PASSED"); |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
124 } |
9dc314de223d
8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff
changeset
|
125 } |