Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hotspot/share/opto/parse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ class Parse : public GraphKit {
bool path_is_suitable_for_uncommon_trap(float prob) const;

void do_ifnull(BoolTest::mask btest, Node* c);
void do_if(BoolTest::mask btest, Node* c, bool can_trap = true, bool new_path = false, Node** ctrl_taken = nullptr);
void do_if(BoolTest::mask btest, Node* c, bool can_trap = true, bool new_path = false, Node** ctrl_taken = nullptr, Node** stress_count_mem = nullptr);
void do_acmp(BoolTest::mask btest, Node* left, Node* right);
void acmp_always_null_input(Node* input, const TypeOopPtr* tinput, BoolTest::mask btest, Node* eq_region);
void acmp_known_non_inline_type_input(Node* input, const TypeOopPtr* tinput, ProfilePtrKind input_ptr, ciKlass* input_type, BoolTest::mask btest, Node* eq_region);
Expand Down
13 changes: 10 additions & 3 deletions src/hotspot/share/opto/parse2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,7 @@ void Parse::do_ifnull(BoolTest::mask btest, Node *c) {
}

//------------------------------------do_if------------------------------------
void Parse::do_if(BoolTest::mask btest, Node* c, bool can_trap, bool new_path, Node** ctrl_taken) {
void Parse::do_if(BoolTest::mask btest, Node* c, bool can_trap, bool new_path, Node** ctrl_taken, Node** stress_count_mem) {
int target_bci = iter().get_dest();

Block* branch_block = successor_for_bci(target_bci);
Expand Down Expand Up @@ -1850,6 +1850,9 @@ void Parse::do_if(BoolTest::mask btest, Node* c, bool can_trap, bool new_path, N
bool do_stress_trap = StressUnstableIfTraps && ((C->random() % 2) == 0);
if (do_stress_trap) {
increment_trap_stress_counter(counter, incr_store);
if (stress_count_mem != nullptr) {
*stress_count_mem = incr_store;
}
}

// Sanity check the probability value
Expand Down Expand Up @@ -2313,22 +2316,26 @@ void Parse::do_acmp(BoolTest::mask btest, Node* left, Node* right) {
// This is the last check, do_if can emit traps now.
Node* subst_cmp = _gvn.transform(new CmpINode(ret, intcon(1)));
Node* ctl = C->top();
Node* stress_count_mem = nullptr;
if (btest == BoolTest::eq) {
PreserveJVMState pjvms(this);
do_if(btest, subst_cmp, can_trap);
do_if(btest, subst_cmp, can_trap, false, nullptr, &stress_count_mem);
if (!stopped()) {
ctl = control();
}
} else {
assert(btest == BoolTest::ne, "only eq or ne");
PreserveJVMState pjvms(this);
do_if(btest, subst_cmp, can_trap, false, &ctl);
do_if(btest, subst_cmp, can_trap, false, &ctl, &stress_count_mem);
if (!stopped()) {
eq_region->init_req(2, control());
eq_io_phi->init_req(2, i_o());
eq_mem_phi->init_req(2, reset_memory());
}
}
if (stress_count_mem != nullptr) {
set_memory(stress_count_mem, stress_count_mem->adr_type());
}
ne_region->init_req(5, ctl);
ne_io_phi->init_req(5, i_o());
ne_mem_phi->init_req(5, reset_memory());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2025, Oracle and/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
* @key randomness
* @bug 8367244
* @summary Ensure the stress counter is wired correctly with StressUnstableIf for acmp.
* @enablePreview
* @run main/othervm -Xbatch -XX:-TieredCompilation
* -XX:CompileCommand=compileonly,compiler/valhalla/inlinetypes/TestAcmpStressUnstableIf.test
* -XX:+UnlockDiagnosticVMOptions -XX:+StressUnstableIfTraps -XX:StressSeed=3862475856
* compiler.valhalla.inlinetypes.TestAcmpStressUnstableIf
* @run main/othervm -Xbatch -XX:-TieredCompilation
* -XX:CompileCommand=compileonly,compiler/valhalla/inlinetypes/TestAcmpStressUnstableIf.test
* -XX:+UnlockDiagnosticVMOptions -XX:+StressUnstableIfTraps
* compiler.valhalla.inlinetypes.TestAcmpStressUnstableIf
* @run main compiler.valhalla.inlinetypes.TestAcmpStressUnstableIf
*/

package compiler.valhalla.inlinetypes;

public class TestAcmpStressUnstableIf {
static value class MyValue {
int x;

public MyValue(int x) {
this.x = x;
}
}

public static void main(String[] args) {
MyValue val = new MyValue(123456);
MyValue val_copy = new MyValue(123456);
MyValue val_diff = new MyValue(123456 + 1);

test(val, val_copy, val_diff);
}

public static void test(MyValue val, MyValue val_copy, MyValue val_diff) {
for (int i = 0; i < 30_000; ++i) {
if (val != val_copy) {
return;
}
if (val == val_diff) {
return;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@
* @summary Test that deoptimization at unstable ifs in acmp works as expected.
* @library /test/lib
* @enablePreview
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:-StressUnstableIfTraps compiler.valhalla.inlinetypes.TestAcmpWithUnstableIf
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+StressUnstableIfTraps compiler.valhalla.inlinetypes.TestAcmpWithUnstableIf
* @run main/othervm -XX:CompileCommand=compileonly,compiler.valhalla.inlinetypes.TestAcmpWithUnstableIf::test* -Xbatch
* -XX:+UnlockDiagnosticVMOptions -XX:-StressUnstableIfTraps compiler.valhalla.inlinetypes.TestAcmpWithUnstableIf
* -XX:+UnlockDiagnosticVMOptions -XX:+StressUnstableIfTraps compiler.valhalla.inlinetypes.TestAcmpWithUnstableIf
*/

// TODO 8367244: Remove -XX:-StressUnstableIfTraps again.

package compiler.valhalla.inlinetypes;

import jdk.test.lib.Asserts;
Expand Down