1 /*
  2  * Copyright (c) 2021, Red Hat, Inc. 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 
 25 /*
 26  * @test id=passive
 27  * @library /test/lib
 28  * @modules jdk.attach/com.sun.tools.attach
 29  * @requires vm.gc.Shenandoah
 30  *
 31  * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 32  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 33  *      -XX:+ShenandoahDegeneratedGC
 34  *      TestJcmdHeapDump
 35  *
 36  * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 37  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 38  *      -XX:-ShenandoahDegeneratedGC
 39  *      TestJcmdHeapDump
 40  */
 41 
 42 /*
 43  * @test id=aggressive
 44  * @library /test/lib
 45  * @modules jdk.attach/com.sun.tools.attach
 46  * @requires vm.gc.Shenandoah
 47  *
 48  * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 49  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 50  *      -XX:+ShenandoahOOMDuringEvacALot
 51  *      TestJcmdHeapDump
 52  *
 53  * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 54  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 55  *      -XX:+ShenandoahAllocFailureALot
 56  *      TestJcmdHeapDump
 57  *
 58  * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 59  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 60  *      TestJcmdHeapDump
 61  */
 62 
 63 /*
 64  * @test id=adaptive
 65  * @library /test/lib
 66  * @modules jdk.attach/com.sun.tools.attach
 67  * @requires vm.gc.Shenandoah
 68  *
 69  * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 70  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
 71  *      -Dtarget=10000
 72  *      TestJcmdHeapDump
 73  */
 74 












 75 /*
 76  * @test id=static
 77  * @library /test/lib
 78  * @modules jdk.attach/com.sun.tools.attach
 79  * @requires vm.gc.Shenandoah
 80  *
 81  * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 82  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static
 83  *      TestJcmdHeapDump
 84  */
 85 
 86 /*
 87  * @test id=compact
 88  * @library /test/lib
 89  * @modules jdk.attach/com.sun.tools.attach
 90  * @requires vm.gc.Shenandoah
 91  *
 92  * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 93  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
 94  *     TestJcmdHeapDump
 95  */
 96 
 97 /*
 98  * @test id=iu-aggressive
 99  * @library /test/lib
100  * @modules jdk.attach/com.sun.tools.attach
101  * @requires vm.gc.Shenandoah
102  *
103  * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
104  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
105  *      -XX:+ShenandoahOOMDuringEvacALot
106  *      TestJcmdHeapDump
107  *
108  * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
109  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
110  *      -XX:+ShenandoahAllocFailureALot
111  *      TestJcmdHeapDump
112  *
113  * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
114  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
115  *      TestJcmdHeapDump
116  */
117 
118 /*
119  * @test id=iu
120  * @requires vm.gc.Shenandoah
121  * @library /test/lib
122  * @modules jdk.attach/com.sun.tools.attach
123  *
124  * @run main/othervm/timeout=480 -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
125  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
126  *      TestJcmdHeapDump
127  */
128 
129 import jdk.test.lib.JDKToolLauncher;
130 import jdk.test.lib.process.OutputAnalyzer;
131 
132 import java.io.File;
133 
134 public class TestJcmdHeapDump {
135     public static void main(String[] args) {
136         long pid = ProcessHandle.current().pid();
137         JDKToolLauncher jcmd = JDKToolLauncher.createUsingTestJDK("jcmd");
138         jcmd.addToolArg(String.valueOf(pid));
139         jcmd.addToolArg("GC.heap_dump");
140         String dumpFileName = "myheapdump" + String.valueOf(pid);
141         jcmd.addToolArg(dumpFileName);
142 
143         try {
144             ProcessBuilder pb = new ProcessBuilder(jcmd.getCommand());
145             Process jcmdProc = pb.start();
146 
147             OutputAnalyzer output = new OutputAnalyzer(jcmdProc);
148             jcmdProc.waitFor();
149             output.shouldHaveExitValue(0);
150         } catch (Exception e) {
151             throw new RuntimeException("Test failed: " + e);
152         }
153 
154         File f = new File(dumpFileName);
155         if (f.exists()) {
156             f.delete();
157         } else {
158             throw new RuntimeException("Dump file not created");
159         }
160     }
161 }
--- EOF ---