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
74 // Intermittent deflation and inflation may occur due to running the test
75 // with stress flags (like DeoptimizeALot) or with added instrumentation
76 // which runs in the same VM.
77 // An arbitrary fuzzy max difference of 10 (= 0.01% of COUNT) is chosen to
78 // allow for these occurrences to be skipped while still catching regressions.
79 final long fuzzy_max_difference = 10;
|
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
75 // Intermittent deflation and inflation may occur due to running the test
76 // with stress flags (like DeoptimizeALot) or with added instrumentation
77 // which runs in the same VM.
78 // An arbitrary fuzzy max difference of 10 (= 0.01% of COUNT) is chosen to
79 // allow for these occurrences to be skipped while still catching regressions.
80 final long fuzzy_max_difference = 10;
|