Skip to content

Commit f87d6d1

Browse files
mhaessigTobiHartmann
authored andcommitted
8380921: [lworld] compiler/stable/TestStableArrayMembars.java IR mismatch with preview enabled
Reviewed-by: thartmann
1 parent e08d163 commit f87d6d1

3 files changed

Lines changed: 54 additions & 14 deletions

File tree

src/hotspot/share/opto/compile.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,7 @@ static bool return_val_keeps_allocations_alive(Node* ret_val) {
20022002
n->in(1)->is_Proj() &&
20032003
n->in(1)->in(0)->is_Allocate()) {
20042004
some_allocations = true;
2005-
} else if (n->is_CheckCastPP()) {
2005+
} else if (n->is_CheckCastPP() || n->is_CastPP()) {
20062006
wq.push(n->in(1));
20072007
}
20082008
}
@@ -3275,10 +3275,13 @@ void Compile::Optimize() {
32753275
if (failing()) {
32763276
return;
32773277
}
3278-
process_inline_types(igvn);
32793278
}
32803279
assert(_late_inlines.length() == 0, "late inline queue must be drained");
32813280

3281+
// Process inline types before macro expansion. Otherwise, we will not be able to
3282+
// remove unused allocations because it cannot match the expanded allocation.
3283+
process_inline_types(igvn);
3284+
32823285
{
32833286
TracePhase tp(_t_macroExpand);
32843287
PhaseMacroExpand mex(igvn);

test/hotspot/jtreg/ProblemList-enable-preview.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
compiler/c2/ReachabilityFenceFlagsTest.java 8382503 generic-all
4040
compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaField.java 8372605 generic-all
4141
compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaType.java 8372605 generic-all
42-
compiler/stable/TestStableArrayMembars.java 8380921 generic-all
4342

4443
# Runtime:
4544
runtime/cds/appcds/aotCode/AOTCodeFlags.java#default_gc 8382398 generic-all

test/hotspot/jtreg/compiler/stable/TestStableArrayMembars.java

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,40 @@
2727
* @summary Test that membars are eliminated when loading from a stable array.
2828
* @library /test/lib /
2929
* @modules java.base/jdk.internal.misc
30+
* @modules java.base/jdk.internal.value
3031
* @modules java.base/jdk.internal.vm.annotation
3132
* @run driver ${test.main.class}
3233
*/
3334

3435
package compiler.stable;
3536

3637
import java.util.Objects;
38+
import java.util.Set;
3739

3840
import jdk.internal.misc.Unsafe;
41+
import jdk.internal.value.ValueClass;
3942
import jdk.internal.vm.annotation.Stable;
4043

44+
import jdk.test.lib.Asserts;
4145
import compiler.lib.ir_framework.*;
4246

4347
public class TestStableArrayMembars {
4448

4549
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
4650

51+
private static final int THE_VALUE = 42;
52+
4753
public static void main(String[] args) {
4854
TestFramework tf = new TestFramework();
4955
tf.addTestClassesToBootClassPath();
50-
tf.addFlags( "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED");
56+
tf.addFlags("--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
57+
"--add-exports=java.base/jdk.internal.value=ALL-UNNAMED");
58+
if (Integer.class.isValue()) {
59+
tf.addCrossProductScenarios(Set.of("", "-XX:-UseArrayFlattening",
60+
"-XX:-UseArrayFlattening -XX:-InlineTypePassFieldsAsArgs",
61+
"-XX:-UseArrayFlattening -XX:-InlineTypeReturnedAsFields",
62+
"-XX:-UseArrayFlattening -XX:-InlineTypePassFieldsAsArgs -XX:-InlineTypeReturnedAsFields"));
63+
}
5164
tf.start();
5265
}
5366

@@ -61,45 +74,70 @@ static final class LazyIntArray {
6174

6275
@ForceInline
6376
Integer get(int idx) {
64-
Integer i = contentsAcquire(offsetFor(idx));
77+
Integer i = contentsAcquire(offsetFor(arr, idx));
6578
return i == null ? slowPath(arr, idx) : i;
6679
}
6780

6881
@ForceInline
6982
private Integer contentsAcquire(long offset) {
70-
return (Integer) UNSAFE.getReferenceAcquire(arr, offset);
83+
return (Integer) (ValueClass.isFlatArray(arr) ?
84+
UNSAFE.getFlatValueAcquire(arr, offset, UNSAFE.arrayLayout(arr), Integer.class) :
85+
UNSAFE.getReferenceAcquire(arr, offset));
7186
}
7287

7388
@ForceInline
74-
private static long offsetFor(long index) {
75-
return Unsafe.ARRAY_OBJECT_BASE_OFFSET + Unsafe.ARRAY_OBJECT_INDEX_SCALE * index;
89+
private static long offsetFor(Integer[] arr, long index) {
90+
return UNSAFE.arrayInstanceBaseOffset(arr) + UNSAFE.arrayInstanceIndexScale(arr) * index;
7691
}
7792

7893
static Integer slowPath(final Integer[] array, final int index) {
79-
final long offset = offsetFor(index);
94+
final long offset = offsetFor(array, index);
8095
final Integer t = array[index];
8196
if (t == null) {
82-
final Integer newValue = Integer.valueOf(42);
97+
final Integer newValue = Integer.valueOf(THE_VALUE);
8398
Objects.requireNonNull(newValue);
84-
set(array, index, newValue);
99+
set(array, index, offset, newValue);
85100

86101
return newValue;
87102
}
88103
return t;
89104
}
90105

91-
static void set(Integer[] array, int index, Integer newValue) {
106+
static void set(Integer[] array, int index, long offset, Integer newValue) {
92107
if (array[index] == null) {
93-
UNSAFE.putReferenceRelease(array, Unsafe.ARRAY_OBJECT_BASE_OFFSET + Unsafe.ARRAY_OBJECT_INDEX_SCALE * (long) index, newValue);
108+
if (!ValueClass.isFlatArray(array)) {
109+
UNSAFE.putReferenceRelease(array, offset, newValue);
110+
} else {
111+
UNSAFE.putFlatValueRelease(array, offset, UNSAFE.arrayLayout(array), Integer.class, newValue);
112+
}
94113
}
95114
}
96115
}
97116

98117
static final LazyIntArray la = new LazyIntArray();
99118

100119
@Test
101-
@IR(failOn = { IRNode.LOAD, IRNode.MEMBAR })
120+
// We cannot eliminate all barriers with flat arrays, because Unsafe.getFlatValueAcquire()
121+
// explicitly adds a loadFence() in Java. Hence, there is no way for C2 to correlate those
122+
// barriers to an eliminated memory access and thus no way to remove them.
123+
// The barrier elimination only works with tiered compilation as the profiling information
124+
// is nessecary to inline the low-frequency Unsafe.put* methods.
125+
@IR(failOn = { IRNode.LOAD, IRNode.MEMBAR },
126+
applyIfAnd = {"enable-valhalla", "false",
127+
"TieredCompilation", "true"})
128+
@IR(failOn = { IRNode.LOAD, IRNode.MEMBAR },
129+
applyIfAnd = {"UseArrayFlattening", "false",
130+
"TieredCompilation", "true"})
131+
@IR(counts = { IRNode.MEMBAR, ">0",
132+
IRNode.LOAD, "=1"}, // There is exactly one load fence, but no load
133+
applyIfAnd = {"enable-valhalla", "true",
134+
"UseArrayFlattening", "true"})
102135
static Integer test() {
103136
return la.get(0);
104137
}
138+
139+
@Check(test = "test")
140+
static void check(Integer testResult) {
141+
Asserts.assertEQ(THE_VALUE, testResult.intValue(), "Incorrect result from LazyIntArray");
142+
}
105143
}

0 commit comments

Comments
 (0)