test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatObjectCorrectnessTest.java
changeset 51138 914f305ba6fa
parent 51136 6d6611346837
child 51559 57f1bf06742e
equal deleted inserted replaced
51137:e3bcc86855dd 51138:914f305ba6fa
    48       obj = new BigObject();
    48       obj = new BigObject();
    49     }
    49     }
    50     HeapMonitor.disableSamplingEvents();
    50     HeapMonitor.disableSamplingEvents();
    51   }
    51   }
    52 
    52 
    53   private static void testBigAllocationRate() {
    53   private static void testBigAllocationInterval() {
    54     final int sizeObject = 1400;
    54     final int sizeObject = 1400;
    55 
    55 
    56     // 111 is as good a number as any.
    56     // 111 is as good a number as any.
    57     final int samplingMultiplier = 111;
    57     final int samplingMultiplier = 111;
    58     HeapMonitor.setSamplingRate(samplingMultiplier * sizeObject);
    58     HeapMonitor.setSamplingInterval(samplingMultiplier * sizeObject);
    59 
    59 
    60     allocate();
    60     allocate();
    61 
    61 
    62     // For simplifications, the code is allocating:
    62     // For simplifications, the code is allocating:
    63     //   (BigObject size) * maxIteration.
    63     //   (BigObject size) * maxIteration.
    77     //   maxIterations / samplingMultiplier
    77     //   maxIterations / samplingMultiplier
    78     double expected = maxIteration;
    78     double expected = maxIteration;
    79     expected /= samplingMultiplier;
    79     expected /= samplingMultiplier;
    80 
    80 
    81     // 10% error ensures a sanity test without becoming flaky.
    81     // 10% error ensures a sanity test without becoming flaky.
    82     // Flakiness is due to the fact that this test is dependent on the sampling rate, which is a
    82     // Flakiness is due to the fact that this test is dependent on the sampling interval, which is a
    83     // statistical geometric variable around the sampling rate. This means that the test could be
    83     // statistical geometric variable around the sampling interval. This means that the test could be
    84     // unlucky and not achieve the mean average fast enough for the test case.
    84     // unlucky and not achieve the mean average fast enough for the test case.
    85     if (!HeapMonitor.statsHaveExpectedNumberSamples((int) expected, 10)) {
    85     if (!HeapMonitor.statsHaveExpectedNumberSamples((int) expected, 10)) {
    86       throw new RuntimeException("Statistics should show about " + expected + " samples.");
    86       throw new RuntimeException("Statistics should show about " + expected + " samples.");
    87     }
    87     }
    88   }
    88   }
    95     }
    95     }
    96   }
    96   }
    97 
    97 
    98   private static void testEveryAllocationSampled() {
    98   private static void testEveryAllocationSampled() {
    99     // 0 means sample every allocation.
    99     // 0 means sample every allocation.
   100     HeapMonitor.setSamplingRate(0);
   100     HeapMonitor.setSamplingInterval(0);
   101 
   101 
   102     allocate();
   102     allocate();
   103 
   103 
   104     double expected = maxIteration;
   104     double expected = maxIteration;
   105 
   105 
   106     // 10% error ensures a sanity test without becoming flaky.
   106     // 10% error ensures a sanity test without becoming flaky.
   107     // Flakiness is due to the fact that this test is dependent on the sampling rate, which is a
   107     // Flakiness is due to the fact that this test is dependent on the sampling interval, which is a
   108     // statistical geometric variable around the sampling rate. This means that the test could be
   108     // statistical geometric variable around the sampling interval. This means that the test could be
   109     // unlucky and not achieve the mean average fast enough for the test case.
   109     // unlucky and not achieve the mean average fast enough for the test case.
   110     if (!HeapMonitor.statsHaveExpectedNumberSamples((int) expected, 10)) {
   110     if (!HeapMonitor.statsHaveExpectedNumberSamples((int) expected, 10)) {
   111       throw new RuntimeException("Statistics should show about " + expected + " samples.");
   111       throw new RuntimeException("Statistics should show about " + expected + " samples.");
   112     }
   112     }
   113   }
   113   }
   114 
   114 
   115   public static void main(String[] args) {
   115   public static void main(String[] args) {
   116     testBigAllocationRate();
   116     testBigAllocationInterval();
   117     testEveryAllocationSampled();
   117     testEveryAllocationSampled();
   118   }
   118   }
   119 
   119 
   120   /**
   120   /**
   121    * Big class on purpose to just be able to ignore the class memory space overhead.
   121    * Big class on purpose to just be able to ignore the class memory space overhead.