69 }
70 }
71 test(args[1]);
72 }
73
74 // Test tries to run java with ulimit unlimited if it is possible
75 static boolean useDefaultUlimit() {
76 if (Platform.isWindows()) {
77 return true;
78 }
79 try {
80 OutputAnalyzer output = ProcessTools.executeProcess("sh", "-c", "ulimit -c unlimited && ulimit -c");
81 return !(output.getExitValue() == 0 && output.getStdout().contains("unlimited"));
82 } catch (Throwable t) {
83 return true;
84 }
85 }
86
87 static void test(String type) throws Throwable {
88 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-XX:+CreateCoredumpOnCrash",
89 "-XX:MaxMetaspaceSize=64m", "-XX:+CrashOnOutOfMemoryError", "-XX:-TransmitErrorReport",
90 TestJmapCore.class.getName(), type);
91
92 boolean useDefaultUlimit = useDefaultUlimit();
93 System.out.println("Run test with ulimit: " + (useDefaultUlimit ? "default" : "unlimited"));
94 OutputAnalyzer output = useDefaultUlimit
95 ? ProcessTools.executeProcess(pb)
96 : ProcessTools.executeProcess("sh", "-c", "ulimit -c unlimited && "
97 + ProcessTools.getCommandLine(pb));
98 File core;
99 String pattern = Platform.isWindows() ? "mdmp" : "core";
100 File[] cores = new File(".").listFiles((dir, name) -> name.contains(pattern));
101 if (cores.length == 0) {
102 // /cores/core.$pid might be generated on macosx by default
103 String pid = output.firstMatch("^(\\d+)" + pidSeparator, 1);
104 core = new File("cores/core." + pid);
105 if (!core.exists()) {
106 System.out.println("Has not been able to find coredump. Test skipped.");
107 return;
108 }
109 } else {
|
69 }
70 }
71 test(args[1]);
72 }
73
74 // Test tries to run java with ulimit unlimited if it is possible
75 static boolean useDefaultUlimit() {
76 if (Platform.isWindows()) {
77 return true;
78 }
79 try {
80 OutputAnalyzer output = ProcessTools.executeProcess("sh", "-c", "ulimit -c unlimited && ulimit -c");
81 return !(output.getExitValue() == 0 && output.getStdout().contains("unlimited"));
82 } catch (Throwable t) {
83 return true;
84 }
85 }
86
87 static void test(String type) throws Throwable {
88 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-XX:+CreateCoredumpOnCrash",
89 "-Xmx512m", "-XX:MaxMetaspaceSize=64m", "-XX:+CrashOnOutOfMemoryError", "-XX:-TransmitErrorReport",
90 TestJmapCore.class.getName(), type);
91
92 boolean useDefaultUlimit = useDefaultUlimit();
93 System.out.println("Run test with ulimit: " + (useDefaultUlimit ? "default" : "unlimited"));
94 OutputAnalyzer output = useDefaultUlimit
95 ? ProcessTools.executeProcess(pb)
96 : ProcessTools.executeProcess("sh", "-c", "ulimit -c unlimited && "
97 + ProcessTools.getCommandLine(pb));
98 File core;
99 String pattern = Platform.isWindows() ? "mdmp" : "core";
100 File[] cores = new File(".").listFiles((dir, name) -> name.contains(pattern));
101 if (cores.length == 0) {
102 // /cores/core.$pid might be generated on macosx by default
103 String pid = output.firstMatch("^(\\d+)" + pidSeparator, 1);
104 core = new File("cores/core." + pid);
105 if (!core.exists()) {
106 System.out.println("Has not been able to find coredump. Test skipped.");
107 return;
108 }
109 } else {
|