Skip to content

Commit 535e8be

Browse files
author
SendaoYan
committed
8371948: TestStackOverflowDuringInit.java fails xss too small on linux-aarch64
Reviewed-by: dholmes Backport-of: 360777c
1 parent 3db9a5a commit 535e8be

File tree

5 files changed

+62
-28
lines changed

5 files changed

+62
-28
lines changed

src/hotspot/share/prims/whitebox.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ WB_ENTRY(jint, WB_TakeLockAndHangInSafepoint(JNIEnv* env, jobject wb))
199199
return 0;
200200
WB_END
201201

202+
WB_ENTRY(jlong, WB_GetMinimumJavaStackSize(JNIEnv* env, jobject o))
203+
return os::get_minimum_java_stack_size();
204+
WB_END
205+
202206
class WBIsKlassAliveClosure : public LockedClassesDo {
203207
Symbol* _name;
204208
int _count;
@@ -3133,7 +3137,8 @@ static JNINativeMethod methods[] = {
31333137
{CC"cleanMetaspaces", CC"()V", (void*)&WB_CleanMetaspaces},
31343138
{CC"rss", CC"()J", (void*)&WB_Rss},
31353139
{CC"printString", CC"(Ljava/lang/String;I)Ljava/lang/String;", (void*)&WB_PrintString},
3136-
{CC"lockAndStuckInSafepoint", CC"()V", (void*)&WB_TakeLockAndHangInSafepoint},
3140+
{CC"lockAndStuckInSafepoint", CC"()V", (void*)&WB_TakeLockAndHangInSafepoint},
3141+
{CC"getMinimumJavaStackSize", CC"()J", (void*)&WB_GetMinimumJavaStackSize},
31373142
{CC"wordSize", CC"()J", (void*)&WB_WordSize},
31383143
{CC"rootChunkWordSize", CC"()J", (void*)&WB_RootChunkWordSize},
31393144
{CC"isStatic", CC"()Z", (void*)&WB_IsStaticallyLinked},

src/hotspot/share/runtime/os.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,6 +2577,10 @@ jint os::set_minimum_stack_sizes() {
25772577
return JNI_OK;
25782578
}
25792579

2580+
jlong os::get_minimum_java_stack_size() {
2581+
return static_cast<jlong>(_java_thread_min_stack_allowed);
2582+
}
2583+
25802584
// Builds a platform dependent Agent_OnLoad_<lib_name> function name
25812585
// which is used to find statically linked in agents.
25822586
// Parameters:

src/hotspot/share/runtime/os.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ class os: AllStatic {
390390
static jint set_minimum_stack_sizes();
391391

392392
public:
393+
// get allowed minimum java stack size
394+
static jlong get_minimum_java_stack_size();
393395
// Find committed memory region within specified range (start, start + size),
394396
// return true if found any
395397
static bool committed_in_range(address start, size_t size, address& committed_start, size_t& committed_size);

test/hotspot/jtreg/runtime/ClassInitErrors/TestStackOverflowDuringInit.java

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,16 +29,25 @@
2929
* cause, even if we can't create the ExceptionInInitializerError
3030
* @comment This test could easily be perturbed so don't allow flag settings.
3131
* @requires vm.flagless
32+
* @library /test/lib
3233
* @comment Run with the smallest stack possible to limit the execution time.
3334
* This is the smallest stack that is supported by all platforms.
34-
* @run main/othervm -Xss384K -Xint TestStackOverflowDuringInit
35+
* @build jdk.test.whitebox.WhiteBox
36+
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
37+
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestStackOverflowDuringInit
3538
*/
3639

3740
import java.io.ByteArrayOutputStream;
3841
import java.io.PrintStream;
42+
import jdk.test.lib.process.OutputAnalyzer;
43+
import jdk.test.lib.process.ProcessTools;
44+
import jdk.test.whitebox.WhiteBox;
3945

4046
public class TestStackOverflowDuringInit {
4147

48+
static String expected = "java.lang.NoClassDefFoundError: Could not initialize class TestStackOverflowDuringInit$LongCache";
49+
static String cause = "Caused by: java.lang.StackOverflowError";
50+
4251
// The setup for this is somewhat intricate. We need to trigger a
4352
// StackOverflowError during execution of the static initializer
4453
// for a class, but we need there to be insufficient stack left
@@ -88,34 +97,47 @@ static void recurse() {
8897
}
8998
}
9099

91-
public static void main(String[] args) throws Exception {
92-
String expected = "java.lang.NoClassDefFoundError: Could not initialize class TestStackOverflowDuringInit$LongCache";
93-
String cause = "Caused by: java.lang.StackOverflowError";
100+
static class Launcher {
101+
public static void main(String[] args) throws Exception {
94102

95-
// Pre-load, but not initialize, LongCache, else we will
96-
// hit SOE during class loading.
97-
System.out.println("Pre-loading ...");
98-
Class<?> c = Class.forName("TestStackOverflowDuringInit$LongCache",
99-
false,
100-
TestStackOverflowDuringInit.class.getClassLoader());
101-
try {
102-
recurse();
103-
} catch (Throwable ex) {
104-
// ex.printStackTrace();
105-
verify_stack(ex, expected, cause);
103+
// Pre-load, but not initialize, LongCache, else we will
104+
// hit SOE during class loading.
105+
System.out.println("Pre-loading ...");
106+
Class<?> c = Class.forName("TestStackOverflowDuringInit$LongCache",
107+
false,
108+
TestStackOverflowDuringInit.class.getClassLoader());
109+
try {
110+
recurse();
111+
} catch (Throwable ex) {
112+
// ex.printStackTrace();
113+
verify_stack(ex, expected, cause);
114+
}
106115
}
107-
}
108116

109-
private static void verify_stack(Throwable e, String expected, String cause) throws Exception {
110-
ByteArrayOutputStream byteOS = new ByteArrayOutputStream();
111-
try (PrintStream printStream = new PrintStream(byteOS)) {
112-
e.printStackTrace(printStream);
113-
}
114-
String stackTrace = byteOS.toString("ASCII");
115-
System.out.println(stackTrace);
116-
if (!stackTrace.contains(expected) ||
117-
(cause != null && !stackTrace.contains(cause))) {
118-
throw new RuntimeException(expected + " and/or " + cause + " missing from stacktrace");
117+
private static void verify_stack(Throwable e, String expected, String cause) throws Exception {
118+
ByteArrayOutputStream byteOS = new ByteArrayOutputStream();
119+
try (PrintStream printStream = new PrintStream(byteOS)) {
120+
e.printStackTrace(printStream);
121+
}
122+
String stackTrace = byteOS.toString("ASCII");
123+
System.out.println(stackTrace);
124+
if (!stackTrace.contains(expected) ||
125+
(cause != null && !stackTrace.contains(cause))) {
126+
throw new RuntimeException(expected + " and/or " + cause + " missing from stacktrace");
127+
}
119128
}
120129
}
130+
131+
public static void main(String[] args) throws Exception {
132+
WhiteBox wb = WhiteBox.getWhiteBox();
133+
long minimumJavaStackSize = wb.getMinimumJavaStackSize();
134+
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
135+
"-Xss" + Long.toString(minimumJavaStackSize), "-Xint",
136+
Launcher.class.getName());
137+
138+
OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
139+
analyzer.shouldHaveExitValue(0);
140+
analyzer.shouldContain(expected);
141+
analyzer.shouldContain(cause);
142+
}
121143
}

test/lib/jdk/test/whitebox/WhiteBox.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public long getObjectAddress(Object o) {
7777
public native long getVMLargePageSize();
7878
public native long getHeapSpaceAlignment();
7979
public native long getHeapAlignment();
80+
public native long getMinimumJavaStackSize();
8081

8182
public native boolean shipsFullDebugInfo();
8283
public native boolean shipsPublicDebugInfo();

0 commit comments

Comments
 (0)