< prev index next >

test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatObjectCorrectnessTest.java

Print this page
rev 49267 : [mq]: event5
rev 49268 : [mq]: event6

@@ -24,11 +24,11 @@
 package MyPackage;
 
 /**
  * @test
  * @build Frame HeapMonitor
- * @summary Verifies the JVMTI Heap Monitor Statistics
+ * @summary Verifies the JVMTI Heap Monitor sampling via object allocation.
  * @compile HeapMonitorStatObjectCorrectnessTest.java
  * @run main/othervm/native -agentlib:HeapMonitor MyPackage.HeapMonitorStatObjectCorrectnessTest
  */
 
 /** This test is checking the object allocation path works with heap sampling. */

@@ -44,21 +44,18 @@
     for (int j = 0; j < maxIteration; j++) {
       obj = new BigObject();
     }
   }
 
-  public static void main(String[] args) {
+  private static void testBigAllocationRate() {
     final int sizeObject = 1400;
 
-    if (!HeapMonitor.eventStorageIsEmpty()) {
-      throw new RuntimeException("Statistics should be null to begin with.");
-    }
-
     // 111 is as good a number as any.
     final int samplingMultiplier = 111;
     HeapMonitor.setSamplingRate(samplingMultiplier * sizeObject);
 
+    emptyStorage();
     allocate();
 
     // For simplifications, the code is allocating:
     //   (BigObject size) * maxIteration.
     //

@@ -80,12 +77,40 @@
 
     // 10% error ensures a sanity test without becoming flaky.
     if (!HeapMonitor.statsHaveExpectedNumberSamples((int) expected, 10)) {
       throw new RuntimeException("Statistics should show about " + expected + " samples.");
     }
+  }
 
+  private static void emptyStorage() {
     HeapMonitor.resetEventStorage();
+
+    if (!HeapMonitor.eventStorageIsEmpty()) {
+      throw new RuntimeException("Statistics should be null to begin with.");
+    }
+  }
+
+  private static void testEveryAllocationSampled() {
+    // 0 means sample every allocation.
+    HeapMonitor.setSamplingRate(0);
+
+    emptyStorage();
+    allocate();
+
+    double expected = maxIteration;
+
+    // 10% error ensures a sanity test without becoming flaky.
+    if (!HeapMonitor.statsHaveExpectedNumberSamples((int) expected, 10)) {
+      throw new RuntimeException("Statistics should show about " + expected + " samples.");
+    }
+  }
+
+  public static void main(String[] args) {
+    HeapMonitor.enableSamplingEvents();
+
+    testBigAllocationRate();
+    testEveryAllocationSampled();
   }
 
   /**
    * Big class on purpose to just be able to ignore the class memory space overhead.
    *
< prev index next >