aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src
diff options
context:
space:
mode:
Diffstat (limited to 'spark-common/src')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java2
-rw-r--r--spark-common/src/main/java/me/lucko/spark/memory/HeapDump.java26
2 files changed, 23 insertions, 5 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java
index 6f748fb..5f17d54 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java
@@ -90,7 +90,7 @@ public class MemoryModule<S> implements CommandModule<S> {
// ignore
}
- Path file = pluginFolder.resolve("heap-" + DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss").format(LocalDateTime.now()) + ".hprof");
+ Path file = pluginFolder.resolve("heap-" + DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss").format(LocalDateTime.now()) + (HeapDump.isOpenJ9() ? ".phd" : ".hprof"));
boolean liveOnly = !arguments.boolFlag("include-non-live");
if (arguments.boolFlag("run-gc-before")) {
diff --git a/spark-common/src/main/java/me/lucko/spark/memory/HeapDump.java b/spark-common/src/main/java/me/lucko/spark/memory/HeapDump.java
index d91c476..4017d64 100644
--- a/spark-common/src/main/java/me/lucko/spark/memory/HeapDump.java
+++ b/spark-common/src/main/java/me/lucko/spark/memory/HeapDump.java
@@ -22,6 +22,7 @@ package me.lucko.spark.memory;
import java.io.IOException;
import java.lang.management.ManagementFactory;
+import java.lang.reflect.Method;
import java.nio.file.Path;
import javax.management.JMX;
@@ -46,11 +47,28 @@ public final class HeapDump {
* @throws Exception catch all
*/
public static void dumpHeap(Path outputPath, boolean live) throws Exception {
- MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
- ObjectName diagnosticBeanName = ObjectName.getInstance(DIAGNOSTIC_BEAN);
+ String outputPathString = outputPath.toAbsolutePath().normalize().toString();
- HotSpotDiagnosticMXBean proxy = JMX.newMXBeanProxy(beanServer, diagnosticBeanName, HotSpotDiagnosticMXBean.class);
- proxy.dumpHeap(outputPath.toAbsolutePath().normalize().toString(), live);
+ if (isOpenJ9()) {
+ Class<?> dumpClass = Class.forName("com.ibm.jvm.Dump");
+ Method heapDumpMethod = dumpClass.getMethod("heapDumpToFile", String.class);
+ heapDumpMethod.invoke(null, outputPathString);
+ } else {
+ MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
+ ObjectName diagnosticBeanName = ObjectName.getInstance(DIAGNOSTIC_BEAN);
+
+ HotSpotDiagnosticMXBean proxy = JMX.newMXBeanProxy(beanServer, diagnosticBeanName, HotSpotDiagnosticMXBean.class);
+ proxy.dumpHeap(outputPathString, live);
+ }
+ }
+
+ public static boolean isOpenJ9() {
+ try {
+ Class.forName("com.ibm.jvm.Dump");
+ return true;
+ } catch (ClassNotFoundException e) {
+ return false;
+ }
}
public interface HotSpotDiagnosticMXBean {