Path: blob/master/test/hotspot/jtreg/gc/shenandoah/jvmti/TestHeapDump.java
64507 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 id=aggressive26* @summary Tests JVMTI heap dumps27* @requires vm.gc.Shenandoah28* @requires vm.jvmti29* @compile TestHeapDump.java30* @run main/othervm/native/timeout=300 -agentlib:TestHeapDump31* -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions32* -XX:+UseShenandoahGC -Xmx128m33* -XX:ShenandoahGCHeuristics=aggressive34* TestHeapDump35*36*/3738/**39* @test id=no-coops-aggressive40* @summary Tests JVMTI heap dumps41* @requires vm.gc.Shenandoah42* @requires vm.jvmti43* @requires vm.bits == "64"44* @compile TestHeapDump.java45* @run main/othervm/native/timeout=300 -agentlib:TestHeapDump46* -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions47* -XX:+UseShenandoahGC -Xmx128m48* -XX:ShenandoahGCHeuristics=aggressive49* -XX:-UseCompressedOops TestHeapDump50*/5152/**53* @test id=aggressive-strdedup54* @summary Tests JVMTI heap dumps55* @requires vm.gc.Shenandoah56* @requires vm.jvmti57* @compile TestHeapDump.java58* @run main/othervm/native/timeout=300 -agentlib:TestHeapDump59* -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions60* -XX:+UseShenandoahGC -Xmx128m61* -XX:ShenandoahGCHeuristics=aggressive62* -XX:+UseStringDeduplication TestHeapDump63*/6465import java.lang.ref.Reference;6667public class TestHeapDump {6869private static final int NUM_ITER = 10000;7071private static final int ARRAY_SIZE = 1000;7273private static final int EXPECTED_OBJECTS =74ARRAY_SIZE + // array reachable from instance field751 + // static field root761; // local field root7778static {79try {80System.loadLibrary("TestHeapDump");81} catch (UnsatisfiedLinkError ule) {82System.err.println("Could not load TestHeapDump library");83System.err.println("java.library.path: "84+ System.getProperty("java.library.path"));85throw ule;86}87}8889native static int heapdump(Class<?> filterClass);9091public static void main(String args[]) {92new TestHeapDump().run();93}9495// This root needs to be discovered96static Object root = new TestObject();9798// This field needs to be discovered99TestObject[] array;100101public void run() {102array = new TestObject[ARRAY_SIZE];103for (int i = 0; i < ARRAY_SIZE; i++) {104array[i] = new TestObject();105}106TestObject localRoot = new TestObject();107for (int i = 0; i < NUM_ITER; i++) {108int numObjs = heapdump(TestObject.class);109if (numObjs != EXPECTED_OBJECTS) {110throw new RuntimeException("Expected " + EXPECTED_OBJECTS + " objects, but got " + numObjs);111}112}113Reference.reachabilityFence(array);114Reference.reachabilityFence(localRoot);115}116117// We look for the instances of this class during the heap scan118public static class TestObject {}119}120121122