OpenJDK / valhalla / valhalla
changeset 55533:f5bc35131607 lworld
8224482: [lworld] Scalar replacement computes incorrect value for uninitialized non-flattened value array
author | thartmann |
---|---|
date | Tue, 21 May 2019 12:42:13 +0200 |
parents | 41d46f42527c |
children | 3a17e853a30b |
files | src/hotspot/share/opto/macro.cpp test/hotspot/jtreg/compiler/valhalla/valuetypes/TestNullableArrays.java |
diffstat | 2 files changed, 33 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/hotspot/share/opto/macro.cpp Tue May 21 10:54:02 2019 +0200 +++ b/src/hotspot/share/opto/macro.cpp Tue May 21 12:42:13 2019 +0200 @@ -427,7 +427,13 @@ Node *val = scan_mem_chain(in, alias_idx, offset, start_mem, alloc, &_igvn); if (val == start_mem || val == alloc_mem) { // hit a sentinel, return appropriate 0 value - values.at_put(j, _igvn.zerocon(ft)); + Node* default_value = alloc->in(AllocateNode::DefaultValue); + if (default_value != NULL) { + values.at_put(j, default_value); + } else { + assert(alloc->in(AllocateNode::RawDefaultValue) == NULL, "default value may not be null"); + values.at_put(j, _igvn.zerocon(ft)); + } continue; } if (val->is_Initialize()) { @@ -444,7 +450,13 @@ n = bs->step_over_gc_barrier(n); values.at_put(j, n); } else if(val->is_Proj() && val->in(0) == alloc) { - values.at_put(j, _igvn.zerocon(ft)); + Node* default_value = alloc->in(AllocateNode::DefaultValue); + if (default_value != NULL) { + values.at_put(j, default_value); + } else { + assert(alloc->in(AllocateNode::RawDefaultValue) == NULL, "default value may not be null"); + values.at_put(j, _igvn.zerocon(ft)); + } } else if (val->is_Phi()) { val = value_from_mem_phi(val, ft, phi_type, adr_t, alloc, value_phis, level-1); if (val == NULL) {
--- a/test/hotspot/jtreg/compiler/valhalla/valuetypes/TestNullableArrays.java Tue May 21 10:54:02 2019 +0200 +++ b/test/hotspot/jtreg/compiler/valhalla/valuetypes/TestNullableArrays.java Tue May 21 12:42:13 2019 +0200 @@ -2436,4 +2436,23 @@ Asserts.assertEquals(va[0], vab[0]); Asserts.assertEquals(va[1], vab[1]); } + + // Test non-escaping allocation with arraycopy + // that does not modify loaded array element. + @Test() + public static long test94() { + MyValue1?[] src = new MyValue1?[8]; + MyValue1[] dst = new MyValue1[8]; + for (int i = 1; i < 8; ++i) { + src[i] = testValue1; + } + System.arraycopy(src, 1, dst, 2, 6); + return dst[0].hash(); + } + + @DontCompile + public static void test94_verifier(boolean warmup) { + long result = test94(); + Asserts.assertEquals(result, MyValue1.default.hash()); + } }