author | jvernee |
Thu, 14 Nov 2019 10:55:46 +0100 | |
changeset 59075 | 355f4f42dda5 |
parent 49790 | 403e2f61f384 |
permissions | -rw-r--r-- |
36221
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
1 |
/* |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
4 |
* |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
10 |
* |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
15 |
* accompanied this code). |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
16 |
* |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
20 |
* |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
23 |
* questions. |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
24 |
*/ |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
25 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
26 |
/* @test |
59075
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
27 |
* @bug 8139885 8150824 8150825 8194238 8233920 |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
28 |
* @run testng/othervm -ea -esa -Xverify:all test.java.lang.invoke.TryFinallyTest |
36221
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
29 |
*/ |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
30 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
31 |
package test.java.lang.invoke; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
32 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
33 |
import java.lang.invoke.MethodHandle; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
34 |
import java.lang.invoke.MethodHandles; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
35 |
import java.lang.invoke.MethodHandles.Lookup; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
36 |
import java.lang.invoke.MethodType; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
37 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
38 |
import static java.lang.invoke.MethodType.methodType; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
39 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
40 |
import static org.testng.AssertJUnit.*; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
41 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
42 |
import org.testng.annotations.*; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
43 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
44 |
/** |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
45 |
* Tests for the tryFinally method handle combinator introduced in JEP 274. |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
46 |
*/ |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
47 |
public class TryFinallyTest { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
48 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
49 |
static final Lookup LOOKUP = MethodHandles.lookup(); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
50 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
51 |
@Test |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
52 |
public static void testTryFinally() throws Throwable { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
53 |
MethodHandle hello = MethodHandles.tryFinally(TryFinally.MH_greet, TryFinally.MH_exclaim); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
54 |
assertEquals(TryFinally.MT_hello, hello.type()); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
55 |
assertEquals("Hello, world!", hello.invoke("world")); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
56 |
} |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
57 |
|
59075
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
58 |
@DataProvider |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
59 |
static Object[][] tryFinallyArgs() { |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
60 |
return new Object[][] { |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
61 |
{ boolean.class, true }, |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
62 |
{ byte.class, (byte) 2 }, |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
63 |
{ short.class, (short) 2 }, |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
64 |
{ char.class, (char) 2 }, |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
65 |
{ int.class, 2 }, |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
66 |
{ long.class, 2L }, |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
67 |
{ float.class, 2f }, |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
68 |
{ double.class, 2D }, |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
69 |
{ Object.class, new Object() } |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
70 |
}; |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
71 |
} |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
72 |
|
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
73 |
@Test(dataProvider = "tryFinallyArgs") |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
74 |
public static void testTryFinally(Class<?> argType, Object arg) throws Throwable { |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
75 |
MethodHandle identity = MethodHandles.identity(argType); |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
76 |
MethodHandle tryFinally = MethodHandles.tryFinally( |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
77 |
identity, |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
78 |
MethodHandles.dropArguments(identity, 0, Throwable.class)); |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
79 |
assertEquals(methodType(argType, argType), tryFinally.type()); |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
80 |
assertEquals(arg, tryFinally.invoke(arg)); |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
81 |
} |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
82 |
|
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
83 |
@Test(dataProvider = "tryFinallyArgs", expectedExceptions = TryFinally.T1.class) |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
84 |
public static void testTryFinallyException(Class<?> argType, Object arg) throws Throwable { |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
85 |
MethodHandle identity = TryFinally.MH_throwingTargetIdentity.asType(methodType(argType, argType)); |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
86 |
MethodHandle tryFinally = MethodHandles.tryFinally( |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
87 |
identity, |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
88 |
MethodHandles.dropArguments(identity, 0, TryFinally.T1.class)); |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
89 |
assertEquals(methodType(argType, argType), tryFinally.type()); |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
90 |
tryFinally.invoke(arg); // should throw |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
91 |
} |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
92 |
|
36221
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
93 |
@Test |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
94 |
public static void testTryFinallyVoid() throws Throwable { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
95 |
MethodHandle tfVoid = MethodHandles.tryFinally(TryFinally.MH_print, TryFinally.MH_printMore); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
96 |
assertEquals(TryFinally.MT_printHello, tfVoid.type()); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
97 |
tfVoid.invoke("world"); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
98 |
} |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
99 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
100 |
@Test |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
101 |
public static void testTryFinallySublist() throws Throwable { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
102 |
MethodHandle helloMore = MethodHandles.tryFinally(TryFinally.MH_greetMore, TryFinally.MH_exclaimMore); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
103 |
assertEquals(TryFinally.MT_moreHello, helloMore.type()); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
104 |
assertEquals("Hello, world and universe (but world first)!", helloMore.invoke("world", "universe")); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
105 |
} |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
106 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
107 |
@DataProvider |
37357
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
108 |
static Object[][] omitTrailingArguments() { |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
109 |
MethodHandle c = TryFinally.MH_voidCleanup; |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
110 |
return new Object[][]{ |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
111 |
{c}, |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
112 |
{MethodHandles.dropArguments(c, 1, int.class)}, |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
113 |
{MethodHandles.dropArguments(c, 1, int.class, long.class)}, |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
114 |
{MethodHandles.dropArguments(c, 1, int.class, long.class, Object.class, int.class)}, |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
115 |
{MethodHandles.dropArguments(c, 1, int.class, long.class, Object.class, int.class, long.class)} |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
116 |
}; |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
117 |
} |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
118 |
|
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
119 |
@Test(dataProvider = "omitTrailingArguments") |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
120 |
public static void testTryFinallyOmitTrailingArguments(MethodHandle cleanup) throws Throwable { |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
121 |
MethodHandle tf = MethodHandles.tryFinally(TryFinally.MH_dummyTarget, cleanup); |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
122 |
tf.invoke(1, 2L, "a", 23, 42L, "b"); |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
123 |
} |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
124 |
|
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
125 |
@DataProvider |
36221
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
126 |
static Object[][] negativeTestData() { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
127 |
MethodHandle intid = MethodHandles.identity(int.class); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
128 |
MethodHandle intco = MethodHandles.constant(int.class, 0); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
129 |
MethodHandle errTarget = MethodHandles.dropArguments(intco, 0, int.class, double.class, String.class, int.class); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
130 |
MethodHandle errCleanup = MethodHandles.dropArguments(MethodHandles.constant(int.class, 0), 0, Throwable.class, |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
131 |
int.class, double.class, Object.class); |
37357
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
132 |
MethodHandle voidTarget = TryFinally.MH_voidTarget; |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
133 |
MethodHandle voidICleanup = MethodHandles.dropArguments(TryFinally.MH_voidCleanup, 1, int.class); |
36221
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
134 |
return new Object[][]{ |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
135 |
{intid, MethodHandles.identity(double.class), |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
136 |
"target and return types must match: double != int"}, |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
137 |
{intid, MethodHandles.dropArguments(intid, 0, String.class), |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
138 |
"cleanup first argument and Throwable must match: (String,int)int != class java.lang.Throwable"}, |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
139 |
{intid, MethodHandles.dropArguments(intid, 0, Throwable.class, double.class), |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
140 |
"cleanup second argument and target return type must match: (Throwable,double,int)int != int"}, |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
141 |
{errTarget, errCleanup, |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
142 |
"cleanup parameters after (Throwable,result) and target parameter list prefix must match: " + |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
143 |
errCleanup.type() + " != " + errTarget.type()}, |
37357
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
144 |
{voidTarget, voidICleanup, |
36221
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
145 |
"cleanup parameters after (Throwable,result) and target parameter list prefix must match: " + |
37357
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
146 |
voidICleanup.type() + " != " + voidTarget.type()} |
36221
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
147 |
}; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
148 |
} |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
149 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
150 |
@Test(dataProvider = "negativeTestData") |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
151 |
public static void testTryFinallyNegative(MethodHandle target, MethodHandle cleanup, String expectedMessage) { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
152 |
boolean caught = false; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
153 |
try { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
154 |
MethodHandles.tryFinally(target, cleanup); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
155 |
} catch (IllegalArgumentException iae) { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
156 |
assertEquals(expectedMessage, iae.getMessage()); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
157 |
caught = true; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
158 |
} |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
159 |
assertTrue(caught); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
160 |
} |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
161 |
|
49790 | 162 |
@Test |
163 |
public static void testTryFinallyThrowableCheck() { |
|
164 |
MethodHandle mh = MethodHandles.tryFinally(TryFinally.MH_throwingTarget, |
|
165 |
TryFinally.MH_catchingCleanup); |
|
166 |
try { |
|
167 |
mh.invoke(); |
|
168 |
fail("ClassCastException expected"); |
|
169 |
} catch (Throwable t) { |
|
170 |
assertTrue("Throwable not assignable to ClassCastException: " + t, |
|
171 |
ClassCastException.class.isAssignableFrom(t.getClass())); |
|
172 |
} |
|
173 |
} |
|
174 |
||
36221
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
175 |
static class TryFinally { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
176 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
177 |
static String greet(String whom) { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
178 |
return "Hello, " + whom; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
179 |
} |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
180 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
181 |
static String exclaim(Throwable t, String r, String whom) { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
182 |
return r + "!"; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
183 |
} |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
184 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
185 |
static void print(String what) { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
186 |
System.out.print("Hello, " + what); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
187 |
} |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
188 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
189 |
static void printMore(Throwable t, String what) { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
190 |
System.out.println("!"); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
191 |
} |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
192 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
193 |
static String greetMore(String first, String second) { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
194 |
return "Hello, " + first + " and " + second; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
195 |
} |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
196 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
197 |
static String exclaimMore(Throwable t, String r, String first) { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
198 |
return r + " (but " + first + " first)!"; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
199 |
} |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
200 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
201 |
static void voidTarget() {} |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
202 |
|
37357
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
203 |
static void voidCleanup(Throwable t) {} |
36221
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
204 |
|
49790 | 205 |
static class T1 extends Throwable {} |
206 |
||
207 |
static class T2 extends Throwable {} |
|
208 |
||
209 |
static void throwingTarget() throws Throwable { |
|
210 |
throw new T1(); |
|
211 |
} |
|
212 |
||
59075
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
213 |
static Object throwingTargetIdentity(Object o) throws Throwable { |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
214 |
throw new T1(); |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
215 |
} |
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
216 |
|
49790 | 217 |
static void catchingCleanup(T2 t) throws Throwable { |
218 |
} |
|
219 |
||
36221
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
220 |
static final Class<TryFinally> TRY_FINALLY = TryFinally.class; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
221 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
222 |
static final MethodType MT_greet = methodType(String.class, String.class); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
223 |
static final MethodType MT_exclaim = methodType(String.class, Throwable.class, String.class, String.class); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
224 |
static final MethodType MT_print = methodType(void.class, String.class); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
225 |
static final MethodType MT_printMore = methodType(void.class, Throwable.class, String.class); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
226 |
static final MethodType MT_greetMore = methodType(String.class, String.class, String.class); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
227 |
static final MethodType MT_exclaimMore = methodType(String.class, Throwable.class, String.class, String.class); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
228 |
static final MethodType MT_voidTarget = methodType(void.class); |
37357
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
229 |
static final MethodType MT_voidCleanup = methodType(void.class, Throwable.class); |
49790 | 230 |
static final MethodType MT_throwingTarget = methodType(void.class); |
59075
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
231 |
static final MethodType MT_throwingTargetIdentity = methodType(Object.class, Object.class); |
49790 | 232 |
static final MethodType MT_catchingCleanup = methodType(void.class, T2.class); |
36221
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
233 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
234 |
static final MethodHandle MH_greet; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
235 |
static final MethodHandle MH_exclaim; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
236 |
static final MethodHandle MH_print; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
237 |
static final MethodHandle MH_printMore; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
238 |
static final MethodHandle MH_greetMore; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
239 |
static final MethodHandle MH_exclaimMore; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
240 |
static final MethodHandle MH_voidTarget; |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
241 |
static final MethodHandle MH_voidCleanup; |
49790 | 242 |
static final MethodHandle MH_throwingTarget; |
59075
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
243 |
static final MethodHandle MH_throwingTargetIdentity; |
49790 | 244 |
static final MethodHandle MH_catchingCleanup; |
36221
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
245 |
|
37357
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
246 |
static final MethodHandle MH_dummyTarget; |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
247 |
|
36221
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
248 |
static final MethodType MT_hello = methodType(String.class, String.class); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
249 |
static final MethodType MT_printHello = methodType(void.class, String.class); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
250 |
static final MethodType MT_moreHello = methodType(String.class, String.class, String.class); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
251 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
252 |
static { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
253 |
try { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
254 |
MH_greet = LOOKUP.findStatic(TRY_FINALLY, "greet", MT_greet); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
255 |
MH_exclaim = LOOKUP.findStatic(TRY_FINALLY, "exclaim", MT_exclaim); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
256 |
MH_print = LOOKUP.findStatic(TRY_FINALLY, "print", MT_print); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
257 |
MH_printMore = LOOKUP.findStatic(TRY_FINALLY, "printMore", MT_printMore); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
258 |
MH_greetMore = LOOKUP.findStatic(TRY_FINALLY, "greetMore", MT_greetMore); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
259 |
MH_exclaimMore = LOOKUP.findStatic(TRY_FINALLY, "exclaimMore", MT_exclaimMore); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
260 |
MH_voidTarget = LOOKUP.findStatic(TRY_FINALLY, "voidTarget", MT_voidTarget); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
261 |
MH_voidCleanup = LOOKUP.findStatic(TRY_FINALLY, "voidCleanup", MT_voidCleanup); |
49790 | 262 |
MH_throwingTarget = LOOKUP.findStatic(TRY_FINALLY, "throwingTarget", MT_throwingTarget); |
59075
355f4f42dda5
8233920: MethodHandles::tryFinally generates illegal bytecode for long/double return type
jvernee
parents:
49790
diff
changeset
|
263 |
MH_throwingTargetIdentity = LOOKUP.findStatic(TRY_FINALLY, "throwingTargetIdentity", MT_throwingTargetIdentity); |
49790 | 264 |
MH_catchingCleanup = LOOKUP.findStatic(TRY_FINALLY, "catchingCleanup", MT_catchingCleanup); |
37357
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
265 |
MH_dummyTarget = MethodHandles.dropArguments(MH_voidTarget, 0, int.class, long.class, Object.class, |
b4ec5a9e18ac
8150824: Exceptions when omitting trailing arguments in cleanup
mhaupt
parents:
36221
diff
changeset
|
266 |
int.class, long.class, Object.class); |
36221
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
267 |
} catch (Exception e) { |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
268 |
throw new ExceptionInInitializerError(e); |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
269 |
} |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
270 |
} |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
271 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
272 |
} |
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
273 |
|
0543ccb78f27
8150832: split T8139885 into several tests by functionality
mhaupt
parents:
diff
changeset
|
274 |
} |