Skip to content

Commit ad591c5

Browse files
committed
8355317: [lworld] C2 Runtime load_unknown_inline should not return null-free type
1 parent cb47c37 commit ad591c5

File tree

5 files changed

+58
-9
lines changed

5 files changed

+58
-9
lines changed

src/hotspot/share/opto/macro.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ SafePointScalarObjectNode* PhaseMacroExpand::create_scalarized_object_descriptio
922922
// Below code only iterates over the flat representation and therefore misses to
923923
// add null markers like we do in InlineTypeNode::add_fields_to_safepoint for value
924924
// class holders.
925+
_igvn._worklist.push(sfpt);
925926
return nullptr;
926927
}
927928

src/hotspot/share/opto/parse2.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ void Parse::array_load(BasicType bt) {
138138
// Element type is unknown, and thus we cannot statically determine the exact flat array layout. Emit a
139139
// runtime call to correctly load the inline type element from the flat array.
140140
Node* inline_type = load_from_unknown_flat_array(array, array_index, element_ptr);
141+
bool is_null_free = array_type->is_null_free() || !UseNullableValueFlattening;
142+
if (is_null_free) {
143+
inline_type = cast_not_null(inline_type);
144+
}
141145
ideal.set(res, inline_type);
142146
}
143147
}

src/hotspot/share/opto/runtime.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2284,7 +2284,7 @@ const TypeFunc* OptoRuntime::load_unknown_inline_Type() {
22842284

22852285
// create result type (range)
22862286
fields = TypeTuple::fields(1);
2287-
fields[TypeFunc::Parms] = TypeInstPtr::NOTNULL;
2287+
fields[TypeFunc::Parms] = TypeInstPtr::BOTTOM;
22882288

22892289
const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
22902290

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -2526,18 +2526,18 @@ public Test92Value() {
25262526
}
25272527

25282528
@Test
2529-
@IR(applyIf = {"UseArrayFlattening", "true"},
2529+
// TODO 8355382 The optimization only applies to null-free, flat arrays
2530+
@IR(applyIfAnd = {"UseArrayFlattening", "true", "UseNullableValueFlattening", "false"},
25302531
counts = {CLASS_CHECK_TRAP, "= 2"},
25312532
failOn = {LOAD_UNKNOWN_INLINE, ALLOC_G, MEMBAR})
25322533
public Object test92(Object[] array) {
25332534
// Dummy loops to ensure we run enough passes of split if
25342535
for (int i = 0; i < 2; i++) {
25352536
for (int j = 0; j < 2; j++) {
2536-
for (int k = 0; k < 2; k++) {
2537-
}
2537+
for (int k = 0; k < 2; k++) {
2538+
}
25382539
}
25392540
}
2540-
25412541
return (NonValueClass)array[0];
25422542
}
25432543

@@ -2561,8 +2561,7 @@ public Object test93(Object[] array) {
25612561
}
25622562
}
25632563

2564-
Object v = (NonValueClass)array[0];
2565-
return v;
2564+
return (NonValueClass)array[0];
25662565
}
25672566

25682567
@Run(test = "test93")
@@ -2595,7 +2594,8 @@ public void test93_verifier(RunInfo info) {
25952594
}
25962595

25972596
@Test
2598-
@IR(applyIf = {"UseArrayFlattening", "true"},
2597+
// TODO 8355382 The optimization only applies to null-free, flat arrays
2598+
@IR(applyIfAnd = {"UseArrayFlattening", "true", "UseNullableValueFlattening", "false"},
25992599
counts = {CLASS_CHECK_TRAP, "= 2", LOOP, "= 1"},
26002600
failOn = {LOAD_UNKNOWN_INLINE, ALLOC_G, MEMBAR})
26012601
public int test94(Object[] array) {

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

+45-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -3293,4 +3293,48 @@ public void test125_verifier(RunInfo info) {
32933293
Asserts.assertEquals(test125(true, val1, info.getTest(), true), val2.hash());
32943294
}
32953295
}
3296+
3297+
static Object oFld = null;
3298+
3299+
static value class MyValue126 {
3300+
int x;
3301+
3302+
MyValue126(int x) {
3303+
this.x = x;
3304+
}
3305+
}
3306+
3307+
// Test that result of access to unknown flat array is not marked as null-free
3308+
@Test
3309+
public void test126(Object[] array, int i) {
3310+
oFld = array[i];
3311+
}
3312+
3313+
@Run(test = "test126")
3314+
@Warmup(0)
3315+
public void test126_verifier() {
3316+
MyValue126[] array = (MyValue126[]) ValueClass.newNullableAtomicArray(MyValue126.class, 2);
3317+
array[1] = new MyValue126(rI);
3318+
test126(array, 1);
3319+
Asserts.assertEquals(oFld, new MyValue126(rI));
3320+
test126(array, 0);
3321+
Asserts.assertEquals(oFld, null);
3322+
}
3323+
3324+
// Same as test126 but different failure mode
3325+
@Test
3326+
public void test127(Object[] array, int i) {
3327+
oFld = (MyValue126)array[i];
3328+
}
3329+
3330+
@Run(test = "test127")
3331+
@Warmup(0)
3332+
public void test127_verifier() {
3333+
MyValue126[] array = (MyValue126[]) ValueClass.newNullableAtomicArray(MyValue126.class, 2);
3334+
array[1] = new MyValue126(rI);
3335+
test127(array, 1);
3336+
Asserts.assertEquals(oFld, new MyValue126(rI));
3337+
test127(array, 0);
3338+
Asserts.assertEquals(oFld, null);
3339+
}
32963340
}

0 commit comments

Comments
 (0)