8173196: [REDO] C2 does not optimize redundant memory operations with G1
Reviewed-by: thartmann, kvn
--- a/src/hotspot/share/gc/g1/c2/g1BarrierSetC2.cpp Tue May 28 14:56:58 2019 +0200
+++ b/src/hotspot/share/gc/g1/c2/g1BarrierSetC2.cpp Tue May 21 15:46:09 2019 +0200
@@ -472,7 +472,7 @@
__ if_then(card_val, BoolTest::ne, young_card); {
kit->sync_kit(ideal);
- kit->insert_mem_bar(Op_MemBarVolatile, oop_store);
+ kit->insert_store_load_for_barrier();
__ sync_kit(kit);
Node* card_val_reload = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw);
--- a/src/hotspot/share/gc/shared/c2/cardTableBarrierSetC2.cpp Tue May 28 14:56:58 2019 +0200
+++ b/src/hotspot/share/gc/shared/c2/cardTableBarrierSetC2.cpp Tue May 21 15:46:09 2019 +0200
@@ -105,7 +105,7 @@
if (UseCondCardMark) {
if (ct->scanned_concurrently()) {
- kit->insert_mem_bar(Op_MemBarVolatile, oop_store);
+ kit->insert_store_load_for_barrier();
__ sync_kit(kit);
}
// The classic GC reference write barrier is typically implemented
--- a/src/hotspot/share/opto/graphKit.cpp Tue May 28 14:56:58 2019 +0200
+++ b/src/hotspot/share/opto/graphKit.cpp Tue May 21 15:46:09 2019 +0200
@@ -3306,6 +3306,18 @@
return membar;
}
+void GraphKit::insert_store_load_for_barrier() {
+ Node* mem = reset_memory();
+ MemBarNode* mb = MemBarNode::make(C, Op_MemBarVolatile, Compile::AliasIdxRaw);
+ mb->init_req(TypeFunc::Control, control());
+ mb->init_req(TypeFunc::Memory, mem);
+ Node* membar = _gvn.transform(mb);
+ set_control(_gvn.transform(new ProjNode(membar, TypeFunc::Control)));
+ Node* newmem = _gvn.transform(new ProjNode(membar, TypeFunc::Memory));
+ set_all_memory(mem);
+ set_memory(newmem, Compile::AliasIdxRaw);
+}
+
//------------------------------shared_lock------------------------------------
// Emit locking code.
FastLockNode* GraphKit::shared_lock(Node* obj) {
--- a/src/hotspot/share/opto/graphKit.hpp Tue May 28 14:56:58 2019 +0200
+++ b/src/hotspot/share/opto/graphKit.hpp Tue May 21 15:46:09 2019 +0200
@@ -811,6 +811,7 @@
int next_monitor();
Node* insert_mem_bar(int opcode, Node* precedent = NULL);
Node* insert_mem_bar_volatile(int opcode, int alias_idx, Node* precedent = NULL);
+ void insert_store_load_for_barrier();
// Optional 'precedent' is appended as an extra edge, to force ordering.
FastLockNode* shared_lock(Node* obj);
void shared_unlock(Node* box, Node* obj);