/** *Returnsa{@codeulimit}commandthatwillallowforanunlimitedcorefilesize *iftheplatformsupportsit. * *@return{@codeString}fortheulimitcommandifsupportedbytheplatform, *otherwise{@codenull}.
*/ privatestatic String getCoreUlimitCommand() {
String result = null; try {
OutputAnalyzer output = ProcessTools.executeProcess("sh", "-c", RUN_SHELL_NO_LIMIT + "ulimit -c"); if (output.getExitValue() != 0) {
result = null;
} elseif (!output.getStdout().contains("unlimited")) {
result = null;
} else {
result = RUN_SHELL_NO_LIMIT; // success
}
} catch (Throwable t) {
System.out.println("Exception in getCoreUlimitCommand(): " + t.toString());
result = null;
}
System.out.println("Run test with ulimit -c: " +
(result == null ? "default" : "unlimited")); return result;
}
/** *Returna{@codeProcessBuilder}thathasbeenprefixedwith *a{@codeulimit}commandtoallowforanunlimitedcorefilesize. * *@parampb{@codeProcessBuilder}toprefixwiththeulimitcommand *@returnNew{@codeProcessBuilder}withprefixed{@codeulimit}commandif *supported.Otherwisethepassedin{@codeProcessBuilder}isreturned.
*/ publicstatic ProcessBuilder addCoreUlimitCommand(ProcessBuilder pb) {
String cmd = ProcessTools.getCommandLine(pb);
String ulimitCmd = getCoreUlimitCommand(); if (ulimitCmd == null) { return pb;
} else { if (Platform.isWindows()) { // In order to launch on Windows using "sh -c", we need to first // convert the path to use forward slashes and do some extra quoting.
cmd = cmd.replace('\\', '/').replace(";", "\\;").replace("|", "\\|");
} returnnew ProcessBuilder("sh", "-c", ulimitCmd + cmd);
}
}
// Make sure the core file is moved into the cwd if not already there. // Core/minidump usually created in current directory (Linux and Windows).
Path corePath = Paths.get(coreFileLocation);
File parent = new File(coreFileLocation).getParentFile();
File cwdParent = new File(".").getAbsoluteFile().getParentFile(); if (parent != null && !parent.equals(cwdParent)) {
Path coreFileName = corePath.getFileName();
System.out.println("Moving core file to cwd: " + coreFileName); long startTime = System.currentTimeMillis();
Files.move(corePath, coreFileName);
System.out.println("Core file move took " + (System.currentTimeMillis() - startTime) + "ms");
coreFileLocation = coreFileName.toString();
}
return coreFileLocation; // success!
}
// See if we can figure out the likely reason the core file was not found. Recover from // failure if possible. // Throw SkippedException if appropriate. if (Platform.isOSX()) {
File coresDir = new File("/cores"); if (!coresDir.isDirectory()) { thrownew RuntimeException(coresDir + " is not a directory");
} // The /cores directory is usually not writable on macOS 10.15 if (!coresDir.canWrite()) { thrownew SkippedException("Directory \"" + coresDir + "\" is not writable");
} if (Platform.isHardenedOSX()) { if (Platform.getOsVersionMajor() > 10 ||
(Platform.getOsVersionMajor() == 10 && Platform.getOsVersionMinor() >= 15))
{ // We can't generate cores files with hardened binaries on OSX 10.15 and later. thrownew SkippedException("Cannot produce core file with hardened binary on OSX 10.15 and later");
}
}
} elseif (Platform.isLinux()) { // Check if a crash report tool is installed.
File corePatternFile = new File(CORE_PATTERN_FILE_NAME); try (Scanner scanner = new Scanner(corePatternFile)) { while (scanner.hasNextLine()) {
String line = scanner.nextLine();
line = line.trim();
System.out.println(line); if (line.startsWith("|")) { if (line.split("\s", 2)[0].endsWith("systemd-coredump")) { // A systemd linux system. Try to retrieve core // file. It can take a few seconds for the system to // process the just produced core file so we may need to // retry a few times.
System.out.println("Running systemd-coredump: trying coredumpctl command");
String core = "core"; try { for (int i = 0; i < 10; i++) { Thread.sleep(5000);
OutputAnalyzer out = ProcessTools.executeProcess("coredumpctl", "dump", "-1", "-o", core, String.valueOf(pid)); if (!out.getOutput().contains("output may be incomplete")) { break;
}
}
} catch(Throwable t) {
} final File coreFile = new File(core); if (coreFile.exists()) {
Asserts.assertGT(coreFile.length(), 0L, "Unexpected core size");
System.out.println("coredumpctl succeeded"); return core;
}
}
System.out.println( "\nThis system uses a crash report tool ($cat /proc/sys/kernel/core_pattern).\n" + "Core files might not be generated. Please reset /proc/sys/kernel/core_pattern\n" + "to enable core generation. Skipping this test."); thrownew SkippedException("This system uses a crash report tool");
}
}
}
} thrownew RuntimeException("Couldn't find core file location in: '" + crashOutputString + "'");
}
// Find the line of output that contains LOCATION_STRING
Asserts.assertTrue(crashOutputString.contains(LOCATION_STRING), "Output doesn't contain the location of core file.");
String stringWithLocation = Arrays.stream(crashOutputString.split("\\r?\\n"))
.filter(str -> str.contains(LOCATION_STRING))
.findFirst()
.get();
stringWithLocation = stringWithLocation.substring(stringWithLocation
.indexOf(LOCATION_STRING) + LOCATION_STRING.length());
System.out.println("getCoreFileLocation found stringWithLocation = " + stringWithLocation);
// Find the core file name in the output.
String coreWithPid; if (stringWithLocation.contains("or ") && !Platform.isWindows()) {
Matcher m = Pattern.compile("or.* ([^ ]+[^\\)])\\)?").matcher(stringWithLocation); if (!m.find()) { thrownew RuntimeException("Couldn't find path to core inside location string");
}
coreWithPid = m.group(1);
} else {
coreWithPid = stringWithLocation.trim();
} if (new File(coreWithPid).exists()) { return coreWithPid;
}
// Look for file named "core" in the cwd.
String justCore = Paths.get("core").toString(); if (new File(justCore).exists()) { return justCore;
}
// Look for the core file name found in the output, but do so in the cwd.
Path coreWithPidPath = Paths.get(coreWithPid);
String justFile = coreWithPidPath.getFileName().toString(); if (new File(justFile).exists()) { return justFile;
}
// Look for file named "core" in the path to the core file found in the output.
Path parent = coreWithPidPath.getParent(); if (parent != null) {
String coreWithoutPid = parent.resolve("core").toString(); if (new File(coreWithoutPid).exists()) { return coreWithoutPid;
}
} returnnull;
}
publicstatic String getAlwaysPretouchArg(boolean withCore) { // macosx-aarch64 has an issue where sometimes the java heap will not be dumped to the // core file. Using -XX:+AlwaysPreTouch fixes the problem. if (withCore && Platform.isOSX() && Platform.isAArch64()) { return"-XX:+AlwaysPreTouch";
} else { return"-XX:-AlwaysPreTouch";
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-10-11)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.