< prev index next >

test/hotspot/jtreg/runtime/whitebox/TestWBDeflateIdleMonitors.java

Print this page

44     static final int N_TRIES = 5;     // number of times to try deflation
45 
46     public static void main(String args[]) throws Exception {
47         ProcessBuilder pb = ProcessTools.createTestJvm(
48                 "-Xbootclasspath/a:.",
49                 "-XX:+UnlockDiagnosticVMOptions",
50                 "-XX:+WhiteBoxAPI",
51                 "-Xlog:monitorinflation=info",
52                 InflateMonitorsTest.class.getName());
53 
54         OutputAnalyzer output = new OutputAnalyzer(pb.start());
55         System.out.println(output.getStdout());
56         output.shouldHaveExitValue(0);
57         output.shouldContain("WhiteBox initiated DeflateIdleMonitors");
58     }
59 
60     public static class InflateMonitorsTest {
61         static WhiteBox wb = WhiteBox.getWhiteBox();
62         public static Object obj;
63 
64         public static void main(String args[]) {
65             obj = new Object();
66             synchronized (obj) {
67                 // HotSpot implementation detail: asking for the hash code
68                 // when the object is locked causes monitor inflation.
69                 if (obj.hashCode() == 0xBAD) System.out.println("!");
70                 Asserts.assertEQ(wb.isMonitorInflated(obj), true,
71                                  "Monitor should be inflated.");
72             }
73             for (int cnt = 1; cnt <= N_TRIES; cnt++) {
74                 System.out.println("Deflation try #" + cnt);
75                 boolean did_deflation = wb.deflateIdleMonitors();
76                 Asserts.assertEQ(did_deflation, true,
77                                  "deflateIdleMonitors() should have worked.");
78                 if (!wb.isMonitorInflated(obj)) {
79                     // Deflation worked so no more retries needed.
80                     break;
81                 }
82                 try {
83                     System.out.println("Deflation try #" + cnt + " failed. "
84                                        + "Delaying before retry.");
85                     Thread.sleep(N_DELAY);
86                 } catch (InterruptedException ie) {
87                 }
88             }
89             Asserts.assertEQ(wb.isMonitorInflated(obj), false,

44     static final int N_TRIES = 5;     // number of times to try deflation
45 
46     public static void main(String args[]) throws Exception {
47         ProcessBuilder pb = ProcessTools.createTestJvm(
48                 "-Xbootclasspath/a:.",
49                 "-XX:+UnlockDiagnosticVMOptions",
50                 "-XX:+WhiteBoxAPI",
51                 "-Xlog:monitorinflation=info",
52                 InflateMonitorsTest.class.getName());
53 
54         OutputAnalyzer output = new OutputAnalyzer(pb.start());
55         System.out.println(output.getStdout());
56         output.shouldHaveExitValue(0);
57         output.shouldContain("WhiteBox initiated DeflateIdleMonitors");
58     }
59 
60     public static class InflateMonitorsTest {
61         static WhiteBox wb = WhiteBox.getWhiteBox();
62         public static Object obj;
63 
64         public static void main(String args[]) throws Exception {
65             obj = new Object();
66             synchronized (obj) {
67                 // The current implementation of notify-wait requires inflation.
68                 obj.wait(1);

69                 Asserts.assertEQ(wb.isMonitorInflated(obj), true,
70                                  "Monitor should be inflated.");
71             }
72             for (int cnt = 1; cnt <= N_TRIES; cnt++) {
73                 System.out.println("Deflation try #" + cnt);
74                 boolean did_deflation = wb.deflateIdleMonitors();
75                 Asserts.assertEQ(did_deflation, true,
76                                  "deflateIdleMonitors() should have worked.");
77                 if (!wb.isMonitorInflated(obj)) {
78                     // Deflation worked so no more retries needed.
79                     break;
80                 }
81                 try {
82                     System.out.println("Deflation try #" + cnt + " failed. "
83                                        + "Delaying before retry.");
84                     Thread.sleep(N_DELAY);
85                 } catch (InterruptedException ie) {
86                 }
87             }
88             Asserts.assertEQ(wb.isMonitorInflated(obj), false,
< prev index next >