|
1 | 1 | /* |
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * 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 { |
73 | 73 | if (Platform.isLinux()) { |
74 | 74 | // On Linux this test sometimes hits the limit for the maximum number of memory mappings, |
75 | 75 | // 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 "; |
79 | 82 | ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(ThreadCountLimit.class.getName()); |
80 | 83 | 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!"); |
84 | 97 | } else { |
85 | 98 | // Not Linux so run directly. |
86 | 99 | test(); |
|
0 commit comments