8208352: Merge HeapMonitorTest and HeapMonitorGCTest code
authorjcbeyler
Wed, 05 Sep 2018 11:12:15 -0700
changeset 51651 3df9c8591afc
parent 51650 35dee171e59c
child 51652 f9d10031512d
8208352: Merge HeapMonitorTest and HeapMonitorGCTest code Summary: Merged the code that enables sampling and allocates Reviewed-by: cjplummer, sspitsyn, amenkov
test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitor.java
test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorGCTest.java
test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorTest.java
--- a/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitor.java	Fri Aug 10 13:36:10 2018 -0700
+++ b/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitor.java	Wed Sep 05 11:12:15 2018 -0700
@@ -188,6 +188,28 @@
     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);
--- a/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorGCTest.java	Fri Aug 10 13:36:10 2018 -0700
+++ b/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorGCTest.java	Wed Sep 05 11:12:15 2018 -0700
@@ -40,23 +40,7 @@
  */
 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();
 
--- a/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorTest.java	Fri Aug 10 13:36:10 2018 -0700
+++ b/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorTest.java	Wed Sep 05 11:12:15 2018 -0700
@@ -24,8 +24,6 @@
 
 package MyPackage;
 
-import java.util.List;
-
 /**
  * @test
  * @summary Verifies the JVMTI Heap Monitor API
@@ -44,22 +42,7 @@
       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();