25
import java.util.stream.Collectors;
27
import jdk.test.lib.apps.LingeredApp;
28
import jdk.test.lib.Asserts;
29
import jdk.test.lib.JDKToolLauncher;
30
import jdk.test.lib.process.ProcessTools;
31
import jdk.test.lib.process.OutputAnalyzer;
32
import jdk.test.lib.SA.SATestUtils;
33
import jdk.test.lib.Utils;
34
import jdk.test.lib.hprof.HprofParser;
48
public class TestHeapDumpForInvokeDynamic {
50
private static LingeredAppWithInvokeDynamic theApp = null;
52
private static void attachDumpAndVerify(String heapDumpFileName,
53
long lingeredAppPid) throws Exception {
55
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
56
launcher.addVMArgs(Utils.getTestJavaOpts());
57
launcher.addToolArg("jmap");
58
launcher.addToolArg("--binaryheap");
59
launcher.addToolArg("--dumpfile");
60
launcher.addToolArg(heapDumpFileName);
61
launcher.addToolArg("--pid");
62
launcher.addToolArg(Long.toString(lingeredAppPid));
64
ProcessBuilder processBuilder = SATestUtils.createProcessBuilder(launcher);
66
processBuilder.command().stream().collect(Collectors.joining(" ")));
68
OutputAnalyzer SAOutput = ProcessTools.executeProcess(processBuilder);
69
SAOutput.shouldHaveExitValue(0);
70
SAOutput.shouldContain("heap written to");
71
SAOutput.shouldContain(heapDumpFileName);
72
System.out.println(SAOutput.getOutput());
74
HprofParser.parseAndVerify(new File(heapDumpFileName));
77
public static void main (String... args) throws Exception {
78
SATestUtils.skipIfCannotAttach();
79
String heapDumpFileName = "lambdaHeapDump.bin";
81
File heapDumpFile = new File(heapDumpFileName);
82
if (heapDumpFile.exists()) {
83
heapDumpFile.delete();
87
theApp = new LingeredAppWithInvokeDynamic();
88
LingeredApp.startApp(theApp, "-XX:+UsePerfData", "-Xmx512m");
89
attachDumpAndVerify(heapDumpFileName, theApp.getPid());
91
LingeredApp.stopApp(theApp);