diff --git a/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp b/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp index b6ecde62af6..c79753618c0 100644 --- a/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp +++ b/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp @@ -1022,15 +1022,18 @@ void C2_MacroAssembler::fast_lock_lightweight(Register obj, Register box, Regist #ifdef ASSERT // Check that locked label is reached with ZF set. Label zf_correct; - jccb(Assembler::zero, zf_correct); - stop("Fast Lock ZF != 1"); + Label zf_bad_zero; + jcc(Assembler::zero, zf_correct); + jmp(zf_bad_zero); #endif bind(slow_path); #ifdef ASSERT // Check that slow_path label is reached with ZF not set. - jccb(Assembler::notZero, zf_correct); + jcc(Assembler::notZero, zf_correct); stop("Fast Lock ZF != 0"); + bind(zf_bad_zero); + stop("Fast Lock ZF != 1"); bind(zf_correct); #endif // C2 uses the value of ZF to determine the continuation. @@ -1161,7 +1164,7 @@ void C2_MacroAssembler::fast_unlock_lightweight(Register obj, Register reg_rax, #ifdef ASSERT // Check that unlocked label is reached with ZF set. Label zf_correct; - jccb(Assembler::zero, zf_correct); + jcc(Assembler::zero, zf_correct); stop("Fast Unlock ZF != 1"); #endif diff --git a/test/hotspot/jtreg/compiler/c2/TestLWLockingCodeGen.java b/test/hotspot/jtreg/compiler/c2/TestLWLockingCodeGen.java new file mode 100644 index 00000000000..ad91ba0b02e --- /dev/null +++ b/test/hotspot/jtreg/compiler/c2/TestLWLockingCodeGen.java @@ -0,0 +1,38 @@ +/* + * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @summary Tests correct code generation of lightweight locking when using -XX:+ShowMessageBoxOnError; times-out on failure + * @bug 8329726 + * @run main/othervm -XX:+ShowMessageBoxOnError -Xcomp -XX:-TieredCompilation -XX:CompileOnly=TestLWLockingCodeGen::sync TestLWLockingCodeGen + */ +public class TestLWLockingCodeGen { + private static int val = 0; + public static void main(String[] args) { + sync(); + } + private static synchronized void sync() { + val = val + (int)(Math.random() * 42); + } +}