Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/invoke/LoopCombinatorLongSignatureTest.java
41149 views
1
/*
2
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
/* @test
27
* @bug 8160717
28
* @run main/othervm -ea -esa -Djava.lang.invoke.MethodHandle.COMPILE_THRESHOLD=-1 test.java.lang.invoke.LoopCombinatorLongSignatureTest
29
* @run main/othervm -ea -esa test.java.lang.invoke.LoopCombinatorLongSignatureTest
30
*/
31
32
package test.java.lang.invoke;
33
34
import java.lang.invoke.MethodHandle;
35
import java.lang.invoke.MethodHandles;
36
import java.util.Arrays;
37
38
/**
39
* If a loop with an excessive amount of clauses is created, so that the number of parameters to the resulting loop
40
* handle exceeds the allowed maximum, an IAE must be signalled. The test is run first in LambdaForm interpretation mode
41
* and then in default mode, wherein bytecode generation falls back to LFI mode due to excessively long methods.
42
* <p>
43
* By default, the test run only checks whether loop handle construction succeeds and fails. If executing the generated
44
* loops is desired, this should be indicated by setting the {@code java.lang.invoke.LoopCombinatorLongSignatureTest.RUN}
45
* environment variable to {@code true}. This is disabled by default as it considerably increases the time needed to run
46
* the test.
47
*/
48
public class LoopCombinatorLongSignatureTest {
49
50
static final MethodHandle INIT = MethodHandles.constant(int.class, 0);
51
static final MethodHandle STEP = MethodHandles.identity(int.class);
52
static final MethodHandle PRED_F = MethodHandles.constant(boolean.class, false);
53
static final MethodHandle PRED_T = MethodHandles.constant(boolean.class, true);
54
static final MethodHandle FINI = MethodHandles.identity(int.class);
55
56
static final int ARG_LIMIT = 254; // for internal reasons, this is the maximum allowed number of arguments
57
58
public static void main(String[] args) {
59
boolean run = Boolean.parseBoolean(
60
System.getProperty("java.lang.invoke.LoopCombinatorLongSignatureTest.RUN", "false"));
61
for (int loopArgs = 0; loopArgs < 2; ++loopArgs) {
62
testLongSignature(loopArgs, false, run);
63
testLongSignature(loopArgs, true, run);
64
}
65
}
66
67
static void testLongSignature(int loopArgs, boolean excessive, boolean run) {
68
int nClauses = ARG_LIMIT - loopArgs + (excessive ? 1 : 0);
69
70
System.out.print((excessive ? "(EXCESSIVE)" : "(LONG )") + " arguments: " + loopArgs + ", clauses: " + nClauses + " -> ");
71
72
// extend init to denote what arguments the loop should accept
73
Class<?>[] argTypes = new Class<?>[loopArgs];
74
Arrays.fill(argTypes, int.class);
75
MethodHandle init = MethodHandles.dropArguments(INIT, 0, argTypes);
76
77
// build clauses
78
MethodHandle[][] clauses = new MethodHandle[nClauses][];
79
MethodHandle[] clause = {init, STEP, PRED_T, FINI};
80
MethodHandle[] fclause = {init, STEP, PRED_F, FINI};
81
Arrays.fill(clauses, clause);
82
clauses[nClauses - 1] = fclause; // make the last clause terminate the loop
83
84
try {
85
MethodHandle loop = MethodHandles.loop(clauses);
86
if (excessive) {
87
throw new AssertionError("loop construction should have failed");
88
} else if (run) {
89
int r;
90
if (loopArgs == 0) {
91
r = (int) loop.invoke();
92
} else {
93
Object[] args = new Object[loopArgs];
94
Arrays.fill(args, 0);
95
r = (int) loop.invokeWithArguments(args);
96
}
97
System.out.println("SUCCEEDED (OK) -> " + r);
98
} else {
99
System.out.println("SUCCEEDED (OK)");
100
}
101
} catch (IllegalArgumentException iae) {
102
if (excessive) {
103
System.out.println("FAILED (OK)");
104
} else {
105
iae.printStackTrace(System.out);
106
throw new AssertionError("loop construction should not have failed (see above)");
107
}
108
} catch (Throwable t) {
109
t.printStackTrace(System.out);
110
throw new AssertionError("unexpected failure (see above)");
111
}
112
}
113
114
}
115
116