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
24 /*
25 * @test ReservedStackTest
26 * @library /test/lib
27 * @modules java.base/jdk.internal.misc
28 * @modules java.base/jdk.internal.vm.annotation
29 * @run main/othervm -Xint ReservedStackTest
30 * @run main/othervm -XX:-Inline -XX:CompileCommand=exclude,java/util/concurrent/locks/AbstractOwnableSynchronizer.setExclusiveOwnerThread ReservedStackTest
31 */
32
33 /* The exclusion of java.util.concurrent.locks.AbstractOwnableSynchronizer.setExclusiveOwnerThread()
34 * from the compilable methods is required to ensure that the test will be able
35 * to trigger a StackOverflowError on the right method.
36 */
37
38
39 /*
40 * Notes about this test:
41 * This test tries to reproduce a rare but nasty corruption bug that
42 * occurs when a StackOverflowError is thrown in some critical sections
43 * of the ReentrantLock implementation.
44 *
45 * Here's the critical section where a corruption could occur
46 * (from java.util.concurrent.ReentrantLock.java)
47 *
48 * final void lock() {
49 * if (compareAndSetState(0, 1))
50 * setExclusiveOwnerThread(Thread.currentThread());
144 for (int i = 0; i < LOCK_ARRAY_SIZE; i++) {
145 if (lockArray[i].isLocked()) {
146 if (!lockArray[i].isHeldByCurrentThread()) {
147 StringBuilder s = new StringBuilder();
148 s.append("FAILED: ReentrantLock ");
149 s.append(i);
150 s.append(" looks corrupted");
151 return s.toString();
152 }
153 }
154 }
155 return "PASSED";
156 }
157
158 public void run() {
159 try {
160 lockAndCall(0);
161 } catch (StackOverflowError e) {
162 soe = e;
163 stackOverflowErrorReceived = true;
164 }
165 }
166
167 private void lockAndCall(int i) {
168 index = i;
169 if (i < LOCK_ARRAY_SIZE) {
170 lockArray[i].lock();
171 lockAndCall(i + 1);
172 }
173 }
174 }
175
176 static class RunWithSOEContext implements Runnable {
177
178 int counter;
179 int deframe;
180 int decounter;
181 int setupSOEFrame;
182 int testStartFrame;
183 ReentrantLockTest test;
184
185 public RunWithSOEContext(ReentrantLockTest test, int deframe) {
186 this.test = test;
187 this.deframe = deframe;
188 }
189
190 @Override
191 @jdk.internal.vm.annotation.ReservedStackAccess
192 public void run() {
193 counter = 0;
194 decounter = deframe;
195 test.initialize();
196 recursiveCall();
197 System.out.println("Framework got StackOverflowError at frame = " + counter);
198 System.out.println("Test started execution at frame = " + (counter - deframe));
199 String result = test.getResult();
200 // The feature is not fully implemented on all platforms,
201 // corruptions are still possible.
202 if (isSupportedPlatform && !result.contains("PASSED")) {
203 System.out.println(result);
204 throw new Error(result);
205 } else {
206 // Either the test passed or this platform is not supported.
207 // On not supported platforms, we only expect the VM to
208 // not crash during the test. This is especially important
209 // on Windows where the detection of SOE in annotated
210 // sections is implemented but the reserved zone mechanism
211 // to avoid the corruption cannot be implemented yet
212 // because of JDK-8067946
213 System.out.println("PASSED");
214 }
215 }
216
217 void recursiveCall() {
218 // Unused local variables to increase the frame size
219 long l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15, l16, l17, l18, l19;
220 long l20, l21, l22, l23, l24, l25, l26, l27, l28, l30, l31, l32, l33, l34, l35, l36, l37;
221 counter++;
222 try {
223 recursiveCall();
272
273 // Do a sanity check. Some platforms we know are always supported. Make sure
274 // we didn't determine that one of those platforms is not supported.
275 if (!isSupportedPlatform && isAlwaysSupportedPlatform()) {
276 String msg = "This platform should be supported: " + Platform.getOsArch();
277 System.err.println("FAILED: " + msg);
278 throw new RuntimeException(msg);
279 }
280
281 // And some platforms we know are never supported. Make sure
282 // we didn't determine that one of those platforms is supported.
283 if (isSupportedPlatform && isNeverSupportedPlatform()) {
284 String msg = "This platform should not be supported: " + Platform.getOsArch();
285 System.err.println("FAILED: " + msg);
286 throw new RuntimeException(msg);
287 }
288 }
289
290 public static void main(String[] args) throws Exception {
291 initIsSupportedPlatform();
292 for (int i = 0; i < 1000; i++) {
293 // Each iteration has to be executed by a new thread. The test
294 // relies on the random size area pushed by the VM at the beginning
295 // of the stack of each Java thread it creates.
296 Thread thread = new Thread(new RunWithSOEContext(new ReentrantLockTest(), 256));
297 thread.start();
298 try {
299 thread.join();
300 } catch (InterruptedException ex) { }
301 }
302 }
303 }
|
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
24 /*
25 * @test ReservedStackTest
26 * @library /test/lib
27 * @modules java.base/jdk.internal.misc
28 * @modules java.base/jdk.internal.vm.annotation
29 * @run main/othervm -XX:InlineSmallCode=4 -XX:CompileCommand=exclude,java/util/concurrent/locks/AbstractOwnableSynchronizer.setExclusiveOwnerThread ReservedStackTest
30 */
31
32 /* The exclusion of java.util.concurrent.locks.AbstractOwnableSynchronizer.setExclusiveOwnerThread()
33 * from the compilable methods is required to ensure that the test will be able
34 * to trigger a StackOverflowError on the right method.
35 */
36
37
38 /*
39 * Notes about this test:
40 * This test tries to reproduce a rare but nasty corruption bug that
41 * occurs when a StackOverflowError is thrown in some critical sections
42 * of the ReentrantLock implementation.
43 *
44 * Here's the critical section where a corruption could occur
45 * (from java.util.concurrent.ReentrantLock.java)
46 *
47 * final void lock() {
48 * if (compareAndSetState(0, 1))
49 * setExclusiveOwnerThread(Thread.currentThread());
143 for (int i = 0; i < LOCK_ARRAY_SIZE; i++) {
144 if (lockArray[i].isLocked()) {
145 if (!lockArray[i].isHeldByCurrentThread()) {
146 StringBuilder s = new StringBuilder();
147 s.append("FAILED: ReentrantLock ");
148 s.append(i);
149 s.append(" looks corrupted");
150 return s.toString();
151 }
152 }
153 }
154 return "PASSED";
155 }
156
157 public void run() {
158 try {
159 lockAndCall(0);
160 } catch (StackOverflowError e) {
161 soe = e;
162 stackOverflowErrorReceived = true;
163 throw e;
164 }
165 }
166
167 private void lockAndCall(int i) {
168 index = i;
169 if (i < LOCK_ARRAY_SIZE) {
170 lockArray[i].lock();
171 lockAndCall(i + 1);
172 }
173 }
174 }
175
176 static class RunWithSOEContext implements Runnable {
177
178 int counter;
179 int deframe;
180 int decounter;
181 int setupSOEFrame;
182 int testStartFrame;
183 ReentrantLockTest test;
184
185 public RunWithSOEContext(ReentrantLockTest test, int deframe) {
186 this.test = test;
187 this.deframe = deframe;
188 }
189
190 @Override
191 @jdk.internal.vm.annotation.ReservedStackAccess
192 public void run() {
193 counter = 0;
194 decounter = deframe;
195 test.initialize();
196 recursiveCall();
197 String result = test.getResult();
198 // The feature is not fully implemented on all platforms,
199 // corruptions are still possible.
200 if (isSupportedPlatform && !result.contains("PASSED")) {
201 throw new Error(result);
202 } else {
203 // Either the test passed or this platform is not supported.
204 // On not supported platforms, we only expect the VM to
205 // not crash during the test. This is especially important
206 // on Windows where the detection of SOE in annotated
207 // sections is implemented but the reserved zone mechanism
208 // to avoid the corruption cannot be implemented yet
209 // because of JDK-8067946
210 System.out.println("PASSED");
211 }
212 }
213
214 void recursiveCall() {
215 // Unused local variables to increase the frame size
216 long l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15, l16, l17, l18, l19;
217 long l20, l21, l22, l23, l24, l25, l26, l27, l28, l30, l31, l32, l33, l34, l35, l36, l37;
218 counter++;
219 try {
220 recursiveCall();
269
270 // Do a sanity check. Some platforms we know are always supported. Make sure
271 // we didn't determine that one of those platforms is not supported.
272 if (!isSupportedPlatform && isAlwaysSupportedPlatform()) {
273 String msg = "This platform should be supported: " + Platform.getOsArch();
274 System.err.println("FAILED: " + msg);
275 throw new RuntimeException(msg);
276 }
277
278 // And some platforms we know are never supported. Make sure
279 // we didn't determine that one of those platforms is supported.
280 if (isSupportedPlatform && isNeverSupportedPlatform()) {
281 String msg = "This platform should not be supported: " + Platform.getOsArch();
282 System.err.println("FAILED: " + msg);
283 throw new RuntimeException(msg);
284 }
285 }
286
287 public static void main(String[] args) throws Exception {
288 initIsSupportedPlatform();
289 for (int i = 0; i < 100; i++) {
290 // Each iteration has to be executed by a new thread. The test
291 // relies on the random size area pushed by the VM at the beginning
292 // of the stack of each Java thread it creates.
293 Thread thread = new Thread(new RunWithSOEContext(new ReentrantLockTest(), 256));
294 thread.start();
295 try {
296 thread.join();
297 } catch (InterruptedException ex) { }
298 }
299 }
300 }
|