changeset 52745:19de50eb561d

8214408: Migrate EventsOnOff to using the same allocateAndCheck method Summary: Move code to the more stable version used by other tests Reviewed-by: sspitsyn, amenkov
author jcbeyler
date Wed, 28 Nov 2018 11:09:27 -0800
parents 732bec44c89e
children f24ae8376e71
files test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitor.java test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorEventOnOffTest.java
diffstat 2 files changed, 27 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitor.java	Wed Nov 28 10:30:15 2018 -0800
+++ b/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitor.java	Wed Nov 28 11:09:27 2018 -0800
@@ -186,7 +186,8 @@
     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 @@
     // 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);
--- a/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorEventOnOffTest.java	Wed Nov 28 10:30:15 2018 -0800
+++ b/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorEventOnOffTest.java	Wed Nov 28 11:09:27 2018 -0800
@@ -34,40 +34,17 @@
  * @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();
   }
 }