Mercurial > hg > graal-jvmci-8
annotate test/runtime/invokedynamic/BootstrapMethodErrorTest.java @ 24234:ea6f94ab283b default tip
Added tag jvmci-0.36 for changeset 8128b98d4736
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Mon, 18 Sep 2017 18:49:45 +0200 |
parents | 81bed6c76a89 |
children |
rev | line source |
---|---|
23061
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
1 /* |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
4 * |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
8 * |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
13 * accompanied this code). |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
14 * |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
18 * |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
21 * questions. |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
22 */ |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
23 |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
24 /* |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
25 * @test |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
26 * @bug 8051045 |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
27 * @summary Test that exceptions from invokedynamic are wrapped in BootstrapMethodError |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
28 * @modules java.base/jdk.internal.org.objectweb.asm |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
29 * @run main BootstrapMethodErrorTest |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
30 */ |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
31 |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
32 import java.lang.reflect.Method; |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
33 import java.lang.invoke.MethodHandle; |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
34 import java.lang.invoke.MethodHandles; |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
35 import static java.lang.invoke.MethodHandles.*; |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
36 import static java.lang.invoke.MethodType.*; |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
37 |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
38 import jdk.internal.org.objectweb.asm.ClassWriter; |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
39 import jdk.internal.org.objectweb.asm.Handle; |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
40 import jdk.internal.org.objectweb.asm.MethodVisitor; |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
41 import jdk.internal.org.objectweb.asm.Opcodes; |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
42 |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
43 public class BootstrapMethodErrorTest extends ClassLoader implements Opcodes { |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
44 |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
45 @Override |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
46 public Class findClass(String name) throws ClassNotFoundException { |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
47 byte[] b; |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
48 try { |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
49 b = loadClassData(name); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
50 } catch (Throwable th) { |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
51 throw new ClassNotFoundException("Loading error", th); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
52 } |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
53 return defineClass(name, b, 0, b.length); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
54 } |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
55 |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
56 private byte[] loadClassData(String name) throws Exception { |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
57 ClassWriter cw = new ClassWriter(0); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
58 MethodVisitor mv; |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
59 |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
60 if (name.equals("C")) { |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
61 cw.visit(52, ACC_SUPER | ACC_PUBLIC, "C", null, "java/lang/Object", null); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
62 { |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
63 mv = cw.visitMethod(ACC_PRIVATE | ACC_STATIC, "m", "()V", null, null); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
64 mv.visitCode(); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
65 mv.visitInsn(RETURN); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
66 mv.visitMaxs(0, 1); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
67 mv.visitEnd(); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
68 } |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
69 cw.visitEnd(); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
70 return cw.toByteArray(); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
71 } else if (name.equals("Exec")) { |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
72 cw.visit(52, ACC_SUPER | ACC_PUBLIC, "Exec", null, "java/lang/Object", null); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
73 { |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
74 mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "invokeRef", "()V", null, null); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
75 mv.visitCode(); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
76 Handle h = new Handle(H_INVOKESTATIC, "C", "m", "()V"); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
77 mv.visitInvokeDynamicInsn("C", "()V", h); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
78 mv.visitInsn(RETURN); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
79 mv.visitMaxs(0, 0); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
80 mv.visitEnd(); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
81 } |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
82 cw.visitEnd(); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
83 return cw.toByteArray(); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
84 } |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
85 return null; |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
86 } |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
87 |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
88 public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, NoSuchMethodException { |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
89 new BootstrapMethodErrorTest().test(); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
90 } |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
91 |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
92 public void test() throws ClassNotFoundException, IllegalAccessException, NoSuchMethodException { |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
93 Class.forName("C", true, this); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
94 Class<?> exec = Class.forName("Exec", true, this); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
95 |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
96 try { |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
97 exec.getMethod("invokeRef").invoke(null); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
98 } catch (Throwable e) { |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
99 Throwable c = e.getCause(); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
100 if (c == null) { |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
101 throw new RuntimeException( |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
102 "Expected BootstrapMethodError wrapped in an InvocationTargetException but it wasn't wrapped", e); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
103 } else if (c instanceof BootstrapMethodError) { |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
104 // Only way to pass test, all else should throw |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
105 return; |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
106 } else { |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
107 throw new RuntimeException( |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
108 "Expected BootstrapMethodError but got another Error: " |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
109 + c.getClass().getName(), |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
110 c); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
111 } |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
112 } |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
113 throw new RuntimeException("Expected BootstrapMethodError but no Error at all was thrown"); |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
114 } |
81bed6c76a89
8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents:
diff
changeset
|
115 } |