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