JDK-8087341 : C2 doesn't optimize redundant memory operations with G1
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-06-12
  • Updated: 2017-01-23
  • Resolved: 2016-02-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b110Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
This java code:
        object.field = other_object;
        object.field = other_object;
should be optimized by c2 as:
        object.field = other_object;
but it's not with G1 enabled because GraphKit::g1_write_barrier_post() has:
// Use Op_MemBarVolatile to achieve the effect of a StoreLoad barrier.
insert_mem_bar(Op_MemBarVolatile, oop_store);

which confuses StoreNode::Ideal()

With the membar above commented out, the redundant store is optimized out but it seems we leave the pre/post barrier for the second store in.

The membar seems too coarse grain as all is required is that store load between the write to a field and the load from the card table.