8087341: C2 doesn't optimize redundant memory operations with G1

Effect of memory barrier in post barrier is too wide

Reviewed-by: kvn, aph
This commit is contained in:
Andrew Dinn 2016-02-15 10:14:33 +01:00 committed by Roland Westrelin
parent 4c22e8e014
commit 78d37841ef
3 changed files with 533 additions and 648 deletions

File diff suppressed because it is too large Load diff

View file

@ -3149,6 +3149,19 @@ Node* GraphKit::insert_mem_bar_volatile(int opcode, int alias_idx, Node* precede
return membar; return membar;
} }
void GraphKit::insert_store_load_for_barrier() {
Node* mem = reset_memory();
MemBarNode* mb = MemBarNode::make(C, Op_MemBarVolatile, Compile::AliasIdxBot);
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------------------------------------ //------------------------------shared_lock------------------------------------
// Emit locking code. // Emit locking code.
FastLockNode* GraphKit::shared_lock(Node* obj) { FastLockNode* GraphKit::shared_lock(Node* obj) {
@ -3840,7 +3853,7 @@ void GraphKit::write_barrier_post(Node* oop_store,
BasicType bt = T_BYTE; BasicType bt = T_BYTE;
if (UseConcMarkSweepGC && UseCondCardMark) { if (UseConcMarkSweepGC && UseCondCardMark) {
insert_mem_bar(Op_MemBarVolatile); // StoreLoad barrier insert_store_load_for_barrier();
__ sync_kit(this); __ sync_kit(this);
} }
@ -4280,8 +4293,7 @@ void GraphKit::g1_write_barrier_post(Node* oop_store,
__ if_then(card_val, BoolTest::ne, young_card); { __ if_then(card_val, BoolTest::ne, young_card); {
sync_kit(ideal); sync_kit(ideal);
// Use Op_MemBarVolatile to achieve the effect of a StoreLoad barrier. insert_store_load_for_barrier();
insert_mem_bar(Op_MemBarVolatile, oop_store);
__ sync_kit(this); __ sync_kit(this);
Node* card_val_reload = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw); Node* card_val_reload = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw);

View file

@ -834,6 +834,7 @@ class GraphKit : public Phase {
int next_monitor(); int next_monitor();
Node* insert_mem_bar(int opcode, Node* precedent = NULL); Node* insert_mem_bar(int opcode, Node* precedent = NULL);
Node* insert_mem_bar_volatile(int opcode, int alias_idx, 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. // Optional 'precedent' is appended as an extra edge, to force ordering.
FastLockNode* shared_lock(Node* obj); FastLockNode* shared_lock(Node* obj);
void shared_unlock(Node* box, Node* obj); void shared_unlock(Node* box, Node* obj);