8208352: Merge HeapMonitorTest and HeapMonitorGCTest code
Merged the code that enables sampling and allocates Reviewed-by: cjplummer, sspitsyn, amenkov
This commit is contained in:
parent
be5de9ef3b
commit
14e4479ca7
test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage
@ -188,6 +188,28 @@ public class HeapMonitor {
|
||||
throw new RuntimeException("Could not set the sampler");
|
||||
}
|
||||
|
||||
public static Frame[] allocateAndCheckFrames() {
|
||||
if (!eventStorageIsEmpty()) {
|
||||
throw new RuntimeException("Statistics should be null to begin with.");
|
||||
}
|
||||
|
||||
// Put sampling rate to 100k to ensure samples are collected.
|
||||
setSamplingInterval(100 * 1024);
|
||||
|
||||
enableSamplingEvents();
|
||||
|
||||
List<Frame> frameList = allocate();
|
||||
frameList.add(new Frame("allocateAndCheckFrames", "()[LMyPackage/Frame;", "HeapMonitor.java",
|
||||
201));
|
||||
Frame[] frames = frameList.toArray(new Frame[0]);
|
||||
|
||||
if (!obtainedEvents(frames) && !garbageContains(frames)) {
|
||||
throw new RuntimeException("No expected events were found.");
|
||||
}
|
||||
|
||||
return frames;
|
||||
}
|
||||
|
||||
public native static int sampledEvents();
|
||||
public native static boolean obtainedEvents(Frame[] frames, boolean checkLines);
|
||||
public native static boolean garbageContains(Frame[] frames, boolean checkLines);
|
||||
|
@ -40,23 +40,7 @@ import java.util.List;
|
||||
*/
|
||||
public class HeapMonitorGCTest {
|
||||
public static void main(String[] args) {
|
||||
if (!HeapMonitor.eventStorageIsEmpty()) {
|
||||
throw new RuntimeException("Statistics should be null to begin with.");
|
||||
}
|
||||
|
||||
// Put sampling rate to 100k to ensure samples are collected.
|
||||
HeapMonitor.setSamplingInterval(100 * 1024);
|
||||
|
||||
HeapMonitor.enableSamplingEvents();
|
||||
|
||||
List<Frame> frameList = HeapMonitor.allocate();
|
||||
frameList.add(new Frame("main", "([Ljava/lang/String;)V", "HeapMonitorGCTest.java", 52));
|
||||
Frame[] frames = frameList.toArray(new Frame[0]);
|
||||
|
||||
if (!HeapMonitor.obtainedEvents(frames)
|
||||
&& !HeapMonitor.garbageContains(frames)) {
|
||||
throw new RuntimeException("No expected events were found.");
|
||||
}
|
||||
Frame[] frames = HeapMonitor.allocateAndCheckFrames();
|
||||
|
||||
HeapMonitor.forceGarbageCollection();
|
||||
|
||||
|
@ -24,8 +24,6 @@
|
||||
|
||||
package MyPackage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @summary Verifies the JVMTI Heap Monitor API
|
||||
@ -44,22 +42,7 @@ public class HeapMonitorTest {
|
||||
HeapMonitor.setAllocationIterations(Integer.parseInt(args[0]));
|
||||
}
|
||||
|
||||
// Put sampling rate to 100k to ensure samples are collected.
|
||||
HeapMonitor.setSamplingInterval(100 * 1024);
|
||||
|
||||
if (!HeapMonitor.eventStorageIsEmpty()) {
|
||||
throw new RuntimeException("Storage is not empty at test start...");
|
||||
}
|
||||
|
||||
HeapMonitor.enableSamplingEvents();
|
||||
List<Frame> frameList = HeapMonitor.allocate();
|
||||
frameList.add(new Frame("main", "([Ljava/lang/String;)V", "HeapMonitorTest.java", 55));
|
||||
|
||||
Frame[] frames = frameList.toArray(new Frame[0]);
|
||||
if (!HeapMonitor.obtainedEvents(frames)
|
||||
&& !HeapMonitor.garbageContains(frames)) {
|
||||
throw new RuntimeException("Events not found with the right frames.");
|
||||
}
|
||||
HeapMonitor.allocateAndCheckFrames();
|
||||
|
||||
HeapMonitor.disableSamplingEvents();
|
||||
HeapMonitor.resetEventStorage();
|
||||
|
Loading…
x
Reference in New Issue
Block a user