author | lana |
Thu, 12 May 2016 15:15:02 +0000 | |
changeset 37915 | be4ff50b6cb6 |
parent 36209 | 8db2a78cbc29 |
child 38152 | 80e5da81fb2c |
permissions | -rw-r--r-- |
35071
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
1 |
/* |
36209
8db2a78cbc29
8151156: [TESTBUG] Integrate trivial Hotspot test changes from Jake before Jigsaw M3
ctornqvi
parents:
35188
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
35071
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
4 |
* |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
8 |
* |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
13 |
* accompanied this code). |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
14 |
* |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
18 |
* |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
21 |
* questions. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
22 |
*/ |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
23 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
24 |
/* |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
25 |
* @test ReservedStackTest |
35188
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
26 |
* @library /testlibrary |
36209
8db2a78cbc29
8151156: [TESTBUG] Integrate trivial Hotspot test changes from Jake before Jigsaw M3
ctornqvi
parents:
35188
diff
changeset
|
27 |
* @modules java.base/jdk.internal.vm.annotation |
35188
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
28 |
* @build jdk.test.lib.* |
35071
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
29 |
* @run main/othervm -XX:-Inline -XX:CompileCommand=exclude,java/util/concurrent/locks/AbstractOwnableSynchronizer.setExclusiveOwnerThread ReservedStackTest |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
30 |
*/ |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
31 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
32 |
/* The exclusion of java.util.concurrent.locks.AbstractOwnableSynchronizer.setExclusiveOwnerThread() |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
33 |
* from the compilable methods is required to ensure that the test will be able |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
34 |
* to trigger a StackOverflowError on the right method. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
35 |
*/ |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
36 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
37 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
38 |
/* |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
39 |
* Notes about this test: |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
40 |
* This test tries to reproduce a rare but nasty corruption bug that |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
41 |
* occurs when a StackOverflowError is thrown in some critical sections |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
42 |
* of the ReentrantLock implementation. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
43 |
* |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
44 |
* Here's the critical section where a corruption could occur |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
45 |
* (from java.util.concurrent.ReentrantLock.java) |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
46 |
* |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
47 |
* final void lock() { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
48 |
* if (compareAndSetState(0, 1)) |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
49 |
* setExclusiveOwnerThread(Thread.currentThread()); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
50 |
* else |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
51 |
* acquire(1); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
52 |
* } |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
53 |
* |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
54 |
* The corruption occurs when the compareAndSetState(0, 1) |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
55 |
* successfully updates the status of the lock but the method |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
56 |
* fails to set the owner because of a stack overflow. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
57 |
* HotSpot checks for stack overflow on method invocations. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
58 |
* The test must trigger a stack overflow either when |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
59 |
* Thread.currentThread() or setExclusiveOwnerThread() is |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
60 |
* invoked. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
61 |
* |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
62 |
* The test starts with a recursive invocation loop until a |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
63 |
* first StackOverflowError is thrown, the Error is caught |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
64 |
* and a few dozen frames are exited. Now the thread has |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
65 |
* little free space on its execution stack and will try |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
66 |
* to trigger a stack overflow in the critical section. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
67 |
* The test has a huge array of ReentrantLocks instances. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
68 |
* The thread invokes a recursive method which, at each |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
69 |
* of its invocations, tries to acquire the next lock |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
70 |
* in the array. The execution continues until a |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
71 |
* StackOverflowError is thrown or the end of the array |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
72 |
* is reached. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
73 |
* If no StackOverflowError has been thrown, the test |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
74 |
* is non conclusive (recommendation: increase the size |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
75 |
* of the ReentrantLock array). |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
76 |
* The status of all Reentrant locks in the array is checked, |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
77 |
* if a corruption is detected, the test failed, otherwise |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
78 |
* the test passed. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
79 |
* |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
80 |
* To have a chance that the stack overflow occurs on one |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
81 |
* of the two targeted method invocations, the test is |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
82 |
* repeated in different threads. Each Java thread has a |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
83 |
* random size area allocated at the beginning of its |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
84 |
* stack to prevent false sharing. The test relies on this |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
85 |
* to have different stack alignments when it hits the targeted |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
86 |
* methods (the test could have been written with a native |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
87 |
* method with alloca, but using different Java threads makes |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
88 |
* the test 100% Java). |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
89 |
* |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
90 |
* One additional trick is required to ensure that the stack |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
91 |
* overflow will occur on the Thread.currentThread() getter |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
92 |
* or the setExclusiveOwnerThread() setter. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
93 |
* |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
94 |
* Potential stack overflows are detected by stack banging, |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
95 |
* at method invocation time. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
96 |
* In interpreted code, the stack banging performed for the |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
97 |
* lock() method goes further than the stack banging performed |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
98 |
* for the getter or the setter method, so the potential stack |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
99 |
* overflow is detected before entering the critical section. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
100 |
* In compiled code, the getter and the setter are in-lined, |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
101 |
* so the stack banging is only performed before entering the |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
102 |
* critical section. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
103 |
* In order to have a stack banging that goes further for the |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
104 |
* getter/setter methods than for the lock() method, the test |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
105 |
* exploits the property that interpreter frames are (much) |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
106 |
* bigger than compiled code frames. When the test is run, |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
107 |
* a compiler option disables the compilation of the |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
108 |
* setExclusiveOwnerThread() method. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
109 |
* |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
110 |
*/ |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
111 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
112 |
import java.util.concurrent.locks.ReentrantLock; |
35188
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
113 |
import jdk.test.lib.Platform; |
35071
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
114 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
115 |
public class ReservedStackTest { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
116 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
117 |
static class ReentrantLockTest { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
118 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
119 |
private ReentrantLock lockArray[]; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
120 |
// Frame sizes vary a lot between interpreted code and compiled code |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
121 |
// so the lock array has to be big enough to cover all cases. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
122 |
// If test fails with message "Not conclusive test", try to increase |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
123 |
// LOCK_ARRAY_SIZE value |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
124 |
private static final int LOCK_ARRAY_SIZE = 8192; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
125 |
private boolean stackOverflowErrorReceived; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
126 |
StackOverflowError soe = null; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
127 |
private int index = -1; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
128 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
129 |
public void initialize() { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
130 |
lockArray = new ReentrantLock[LOCK_ARRAY_SIZE]; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
131 |
for (int i = 0; i < LOCK_ARRAY_SIZE; i++) { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
132 |
lockArray[i] = new ReentrantLock(); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
133 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
134 |
stackOverflowErrorReceived = false; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
135 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
136 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
137 |
public String getResult() { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
138 |
if (!stackOverflowErrorReceived) { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
139 |
return "ERROR: Not conclusive test: no StackOverflowError received"; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
140 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
141 |
for (int i = 0; i < LOCK_ARRAY_SIZE; i++) { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
142 |
if (lockArray[i].isLocked()) { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
143 |
if (!lockArray[i].isHeldByCurrentThread()) { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
144 |
StringBuilder s = new StringBuilder(); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
145 |
s.append("FAILED: ReentrantLock "); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
146 |
s.append(i); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
147 |
s.append(" looks corrupted"); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
148 |
return s.toString(); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
149 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
150 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
151 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
152 |
return "PASSED"; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
153 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
154 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
155 |
public void run() { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
156 |
try { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
157 |
lockAndCall(0); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
158 |
} catch (StackOverflowError e) { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
159 |
soe = e; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
160 |
stackOverflowErrorReceived = true; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
161 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
162 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
163 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
164 |
private void lockAndCall(int i) { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
165 |
index = i; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
166 |
if (i < LOCK_ARRAY_SIZE) { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
167 |
lockArray[i].lock(); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
168 |
lockAndCall(i + 1); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
169 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
170 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
171 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
172 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
173 |
static class RunWithSOEContext implements Runnable { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
174 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
175 |
int counter; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
176 |
int deframe; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
177 |
int decounter; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
178 |
int setupSOEFrame; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
179 |
int testStartFrame; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
180 |
ReentrantLockTest test; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
181 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
182 |
public RunWithSOEContext(ReentrantLockTest test, int deframe) { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
183 |
this.test = test; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
184 |
this.deframe = deframe; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
185 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
186 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
187 |
@Override |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
188 |
@jdk.internal.vm.annotation.ReservedStackAccess |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
189 |
public void run() { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
190 |
counter = 0; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
191 |
decounter = deframe; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
192 |
test.initialize(); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
193 |
recursiveCall(); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
194 |
System.out.println("Framework got StackOverflowError at frame = " + counter); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
195 |
System.out.println("Test started execution at frame = " + (counter - deframe)); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
196 |
String result = test.getResult(); |
35188
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
197 |
// The feature is not fully implemented on all platforms, |
35071
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
198 |
// corruptions are still possible |
35188
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
199 |
boolean supportedPlatform = Platform.isSolaris() || Platform.isOSX() |
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
200 |
|| (Platform.isLinux() && (Platform.isX86() || Platform.isX64())); |
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
201 |
if (supportedPlatform && !result.contains("PASSED")) { |
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
202 |
System.out.println(result); |
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
203 |
throw new Error(result); |
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
204 |
} else { |
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
205 |
// Either the test passed or this platform is not supported. |
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
206 |
// On not supported platforms, we only expect the VM to |
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
207 |
// not crash during the test. This is especially important |
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
208 |
// on Windows where the detection of SOE in annotated |
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
209 |
// sections is implemented but the reserved zone mechanism |
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
210 |
// to avoid the corruption cannot be implemented yet |
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
211 |
// because of JDK-8067946 |
c058f99ad8fe
8145317: ReservedStackTest fails with ReentrantLock looks corrupted
fparain
parents:
35071
diff
changeset
|
212 |
System.out.println("PASSED"); |
35071
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
213 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
214 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
215 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
216 |
void recursiveCall() { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
217 |
// Unused local variables to increase the frame size |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
218 |
long l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15, l16, l17, l18, l19; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
219 |
long l20, l21, l22, l23, l24, l25, l26, l27, l28, l30, l31, l32, l33, l34, l35, l36, l37; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
220 |
counter++; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
221 |
try { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
222 |
recursiveCall(); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
223 |
} catch (StackOverflowError e) { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
224 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
225 |
decounter--; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
226 |
if (decounter == 0) { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
227 |
setupSOEFrame = counter; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
228 |
testStartFrame = counter - deframe; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
229 |
test.run(); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
230 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
231 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
232 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
233 |
|
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
234 |
public static void main(String[] args) { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
235 |
for (int i = 0; i < 1000; i++) { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
236 |
// Each iteration has to be executed by a new thread. The test |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
237 |
// relies on the random size area pushed by the VM at the beginning |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
238 |
// of the stack of each Java thread it creates. |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
239 |
Thread thread = new Thread(new RunWithSOEContext(new ReentrantLockTest(), 256)); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
240 |
thread.start(); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
241 |
try { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
242 |
thread.join(); |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
243 |
} catch (InterruptedException ex) { } |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
244 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
245 |
} |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
diff
changeset
|
246 |
} |