test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorEventOnOffTest.java
changeset 52722 19de50eb561d
parent 51559 57f1bf06742e
child 52886 2708a32dc964
equal deleted inserted replaced
52721:732bec44c89e 52722:19de50eb561d
    32  * @build Frame HeapMonitor
    32  * @build Frame HeapMonitor
    33  * @compile HeapMonitorEventOnOffTest.java
    33  * @compile HeapMonitorEventOnOffTest.java
    34  * @run main/othervm/native -agentlib:HeapMonitorTest MyPackage.HeapMonitorEventOnOffTest
    34  * @run main/othervm/native -agentlib:HeapMonitorTest MyPackage.HeapMonitorEventOnOffTest
    35  */
    35  */
    36 public class HeapMonitorEventOnOffTest {
    36 public class HeapMonitorEventOnOffTest {
    37   private static void checkNoEventsAreBeingSent() {
       
    38     HeapMonitor.resetEventStorage();
       
    39     HeapMonitor.repeatAllocate(5);
       
    40 
       
    41     // Check that the data is not available while heap sampling is disabled.
       
    42     boolean status = HeapMonitor.eventStorageIsEmpty();
       
    43     if (!status) {
       
    44       throw new RuntimeException("Storage is not empty after allocating with disabled events.");
       
    45     }
       
    46   }
       
    47 
       
    48   private static void checkEventsAreBeingSent() {
       
    49     List<Frame> frameList = HeapMonitor.repeatAllocate(5);
       
    50 
       
    51     frameList.add(new Frame("checkEventsAreBeingSent", "()V", "HeapMonitorEventOnOffTest.java", 49));
       
    52     Frame[] frames = frameList.toArray(new Frame[0]);
       
    53 
       
    54     // Check that the data is available while heap sampling is enabled.
       
    55     boolean status = HeapMonitor.obtainedEvents(frames);
       
    56     if (!status) {
       
    57       throw new RuntimeException("Failed to find the traces after allocating with enabled events.");
       
    58     }
       
    59   }
       
    60 
       
    61   public static void main(String[] args) {
    37   public static void main(String[] args) {
    62     HeapMonitor.enableSamplingEvents();
    38     HeapMonitor.enableSamplingEvents();
    63     checkEventsAreBeingSent();
    39     HeapMonitor.allocateAndCheckFrames();
    64 
    40 
    65     // Disabling the notification system should stop events.
    41     // Disabling the notification system should stop events.
    66     HeapMonitor.disableSamplingEvents();
    42     HeapMonitor.disableSamplingEvents();
    67     checkNoEventsAreBeingSent();
    43     HeapMonitor.resetEventStorage();
       
    44     HeapMonitor.allocateAndCheckFrames(false, false);
    68 
    45 
    69     // Enabling the notification system should start events again.
    46     // Enabling the notification system should start events again.
    70     HeapMonitor.enableSamplingEvents();
    47     HeapMonitor.enableSamplingEvents();
    71     checkEventsAreBeingSent();
    48     HeapMonitor.allocateAndCheckFrames();
    72   }
    49   }
    73 }
    50 }