1 /*
2 * Copyright (c) 2018, 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.
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
24
25 package org.graalvm.compiler.hotspot.test;
26
27 import java.io.IOException;
28 import java.util.concurrent.locks.ReentrantLock;
29 import java.util.List;
30
31 import org.graalvm.compiler.test.SubprocessUtil;
32 import org.graalvm.compiler.test.SubprocessUtil.Subprocess;
33
34 import org.junit.Assume;
35 import org.junit.Before;
36 import org.junit.Test;
37
38 public class ReservedStackAccessTest extends HotSpotGraalCompilerTest {
39 @Before
40 public void check() {
41 Assume.assumeTrue(runtime().getVMConfig().enableStackReservedZoneAddress != 0);
42 }
43
44 public void stackAccessTest() {
45 Assume.assumeTrue(runtime().getVMConfig().enableStackReservedZoneAddress != 0);
46
47 int passed = 0;
48 for (int i = 0; i < 1000; i++) {
49 // Each iteration has to be executed by a new thread. The test
50 // relies on the random size area pushed by the VM at the beginning
51 // of the stack of each Java thread it creates.
52 RunWithSOEContext r = new RunWithSOEContext(new ReentrantLockTest(), 256);
53 Thread thread = new Thread(r);
56 thread.join();
57 assertTrue(r.result.equals("PASSED"), r.result);
58 ++passed;
59 } catch (InterruptedException ex) {
60 }
61 }
62 System.out.println("RESULT: " + (passed == 1000 ? "PASSED" : "FAILED"));
63 }
64
65 public static void main(String[] args) {
66 new ReservedStackAccessTest().stackAccessTest();
67 }
68
69 @Test
70 public void run() throws IOException, InterruptedException {
71 Assume.assumeTrue(runtime().getVMConfig().enableStackReservedZoneAddress != 0);
72 List<String> vmArgs = SubprocessUtil.withoutDebuggerArguments(SubprocessUtil.getVMCommandLine());
73 vmArgs.add("-XX:+UseJVMCICompiler");
74 vmArgs.add("-Dgraal.Inline=false");
75 vmArgs.add("-XX:CompileCommand=exclude,java/util/concurrent/locks/AbstractOwnableSynchronizer.setExclusiveOwnerThread");
76
77 // Avoid SOE in HotSpotJVMCIRuntime.adjustCompilationLevel
78 vmArgs.add("-Dgraal.CompileGraalWithC1Only=false");
79
80 Subprocess proc = SubprocessUtil.java(vmArgs, ReservedStackAccessTest.class.getName());
81 boolean passed = false;
82 for (String line : proc.output) {
83 if (line.equals("RESULT: PASSED")) {
84 passed = true;
85 }
86 }
87 if (!passed) {
88 System.err.println(proc);
89 }
90 assertTrue(passed);
91 }
92
93 static class ReentrantLockTest {
94
95 private ReentrantLock[] lockArray;
|
1 /*
2 * Copyright (c) 2018, 2019, 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.
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
24
25 package org.graalvm.compiler.hotspot.test;
26
27 import java.io.IOException;
28 import java.util.List;
29 import java.util.concurrent.locks.ReentrantLock;
30
31 import org.graalvm.compiler.test.SubprocessUtil;
32 import org.graalvm.compiler.test.SubprocessUtil.Subprocess;
33 import org.junit.Assume;
34 import org.junit.Before;
35 import org.junit.Test;
36
37 public class ReservedStackAccessTest extends HotSpotGraalCompilerTest {
38 @Before
39 public void check() {
40 Assume.assumeTrue(runtime().getVMConfig().enableStackReservedZoneAddress != 0);
41 }
42
43 public void stackAccessTest() {
44 Assume.assumeTrue(runtime().getVMConfig().enableStackReservedZoneAddress != 0);
45
46 int passed = 0;
47 for (int i = 0; i < 1000; i++) {
48 // Each iteration has to be executed by a new thread. The test
49 // relies on the random size area pushed by the VM at the beginning
50 // of the stack of each Java thread it creates.
51 RunWithSOEContext r = new RunWithSOEContext(new ReentrantLockTest(), 256);
52 Thread thread = new Thread(r);
55 thread.join();
56 assertTrue(r.result.equals("PASSED"), r.result);
57 ++passed;
58 } catch (InterruptedException ex) {
59 }
60 }
61 System.out.println("RESULT: " + (passed == 1000 ? "PASSED" : "FAILED"));
62 }
63
64 public static void main(String[] args) {
65 new ReservedStackAccessTest().stackAccessTest();
66 }
67
68 @Test
69 public void run() throws IOException, InterruptedException {
70 Assume.assumeTrue(runtime().getVMConfig().enableStackReservedZoneAddress != 0);
71 List<String> vmArgs = SubprocessUtil.withoutDebuggerArguments(SubprocessUtil.getVMCommandLine());
72 vmArgs.add("-XX:+UseJVMCICompiler");
73 vmArgs.add("-Dgraal.Inline=false");
74 vmArgs.add("-XX:CompileCommand=exclude,java/util/concurrent/locks/AbstractOwnableSynchronizer.setExclusiveOwnerThread");
75 vmArgs.addAll(SubprocessUtil.getPackageOpeningOptions());
76
77 // Avoid SOE in HotSpotJVMCIRuntime.adjustCompilationLevel
78 vmArgs.add("-Dgraal.CompileGraalWithC1Only=false");
79
80 Subprocess proc = SubprocessUtil.java(vmArgs, ReservedStackAccessTest.class.getName());
81 boolean passed = false;
82 for (String line : proc.output) {
83 if (line.equals("RESULT: PASSED")) {
84 passed = true;
85 }
86 }
87 if (!passed) {
88 System.err.println(proc);
89 }
90 assertTrue(passed);
91 }
92
93 static class ReentrantLockTest {
94
95 private ReentrantLock[] lockArray;
|