Path: blob/master/test/hotspot/jtreg/gc/shenandoah/jvmti/TestHeapDump.java
41153 views
/*1* Copyright (c) 2017, 2020, Red Hat, Inc. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324/**25* @test TestHeapDump26* @summary Tests JVMTI heap dumps27* @requires vm.gc.Shenandoah28* @requires vm.jvmti29* @compile TestHeapDump.java30* @run main/othervm/native/timeout=300 -agentlib:TestHeapDump -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx128m -XX:ShenandoahGCHeuristics=aggressive TestHeapDump31*32*/3334/**35* @test TestHeapDump36* @summary Tests JVMTI heap dumps37* @requires vm.gc.Shenandoah38* @requires vm.jvmti39* @requires vm.bits == "64"40* @compile TestHeapDump.java41* @run main/othervm/native/timeout=300 -agentlib:TestHeapDump -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx128m -XX:ShenandoahGCHeuristics=aggressive -XX:-UseCompressedOops TestHeapDump42*/4344/**45* @test TestHeapDump46* @summary Tests JVMTI heap dumps47* @requires vm.gc.Shenandoah48* @requires vm.jvmti49* @compile TestHeapDump.java50* @run main/othervm/native/timeout=300 -agentlib:TestHeapDump -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx128m -XX:ShenandoahGCHeuristics=aggressive -XX:+UseStringDeduplication TestHeapDump51*/5253import java.lang.ref.Reference;5455public class TestHeapDump {5657private static final int NUM_ITER = 10000;5859private static final int ARRAY_SIZE = 1000;6061private static final int EXPECTED_OBJECTS =62ARRAY_SIZE + // array reachable from instance field631 + // static field root641; // local field root6566static {67try {68System.loadLibrary("TestHeapDump");69} catch (UnsatisfiedLinkError ule) {70System.err.println("Could not load TestHeapDump library");71System.err.println("java.library.path: "72+ System.getProperty("java.library.path"));73throw ule;74}75}7677native static int heapdump(Class<?> filterClass);7879public static void main(String args[]) {80new TestHeapDump().run();81}8283// This root needs to be discovered84static Object root = new TestObject();8586// This field needs to be discovered87TestObject[] array;8889public void run() {90array = new TestObject[ARRAY_SIZE];91for (int i = 0; i < ARRAY_SIZE; i++) {92array[i] = new TestObject();93}94TestObject localRoot = new TestObject();95for (int i = 0; i < NUM_ITER; i++) {96int numObjs = heapdump(TestObject.class);97if (numObjs != EXPECTED_OBJECTS) {98throw new RuntimeException("Expected " + EXPECTED_OBJECTS + " objects, but got " + numObjs);99}100}101Reference.reachabilityFence(array);102Reference.reachabilityFence(localRoot);103}104105// We look for the instances of this class during the heap scan106public static class TestObject {}107}108109110