author | iignatyev |
Fri, 26 May 2017 22:53:26 -0700 | |
changeset 45283 | fcb2af038805 |
parent 31178 | 6ad68e35506d |
permissions | -rw-r--r-- |
18769
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
1 |
/* |
45283
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
2 |
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. |
18769
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
4 |
* |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
21596 | 7 |
* published by the Free Software Foundation. |
18769
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
8 |
* |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
13 |
* accompanied this code). |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
14 |
* |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
18 |
* |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
21 |
* questions. |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
22 |
*/ |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
23 |
|
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
24 |
/* |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
25 |
* @test |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
26 |
* @bug 8019184 |
45283
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
27 |
* @library /lib/testlibrary /java/lang/invoke/common |
18769
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
28 |
* @summary MethodHandles.catchException() fails when methods have 8 args + varargs |
31178
6ad68e35506d
8067005: Several java/lang/invoke tests fail due to exhausted code cache
kshefov
parents:
21596
diff
changeset
|
29 |
* @run main TestCatchExceptionWithVarargs |
18769
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
30 |
*/ |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
31 |
|
45283
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
32 |
import test.java.lang.invoke.lib.CodeCacheOverflowProcessor; |
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
33 |
|
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
34 |
import java.lang.invoke.MethodHandle; |
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
35 |
import java.lang.invoke.MethodHandles; |
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
36 |
import java.lang.invoke.MethodType; |
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
37 |
import java.util.LinkedList; |
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
38 |
import java.util.List; |
18769
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
39 |
|
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
40 |
public class TestCatchExceptionWithVarargs { |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
41 |
|
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
42 |
private static final Class<?> CLASS = TestCatchExceptionWithVarargs.class; |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
43 |
private static final int MAX_MH_ARITY = 254; |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
44 |
|
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
45 |
public static MethodHandle target; |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
46 |
public static MethodHandle handler; |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
47 |
|
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
48 |
private static Object firstArg; |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
49 |
|
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
50 |
static class MyException extends Exception { |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
51 |
} |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
52 |
|
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
53 |
public static Object target(Object... a) throws Exception { |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
54 |
if (a[0] != firstArg) { |
45283
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
55 |
throw new AssertionError("first argument different than expected: " |
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
56 |
+ a[0] + " != " + firstArg); |
18769
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
57 |
} |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
58 |
throw new MyException(); |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
59 |
} |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
60 |
|
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
61 |
public static Object handler(Object... a) { |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
62 |
if (a[0] != firstArg) { |
45283
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
63 |
throw new AssertionError("first argument different than expected: " |
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
64 |
+ a[0] + " != " + firstArg); |
18769
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
65 |
} |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
66 |
return a[0]; |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
67 |
} |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
68 |
|
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
69 |
static { |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
70 |
try { |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
71 |
MethodType mtype = MethodType.methodType(Object.class, Object[].class); |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
72 |
target = MethodHandles.lookup().findStatic(CLASS, "target", mtype); |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
73 |
handler = MethodHandles.lookup().findStatic(CLASS, "handler", mtype); |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
74 |
} catch (Exception e) { |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
75 |
throw new AssertionError(e); |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
76 |
} |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
77 |
} |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
78 |
|
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
79 |
public static void main(String[] args) throws Throwable { |
31178
6ad68e35506d
8067005: Several java/lang/invoke tests fail due to exhausted code cache
kshefov
parents:
21596
diff
changeset
|
80 |
CodeCacheOverflowProcessor |
6ad68e35506d
8067005: Several java/lang/invoke tests fail due to exhausted code cache
kshefov
parents:
21596
diff
changeset
|
81 |
.runMHTest(TestCatchExceptionWithVarargs::test); |
6ad68e35506d
8067005: Several java/lang/invoke tests fail due to exhausted code cache
kshefov
parents:
21596
diff
changeset
|
82 |
} |
6ad68e35506d
8067005: Several java/lang/invoke tests fail due to exhausted code cache
kshefov
parents:
21596
diff
changeset
|
83 |
|
6ad68e35506d
8067005: Several java/lang/invoke tests fail due to exhausted code cache
kshefov
parents:
21596
diff
changeset
|
84 |
public static void test() throws Throwable { |
18769
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
85 |
List<Class<?>> ptypes = new LinkedList<>(); |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
86 |
ptypes.add(Object[].class); |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
87 |
|
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
88 |
// We use MAX_MH_ARITY - 1 here to account for the Object[] argument. |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
89 |
for (int i = 1; i < MAX_MH_ARITY - 1; i++) { |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
90 |
ptypes.add(0, Object.class); |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
91 |
|
45283
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
92 |
MethodHandle targetWithArgs = target.asType( |
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
93 |
MethodType.methodType(Object.class, ptypes)); |
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
94 |
MethodHandle handlerWithArgs = handler.asType( |
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
95 |
MethodType.methodType(Object.class, ptypes)); |
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
96 |
handlerWithArgs = MethodHandles.dropArguments( |
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
97 |
handlerWithArgs, 0, MyException.class); |
18769
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
98 |
|
45283
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
99 |
MethodHandle gwc1 = MethodHandles.catchException( |
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
100 |
targetWithArgs, MyException.class, handlerWithArgs); |
18769
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
101 |
|
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
102 |
// The next line throws an IllegalArgumentException if there is a bug. |
45283
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
103 |
MethodHandle gwc2 = MethodHandles.catchException( |
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
104 |
gwc1, MyException.class, handlerWithArgs); |
18769
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
105 |
|
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
106 |
// This is only to verify that the method handles can actually be invoked and do the right thing. |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
107 |
firstArg = new Object(); |
45283
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
108 |
Object o = gwc2.asSpreader(Object[].class, ptypes.size() - 1) |
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
109 |
.invoke(firstArg, new Object[i]); |
18769
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
110 |
if (o != firstArg) { |
45283
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
111 |
throw new AssertionError("return value different than expected: " |
fcb2af038805
8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
iignatyev
parents:
31178
diff
changeset
|
112 |
+ o + " != " + firstArg); |
18769
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
113 |
} |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
114 |
} |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
115 |
} |
53b3406abedf
8019184: MethodHandles.catchException() fails when methods have 8 args + varargs
twisti
parents:
diff
changeset
|
116 |
} |