2018-12-10 14:47:44 +00:00
|
|
|
/*
|
2020-01-10 12:21:32 +00:00
|
|
|
* Copyright (c) 2017, 2020, Red Hat, Inc. All rights reserved.
|
2020-01-15 03:27:03 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2018-12-10 14:47:44 +00:00
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-07-09 07:54:40 +00:00
|
|
|
* @test id=aggressive
|
2018-12-10 14:47:44 +00:00
|
|
|
* @summary Tests JVMTI heap dumps
|
2020-07-10 18:52:35 +00:00
|
|
|
* @requires vm.gc.Shenandoah
|
2020-09-23 21:11:31 +00:00
|
|
|
* @requires vm.jvmti
|
2018-12-10 14:47:44 +00:00
|
|
|
* @compile TestHeapDump.java
|
2021-07-09 07:54:40 +00:00
|
|
|
* @run main/othervm/native/timeout=300 -agentlib:TestHeapDump
|
|
|
|
* -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
|
|
|
|
* -XX:+UseShenandoahGC -Xmx128m
|
|
|
|
* -XX:ShenandoahGCHeuristics=aggressive
|
|
|
|
* TestHeapDump
|
2019-06-02 08:08:38 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-07-09 07:54:40 +00:00
|
|
|
* @test id=no-coops-aggressive
|
2019-06-02 08:08:38 +00:00
|
|
|
* @summary Tests JVMTI heap dumps
|
2020-07-10 18:52:35 +00:00
|
|
|
* @requires vm.gc.Shenandoah
|
2020-09-23 21:11:31 +00:00
|
|
|
* @requires vm.jvmti
|
2020-07-10 18:52:35 +00:00
|
|
|
* @requires vm.bits == "64"
|
2019-06-02 08:08:38 +00:00
|
|
|
* @compile TestHeapDump.java
|
2021-07-09 07:54:40 +00:00
|
|
|
* @run main/othervm/native/timeout=300 -agentlib:TestHeapDump
|
|
|
|
* -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
|
|
|
|
* -XX:+UseShenandoahGC -Xmx128m
|
|
|
|
* -XX:ShenandoahGCHeuristics=aggressive
|
|
|
|
* -XX:-UseCompressedOops TestHeapDump
|
2018-12-10 14:47:44 +00:00
|
|
|
*/
|
|
|
|
|
2020-01-10 12:21:32 +00:00
|
|
|
/**
|
2021-07-09 07:54:40 +00:00
|
|
|
* @test id=aggressive-strdedup
|
2020-01-10 12:21:32 +00:00
|
|
|
* @summary Tests JVMTI heap dumps
|
2020-07-10 18:52:35 +00:00
|
|
|
* @requires vm.gc.Shenandoah
|
2020-09-23 21:11:31 +00:00
|
|
|
* @requires vm.jvmti
|
2020-01-10 12:21:32 +00:00
|
|
|
* @compile TestHeapDump.java
|
2021-07-09 07:54:40 +00:00
|
|
|
* @run main/othervm/native/timeout=300 -agentlib:TestHeapDump
|
|
|
|
* -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
|
|
|
|
* -XX:+UseShenandoahGC -Xmx128m
|
|
|
|
* -XX:ShenandoahGCHeuristics=aggressive
|
|
|
|
* -XX:+UseStringDeduplication TestHeapDump
|
2020-01-10 12:21:32 +00:00
|
|
|
*/
|
|
|
|
|
2019-11-15 12:39:26 +00:00
|
|
|
import java.lang.ref.Reference;
|
|
|
|
|
2018-12-10 14:47:44 +00:00
|
|
|
public class TestHeapDump {
|
|
|
|
|
|
|
|
private static final int NUM_ITER = 10000;
|
|
|
|
|
|
|
|
private static final int ARRAY_SIZE = 1000;
|
|
|
|
|
|
|
|
private static final int EXPECTED_OBJECTS =
|
|
|
|
ARRAY_SIZE + // array reachable from instance field
|
|
|
|
1 + // static field root
|
|
|
|
1; // local field root
|
|
|
|
|
|
|
|
static {
|
|
|
|
try {
|
|
|
|
System.loadLibrary("TestHeapDump");
|
|
|
|
} catch (UnsatisfiedLinkError ule) {
|
|
|
|
System.err.println("Could not load TestHeapDump library");
|
|
|
|
System.err.println("java.library.path: "
|
|
|
|
+ System.getProperty("java.library.path"));
|
|
|
|
throw ule;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
native static int heapdump(Class<?> filterClass);
|
|
|
|
|
|
|
|
public static void main(String args[]) {
|
|
|
|
new TestHeapDump().run();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This root needs to be discovered
|
|
|
|
static Object root = new TestObject();
|
|
|
|
|
|
|
|
// This field needs to be discovered
|
|
|
|
TestObject[] array;
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
array = new TestObject[ARRAY_SIZE];
|
|
|
|
for (int i = 0; i < ARRAY_SIZE; i++) {
|
|
|
|
array[i] = new TestObject();
|
|
|
|
}
|
|
|
|
TestObject localRoot = new TestObject();
|
|
|
|
for (int i = 0; i < NUM_ITER; i++) {
|
|
|
|
int numObjs = heapdump(TestObject.class);
|
|
|
|
if (numObjs != EXPECTED_OBJECTS) {
|
|
|
|
throw new RuntimeException("Expected " + EXPECTED_OBJECTS + " objects, but got " + numObjs);
|
|
|
|
}
|
|
|
|
}
|
2019-11-15 12:39:26 +00:00
|
|
|
Reference.reachabilityFence(array);
|
|
|
|
Reference.reachabilityFence(localRoot);
|
2018-12-10 14:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We look for the instances of this class during the heap scan
|
|
|
|
public static class TestObject {}
|
|
|
|
}
|