1 /* 2 * Copyright (c) 2021, Red Hat, Inc. All rights reserved. 3 * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 /* 27 * @test id=passive 28 * @library /test/lib 29 * @modules jdk.attach/com.sun.tools.attach 30 * @requires vm.gc.Shenandoah 31 * 32 * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 33 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive 34 * -XX:+ShenandoahDegeneratedGC 35 * TestJcmdHeapDump 36 * 37 * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 38 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive 39 * -XX:-ShenandoahDegeneratedGC 40 * TestJcmdHeapDump 41 */ 42 43 /* 44 * @test id=aggressive 45 * @library /test/lib 46 * @modules jdk.attach/com.sun.tools.attach 47 * @requires vm.gc.Shenandoah 48 * 49 * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 50 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive 51 * -XX:+ShenandoahOOMDuringEvacALot 52 * TestJcmdHeapDump 53 * 54 * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 55 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive 56 * -XX:+ShenandoahAllocFailureALot 57 * TestJcmdHeapDump 58 * 59 * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 60 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive 61 * TestJcmdHeapDump 62 */ 63 64 /* 65 * @test id=adaptive 66 * @library /test/lib 67 * @modules jdk.attach/com.sun.tools.attach 68 * @requires vm.gc.Shenandoah 69 * 70 * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 71 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive 72 * -Dtarget=10000 73 * TestJcmdHeapDump 74 */ 75 76 /* 77 * @test id=generational 78 * @library /test/lib 79 * @modules jdk.attach/com.sun.tools.attach 80 * @requires vm.gc.Shenandoah 81 * 82 * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 83 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -XX:ShenandoahGCMode=generational 84 * -Dtarget=10000 85 * TestJcmdHeapDump 86 */ 87 88 /* 89 * @test id=static 90 * @library /test/lib 91 * @modules jdk.attach/com.sun.tools.attach 92 * @requires vm.gc.Shenandoah 93 * 94 * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 95 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static 96 * TestJcmdHeapDump 97 */ 98 99 /* 100 * @test id=compact 101 * @library /test/lib 102 * @modules jdk.attach/com.sun.tools.attach 103 * @requires vm.gc.Shenandoah 104 * 105 * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 106 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact 107 * TestJcmdHeapDump 108 */ 109 110 /* 111 * @test id=iu-aggressive 112 * @library /test/lib 113 * @modules jdk.attach/com.sun.tools.attach 114 * @requires vm.gc.Shenandoah 115 * 116 * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 117 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive 118 * -XX:+ShenandoahOOMDuringEvacALot 119 * TestJcmdHeapDump 120 * 121 * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 122 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive 123 * -XX:+ShenandoahAllocFailureALot 124 * TestJcmdHeapDump 125 * 126 * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 127 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive 128 * TestJcmdHeapDump 129 */ 130 131 /* 132 * @test id=iu 133 * @requires vm.gc.Shenandoah 134 * @library /test/lib 135 * @modules jdk.attach/com.sun.tools.attach 136 * 137 * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 138 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu 139 * TestJcmdHeapDump 140 */ 141 142 import jdk.test.lib.JDKToolLauncher; 143 import jdk.test.lib.process.ProcessTools; 144 import jdk.test.lib.process.OutputAnalyzer; 145 146 import java.io.File; 147 148 public class TestJcmdHeapDump { 149 public static void main(String[] args) { 150 long pid = ProcessHandle.current().pid(); 151 JDKToolLauncher jcmd = JDKToolLauncher.createUsingTestJDK("jcmd"); 152 jcmd.addToolArg(String.valueOf(pid)); 153 jcmd.addToolArg("GC.heap_dump"); 154 String dumpFileName = "myheapdump" + String.valueOf(pid); 155 jcmd.addToolArg(dumpFileName); 156 157 try { 158 OutputAnalyzer output = ProcessTools.executeProcess(jcmd.getCommand()); 159 output.shouldHaveExitValue(0); 160 } catch (Exception e) { 161 throw new RuntimeException("Test failed: " + e); 162 } 163 164 File f = new File(dumpFileName); 165 if (f.exists()) { 166 f.delete(); 167 } else { 168 throw new RuntimeException("Dump file not created"); 169 } 170 } 171 }