< prev index next >

test/hotspot/jtreg/runtime/locking/TestRecursiveMonitorChurn.java

Print this page

40     static class Monitor {
41         public static volatile int i, j;
42         synchronized void doSomething() {
43             i++;
44             doSomethingElse();
45         }
46         synchronized void doSomethingElse() {
47             j++;
48         }
49     }
50 
51     static final WhiteBox WB = WhiteBox.getWhiteBox();
52     static final int LM_MONITOR = 0;
53     static final int COUNT = 100000;
54 
55     public static volatile Monitor monitor;
56     public static void main(String[] args) {
57         if (WB.getIntVMFlag("LockingMode") == LM_MONITOR) {
58             throw new SkippedException("LM_MONITOR always inflates. Invalid test.");
59         }

60         final long pre_monitor_count = WB.getInUseMonitorCount();
61         System.out.println(" Precount = " + pre_monitor_count);
62         for (int i = 0; i < COUNT; i++) {
63             monitor = new Monitor();
64             monitor.doSomething();
65         }
66         System.out.println("i + j = " + (Monitor.i + Monitor.j));
67         final long post_monitor_count = WB.getInUseMonitorCount();
68         System.out.println("Postcount = " + post_monitor_count);
69 
70         if (pre_monitor_count != post_monitor_count) {
71             final long monitor_count_change = post_monitor_count - pre_monitor_count;
72             System.out.println("Unexpected change in monitor count: " + monitor_count_change);
73             if (monitor_count_change < 0) {
74                 throw new RuntimeException("Unexpected Deflation");
75             }
76             throw new RuntimeException("Unexpected Inflation");
77         }
78     }
79 }

40     static class Monitor {
41         public static volatile int i, j;
42         synchronized void doSomething() {
43             i++;
44             doSomethingElse();
45         }
46         synchronized void doSomethingElse() {
47             j++;
48         }
49     }
50 
51     static final WhiteBox WB = WhiteBox.getWhiteBox();
52     static final int LM_MONITOR = 0;
53     static final int COUNT = 100000;
54 
55     public static volatile Monitor monitor;
56     public static void main(String[] args) {
57         if (WB.getIntVMFlag("LockingMode") == LM_MONITOR) {
58             throw new SkippedException("LM_MONITOR always inflates. Invalid test.");
59         }
60         System.out.println("Starting test...");
61         final long pre_monitor_count = WB.getInUseMonitorCount();
62         System.out.println(" Precount = " + pre_monitor_count);
63         for (int i = 0; i < COUNT; i++) {
64             monitor = new Monitor();
65             monitor.doSomething();
66         }
67         System.out.println("i + j = " + (Monitor.i + Monitor.j));
68         final long post_monitor_count = WB.getInUseMonitorCount();
69         System.out.println("Postcount = " + post_monitor_count);
70 
71         if (pre_monitor_count != post_monitor_count) {
72             final long monitor_count_change = post_monitor_count - pre_monitor_count;
73             System.out.println("Unexpected change in monitor count: " + monitor_count_change);
74             if (monitor_count_change < 0) {
75                 throw new RuntimeException("Unexpected Deflation");
76             }
77             throw new RuntimeException("Unexpected Inflation");
78         }
79     }
80 }
< prev index next >