1 /*
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /**
25 * @test
26 * @bug 8031320
27 * @summary Verify that RTMLockingThreshold affects rtm state transition
28 * ProfileRTM => UseRTM.
29 * @library /test/lib /
30 * @modules java.base/jdk.internal.misc
31 * java.management
32 * @requires vm.rtm.cpu & vm.rtm.compiler
33 * @build sun.hotspot.WhiteBox
34 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
35 * sun.hotspot.WhiteBox$WhiteBoxPermission
36 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
37 * -XX:+WhiteBoxAPI
38 * compiler.rtm.locking.TestRTMLockingThreshold
39 */
40
41 package compiler.rtm.locking;
42
43 import compiler.testlibrary.rtm.AbortProvoker;
44 import compiler.testlibrary.rtm.CompilableTest;
45 import compiler.testlibrary.rtm.RTMLockingStatistics;
46 import compiler.testlibrary.rtm.RTMTestBase;
47 import jdk.internal.misc.Unsafe;
48 import jdk.test.lib.Asserts;
49 import jdk.test.lib.process.OutputAnalyzer;
50 import jdk.test.lib.cli.CommandLineOptionTest;
51
52 import java.util.List;
53
54 /**
55 * Test verifies that RTMLockingThreshold option actually affects how soon
56 * method will be deoptimized on low abort ratio.
57 */
58 public class TestRTMLockingThreshold {
59
60 /**
61 * We use non-zero abort threshold to avoid abort related to
62 * interrupts, VMM calls, etc. during first lock attempt.
63 *
64 */
65 private static final int MIN_ABORT_THRESHOLD = 10;
66
67 protected void runTestCases() throws Throwable {
117 }
118
119 RTMLockingStatistics statBeforeDeopt = null;
120 for (RTMLockingStatistics s : statistics) {
121 if (s.getTotalLocks() == expectedValue) {
122 Asserts.assertNull(statBeforeDeopt,
123 "Only one statistics entry should contain aborts");
124 statBeforeDeopt = s;
125 }
126 }
127
128 Asserts.assertNotNull(statBeforeDeopt, "There should be exactly one "
129 + "statistics entry corresponding to ProfileRTM state.");
130 }
131
132 public static class Test implements CompilableTest {
133 // Following field have to be static in order to avoid escape analysis.
134 @SuppressWarnings("UnsuedDeclaration")
135 private static int field = 0;
136 private static final int TOTAL_ITERATIONS = 10000;
137 private static final Unsafe UNSAFE = Unsafe.getUnsafe();
138 private final Object monitor = new Object();
139
140
141 @Override
142 public String getMethodWithLockName() {
143 return this.getClass().getName() + "::lock";
144 }
145
146 @Override
147 public String[] getMethodsToCompileNames() {
148 return new String[] { getMethodWithLockName() };
149 }
150
151 public void lock(boolean abort) {
152 synchronized(monitor) {
153 if (abort) {
154 Test.field += Test.UNSAFE.pageSize();
155 }
156 }
157 }
158
159 /**
160 * Usage:
161 * Test <inflate monitor>
162 */
163 public static void main(String args[]) throws Throwable {
164 Asserts.assertGTE(args.length, 2, "Two arguments required.");
165 Test t = new Test();
166 boolean shouldBeInflated = Boolean.valueOf(args[0]);
167 int lockingThreshold = Integer.valueOf(args[1]);
168 if (shouldBeInflated) {
169 AbortProvoker.inflateMonitor(t.monitor);
170 }
171 for (int i = 0; i < Test.TOTAL_ITERATIONS; i++) {
172 AbortProvoker.verifyMonitorState(t.monitor, shouldBeInflated);
173 t.lock(i >= lockingThreshold / 2);
174 }
|
1 /*
2 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /**
25 * @test
26 * @bug 8031320
27 * @summary Verify that RTMLockingThreshold affects rtm state transition
28 * ProfileRTM => UseRTM.
29 * @library /test/lib /
30 * @modules java.base/jdk.internal.misc
31 * java.management
32 * @requires vm.rtm.cpu & vm.rtm.compiler
33 * @build sun.hotspot.WhiteBox
34 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
35 * sun.hotspot.WhiteBox$WhiteBoxPermission
36 * @run main/othervm/native -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
37 * -XX:+WhiteBoxAPI
38 * compiler.rtm.locking.TestRTMLockingThreshold
39 */
40
41 package compiler.rtm.locking;
42
43 import compiler.testlibrary.rtm.AbortProvoker;
44 import compiler.testlibrary.rtm.XAbortProvoker;
45 import compiler.testlibrary.rtm.CompilableTest;
46 import compiler.testlibrary.rtm.RTMLockingStatistics;
47 import compiler.testlibrary.rtm.RTMTestBase;
48 import jdk.test.lib.Asserts;
49 import jdk.test.lib.process.OutputAnalyzer;
50 import jdk.test.lib.cli.CommandLineOptionTest;
51
52 import java.util.List;
53
54 /**
55 * Test verifies that RTMLockingThreshold option actually affects how soon
56 * method will be deoptimized on low abort ratio.
57 */
58 public class TestRTMLockingThreshold {
59
60 /**
61 * We use non-zero abort threshold to avoid abort related to
62 * interrupts, VMM calls, etc. during first lock attempt.
63 *
64 */
65 private static final int MIN_ABORT_THRESHOLD = 10;
66
67 protected void runTestCases() throws Throwable {
117 }
118
119 RTMLockingStatistics statBeforeDeopt = null;
120 for (RTMLockingStatistics s : statistics) {
121 if (s.getTotalLocks() == expectedValue) {
122 Asserts.assertNull(statBeforeDeopt,
123 "Only one statistics entry should contain aborts");
124 statBeforeDeopt = s;
125 }
126 }
127
128 Asserts.assertNotNull(statBeforeDeopt, "There should be exactly one "
129 + "statistics entry corresponding to ProfileRTM state.");
130 }
131
132 public static class Test implements CompilableTest {
133 // Following field have to be static in order to avoid escape analysis.
134 @SuppressWarnings("UnsuedDeclaration")
135 private static int field = 0;
136 private static final int TOTAL_ITERATIONS = 10000;
137 private final XAbortProvoker xabort = new XAbortProvoker();
138 private final Object monitor = new Object();
139
140 @Override
141 public String getMethodWithLockName() {
142 return this.getClass().getName() + "::lock";
143 }
144
145 @Override
146 public String[] getMethodsToCompileNames() {
147 return new String[] { getMethodWithLockName(),
148 XAbortProvoker.class.getName() + "::doAbort" };
149 }
150
151 public void lock(boolean abort) {
152 synchronized(monitor) {
153 if (abort) {
154 Test.field += xabort.doAbort();
155 }
156 }
157 }
158
159 /**
160 * Usage:
161 * Test <inflate monitor>
162 */
163 public static void main(String args[]) throws Throwable {
164 Asserts.assertGTE(args.length, 2, "Two arguments required.");
165 Test t = new Test();
166 boolean shouldBeInflated = Boolean.valueOf(args[0]);
167 int lockingThreshold = Integer.valueOf(args[1]);
168 if (shouldBeInflated) {
169 AbortProvoker.inflateMonitor(t.monitor);
170 }
171 for (int i = 0; i < Test.TOTAL_ITERATIONS; i++) {
172 AbortProvoker.verifyMonitorState(t.monitor, shouldBeInflated);
173 t.lock(i >= lockingThreshold / 2);
174 }
|