Skip to content

Commit ff2f39f

Browse files
committed
8340214: C2 compilation asserts with "no node with a side effect" in PhaseIdealLoop::try_sink_out_of_loop
Reviewed-by: chagedorn, thartmann
1 parent ecc77a5 commit ff2f39f

File tree

4 files changed

+123
-12
lines changed

4 files changed

+123
-12
lines changed

src/hotspot/share/opto/compile.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,12 +1466,18 @@ const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const {
14661466
} else {
14671467
ciInstanceKlass *canonical_holder = ik->get_canonical_holder(offset);
14681468
assert(offset < canonical_holder->layout_helper_size_in_bytes(), "");
1469-
if (!ik->equals(canonical_holder) || tj->offset() != offset) {
1470-
if( is_known_inst ) {
1471-
tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, true, nullptr, offset, to->instance_id());
1472-
} else {
1473-
tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, false, nullptr, offset);
1474-
}
1469+
assert(tj->offset() == offset, "no change to offset expected");
1470+
bool xk = to->klass_is_exact();
1471+
int instance_id = to->instance_id();
1472+
1473+
// If the input type's class is the holder: if exact, the type only includes interfaces implemented by the holder
1474+
// but if not exact, it may include extra interfaces: build new type from the holder class to make sure only
1475+
// its interfaces are included.
1476+
if (xk && ik->equals(canonical_holder)) {
1477+
assert(tj == TypeInstPtr::make(to->ptr(), canonical_holder, is_known_inst, nullptr, offset, instance_id), "exact type should be canonical type");
1478+
} else {
1479+
assert(xk || !is_known_inst, "Known instance should be exact type");
1480+
tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, is_known_inst, nullptr, offset, instance_id);
14751481
}
14761482
}
14771483
}

src/hotspot/share/opto/graphKit.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,7 @@ Node* GraphKit::make_load(Node* ctl, Node* adr, const Type* t, BasicType bt,
15581558
bool mismatched,
15591559
bool unsafe,
15601560
uint8_t barrier_data) {
1561+
assert(adr_idx == C->get_alias_index(_gvn.type(adr)->isa_ptr()), "slice of address and input slice don't match");
15611562
assert(adr_idx != Compile::AliasIdxTop, "use other make_load factory" );
15621563
const TypePtr* adr_type = nullptr; // debug-mode-only argument
15631564
debug_only(adr_type = C->get_adr_type(adr_idx));
@@ -1587,6 +1588,7 @@ Node* GraphKit::store_to_memory(Node* ctl, Node* adr, Node *val, BasicType bt,
15871588
bool unsafe,
15881589
int barrier_data) {
15891590
assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory" );
1591+
assert(adr_idx == C->get_alias_index(_gvn.type(adr)->isa_ptr()), "slice of address and input slice don't match");
15901592
const TypePtr* adr_type = nullptr;
15911593
debug_only(adr_type = C->get_adr_type(adr_idx));
15921594
Node *mem = memory(adr_idx);

src/hotspot/share/opto/library_call.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,11 +2959,10 @@ bool LibraryCallKit::inline_native_notify_jvmti_funcs(address funcAddr, const ch
29592959
Node* thread = ideal.thread();
29602960
Node* jt_addr = basic_plus_adr(thread, in_bytes(JavaThread::is_in_VTMS_transition_offset()));
29612961
Node* vt_addr = basic_plus_adr(vt_oop, java_lang_Thread::is_in_VTMS_transition_offset());
2962-
const TypePtr *addr_type = _gvn.type(addr)->isa_ptr();
29632962

29642963
sync_kit(ideal);
2965-
access_store_at(nullptr, jt_addr, addr_type, hide, _gvn.type(hide), T_BOOLEAN, IN_NATIVE | MO_UNORDERED);
2966-
access_store_at(nullptr, vt_addr, addr_type, hide, _gvn.type(hide), T_BOOLEAN, IN_NATIVE | MO_UNORDERED);
2964+
access_store_at(nullptr, jt_addr, _gvn.type(jt_addr)->is_ptr(), hide, _gvn.type(hide), T_BOOLEAN, IN_NATIVE | MO_UNORDERED);
2965+
access_store_at(nullptr, vt_addr, _gvn.type(vt_addr)->is_ptr(), hide, _gvn.type(hide), T_BOOLEAN, IN_NATIVE | MO_UNORDERED);
29672966

29682967
ideal.sync_kit(this);
29692968
} ideal.end_if();
@@ -3325,7 +3324,9 @@ bool LibraryCallKit::inline_native_getEventWriter() {
33253324

33263325
// Load the raw epoch value from the threadObj.
33273326
Node* threadObj_epoch_offset = basic_plus_adr(threadObj, java_lang_Thread::jfr_epoch_offset());
3328-
Node* threadObj_epoch_raw = access_load_at(threadObj, threadObj_epoch_offset, TypeRawPtr::BOTTOM, TypeInt::CHAR, T_CHAR,
3327+
Node* threadObj_epoch_raw = access_load_at(threadObj, threadObj_epoch_offset,
3328+
_gvn.type(threadObj_epoch_offset)->isa_ptr(),
3329+
TypeInt::CHAR, T_CHAR,
33293330
IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD);
33303331

33313332
// Mask off the excluded information from the epoch.
@@ -3344,7 +3345,8 @@ bool LibraryCallKit::inline_native_getEventWriter() {
33443345

33453346
// Load the raw epoch value from the vthread.
33463347
Node* vthread_epoch_offset = basic_plus_adr(vthread, java_lang_Thread::jfr_epoch_offset());
3347-
Node* vthread_epoch_raw = access_load_at(vthread, vthread_epoch_offset, TypeRawPtr::BOTTOM, TypeInt::CHAR, T_CHAR,
3348+
Node* vthread_epoch_raw = access_load_at(vthread, vthread_epoch_offset, _gvn.type(vthread_epoch_offset)->is_ptr(),
3349+
TypeInt::CHAR, T_CHAR,
33483350
IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD);
33493351

33503352
// Mask off the excluded information from the epoch.
@@ -3590,7 +3592,7 @@ void LibraryCallKit::extend_setCurrentThread(Node* jt, Node* thread) {
35903592

35913593
// Load the raw epoch value from the vthread.
35923594
Node* epoch_offset = basic_plus_adr(thread, java_lang_Thread::jfr_epoch_offset());
3593-
Node* epoch_raw = access_load_at(thread, epoch_offset, TypeRawPtr::BOTTOM, TypeInt::CHAR, T_CHAR,
3595+
Node* epoch_raw = access_load_at(thread, epoch_offset, _gvn.type(epoch_offset)->is_ptr(), TypeInt::CHAR, T_CHAR,
35943596
IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD);
35953597

35963598
// Mask off the excluded information from the epoch.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright (c) 2024, Red Hat, Inc. 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 8340214
27+
* @summary C2 compilation asserts with "no node with a side effect" in PhaseIdealLoop::try_sink_out_of_loop
28+
*
29+
* @run main/othervm -XX:-BackgroundCompilation TestBadMemSliceWithInterfaces
30+
*
31+
*/
32+
33+
public class TestBadMemSliceWithInterfaces {
34+
public static void main(String[] args) {
35+
B b = new B();
36+
C c = new C();
37+
for (int i = 0; i < 20_000; i++) {
38+
test1(b, c, true);
39+
test1(b, c, false);
40+
b.field = 0;
41+
c.field = 0;
42+
int res = test2(b, c, true);
43+
if (res != 42) {
44+
throw new RuntimeException("incorrect result " + res);
45+
}
46+
res = test2(b, c, false);
47+
if (res != 42) {
48+
throw new RuntimeException("incorrect result " + res);
49+
}
50+
}
51+
}
52+
53+
private static void test1(B b, C c, boolean flag) {
54+
A a;
55+
if (flag) {
56+
a = b;
57+
} else {
58+
a = c;
59+
}
60+
for (int i = 0; i < 1000; i++) {
61+
a.field = 42;
62+
}
63+
}
64+
65+
private static int test2(B b, C c, boolean flag) {
66+
A a;
67+
if (flag) {
68+
a = b;
69+
} else {
70+
a = c;
71+
}
72+
int v = 0;
73+
for (int i = 0; i < 2; i++) {
74+
v += a.field;
75+
a.field = 42;
76+
}
77+
return v;
78+
}
79+
80+
interface I {
81+
void m();
82+
}
83+
84+
static class A {
85+
int field;
86+
}
87+
88+
static class B extends A implements I {
89+
@Override
90+
public void m() {
91+
92+
}
93+
}
94+
95+
static class C extends A implements I {
96+
@Override
97+
public void m() {
98+
99+
}
100+
}
101+
}

0 commit comments

Comments
 (0)