소스 검색

[github-197] Modify test class HeapDump to allow it work in different JDKs. Thanks to Marius Volkhart. This closes #197

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1883393 13f79535-47bb-0310-9956-ffa450edef68
tags/before_ooxml_3rd_edition
PJ Fanning 3 년 전
부모
커밋
00b9048d59
1개의 변경된 파일39개의 추가작업 그리고 5개의 파일을 삭제
  1. 39
    5
      src/integrationtest/org/apache/poi/stress/HeapDump.java

+ 39
- 5
src/integrationtest/org/apache/poi/stress/HeapDump.java 파일 보기

@@ -18,8 +18,11 @@ package org.apache.poi.stress;

import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import com.sun.management.HotSpotDiagnosticMXBean;
import org.apache.poi.ss.formula.eval.NotImplementedException;
import org.apache.poi.util.SuppressForbidden;

@SuppressForbidden("class only exists for manual tests in XSSFFileHandler")
@@ -40,9 +43,18 @@ public class HeapDump {
* only the live objects
*/
public static void dumpHeap(String fileName, boolean live) throws IOException {
// initialize hotspot diagnostic MBean
initHotspotMBean();
hotspotMBean.dumpHeap(fileName, live);
try {
if (isIbmVm()) {
dumpHeapJ9(fileName);
} else {

// initialize hotspot diagnostic MBean
initHotspotMBean();
dumpHeapHotSpot(fileName, live);
}
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
}

// initialize the hotspot diagnostic MBean field
@@ -59,6 +71,28 @@ public class HeapDump {
// get the hotspot diagnostic MBean from the platform MBean server
private static HotSpotDiagnosticMXBean getHotspotMBean() throws IOException {
return ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.getPlatformMBeanServer(),
HOTSPOT_BEAN_NAME, HotSpotDiagnosticMXBean.class);
HOTSPOT_BEAN_NAME, HotSpotDiagnosticMXBean.class);
}

private static boolean isIbmVm() {
try {
Class.forName("com.ibm.jvm.Dump");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}

private static void dumpHeapJ9(String fileName) throws ClassNotFoundException, NoSuchMethodException,
InvocationTargetException, IllegalAccessException {
Class<?> dump = Class.forName("com.ibm.jvm.Dump");
Method heapDumpToFile = dump.getMethod("heapDumpToFile", String.class);
heapDumpToFile.invoke(dump, fileName);
}

private static void dumpHeapHotSpot(String fileName, boolean live) throws NoSuchMethodException,
InvocationTargetException, IllegalAccessException {
Method dumpHeap = hotspotMBean.getClass().getMethod("dumpHeap", String.class, boolean.class);
dumpHeap.invoke(hotspotMBean, fileName, live);
}
}
}

Loading…
취소
저장