Skip to content

Commit c75f0f1

Browse files
committed
8252111: [lworld] C2 intrinsic needs to handle unsafe access to non-flattened field of constant inline type holder
1 parent 2d8688f commit c75f0f1

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

src/hotspot/share/opto/library_call.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,7 +2490,6 @@ bool LibraryCallKit::inline_unsafe_access(bool is_store, const BasicType type, c
24902490

24912491
if (base->is_InlineType()) {
24922492
InlineTypeNode* vt = base->as_InlineType();
2493-
24942493
if (is_store) {
24952494
if (!vt->is_allocated(&_gvn) || !_gvn.type(vt)->is_inlinetype()->larval()) {
24962495
return false;
@@ -2504,18 +2503,15 @@ bool LibraryCallKit::inline_unsafe_access(bool is_store, const BasicType type, c
25042503
return false;
25052504
}
25062505

2507-
ciField* f = vk->get_non_flattened_field_by_offset((int)off);
2508-
2509-
if (f != NULL) {
2510-
BasicType bt = f->layout_type();
2511-
if (bt == T_ARRAY || bt == T_NARROWOOP) {
2506+
ciField* field = vk->get_non_flattened_field_by_offset(off);
2507+
if (field != NULL) {
2508+
BasicType bt = field->layout_type();
2509+
if (bt == T_ARRAY || bt == T_NARROWOOP || (bt == T_INLINE_TYPE && !field->is_flattened())) {
25122510
bt = T_OBJECT;
25132511
}
2514-
if (bt == type) {
2515-
if (bt != T_INLINE_TYPE || f->type() == inline_klass) {
2516-
set_result(vt->field_value_by_offset((int)off, false));
2517-
return true;
2518-
}
2512+
if (bt == type && (bt != T_INLINE_TYPE || field->type() == inline_klass)) {
2513+
set_result(vt->field_value_by_offset(off, false));
2514+
return true;
25192515
}
25202516
}
25212517
}

test/hotspot/jtreg/compiler/valhalla/inlinetypes/TestIntrinsics.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,4 +1027,21 @@ public void test54_verifier(boolean warmup) {
10271027
MyValue1 res = test54(v.setX(v, 0));
10281028
Asserts.assertEQ(res.hash(), v.hash());
10291029
}
1030+
1031+
static final MyValue1 test55_vt = MyValue1.createWithFieldsInline(rI, rL);
1032+
1033+
// Same as test30 but with constant field holder
1034+
@Test(failOn=CALL_Unsafe)
1035+
public MyValue2 test55() {
1036+
if (V1_FLATTENED) {
1037+
return U.getValue(test55_vt, V1_OFFSET, MyValue2.val.class);
1038+
}
1039+
return (MyValue2)U.getReference(test55_vt, V1_OFFSET);
1040+
}
1041+
1042+
@DontCompile
1043+
public void test55_verifier(boolean warmup) {
1044+
MyValue2 res = test55();
1045+
Asserts.assertEQ(res.hash(), test55_vt.v1.hash());
1046+
}
10301047
}

0 commit comments

Comments
 (0)