8214408: Migrate EventsOnOff to using the same allocateAndCheck method

Move code to the more stable version used by other tests

Reviewed-by: sspitsyn, amenkov
This commit is contained in:
Jean Christophe Beyler 2018-11-28 11:09:27 -08:00
parent 5f05f78bd4
commit 42563fdad8
2 changed files with 27 additions and 33 deletions
test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage

@ -186,7 +186,8 @@ public class HeapMonitor {
throw new RuntimeException("Could not set the sampler");
}
public static Frame[] allocateAndCheckFrames() {
public static Frame[] allocateAndCheckFrames(boolean shouldFindFrames,
boolean enableSampling) {
if (!eventStorageIsEmpty()) {
throw new RuntimeException("Statistics should be null to begin with.");
}
@ -194,20 +195,36 @@ public class HeapMonitor {
// Put sampling rate to 100k to ensure samples are collected.
setSamplingInterval(100 * 1024);
enableSamplingEvents();
if (enableSampling) {
enableSamplingEvents();
}
List<Frame> frameList = allocate();
frameList.add(new Frame("allocateAndCheckFrames", "()[LMyPackage/Frame;", "HeapMonitor.java",
199));
frameList.add(new Frame("allocateAndCheckFrames", "(ZZ)[LMyPackage/Frame;", "HeapMonitor.java",
202));
Frame[] frames = frameList.toArray(new Frame[0]);
if (!obtainedEvents(frames) && !garbageContains(frames)) {
throw new RuntimeException("No expected events were found.");
boolean foundLive = obtainedEvents(frames);
boolean foundGarbage = garbageContains(frames);
if (shouldFindFrames) {
if (!foundLive && !foundGarbage) {
throw new RuntimeException("No expected events were found: "
+ foundLive + ", " + foundGarbage);
}
} else {
if (foundLive || foundGarbage) {
throw new RuntimeException("Were not expecting events, but found some: "
+ foundLive + ", " + foundGarbage);
}
}
return frames;
}
public static Frame[] allocateAndCheckFrames() {
return allocateAndCheckFrames(true, true);
}
public native static int sampledEvents();
public native static boolean obtainedEvents(Frame[] frames, boolean checkLines);
public native static boolean garbageContains(Frame[] frames, boolean checkLines);

@ -34,40 +34,17 @@ import java.util.List;
* @run main/othervm/native -agentlib:HeapMonitorTest MyPackage.HeapMonitorEventOnOffTest
*/
public class HeapMonitorEventOnOffTest {
private static void checkNoEventsAreBeingSent() {
HeapMonitor.resetEventStorage();
HeapMonitor.repeatAllocate(5);
// Check that the data is not available while heap sampling is disabled.
boolean status = HeapMonitor.eventStorageIsEmpty();
if (!status) {
throw new RuntimeException("Storage is not empty after allocating with disabled events.");
}
}
private static void checkEventsAreBeingSent() {
List<Frame> frameList = HeapMonitor.repeatAllocate(5);
frameList.add(new Frame("checkEventsAreBeingSent", "()V", "HeapMonitorEventOnOffTest.java", 49));
Frame[] frames = frameList.toArray(new Frame[0]);
// Check that the data is available while heap sampling is enabled.
boolean status = HeapMonitor.obtainedEvents(frames);
if (!status) {
throw new RuntimeException("Failed to find the traces after allocating with enabled events.");
}
}
public static void main(String[] args) {
HeapMonitor.enableSamplingEvents();
checkEventsAreBeingSent();
HeapMonitor.allocateAndCheckFrames();
// Disabling the notification system should stop events.
HeapMonitor.disableSamplingEvents();
checkNoEventsAreBeingSent();
HeapMonitor.resetEventStorage();
HeapMonitor.allocateAndCheckFrames(false, false);
// Enabling the notification system should start events again.
HeapMonitor.enableSamplingEvents();
checkEventsAreBeingSent();
HeapMonitor.allocateAndCheckFrames();
}
}