7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package test.java.lang.invoke.MethodHandles;
24
25 import com.oracle.testlibrary.jsr292.Helper;
26 import jdk.testlibrary.Asserts;
27
28 import java.lang.invoke.MethodHandle;
29 import java.lang.invoke.MethodHandles;
30 import java.lang.invoke.MethodType;
31 import java.lang.reflect.Array;
32 import java.util.*;
33 import java.util.function.BiFunction;
34 import java.util.function.Function;
35 import java.util.function.Supplier;
36
37 /* @test
38 * @library /lib/testlibrary/jsr292 /lib/testlibrary/
39 * @compile CatchExceptionTest.java
40 * @run main/othervm -esa test.java.lang.invoke.MethodHandles.CatchExceptionTest
41 */
42 public class CatchExceptionTest {
43 private static final List<Class<?>> ARGS_CLASSES;
44 protected static final int MAX_ARITY = Helper.MAX_ARITY - 1;
45
46 static {
47 Class<?> classes[] = {
48 Object.class,
49 long.class,
50 int.class,
51 byte.class,
52 Integer[].class,
53 double[].class,
54 String.class,
55 };
76 }
77 MethodHandle thrower = testCase.thrower;
78 int throwerLen = thrower.type().parameterCount();
79 List<Class<?>> classes;
80 int extra = Math.max(0, argsCount - throwerLen);
81 classes = getThrowerParams(isVararg, extra);
82 this.argsCount = throwerLen + classes.size();
83 thrower = Helper.addTrailingArgs(thrower, this.argsCount, classes);
84 if (isVararg && argsCount > throwerLen) {
85 MethodType mt = thrower.type();
86 Class<?> lastParam = mt.parameterType(mt.parameterCount() - 1);
87 thrower = thrower.asVarargsCollector(lastParam);
88 }
89 this.thrower = thrower;
90 this.dropped = Math.min(this.argsCount, catchDrops);
91 catcher = testCase.getCatcher(getCatcherParams());
92 nargs = Math.max(2, this.argsCount);
93 }
94
95 public static void main(String[] args) throws Throwable {
96 for (CatchExceptionTest test : TestFactory.MANDATORY_TEST_CASES) {
97 test.runTest();
98 }
99 TestFactory factory = new TestFactory();
100 CatchExceptionTest test;
101 while ((test = factory.nextTest()) != null ) {
102 test.runTest();
103 }
104 }
105
106 private List<Class<?>> getThrowerParams(boolean isVararg, int argsCount) {
107 return Helper.getParams(ARGS_CLASSES, isVararg, argsCount);
108 }
109
110
111 private List<Class<?>> getCatcherParams() {
112 int catchArgc = 1 + this.argsCount - dropped;
113 List<Class<?>> result = new ArrayList<>(
114 thrower.type().parameterList().subList(0, catchArgc - 1));
115 // prepend throwable
116 result.add(0, testCase.throwableClass);
117 return result;
118 }
119
120 private void runTest() {
121 Helper.clear();
122
123 Object[] args = Helper.randomArgs(
|
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package test.java.lang.invoke.MethodHandles;
24
25 import com.oracle.testlibrary.jsr292.Helper;
26 import jdk.testlibrary.Asserts;
27 import jdk.testlibrary.TimeLimitedRunner;
28 import jdk.testlibrary.Utils;
29
30 import java.lang.invoke.MethodHandle;
31 import java.lang.invoke.MethodHandles;
32 import java.lang.invoke.MethodType;
33 import java.lang.reflect.Array;
34 import java.util.*;
35 import java.util.function.BiFunction;
36 import java.util.function.Function;
37 import java.util.function.Supplier;
38 import java.util.concurrent.TimeUnit;
39
40 /* @test
41 * @library /lib/testlibrary/jsr292 /lib/testlibrary/
42 * @compile CatchExceptionTest.java
43 * @run main/othervm -esa test.java.lang.invoke.MethodHandles.CatchExceptionTest
44 */
45 public class CatchExceptionTest {
46 private static final List<Class<?>> ARGS_CLASSES;
47 protected static final int MAX_ARITY = Helper.MAX_ARITY - 1;
48
49 static {
50 Class<?> classes[] = {
51 Object.class,
52 long.class,
53 int.class,
54 byte.class,
55 Integer[].class,
56 double[].class,
57 String.class,
58 };
79 }
80 MethodHandle thrower = testCase.thrower;
81 int throwerLen = thrower.type().parameterCount();
82 List<Class<?>> classes;
83 int extra = Math.max(0, argsCount - throwerLen);
84 classes = getThrowerParams(isVararg, extra);
85 this.argsCount = throwerLen + classes.size();
86 thrower = Helper.addTrailingArgs(thrower, this.argsCount, classes);
87 if (isVararg && argsCount > throwerLen) {
88 MethodType mt = thrower.type();
89 Class<?> lastParam = mt.parameterType(mt.parameterCount() - 1);
90 thrower = thrower.asVarargsCollector(lastParam);
91 }
92 this.thrower = thrower;
93 this.dropped = Math.min(this.argsCount, catchDrops);
94 catcher = testCase.getCatcher(getCatcherParams());
95 nargs = Math.max(2, this.argsCount);
96 }
97
98 public static void main(String[] args) throws Throwable {
99 TestFactory factory = new TestFactory();
100 long timeout = Helper.IS_THOROUGH ? 0L : Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT);
101 // substract vm init time and reserve time for vm exit
102 timeout *= 0.9;
103 TimeLimitedRunner runner = new TimeLimitedRunner(timeout,
104 () -> {
105 CatchExceptionTest test = factory.nextTest();
106 if (test != null) {
107 test.runTest();
108 return true;
109 }
110 return false;
111 });
112 for (CatchExceptionTest test : TestFactory.MANDATORY_TEST_CASES) {
113 test.runTest();
114 }
115 runner.call();
116 }
117
118 private List<Class<?>> getThrowerParams(boolean isVararg, int argsCount) {
119 return Helper.getParams(ARGS_CLASSES, isVararg, argsCount);
120 }
121
122
123 private List<Class<?>> getCatcherParams() {
124 int catchArgc = 1 + this.argsCount - dropped;
125 List<Class<?>> result = new ArrayList<>(
126 thrower.type().parameterList().subList(0, catchArgc - 1));
127 // prepend throwable
128 result.add(0, testCase.throwableClass);
129 return result;
130 }
131
132 private void runTest() {
133 Helper.clear();
134
135 Object[] args = Helper.randomArgs(
|