< prev index next >

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

Print this page

 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  */
 24 
 25 package MyPackage;
 26 
 27 import java.util.ArrayList;
 28 import java.util.List;
 29 
 30 // Graal is not tested here due to Graal not supporting DisableIntrinsic.
 31 /**
 32  * @test
 33  * @summary Verifies that when the VM event is sent, sampled events are also collected.


 34  * @build Frame HeapMonitor
 35  * @compile HeapMonitorVMEventsTest.java









 36  * @requires vm.jvmti
 37  * @requires !vm.graal.enabled
 38  * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions



 39  *                          -XX:DisableIntrinsic=_clone
 40  *                          -agentlib:HeapMonitorTest MyPackage.HeapMonitorVMEventsTest
 41  */
 42 
 43 public class HeapMonitorVMEventsTest implements Cloneable {
 44   private static native int vmEvents();
 45   private static final int ITERATIONS = 1 << 15;
 46   private static final Object[] array = new Object[ITERATIONS];
 47 
 48   private static void cloneObjects(int iterations) {
 49     HeapMonitorVMEventsTest object = new HeapMonitorVMEventsTest();
 50     for (int i = 0; i < iterations; i++) {
 51       try {
 52         array[i] = object.clone();
 53       } catch (Exception e) {
 54         throw new RuntimeException(e);
 55       }
 56     }
 57   }
 58 
 59   public Object clone() throws CloneNotSupportedException {
 60     return super.clone();

 77     cloneObjects(ITERATIONS);
 78 
 79     int onlySampleCount = HeapMonitor.sampledEvents();
 80 
 81     HeapMonitor.enableVMEvents();
 82     HeapMonitor.resetEventStorage();
 83     if (!HeapMonitor.eventStorageIsEmpty()) {
 84       throw new RuntimeException("Storage is not empty after reset.");
 85     }
 86 
 87     cloneObjects(ITERATIONS);
 88 
 89     int sampleCount = HeapMonitor.sampledEvents();
 90     int vmCount = vmEvents();
 91 
 92     System.err.println("Obtained: " + onlySampleCount + " - " + sampleCount + " - "  + vmCount);
 93     checkDifference(onlySampleCount, sampleCount);
 94     checkDifference(onlySampleCount, vmCount);
 95   }
 96 
 97   public static void main(String[] args) {
 98     if (!HeapMonitor.eventStorageIsEmpty()) {
 99       throw new RuntimeException("Storage is not empty at test start...");
100     }
101 
102     HeapMonitor.sampleEverything();
103     compareSampledAndVM();








104   }
105 }

 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  */
 24 
 25 package MyPackage;
 26 
 27 import java.util.ArrayList;
 28 import java.util.List;
 29 
 30 // Graal is not tested here due to Graal not supporting DisableIntrinsic.
 31 /**
 32  * @test
 33  * @summary Verifies that when the VM event is sent, sampled events are also collected.
 34  * @requires vm.jvmti
 35  * @requires !vm.graal.enabled
 36  * @build Frame HeapMonitor
 37  * @compile --enable-preview -source ${jdk.version} HeapMonitorVMEventsTest.java
 38  * @run main/othervm/native --enable-preview
 39  *                          -XX:+UnlockDiagnosticVMOptions
 40  *                          -XX:DisableIntrinsic=_clone
 41  *                          -agentlib:HeapMonitorTest MyPackage.HeapMonitorVMEventsTest platform
 42  */
 43 
 44 /**
 45  * @test
 46  * @summary Verifies that when the VM event is sent, sampled events are also collected.
 47  * @requires vm.jvmti
 48  * @requires !vm.graal.enabled
 49  * @build Frame HeapMonitor
 50  * @compile --enable-preview -source ${jdk.version} HeapMonitorVMEventsTest.java
 51  * @run main/othervm/native --enable-preview
 52  *                          -XX:+UnlockDiagnosticVMOptions
 53  *                          -XX:DisableIntrinsic=_clone
 54  *                          -agentlib:HeapMonitorTest MyPackage.HeapMonitorVMEventsTest virtual
 55  */
 56 
 57 public class HeapMonitorVMEventsTest implements Cloneable {
 58   private static native int vmEvents();
 59   private static final int ITERATIONS = 1 << 15;
 60   private static final Object[] array = new Object[ITERATIONS];
 61 
 62   private static void cloneObjects(int iterations) {
 63     HeapMonitorVMEventsTest object = new HeapMonitorVMEventsTest();
 64     for (int i = 0; i < iterations; i++) {
 65       try {
 66         array[i] = object.clone();
 67       } catch (Exception e) {
 68         throw new RuntimeException(e);
 69       }
 70     }
 71   }
 72 
 73   public Object clone() throws CloneNotSupportedException {
 74     return super.clone();

 91     cloneObjects(ITERATIONS);
 92 
 93     int onlySampleCount = HeapMonitor.sampledEvents();
 94 
 95     HeapMonitor.enableVMEvents();
 96     HeapMonitor.resetEventStorage();
 97     if (!HeapMonitor.eventStorageIsEmpty()) {
 98       throw new RuntimeException("Storage is not empty after reset.");
 99     }
100 
101     cloneObjects(ITERATIONS);
102 
103     int sampleCount = HeapMonitor.sampledEvents();
104     int vmCount = vmEvents();
105 
106     System.err.println("Obtained: " + onlySampleCount + " - " + sampleCount + " - "  + vmCount);
107     checkDifference(onlySampleCount, sampleCount);
108     checkDifference(onlySampleCount, vmCount);
109   }
110 
111   public static void main(String[] args) throws Exception {
112     if (!HeapMonitor.eventStorageIsEmpty()) {
113       throw new RuntimeException("Storage is not empty at test start...");
114     }
115 
116     HeapMonitor.sampleEverything();
117 
118     if(args[0].equals("virtual")) {
119         Thread t = Thread.ofVirtual().start(() -> {
120                 compareSampledAndVM();
121             });
122         t.join();
123     } else {
124         compareSampledAndVM();
125     }
126   }
127 }
< prev index next >