< prev index next >
test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatObjectCorrectnessTest.java
Print this page
rev 49267 : [mq]: event5
rev 49268 : [mq]: event6
*** 24,34 ****
package MyPackage;
/**
* @test
* @build Frame HeapMonitor
! * @summary Verifies the JVMTI Heap Monitor Statistics
* @compile HeapMonitorStatObjectCorrectnessTest.java
* @run main/othervm/native -agentlib:HeapMonitor MyPackage.HeapMonitorStatObjectCorrectnessTest
*/
/** This test is checking the object allocation path works with heap sampling. */
--- 24,34 ----
package MyPackage;
/**
* @test
* @build Frame HeapMonitor
! * @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,64 ****
for (int j = 0; j < maxIteration; j++) {
obj = new BigObject();
}
}
! public static void main(String[] args) {
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);
allocate();
// For simplifications, the code is allocating:
// (BigObject size) * maxIteration.
//
--- 44,61 ----
for (int j = 0; j < maxIteration; j++) {
obj = new BigObject();
}
}
! private static void testBigAllocationRate() {
final int sizeObject = 1400;
// 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,91 ****
--- 77,116 ----
// 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 >