< prev index next >
test/runtime/ReservedStack/ReservedStackTest.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -110,10 +110,12 @@
*
*/
import java.util.concurrent.locks.ReentrantLock;
import jdk.test.lib.Platform;
+import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.process.OutputAnalyzer;
public class ReservedStackTest {
static class ReentrantLockTest {
@@ -195,18 +197,11 @@
System.out.println("Framework got StackOverflowError at frame = " + counter);
System.out.println("Test started execution at frame = " + (counter - deframe));
String result = test.getResult();
// The feature is not fully implemented on all platforms,
// corruptions are still possible.
- boolean supportedPlatform =
- Platform.isAix() ||
- (Platform.isLinux() &&
- (Platform.isPPC() || Platform.isS390x() || Platform.isX64() ||
- Platform.isX86() || Platform.isAArch64())) ||
- Platform.isOSX() ||
- Platform.isSolaris();
- if (supportedPlatform && !result.contains("PASSED")) {
+ if (isSupportedPlatform && !result.contains("PASSED")) {
System.out.println(result);
throw new Error(result);
} else {
// Either the test passed or this platform is not supported.
// On not supported platforms, we only expect the VM to
@@ -235,11 +230,67 @@
test.run();
}
}
}
- public static void main(String[] args) {
+ public static boolean isAlwaysSupportedPlatform() {
+ // Note: To date Aarch64 is the only platform that we don't statically
+ // know if it supports the reserved stack area. This is because the
+ // open Aarch64 port supports it and the Oracle arm64 port does not.
+ return Platform.isAix() ||
+ (Platform.isLinux() &&
+ (Platform.isPPC() || Platform.isS390x() || Platform.isX64() ||
+ Platform.isX86())) ||
+ Platform.isOSX() ||
+ Platform.isSolaris();
+ }
+
+ public static boolean isNeverSupportedPlatform() {
+ return !isAlwaysSupportedPlatform() && !Platform.isAArch64();
+ }
+
+ public static boolean isSupportedPlatform;
+
+ public static void initIsSupportedPlatform() throws Exception {
+ // In order to dynamicaly determine if the platform supports the reserved
+ // stack area, run with -XX:StackReservedPages=1 and see if we get the
+ // expected warning message for platforms that don't support it.
+ ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:StackReservedPages=1", "-version");
+ OutputAnalyzer output = new OutputAnalyzer(pb.start());
+ System.out.println("StackReservedPages=1 log: [" + output.getOutput() + "]");
+ if (output.getExitValue() != 0) {
+ String msg = "Could not launch with -XX:StackReservedPages=1: exit " + output.getExitValue();
+ System.err.println("FAILED: " + msg);
+ throw new RuntimeException(msg);
+ }
+
+ boolean isSupportedPlatform = true;
+ String matchStr = "Reserved Stack Area not supported on this platform";
+ int match_idx = output.getOutput().indexOf(matchStr);
+ if (match_idx >= 0) {
+ isSupportedPlatform = false;
+ }
+
+ // Do a sanity check. Some platforms we know are always supported. Make sure
+ // we didn't determine that one of those platforms is not supported.
+ if (!isSupportedPlatform && isAlwaysSupportedPlatform()) {
+ String msg = "This platform should be supported: " + Platform.getOsArch();
+ System.err.println("FAILED: " + msg);
+ throw new RuntimeException(msg);
+ }
+
+ // And some platforms we know are never supported. Make sure
+ // we didn't determine that one of those platforms is supported.
+ if (isSupportedPlatform && isNeverSupportedPlatform()) {
+ String msg = "This platform should not be supported: " + Platform.getOsArch();
+ System.err.println("FAILED: " + msg);
+ throw new RuntimeException(msg);
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ initIsSupportedPlatform();
for (int i = 0; i < 1000; i++) {
// Each iteration has to be executed by a new thread. The test
// relies on the random size area pushed by the VM at the beginning
// of the stack of each Java thread it creates.
Thread thread = new Thread(new RunWithSOEContext(new ReentrantLockTest(), 256));
< prev index next >