diff options
author | Luck <git@lucko.me> | 2019-01-13 11:34:48 +0000 |
---|---|---|
committer | Luck <git@lucko.me> | 2019-01-13 11:34:48 +0000 |
commit | 788a61af26563f6f0d73b47c64d1bf8f6547997d (patch) | |
tree | 58583dd99be90d76429e5b3666213fcd9736f2a4 /spark-common/src/main/java/me/lucko/spark | |
parent | 0b7e2600ca258d729c9f156c45e38c495a4d3a12 (diff) | |
download | spark-788a61af26563f6f0d73b47c64d1bf8f6547997d.tar.gz spark-788a61af26563f6f0d73b47c64d1bf8f6547997d.tar.bz2 spark-788a61af26563f6f0d73b47c64d1bf8f6547997d.zip |
Add support for creating .phd heap dumps with OpenJ9 JVMs
Diffstat (limited to 'spark-common/src/main/java/me/lucko/spark')
-rw-r--r-- | spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java | 2 | ||||
-rw-r--r-- | spark-common/src/main/java/me/lucko/spark/memory/HeapDump.java | 26 |
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 { |