Mon, 28 Jul 2014 15:06:38 -0700
8051344: JVM crashed in Compile::start() during method parsing w/ UseRTMDeopt turned on
Summary: call rtm_deopt() only if there were no compilation bailouts before.
Reviewed-by: kvn
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | /** |
aoqi@0 | 26 | * @test |
aoqi@0 | 27 | * @bug 8031320 |
aoqi@0 | 28 | * @summary Verify that RTMAbortRatio affects amount of aborts before |
aoqi@0 | 29 | * deoptimization. |
aoqi@0 | 30 | * @library /testlibrary /testlibrary/whitebox /compiler/testlibrary |
aoqi@0 | 31 | * @build TestRTMAbortRatio |
aoqi@0 | 32 | * @run main ClassFileInstaller sun.hotspot.WhiteBox |
aoqi@0 | 33 | * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions |
aoqi@0 | 34 | * -XX:+WhiteBoxAPI TestRTMAbortRatio |
aoqi@0 | 35 | */ |
aoqi@0 | 36 | |
aoqi@0 | 37 | import java.util.List; |
aoqi@0 | 38 | import com.oracle.java.testlibrary.*; |
aoqi@0 | 39 | import com.oracle.java.testlibrary.cli.CommandLineOptionTest; |
aoqi@0 | 40 | import com.oracle.java.testlibrary.cli.predicate.AndPredicate; |
aoqi@0 | 41 | import rtm.*; |
aoqi@0 | 42 | import rtm.predicate.SupportedCPU; |
aoqi@0 | 43 | import rtm.predicate.SupportedVM; |
aoqi@0 | 44 | import sun.misc.Unsafe; |
aoqi@0 | 45 | |
aoqi@0 | 46 | /** |
aoqi@0 | 47 | * Test verifies that method will be deoptimized on high abort ratio |
aoqi@0 | 48 | * as soon as abort ratio reaches RTMAbortRatio's value. |
aoqi@0 | 49 | */ |
aoqi@0 | 50 | public class TestRTMAbortRatio extends CommandLineOptionTest { |
aoqi@0 | 51 | private TestRTMAbortRatio() { |
aoqi@0 | 52 | super(new AndPredicate(new SupportedCPU(), new SupportedVM())); |
aoqi@0 | 53 | } |
aoqi@0 | 54 | |
aoqi@0 | 55 | @Override |
aoqi@0 | 56 | protected void runTestCases() throws Throwable { |
aoqi@0 | 57 | verifyAbortRatio(0, false); |
aoqi@0 | 58 | verifyAbortRatio(10, false); |
aoqi@0 | 59 | verifyAbortRatio(50, false); |
aoqi@0 | 60 | verifyAbortRatio(100, false); |
aoqi@0 | 61 | |
aoqi@0 | 62 | verifyAbortRatio(0, true); |
aoqi@0 | 63 | verifyAbortRatio(10, true); |
aoqi@0 | 64 | verifyAbortRatio(50, true); |
aoqi@0 | 65 | verifyAbortRatio(100, true); |
aoqi@0 | 66 | } |
aoqi@0 | 67 | |
aoqi@0 | 68 | private void verifyAbortRatio(int abortRatio, boolean useStackLock) |
aoqi@0 | 69 | throws Throwable { |
aoqi@0 | 70 | CompilableTest test = new Test(); |
aoqi@0 | 71 | |
aoqi@0 | 72 | OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest( |
aoqi@0 | 73 | test, |
aoqi@0 | 74 | CommandLineOptionTest.prepareBooleanFlag("UseRTMForStackLocks", |
aoqi@0 | 75 | useStackLock), |
aoqi@0 | 76 | "-XX:+UseRTMDeopt", |
aoqi@0 | 77 | "-XX:RTMTotalCountIncrRate=1", |
aoqi@0 | 78 | "-XX:RTMAbortThreshold=0", |
aoqi@0 | 79 | CommandLineOptionTest.prepareNumericFlag("RTMLockingThreshold", |
aoqi@0 | 80 | 10 * Test.TOTAL_ITERATIONS), |
aoqi@0 | 81 | CommandLineOptionTest.prepareNumericFlag("RTMAbortRatio", |
aoqi@0 | 82 | abortRatio), |
aoqi@0 | 83 | "-XX:+PrintPreciseRTMLockingStatistics", |
aoqi@0 | 84 | test.getClass().getName(), |
aoqi@0 | 85 | Boolean.toString(!useStackLock)); |
aoqi@0 | 86 | |
aoqi@0 | 87 | outputAnalyzer.shouldHaveExitValue(0); |
aoqi@0 | 88 | |
aoqi@0 | 89 | List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString( |
aoqi@0 | 90 | test.getMethodWithLockName(), outputAnalyzer.getOutput()); |
aoqi@0 | 91 | |
aoqi@0 | 92 | Asserts.assertEQ(statistics.size(), 1, "VM output should contain " |
aoqi@0 | 93 | + "exactly one RTM locking statistics entry."); |
aoqi@0 | 94 | |
aoqi@0 | 95 | RTMLockingStatistics lock = statistics.get(0); |
aoqi@0 | 96 | int actualRatio; |
aoqi@0 | 97 | |
aoqi@0 | 98 | if (lock.getTotalAborts() == 1L) { |
aoqi@0 | 99 | actualRatio = 0; |
aoqi@0 | 100 | } else { |
aoqi@0 | 101 | actualRatio = (int) (lock.getTotalLocks() |
aoqi@0 | 102 | / (lock.getTotalAborts() - 1L)); |
aoqi@0 | 103 | } |
aoqi@0 | 104 | |
aoqi@0 | 105 | Asserts.assertLTE(actualRatio, abortRatio, String.format( |
aoqi@0 | 106 | "Actual abort ratio (%d) should lower or equal to " |
aoqi@0 | 107 | + "specified (%d).", actualRatio, abortRatio)); |
aoqi@0 | 108 | } |
aoqi@0 | 109 | |
aoqi@0 | 110 | /** |
aoqi@0 | 111 | * Force abort after {@code Test.WARMUP_ITERATIONS} is done. |
aoqi@0 | 112 | */ |
aoqi@0 | 113 | public static class Test implements CompilableTest { |
aoqi@0 | 114 | private static final int TOTAL_ITERATIONS = 10000; |
aoqi@0 | 115 | private static final int WARMUP_ITERATIONS = 1000; |
aoqi@0 | 116 | private static final Unsafe UNSAFE = Utils.getUnsafe(); |
aoqi@0 | 117 | private final Object monitor = new Object(); |
aoqi@0 | 118 | // Following field have to be static in order to avoid escape analysis. |
aoqi@0 | 119 | @SuppressWarnings("UnsuedDeclaration") |
aoqi@0 | 120 | private static int field = 0; |
aoqi@0 | 121 | |
aoqi@0 | 122 | @Override |
aoqi@0 | 123 | public String getMethodWithLockName() { |
aoqi@0 | 124 | return this.getClass().getName() + "::lock"; |
aoqi@0 | 125 | } |
aoqi@0 | 126 | |
aoqi@0 | 127 | @Override |
aoqi@0 | 128 | public String[] getMethodsToCompileNames() { |
aoqi@0 | 129 | return new String[] { |
aoqi@0 | 130 | getMethodWithLockName(), |
aoqi@0 | 131 | Unsafe.class.getName() + "::addressSize" |
aoqi@0 | 132 | }; |
aoqi@0 | 133 | } |
aoqi@0 | 134 | |
aoqi@0 | 135 | public void lock(boolean abort) { |
aoqi@0 | 136 | synchronized(monitor) { |
aoqi@0 | 137 | if (abort) { |
aoqi@0 | 138 | Test.UNSAFE.addressSize(); |
aoqi@0 | 139 | } |
aoqi@0 | 140 | } |
aoqi@0 | 141 | } |
aoqi@0 | 142 | |
aoqi@0 | 143 | /** |
aoqi@0 | 144 | * Usage: |
aoqi@0 | 145 | * Test <inflate monitor> |
aoqi@0 | 146 | */ |
aoqi@0 | 147 | public static void main(String args[]) throws Throwable { |
aoqi@0 | 148 | Asserts.assertGTE(args.length, 1, "One argument required."); |
aoqi@0 | 149 | Test t = new Test(); |
aoqi@0 | 150 | if (Boolean.valueOf(args[0])) { |
aoqi@0 | 151 | AbortProvoker.inflateMonitor(t.monitor); |
aoqi@0 | 152 | } |
aoqi@0 | 153 | for (int i = 0; i < Test.TOTAL_ITERATIONS; i++) { |
aoqi@0 | 154 | t.lock(i >= Test.WARMUP_ITERATIONS); |
aoqi@0 | 155 | } |
aoqi@0 | 156 | } |
aoqi@0 | 157 | } |
aoqi@0 | 158 | |
aoqi@0 | 159 | public static void main(String args[]) throws Throwable { |
aoqi@0 | 160 | new TestRTMAbortRatio().test(); |
aoqi@0 | 161 | } |
aoqi@0 | 162 | } |
aoqi@0 | 163 |