Skip to content

Commit cfe0717

Browse files
author
duke
committed
Backport fc8038441daebc717fedaeb107e37bf216d542d3
1 parent c168d3b commit cfe0717

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

test/hotspot/jtreg/runtime/Thread/ThreadCountLimit.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 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
@@ -73,14 +73,27 @@ public static void main(String[] args) throws Exception {
7373
if (Platform.isLinux()) {
7474
// On Linux this test sometimes hits the limit for the maximum number of memory mappings,
7575
// which leads to various other failure modes. Run this test with a limit on how many
76-
// threads the process is allowed to create, so we hit that limit first.
77-
78-
final String ULIMIT_CMD = "ulimit -u 4096";
76+
// threads the process is allowed to create, so we hit that limit first. What we want is
77+
// for another "limit" processes to be available, but ulimit doesn't work that way and
78+
// if there are already many running processes we could fail to even start the JVM properly.
79+
// So we loop increasing the limit until we get a successful run. This is not foolproof.
80+
int pLimit = 4096;
81+
final String ULIMIT_CMD = "ulimit -u ";
7982
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(ThreadCountLimit.class.getName());
8083
String javaCmd = ProcessTools.getCommandLine(pb);
81-
// Relaunch the test with args.length > 0, and the ulimit set
82-
ProcessTools.executeCommand("bash", "-c", ULIMIT_CMD + " && " + javaCmd + " dummy")
83-
.shouldHaveExitValue(0);
84+
for (int i = 1; i <= 10; i++) {
85+
// Relaunch the test with args.length > 0, and the ulimit set
86+
String cmd = ULIMIT_CMD + Integer.toString(pLimit * i) + " && " + javaCmd + " dummy";
87+
System.out.println("Trying: bash -c " + cmd);
88+
OutputAnalyzer oa = ProcessTools.executeCommand("bash", "-c", cmd);
89+
int exitValue = oa.getExitValue();
90+
switch (exitValue) {
91+
case 0: System.out.println("Success!"); return;
92+
case 1: System.out.println("Retry ..."); continue;
93+
default: oa.shouldHaveExitValue(0); // generate error report
94+
}
95+
}
96+
throw new Error("Failed to perform a successful run!");
8497
} else {
8598
// Not Linux so run directly.
8699
test();

0 commit comments

Comments
 (0)