test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorArrayAllSampledTest.java
changeset 51138 914f305ba6fa
parent 50579 1596f418ffe4
child 51559 57f1bf06742e
equal deleted inserted replaced
51137:e3bcc86855dd 51138:914f305ba6fa
    24 package MyPackage;
    24 package MyPackage;
    25 
    25 
    26 /**
    26 /**
    27  * @test
    27  * @test
    28  * @build Frame HeapMonitor
    28  * @build Frame HeapMonitor
    29  * @summary Verifies the JVMTI Heap Monitor rate when allocating arrays.
    29  * @summary Verifies the JVMTI Heap Monitor interval when allocating arrays.
    30  * @compile HeapMonitorArrayAllSampledTest.java
    30  * @compile HeapMonitorArrayAllSampledTest.java
    31  * @run main/othervm/native -agentlib:HeapMonitorTest MyPackage.HeapMonitorArrayAllSampledTest
    31  * @run main/othervm/native -agentlib:HeapMonitorTest MyPackage.HeapMonitorArrayAllSampledTest
    32  */
    32  */
    33 
    33 
    34 public class HeapMonitorArrayAllSampledTest {
    34 public class HeapMonitorArrayAllSampledTest {
    44   }
    44   }
    45 
    45 
    46   public static void main(String[] args) {
    46   public static void main(String[] args) {
    47     int sizes[] = {1000, 10000, 100000, 1000000};
    47     int sizes[] = {1000, 10000, 100000, 1000000};
    48 
    48 
    49     HeapMonitor.setSamplingRate(0);
    49     HeapMonitor.setSamplingInterval(0);
    50     HeapMonitor.enableSamplingEvents();
    50     HeapMonitor.enableSamplingEvents();
    51 
    51 
    52     for (int currentSize : sizes) {
    52     for (int currentSize : sizes) {
    53       System.out.println("Testing size " + currentSize);
    53       System.out.println("Testing size " + currentSize);
    54 
    54 
    55       HeapMonitor.resetEventStorage();
    55       HeapMonitor.resetEventStorage();
    56       allocate(currentSize);
    56       allocate(currentSize);
    57 
    57 
    58       // 10% error ensures a sanity test without becoming flaky.
    58       // 10% error ensures a sanity test without becoming flaky.
    59       // Flakiness is due to the fact that this test is dependent on the sampling rate, which is a
    59       // Flakiness is due to the fact that this test is dependent on the sampling interval, which is a
    60       // statistical geometric variable around the sampling rate. This means that the test could be
    60       // statistical geometric variable around the sampling interval. This means that the test could be
    61       // unlucky and not achieve the mean average fast enough for the test case.
    61       // unlucky and not achieve the mean average fast enough for the test case.
    62       if (!HeapMonitor.statsHaveExpectedNumberSamples(maxIteration, 10)) {
    62       if (!HeapMonitor.statsHaveExpectedNumberSamples(maxIteration, 10)) {
    63         throw new RuntimeException("Statistics should show about " + maxIteration + " samples.");
    63         throw new RuntimeException("Statistics should show about " + maxIteration + " samples.");
    64       }
    64       }
    65     }
    65     }