Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/shenandoah/jvmti/TestHeapDump.java
32285 views
/*1* Copyright (c) 2019, Red Hat, Inc. All rights reserved.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation.6*7* This code is distributed in the hope that it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License10* version 2 for more details (a copy is included in the LICENSE file that11* accompanied this code).12*13* You should have received a copy of the GNU General Public License version14* 2 along with this work; if not, write to the Free Software Foundation,15* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.16*17* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA18* or visit www.oracle.com if you need additional information or have any19* questions.20*21*/2223public class TestHeapDump {2425private static final int NUM_ITER = 10000;2627private static final int ARRAY_SIZE = 1000;2829private static final int EXPECTED_OBJECTS =30ARRAY_SIZE + // array reachable from instance field311 + // static field root321; // local field root3334static {35try {36System.loadLibrary("TestHeapDump");37} catch (UnsatisfiedLinkError ule) {38System.err.println("Could not load TestHeapDump library");39System.err.println("java.library.path: "40+ System.getProperty("java.library.path"));41throw ule;42}43}4445native static int heapdump(Class<?> filterClass);4647public static void main(String args[]) {48new TestHeapDump().run();49}5051// This root needs to be discovered52static Object root = new TestObject();5354// This field needs to be discovered55TestObject[] array;5657public void run() {58array = new TestObject[ARRAY_SIZE];59for (int i = 0; i < ARRAY_SIZE; i++) {60array[i] = new TestObject();61}62TestObject localRoot = new TestObject();63for (int i = 0; i < NUM_ITER; i++) {64int numObjs = heapdump(TestObject.class);65if (numObjs != EXPECTED_OBJECTS) {66throw new RuntimeException("Expected " + EXPECTED_OBJECTS + " objects, but got " + numObjs);67}68}69reachabilityFence(array);70reachabilityFence(localRoot);71}7273// We look for the instances of this class during the heap scan74public static class TestObject {}7576// See Reference.reachabilityFence() implementation in later77// JDKs.78static void reachabilityFence(Object obj) {}79}808182