< prev index next >

src/hotspot/share/gc/g1/c2/g1BarrierSetC2.cpp

Print this page

 395     // elision safe.
 396     return;
 397   }
 398 
 399   if (use_ReduceInitialCardMarks()
 400       && g1_can_remove_post_barrier(kit, &kit->gvn(), oop_store, adr)) {
 401     return;
 402   }
 403 
 404   if (!use_precise) {
 405     // All card marks for a (non-array) instance are in one place:
 406     adr = obj;
 407   }
 408   // (Else it's an array (or unknown), and we want more precise card marks.)
 409   assert(adr != NULL, "");
 410 
 411   IdealKit ideal(kit, true);
 412 
 413   Node* tls = __ thread(); // ThreadLocalStorage
 414 




 415   Node* no_base = __ top();
 416   float likely = PROB_LIKELY_MAG(3);
 417   float unlikely = PROB_UNLIKELY_MAG(3);
 418   Node* young_card = __ ConI((jint)G1CardTable::g1_young_card_val());
 419   Node* dirty_card = __ ConI((jint)G1CardTable::dirty_card_val());
 420   Node* zeroX = __ ConX(0);
 421 
 422   const TypeFunc *tf = write_ref_field_post_entry_Type();
 423 
 424   // Offsets into the thread
 425   const int index_offset  = in_bytes(G1ThreadLocalData::dirty_card_queue_index_offset());
 426   const int buffer_offset = in_bytes(G1ThreadLocalData::dirty_card_queue_buffer_offset());
 427 
 428   // Pointers into the thread
 429 
 430   Node* buffer_adr = __ AddP(no_base, tls, __ ConX(buffer_offset));
 431   Node* index_adr =  __ AddP(no_base, tls, __ ConX(index_offset));
 432 
 433   // Now some values
 434   // Use ctrl to avoid hoisting these values past a safepoint, which could

 442 
 443   // Divide pointer by card size
 444   Node* card_offset = __ URShiftX( cast, __ ConI(CardTable::card_shift) );
 445 
 446   // Combine card table base and card offset
 447   Node* card_adr = __ AddP(no_base, byte_map_base_node(kit), card_offset );
 448 
 449   // If we know the value being stored does it cross regions?
 450 
 451   if (val != NULL) {
 452     // Does the store cause us to cross regions?
 453 
 454     // Should be able to do an unsigned compare of region_size instead of
 455     // and extra shift. Do we have an unsigned compare??
 456     // Node* region_size = __ ConI(1 << HeapRegion::LogOfHRGrainBytes);
 457     Node* xor_res =  __ URShiftX ( __ XorX( cast,  __ CastPX(__ ctrl(), val)), __ ConI(HeapRegion::LogOfHRGrainBytes));
 458 
 459     // if (xor_res == 0) same region so skip
 460     __ if_then(xor_res, BoolTest::ne, zeroX, likely); {
 461 
 462       // No barrier if we are storing a NULL
 463       __ if_then(val, BoolTest::ne, kit->null(), likely); {




 464 
 465         // Ok must mark the card if not already dirty
 466 
 467         // load the original value of the card
 468         Node* card_val = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw);





 469 
 470         __ if_then(card_val, BoolTest::ne, young_card, unlikely); {
 471           kit->sync_kit(ideal);
 472           kit->insert_mem_bar(Op_MemBarVolatile, oop_store);
 473           __ sync_kit(kit);
 474 
 475           Node* card_val_reload = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw);
 476           __ if_then(card_val_reload, BoolTest::ne, dirty_card); {
 477             g1_mark_card(kit, ideal, card_adr, oop_store, alias_idx, index, index_adr, buffer, tf);


 478           } __ end_if();
 479         } __ end_if();
 480       } __ end_if();

 481     } __ end_if();
 482   } else {
 483     // The Object.clone() intrinsic uses this path if !ReduceInitialCardMarks.
 484     // We don't need a barrier here if the destination is a newly allocated object
 485     // in Eden. Otherwise, GC verification breaks because we assume that cards in Eden
 486     // are set to 'g1_young_gen' (see G1CardTable::verify_g1_young_region()).
 487     assert(!use_ReduceInitialCardMarks(), "can only happen with card marking");
 488     Node* card_val = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw);
 489     __ if_then(card_val, BoolTest::ne, young_card); {
 490       g1_mark_card(kit, ideal, card_adr, oop_store, alias_idx, index, index_adr, buffer, tf);
 491     } __ end_if();














 492   }
 493 
 494   // Final sync IdealKit and GraphKit.
 495   kit->final_sync(ideal);
 496 }
 497 
 498 // Helper that guards and inserts a pre-barrier.
 499 void G1BarrierSetC2::insert_pre_barrier(GraphKit* kit, Node* base_oop, Node* offset,
 500                                         Node* pre_val, bool need_mem_bar) const {
 501   // We could be accessing the referent field of a reference object. If so, when G1
 502   // is enabled, we need to log the value in the referent field in an SATB buffer.
 503   // This routine performs some compile time filters and generates suitable
 504   // runtime filters that guard the pre-barrier code.
 505   // Also add memory barrier for non volatile load from the referent field
 506   // to prevent commoning of loads across safepoint.
 507 
 508   // Some compile time checks.
 509 
 510   // If offset is a constant, is it java_lang_ref_Reference::_reference_offset?
 511   const TypeX* otype = offset->find_intptr_t_type();

 644   }
 645 
 646   return load;
 647 }
 648 
 649 bool G1BarrierSetC2::is_gc_barrier_node(Node* node) const {
 650   if (CardTableBarrierSetC2::is_gc_barrier_node(node)) {
 651     return true;
 652   }
 653   if (node->Opcode() != Op_CallLeaf) {
 654     return false;
 655   }
 656   CallLeafNode *call = node->as_CallLeaf();
 657   if (call->_name == NULL) {
 658     return false;
 659   }
 660 
 661   return strcmp(call->_name, "write_ref_field_pre_entry") == 0 || strcmp(call->_name, "write_ref_field_post_entry") == 0;
 662 }
 663 





































































































 664 void G1BarrierSetC2::eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const {
 665   assert(node->Opcode() == Op_CastP2X, "ConvP2XNode required");
 666   assert(node->outcnt() <= 2, "expects 1 or 2 users: Xor and URShift nodes");
 667   // It could be only one user, URShift node, in Object.clone() intrinsic
 668   // but the new allocation is passed to arraycopy stub and it could not
 669   // be scalar replaced. So we don't check the case.
 670 







 671   // An other case of only one user (Xor) is when the value check for NULL
 672   // in G1 post barrier is folded after CCP so the code which used URShift
 673   // is removed.
 674 
 675   // Take Region node before eliminating post barrier since it also
 676   // eliminates CastP2X node when it has only one user.
 677   Node* this_region = node->in(0);
 678   assert(this_region != NULL, "");
 679 
 680   // Remove G1 post barrier.
 681 
 682   // Search for CastP2X->Xor->URShift->Cmp path which
 683   // checks if the store done to a different from the value's region.
 684   // And replace Cmp with #0 (false) to collapse G1 post barrier.
 685   Node* xorx = node->find_out_with(Op_XorX);
 686   if (xorx != NULL) {
 687     Node* shift = xorx->unique_out();
 688     Node* cmpx = shift->unique_out();
 689     assert(cmpx->is_Cmp() && cmpx->unique_out()->is_Bool() &&
 690     cmpx->unique_out()->as_Bool()->_test._test == BoolTest::ne,

 703       }
 704       if (this_region->in(ind)->is_IfFalse() &&
 705           this_region->in(ind)->in(0)->Opcode() == Op_If) {
 706         Node* bol = this_region->in(ind)->in(0)->in(1);
 707         assert(bol->is_Bool(), "");
 708         cmpx = bol->in(1);
 709         if (bol->as_Bool()->_test._test == BoolTest::ne &&
 710             cmpx->is_Cmp() && cmpx->in(2) == macro->intcon(0) &&
 711             cmpx->in(1)->is_Load()) {
 712           Node* adr = cmpx->in(1)->as_Load()->in(MemNode::Address);
 713           const int marking_offset = in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset());
 714           if (adr->is_AddP() && adr->in(AddPNode::Base) == macro->top() &&
 715               adr->in(AddPNode::Address)->Opcode() == Op_ThreadLocal &&
 716               adr->in(AddPNode::Offset) == macro->MakeConX(marking_offset)) {
 717             macro->replace_node(cmpx, macro->makecon(TypeInt::CC_EQ));
 718           }
 719         }
 720       }
 721     }
 722   } else {
 723     assert(!use_ReduceInitialCardMarks(), "can only happen with card marking");







 724     // This is a G1 post barrier emitted by the Object.clone() intrinsic.
 725     // Search for the CastP2X->URShiftX->AddP->LoadB->Cmp path which checks if the card
 726     // is marked as young_gen and replace the Cmp with 0 (false) to collapse the barrier.
 727     Node* shift = node->find_out_with(Op_URShiftX);
 728     assert(shift != NULL, "missing G1 post barrier");
 729     Node* addp = shift->unique_out();
 730     Node* load = addp->find_out_with(Op_LoadB);
 731     assert(load != NULL, "missing G1 post barrier");
 732     Node* cmpx = load->unique_out();
 733     assert(cmpx->is_Cmp() && cmpx->unique_out()->is_Bool() &&
 734            cmpx->unique_out()->as_Bool()->_test._test == BoolTest::ne,
 735            "missing card value check in G1 post barrier");
 736     macro->replace_node(cmpx, macro->makecon(TypeInt::CC_EQ));
 737     // There is no G1 pre barrier in this case
 738   }
 739   // Now CastP2X can be removed since it is used only on dead path
 740   // which currently still alive until igvn optimize it.
 741   assert(node->outcnt() == 0 || node->unique_out()->Opcode() == Op_URShiftX, "");

 742   macro->replace_node(node, macro->top());



 743 }
 744 
 745 Node* G1BarrierSetC2::step_over_gc_barrier(Node* c) const {
 746   if (!use_ReduceInitialCardMarks() &&
 747       c != NULL && c->is_Region() && c->req() == 3) {
 748     for (uint i = 1; i < c->req(); i++) {
 749       if (c->in(i) != NULL && c->in(i)->is_Region() &&
 750           c->in(i)->req() == 3) {
 751         Node* r = c->in(i);
 752         for (uint j = 1; j < r->req(); j++) {
 753           if (r->in(j) != NULL && r->in(j)->is_Proj() &&
 754               r->in(j)->in(0) != NULL &&
 755               r->in(j)->in(0)->Opcode() == Op_CallLeaf &&
 756               r->in(j)->in(0)->as_Call()->entry_point() == CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_post_entry)) {
 757             Node* call = r->in(j)->in(0);
 758             c = c->in(i == 1 ? 2 : 1);
 759             if (c != NULL) {
 760               c = c->in(0);
 761               if (c != NULL) {
 762                 c = c->in(0);

 395     // elision safe.
 396     return;
 397   }
 398 
 399   if (use_ReduceInitialCardMarks()
 400       && g1_can_remove_post_barrier(kit, &kit->gvn(), oop_store, adr)) {
 401     return;
 402   }
 403 
 404   if (!use_precise) {
 405     // All card marks for a (non-array) instance are in one place:
 406     adr = obj;
 407   }
 408   // (Else it's an array (or unknown), and we want more precise card marks.)
 409   assert(adr != NULL, "");
 410 
 411   IdealKit ideal(kit, true);
 412 
 413   Node* tls = __ thread(); // ThreadLocalStorage
 414 
 415   BarrierSet* bs = BarrierSet::barrier_set();
 416   CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);
 417   CardTable* ct = ctbs->card_table();
 418 
 419   Node* no_base = __ top();
 420   float likely = PROB_LIKELY_MAG(3);
 421   float unlikely = PROB_UNLIKELY_MAG(3);
 422   Node* young_card = __ ConI((jint)G1CardTable::g1_young_card_val());
 423   Node* dirty_card = __ ConI((jint)G1CardTable::dirty_card_val());
 424   Node* zeroX = __ ConX(0);
 425 
 426   const TypeFunc *tf = write_ref_field_post_entry_Type();
 427 
 428   // Offsets into the thread
 429   const int index_offset  = in_bytes(G1ThreadLocalData::dirty_card_queue_index_offset());
 430   const int buffer_offset = in_bytes(G1ThreadLocalData::dirty_card_queue_buffer_offset());
 431 
 432   // Pointers into the thread
 433 
 434   Node* buffer_adr = __ AddP(no_base, tls, __ ConX(buffer_offset));
 435   Node* index_adr =  __ AddP(no_base, tls, __ ConX(index_offset));
 436 
 437   // Now some values
 438   // Use ctrl to avoid hoisting these values past a safepoint, which could

 446 
 447   // Divide pointer by card size
 448   Node* card_offset = __ URShiftX( cast, __ ConI(CardTable::card_shift) );
 449 
 450   // Combine card table base and card offset
 451   Node* card_adr = __ AddP(no_base, byte_map_base_node(kit), card_offset );
 452 
 453   // If we know the value being stored does it cross regions?
 454 
 455   if (val != NULL) {
 456     // Does the store cause us to cross regions?
 457 
 458     // Should be able to do an unsigned compare of region_size instead of
 459     // and extra shift. Do we have an unsigned compare??
 460     // Node* region_size = __ ConI(1 << HeapRegion::LogOfHRGrainBytes);
 461     Node* xor_res =  __ URShiftX ( __ XorX( cast,  __ CastPX(__ ctrl(), val)), __ ConI(HeapRegion::LogOfHRGrainBytes));
 462 
 463     // if (xor_res == 0) same region so skip
 464     __ if_then(xor_res, BoolTest::ne, zeroX, likely); {
 465 
 466       // if ((unsigned)(card_offset - low_map_offset) >= (high_map_offset - low_map_offset)) stack allocated object, so skip
 467       if (kit->C->do_stack_allocation()) {
 468         state()->add_enqueue_barrier(static_cast<CastP2XNode*>(cast));
 469         Node* low_off = kit->longcon(ct->byte_map_bottom_offset());
 470         Node* delta_off = kit->longcon(ct->byte_map_top_offset() - ct->byte_map_bottom_offset());
 471         Node* sub_off = __ SubL(cast, low_off);
 472 
 473         __ uif_then(sub_off, BoolTest::le, delta_off, likely); } {
 474 
 475           // No barrier if we are storing a NULL
 476           __ if_then(val, BoolTest::ne, kit->null(), likely); {
 477 
 478             // Ok must mark the card if not already dirty
 479 
 480             // load the original value of the card
 481             Node* card_val = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw);
 482 
 483             __ if_then(card_val, BoolTest::ne, young_card, unlikely); {
 484               kit->sync_kit(ideal);
 485               kit->insert_mem_bar(Op_MemBarVolatile, oop_store);
 486               __ sync_kit(kit);
 487 
 488               Node* card_val_reload = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw);
 489               __ if_then(card_val_reload, BoolTest::ne, dirty_card); {
 490                 g1_mark_card(kit, ideal, card_adr, oop_store, alias_idx, index, index_adr, buffer, tf);
 491               } __ end_if();
 492             } __ end_if();
 493           } __ end_if();
 494       } if (kit->C->do_stack_allocation()) {
 495         __ end_if();
 496       }
 497     } __ end_if();
 498   } else {
 499     // The Object.clone() intrinsic uses this path if !ReduceInitialCardMarks.
 500     // We don't need a barrier here if the destination is a newly allocated object
 501     // in Eden. Otherwise, GC verification breaks because we assume that cards in Eden
 502     // are set to 'g1_young_gen' (see G1CardTable::verify_g1_young_region()).
 503     assert(!use_ReduceInitialCardMarks(), "can only happen with card marking");
 504 
 505     // if ((unsigned)(card_offset - low_map_offset) >= (high_map_offset - low_map_offset)) stack allocated object, so skip
 506     if (kit->C->do_stack_allocation()) {
 507       state()->add_enqueue_barrier(static_cast<CastP2XNode*>(cast));
 508       Node* low_off = kit->longcon(ct->byte_map_bottom_offset());
 509       Node* delta_off = kit->longcon(ct->byte_map_top_offset() - ct->byte_map_bottom_offset());
 510       Node* sub_off = __ SubL(cast, low_off);
 511 
 512       __ uif_then(sub_off, BoolTest::le, delta_off, likely); } {
 513 
 514         Node* card_val = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw);
 515         __ if_then(card_val, BoolTest::ne, young_card); {
 516           g1_mark_card(kit, ideal, card_adr, oop_store, alias_idx, index, index_adr, buffer, tf);
 517         } __ end_if();
 518 
 519       } if (kit->C->do_stack_allocation()) {
 520         __ end_if();
 521       }
 522   }
 523 
 524   // Final sync IdealKit and GraphKit.
 525   kit->final_sync(ideal);
 526 }
 527 
 528 // Helper that guards and inserts a pre-barrier.
 529 void G1BarrierSetC2::insert_pre_barrier(GraphKit* kit, Node* base_oop, Node* offset,
 530                                         Node* pre_val, bool need_mem_bar) const {
 531   // We could be accessing the referent field of a reference object. If so, when G1
 532   // is enabled, we need to log the value in the referent field in an SATB buffer.
 533   // This routine performs some compile time filters and generates suitable
 534   // runtime filters that guard the pre-barrier code.
 535   // Also add memory barrier for non volatile load from the referent field
 536   // to prevent commoning of loads across safepoint.
 537 
 538   // Some compile time checks.
 539 
 540   // If offset is a constant, is it java_lang_ref_Reference::_reference_offset?
 541   const TypeX* otype = offset->find_intptr_t_type();

 674   }
 675 
 676   return load;
 677 }
 678 
 679 bool G1BarrierSetC2::is_gc_barrier_node(Node* node) const {
 680   if (CardTableBarrierSetC2::is_gc_barrier_node(node)) {
 681     return true;
 682   }
 683   if (node->Opcode() != Op_CallLeaf) {
 684     return false;
 685   }
 686   CallLeafNode *call = node->as_CallLeaf();
 687   if (call->_name == NULL) {
 688     return false;
 689   }
 690 
 691   return strcmp(call->_name, "write_ref_field_pre_entry") == 0 || strcmp(call->_name, "write_ref_field_post_entry") == 0;
 692 }
 693 
 694 bool G1BarrierSetC2::process_barrier_node(Node* node, PhaseIterGVN& igvn) const {
 695   assert(node->Opcode() == Op_CastP2X, "ConvP2XNode required");
 696 
 697   // Must have a control node
 698   if (node->in(0) == NULL) {
 699     return false;
 700   }
 701 
 702   // Search for CastP2X->Xor->URShift->Cmp path which
 703   // checks if the store done to a different from the value's region.
 704   Node* xorx = node->find_out_with(Op_XorX);
 705   BoolNode* bool_node = NULL;
 706 
 707   if (xorx != NULL) {
 708 
 709     Node* shift = shift = xorx->unique_out();
 710     Node* cmpx = shift->unique_out();
 711 
 712     assert(cmpx->is_Cmp() && cmpx->unique_out()->is_Bool() &&
 713             cmpx->unique_out()->as_Bool()->_test._test == BoolTest::ne,
 714             "missing region check in G1 post barrier");
 715 
 716     Node* bol = cmpx->unique_out();
 717     assert(bol->unique_out()->is_If(), "should find if after the bool node");
 718     Node* if_node = bol->unique_out();
 719     Node* if_true = if_node->find_out_with(Op_IfTrue);
 720     assert(if_true != NULL, "there should be false projection");
 721 
 722     Node* iff_check = if_true->find_out_with(Op_If);
 723     // Not a barrier with bound check
 724     if (iff_check == NULL) {
 725       return false;
 726     }
 727 
 728     Node* iff_check_in_1_node = iff_check->in(1);
 729     if (!iff_check_in_1_node->is_Bool()) {
 730       return false;
 731     }
 732     bool_node = iff_check_in_1_node->as_Bool();
 733 
 734   } else {
 735     // this "could" be the the path followed when !use_ReduceInitialCardMarks() is
 736     // used or when the two sides of the barrier are scalar replaced
 737     //assert(false, "we managed to get here!!! process_barrier_node");
 738     Node *addl_node = node->find_out_with(Op_AddL);
 739     if (addl_node == NULL) {
 740       return false;
 741     }
 742 
 743     Node* cmpx = addl_node->unique_out();
 744     assert(cmpx->is_Cmp() && cmpx->unique_out()->is_Bool() &&
 745           cmpx->unique_out()->as_Bool()->_test._test == BoolTest::le,
 746           "missing region check in G1 post barrier");
 747 
 748     bool_node = cmpx->unique_out()->as_Bool();
 749   }
 750 
 751   if (bool_node->_test._test != BoolTest::le) {
 752     return false;
 753   }
 754 
 755   // the input to the bool is the CMPX
 756   Node* bool_node_in_1_node = bool_node->in(1);
 757   if (!bool_node_in_1_node->is_Cmp()) {
 758     return false;
 759   }
 760   CmpNode* cmp_node = bool_node_in_1_node->as_Cmp();
 761 
 762   // the input to the CMPX is the card_table_top_offset constant
 763   Node* cmp_node_in_2_node = cmp_node->in(2);
 764   if (!cmp_node_in_2_node->is_Con()) {
 765     return false;
 766   }
 767 
 768   BarrierSet* bs = BarrierSet::barrier_set();
 769   CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);
 770   CardTable* ct = ctbs->card_table();
 771   size_t constant = ct->byte_map_top_offset() - ct->byte_map_bottom_offset();
 772 
 773   // Check that the input to this CMP node is the expected constant
 774   const TypeX* otype = cmp_node_in_2_node->find_intptr_t_type();
 775   if (otype != NULL && otype->is_con() &&
 776       size_t(otype->get_con()) != constant) {
 777     // Constant offset but not the card table size constant so just return
 778     return false;
 779   }
 780 
 781   // we can't change the compare or the constant so create a new constant(0) and replace the variable
 782   Node* cmp_node_in_1_node = cmp_node->in(1);
 783   ConNode* zeroConstant_node = igvn.makecon(TypeX_ZERO);
 784   if (cmp_node_in_1_node->_idx == zeroConstant_node->_idx) {
 785     // we can get here via different nodes - but we only want to change the input once
 786     return false;
 787   }
 788 
 789   igvn.rehash_node_delayed(cmp_node);
 790   int numReplaced = cmp_node->replace_edge(cmp_node_in_1_node, zeroConstant_node);
 791   assert(numReplaced == 1, "Failed to replace the card_offset with Conx(0)");
 792   return true;
 793 }
 794 
 795 void G1BarrierSetC2::eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const {
 796   assert(node->Opcode() == Op_CastP2X, "ConvP2XNode required");
 797   assert(node->outcnt() <= 3, "expects 1, 2 or 3 users: Xor, URShift and SubL nodes");
 798   // It could be only one user, URShift node, in Object.clone() intrinsic
 799   // but the new allocation is passed to arraycopy stub and it could not
 800   // be scalar replaced. So we don't check the case.
 801 
 802   // Certain loop optimisations may introduce a CastP2X node with
 803   // ConvL2I in case of an AllocateArray op. Check for that case
 804   // here and do not attempt to eliminate it as write barrier.
 805   if (macro->C->do_stack_allocation() && !state()->is_a_barrier(static_cast<CastP2XNode*>(node))) {
 806     return;
 807   }
 808 
 809   // An other case of only one user (Xor) is when the value check for NULL
 810   // in G1 post barrier is folded after CCP so the code which used URShift
 811   // is removed.
 812 
 813   // Take Region node before eliminating post barrier since it also
 814   // eliminates CastP2X node when it has only one user.
 815   Node* this_region = node->in(0);
 816   assert(this_region != NULL, "");
 817 
 818   // Remove G1 post barrier.
 819 
 820   // Search for CastP2X->Xor->URShift->Cmp path which
 821   // checks if the store done to a different from the value's region.
 822   // And replace Cmp with #0 (false) to collapse G1 post barrier.
 823   Node* xorx = node->find_out_with(Op_XorX);
 824   if (xorx != NULL) {
 825     Node* shift = xorx->unique_out();
 826     Node* cmpx = shift->unique_out();
 827     assert(cmpx->is_Cmp() && cmpx->unique_out()->is_Bool() &&
 828     cmpx->unique_out()->as_Bool()->_test._test == BoolTest::ne,

 841       }
 842       if (this_region->in(ind)->is_IfFalse() &&
 843           this_region->in(ind)->in(0)->Opcode() == Op_If) {
 844         Node* bol = this_region->in(ind)->in(0)->in(1);
 845         assert(bol->is_Bool(), "");
 846         cmpx = bol->in(1);
 847         if (bol->as_Bool()->_test._test == BoolTest::ne &&
 848             cmpx->is_Cmp() && cmpx->in(2) == macro->intcon(0) &&
 849             cmpx->in(1)->is_Load()) {
 850           Node* adr = cmpx->in(1)->as_Load()->in(MemNode::Address);
 851           const int marking_offset = in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset());
 852           if (adr->is_AddP() && adr->in(AddPNode::Base) == macro->top() &&
 853               adr->in(AddPNode::Address)->Opcode() == Op_ThreadLocal &&
 854               adr->in(AddPNode::Offset) == macro->MakeConX(marking_offset)) {
 855             macro->replace_node(cmpx, macro->makecon(TypeInt::CC_EQ));
 856           }
 857         }
 858       }
 859     }
 860   } else {
 861     // In a scenario where the two sides of the barrier are scalar replaced
 862     // or stack allocated, the XorX node will be visited more than once, because
 863     // both edges will be CastP2X nodes from two distinct allocates. In certain
 864     // instances, the removal of the CastP2X node will result in removal of the
 865     // XorX node, causing the assert below to be hit when eliminate_gc_barrier is
 866     // called for the second node.
 867     // assert(!use_ReduceInitialCardMarks(), "can only happen with card marking");
 868 
 869     // This is a G1 post barrier emitted by the Object.clone() intrinsic.
 870     // Search for the CastP2X->URShiftX->AddP->LoadB->Cmp path which checks if the card
 871     // is marked as young_gen and replace the Cmp with 0 (false) to collapse the barrier.
 872     Node* shift = node->find_out_with(Op_URShiftX);
 873     assert(shift != NULL, "missing G1 post barrier");
 874     Node* addp = shift->unique_out();
 875     Node* load = addp->find_out_with(Op_LoadB);
 876     assert(load != NULL, "missing G1 post barrier");
 877     Node* cmpx = load->unique_out();
 878     assert(cmpx->is_Cmp() && cmpx->unique_out()->is_Bool() &&
 879            cmpx->unique_out()->as_Bool()->_test._test == BoolTest::ne,
 880            "missing card value check in G1 post barrier");
 881     macro->replace_node(cmpx, macro->makecon(TypeInt::CC_EQ));
 882     // There is no G1 pre barrier in this case
 883   }
 884   // Now CastP2X can be removed since it is used only on dead path
 885   // which currently still alive until igvn optimize it.
 886   // TODO: fix this following assert becuase of SUBL
 887   // assert(node->outcnt() == 0 || node->unique_out()->Opcode() == Op_URShiftX, "");
 888   macro->replace_node(node, macro->top());
 889 
 890   // Remove this node from our state
 891   state()->remove_enqueue_barrier(static_cast<CastP2XNode*>(node));
 892 }
 893 
 894 Node* G1BarrierSetC2::step_over_gc_barrier(Node* c) const {
 895   if (!use_ReduceInitialCardMarks() &&
 896       c != NULL && c->is_Region() && c->req() == 3) {
 897     for (uint i = 1; i < c->req(); i++) {
 898       if (c->in(i) != NULL && c->in(i)->is_Region() &&
 899           c->in(i)->req() == 3) {
 900         Node* r = c->in(i);
 901         for (uint j = 1; j < r->req(); j++) {
 902           if (r->in(j) != NULL && r->in(j)->is_Proj() &&
 903               r->in(j)->in(0) != NULL &&
 904               r->in(j)->in(0)->Opcode() == Op_CallLeaf &&
 905               r->in(j)->in(0)->as_Call()->entry_point() == CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_post_entry)) {
 906             Node* call = r->in(j)->in(0);
 907             c = c->in(i == 1 ? 2 : 1);
 908             if (c != NULL) {
 909               c = c->in(0);
 910               if (c != NULL) {
 911                 c = c->in(0);
< prev index next >