Skip to content

Commit

Permalink
Add test to motivate compile-time null checks in 'refine_barrier_by_n…
Browse files Browse the repository at this point in the history
…ew_val_type'
  • Loading branch information
robcasloz committed Aug 30, 2024
1 parent 72a04c4 commit 57adcfb
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ public static void testStoreNull(Outer o) {
o.f = null;
}

@Test
@IR(applyIf = {"UseCompressedOops", "false"},
counts = {IRNode.G1_STORE_P_WITH_BARRIER_FLAG, PRE_ONLY, "1"},
phase = CompilePhase.FINAL_CODE)
@IR(applyIf = {"UseCompressedOops", "true"},
counts = {IRNode.G1_STORE_N_WITH_BARRIER_FLAG, PRE_ONLY, "1"},
phase = CompilePhase.FINAL_CODE)
public static void testStoreObfuscatedNull(Outer o, Object o1) {
Object o2 = o1;
for (int i = 0; i < 4; i++) {
if ((i % 2) == 0) {
o2 = null;
}
}
// o2 is null here, but this is only known to C2 after applying some
// optimizations (loop unrolling, IGVN).
o.f = o2;
}

@Test
@IR(applyIf = {"UseCompressedOops", "false"},
counts = {IRNode.G1_STORE_P_WITH_BARRIER_FLAG, PRE_AND_POST_NOT_NULL, "1"},
Expand Down Expand Up @@ -165,6 +184,7 @@ public static Outer testStoreOnNewObject(Object o1) {

@Run(test = {"testStore",
"testStoreNull",
"testStoreObfuscatedNull",
"testStoreNotNull",
"testStoreTwice",
"testStoreOnNewObject"})
Expand All @@ -180,6 +200,12 @@ public void runStoreTests() {
testStoreNull(o);
Asserts.assertNull(o.f);
}
{
Outer o = new Outer();
Object o1 = new Object();
testStoreObfuscatedNull(o, o1);
Asserts.assertNull(o.f);
}
{
Outer o = new Outer();
Object o1 = new Object();
Expand Down

0 comments on commit 57adcfb

Please sign in to comment.