jdk

Форк
0
/
TestHeapDumpForInvokeDynamic.java 
94 строки · 3.5 Кб
1
/*
2
 * Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.
8
 *
9
 * This code is distributed in the hope that it will be useful, but WITHOUT
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
 * version 2 for more details (a copy is included in the LICENSE file that
13
 * accompanied this code).
14
 *
15
 * You should have received a copy of the GNU General Public License version
16
 * 2 along with this work; if not, write to the Free Software Foundation,
17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
 * or visit www.oracle.com if you need additional information or have any
21
 * questions.
22
 */
23

24
import java.io.File;
25
import java.util.stream.Collectors;
26

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;
35

36
/**
37
 * @test
38
 * @library /test/lib
39
 * @requires vm.hasSA
40
 * @modules java.base/jdk.internal.misc
41
 *          jdk.hotspot.agent/sun.jvm.hotspot
42
 *          jdk.hotspot.agent/sun.jvm.hotspot.utilities
43
 *          jdk.hotspot.agent/sun.jvm.hotspot.oops
44
 *          jdk.hotspot.agent/sun.jvm.hotspot.debugger
45
 * @run driver TestHeapDumpForInvokeDynamic
46
 */
47

48
public class TestHeapDumpForInvokeDynamic {
49

50
    private static LingeredAppWithInvokeDynamic theApp = null;
51

52
    private static void attachDumpAndVerify(String heapDumpFileName,
53
                                            long lingeredAppPid) throws Exception {
54

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));
63

64
        ProcessBuilder processBuilder = SATestUtils.createProcessBuilder(launcher);
65
        System.out.println(
66
            processBuilder.command().stream().collect(Collectors.joining(" ")));
67

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());
73

74
        HprofParser.parseAndVerify(new File(heapDumpFileName));
75
    }
76

77
    public static void main (String... args) throws Exception {
78
        SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
79
        String heapDumpFileName = "lambdaHeapDump.bin";
80

81
        File heapDumpFile = new File(heapDumpFileName);
82
        if (heapDumpFile.exists()) {
83
            heapDumpFile.delete();
84
        }
85

86
        try {
87
            theApp = new LingeredAppWithInvokeDynamic();
88
            LingeredApp.startApp(theApp, "-XX:+UsePerfData", "-Xmx512m");
89
            attachDumpAndVerify(heapDumpFileName, theApp.getPid());
90
        } finally {
91
            LingeredApp.stopApp(theApp);
92
        }
93
    }
94
}
95

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.