RFR(S): 8087341: C2 doesn't optimize redundant memory operations with G1

Roland Westrelin roland.westrelin at oracle.com
Fri Jan 29 14:04:39 UTC 2016


Hi Vladimir,

Thanks for looking at this.

> G1 barrier was added by Mikael Gerdin from GC. He should also look on this change.
> 
> https://bugs.openjdk.java.net/browse/JDK-8014555
> 
> Also we have specialized insert_mem_bar_volatile() if we don't want wide memory affect. Why not use it?

The membar in the change takes the entire memory state as input but only changes raw memory. I don’t think that can be achieved with insert_mem_bar_volatile(). As explained by Mikael, the membar is here to force ordering between the oop store and the card table load. That’s why I think the membar’s inputs and outputs should be set up that way.

> And we need to keep precedent edge link to oop store in case EA eliminates related allocation.

I missed that, indeed. Mikael, can you confirm if this is ok (eliminating the barrier if the object being stored to doesn’t escape)?

Roland.

> 
> Thanks,
> Vladimir
> 
> On 1/28/16 4:49 AM, Roland Westrelin wrote:
>> http://cr.openjdk.java.net/~roland/8087341/webrev.00/
>> 
>> C2 currently doesn’t optimize the field load in the following code:
>> 
>>     static Object field;
>> 
>>     static Object m(Object o) {
>>         field = o;
>>         return field;
>>     }
>> 
>> It should return o but instead loads the value back from memory. The reason it misses such simple optimization is that the G1 post barrier has a memory barrier with a wide effect on the memory state. C2 doesn’t optimize this either:
>> 
>>         object.field = other_object;
>>         object.field = other_object;
>> 
>> Same applies to -XX:+UseConcMarkSweepGC -XX:+UseCondCardMark
>> 
>> That memory barrier was added to have a memory barrier instruction and doesn’t have to have a wide memory effect.
>> 
>> Roland.
>> 



More information about the hotspot-compiler-dev mailing list