< prev index next >

src/hotspot/share/opto/graphKit.cpp

BarrierSetC2

7  *                                                                                                                                   
8  * This code is distributed in the hope that it will be useful, but WITHOUT                                                          
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or                                                             
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License                                                             
11  * version 2 for more details (a copy is included in the LICENSE file that                                                           
12  * accompanied this code).                                                                                                           
13  *                                                                                                                                   
14  * You should have received a copy of the GNU General Public License version                                                         
15  * 2 along with this work; if not, write to the Free Software Foundation,                                                            
16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.                                                                     
17  *                                                                                                                                   
18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA                                                           
19  * or visit www.oracle.com if you need additional information or have any                                                            
20  * questions.                                                                                                                        
21  *                                                                                                                                   
22  */                                                                                                                                  
23 
24 #include "precompiled.hpp"                                                                                                           
25 #include "ci/ciUtilities.hpp"                                                                                                        
26 #include "compiler/compileLog.hpp"                                                                                                   
27 #include "gc/g1/g1BarrierSet.hpp"                                                                                                    
28 #include "gc/g1/g1CardTable.hpp"                                                                                                     
29 #include "gc/g1/heapRegion.hpp"                                                                                                      
30 #include "gc/shared/barrierSet.hpp"                                                                                                  
31 #include "gc/shared/cardTable.hpp"                                                                                                   
32 #include "gc/shared/cardTableBarrierSet.hpp"                                                                                         
33 #include "gc/shared/collectedHeap.hpp"                                                                                               
34 #include "interpreter/interpreter.hpp"                                                                                               
35 #include "memory/resourceArea.hpp"                                                                                                   
36 #include "opto/addnode.hpp"                                                                                                          
37 #include "opto/castnode.hpp"                                                                                                         
38 #include "opto/convertnode.hpp"                                                                                                      
39 #include "opto/graphKit.hpp"                                                                                                         
40 #include "opto/idealKit.hpp"                                                                                                         
41 #include "opto/intrinsicnode.hpp"                                                                                                    
42 #include "opto/locknode.hpp"                                                                                                         
43 #include "opto/machnode.hpp"                                                                                                         
44 #include "opto/opaquenode.hpp"                                                                                                       
45 #include "opto/parse.hpp"                                                                                                            
46 #include "opto/rootnode.hpp"                                                                                                         
47 #include "opto/runtime.hpp"                                                                                                          
48 #include "runtime/deoptimization.hpp"                                                                                                
49 #include "runtime/sharedRuntime.hpp"                                                                                                 
50 #if INCLUDE_ALL_GCS                                                                                                                  
51 #include "gc/g1/g1ThreadLocalData.hpp"                                                                                               
52 #endif // INCLUDE_ALL_GCS                                                                                                            
53 
54 //----------------------------GraphKit-----------------------------------------                                                      
55 // Main utility constructor.                                                                                                         
56 GraphKit::GraphKit(JVMState* jvms)                                                                                                   
57   : Phase(Phase::Parser),                                                                                                            
58     _env(C->env()),                                                                                                                  
59     _gvn(*C->initial_gvn())                                                                                                          
                                                                                                                                     
60 {                                                                                                                                    
61   _exceptions = jvms->map()->next_exception();                                                                                       
62   if (_exceptions != NULL)  jvms->map()->set_next_exception(NULL);                                                                   
63   set_jvms(jvms);                                                                                                                    
64 }                                                                                                                                    
65 
66 // Private constructor for parser.                                                                                                   
67 GraphKit::GraphKit()                                                                                                                 
68   : Phase(Phase::Parser),                                                                                                            
69     _env(C->env()),                                                                                                                  
70     _gvn(*C->initial_gvn())                                                                                                          
                                                                                                                                     
71 {                                                                                                                                    
72   _exceptions = NULL;                                                                                                                
73   set_map(NULL);                                                                                                                     
74   debug_only(_sp = -99);                                                                                                             
75   debug_only(set_bci(-99));                                                                                                          
76 }                                                                                                                                    
77 
78 
79 
80 //---------------------------clean_stack---------------------------------------                                                      
81 // Clear away rubbish from the stack area of the JVM state.                                                                          
82 // This destroys any arguments that may be waiting on the stack.                                                                     
83 void GraphKit::clean_stack(int from_sp) {                                                                                            
84   SafePointNode* map      = this->map();                                                                                             
85   JVMState*      jvms     = this->jvms();                                                                                            
86   int            stk_size = jvms->stk_size();                                                                                        
87   int            stkoff   = jvms->stkoff();                                                                                          
88   Node*          top      = this->top();                                                                                             
89   for (int i = from_sp; i < stk_size; i++) {                                                                                         

7  *
8  * This code is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * version 2 for more details (a copy is included in the LICENSE file that
12  * accompanied this code).
13  *
14  * You should have received a copy of the GNU General Public License version
15  * 2 along with this work; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19  * or visit www.oracle.com if you need additional information or have any
20  * questions.
21  *
22  */
23 
24 #include "precompiled.hpp"
25 #include "ci/ciUtilities.hpp"
26 #include "compiler/compileLog.hpp"


27 #include "gc/g1/heapRegion.hpp"
28 #include "gc/shared/barrierSet.hpp"
29 #include "gc/shared/c2/barrierSetC2.hpp"


30 #include "interpreter/interpreter.hpp"
31 #include "memory/resourceArea.hpp"
32 #include "opto/addnode.hpp"
33 #include "opto/castnode.hpp"
34 #include "opto/convertnode.hpp"
35 #include "opto/graphKit.hpp"
36 #include "opto/idealKit.hpp"
37 #include "opto/intrinsicnode.hpp"
38 #include "opto/locknode.hpp"
39 #include "opto/machnode.hpp"
40 #include "opto/opaquenode.hpp"
41 #include "opto/parse.hpp"
42 #include "opto/rootnode.hpp"
43 #include "opto/runtime.hpp"
44 #include "runtime/deoptimization.hpp"
45 #include "runtime/sharedRuntime.hpp"



46 
47 //----------------------------GraphKit-----------------------------------------
48 // Main utility constructor.
49 GraphKit::GraphKit(JVMState* jvms)
50   : Phase(Phase::Parser),
51     _env(C->env()),
52     _gvn(*C->initial_gvn()),
53     _barrier_set(BarrierSet::barrier_set()->barrier_set_c2())
54 {
55   _exceptions = jvms->map()->next_exception();
56   if (_exceptions != NULL)  jvms->map()->set_next_exception(NULL);
57   set_jvms(jvms);
58 }
59 
60 // Private constructor for parser.
61 GraphKit::GraphKit()
62   : Phase(Phase::Parser),
63     _env(C->env()),
64     _gvn(*C->initial_gvn()),
65     _barrier_set(BarrierSet::barrier_set()->barrier_set_c2())
66 {
67   _exceptions = NULL;
68   set_map(NULL);
69   debug_only(_sp = -99);
70   debug_only(set_bci(-99));
71 }
72 
73 
74 
75 //---------------------------clean_stack---------------------------------------
76 // Clear away rubbish from the stack area of the JVM state.
77 // This destroys any arguments that may be waiting on the stack.
78 void GraphKit::clean_stack(int from_sp) {
79   SafePointNode* map      = this->map();
80   JVMState*      jvms     = this->jvms();
81   int            stk_size = jvms->stk_size();
82   int            stkoff   = jvms->stkoff();
83   Node*          top      = this->top();
84   for (int i = from_sp; i < stk_size; i++) {

593     default:                                                                                                                         
594       break;                                                                                                                         
595     }                                                                                                                                
596     if (failing()) { stop(); return; }  // exception allocation might fail                                                           
597     if (ex_obj != NULL) {                                                                                                            
598       // Cheat with a preallocated exception object.                                                                                 
599       if (C->log() != NULL)                                                                                                          
600         C->log()->elem("hot_throw preallocated='1' reason='%s'",                                                                     
601                        Deoptimization::trap_reason_name(reason));                                                                    
602       const TypeInstPtr* ex_con  = TypeInstPtr::make(ex_obj);                                                                        
603       Node*              ex_node = _gvn.transform(ConNode::make(ex_con));                                                            
604 
605       // Clear the detail message of the preallocated exception object.                                                              
606       // Weblogic sometimes mutates the detail message of exceptions                                                                 
607       // using reflection.                                                                                                           
608       int offset = java_lang_Throwable::get_detailMessage_offset();                                                                  
609       const TypePtr* adr_typ = ex_con->add_offset(offset);                                                                           
610 
611       Node *adr = basic_plus_adr(ex_node, ex_node, offset);                                                                          
612       const TypeOopPtr* val_type = TypeOopPtr::make_from_klass(env()->String_klass());                                               
613       // Conservatively release stores of object references.                                                                         
614       Node *store = store_oop_to_object(control(), ex_node, adr, adr_typ, null(), val_type, T_OBJECT, MemNode::release);             
615 
616       add_exception_state(make_exception_state(ex_node));                                                                            
617       return;                                                                                                                        
618     }                                                                                                                                
619   }                                                                                                                                  
620 
621   // %%% Maybe add entry to OptoRuntime which directly throws the exc.?                                                              
622   // It won't be much cheaper than bailing to the interp., since we'll                                                               
623   // have to pass up all the debug-info, and the runtime will have to                                                                
624   // create the stack trace.                                                                                                         
625 
626   // Usual case:  Bail to interpreter.                                                                                               
627   // Reserve the right to recompile if we haven't seen anything yet.                                                                 
628 
629   ciMethod* m = Deoptimization::reason_is_speculate(reason) ? C->method() : NULL;                                                    
630   Deoptimization::DeoptAction action = Deoptimization::Action_maybe_recompile;                                                       
631   if (treat_throw_as_hot                                                                                                             
632       && (method()->method_data()->trap_recompiled_at(bci(), m)                                                                      
633           || C->too_many_traps(reason))) {                                                                                           

588     default:
589       break;
590     }
591     if (failing()) { stop(); return; }  // exception allocation might fail
592     if (ex_obj != NULL) {
593       // Cheat with a preallocated exception object.
594       if (C->log() != NULL)
595         C->log()->elem("hot_throw preallocated='1' reason='%s'",
596                        Deoptimization::trap_reason_name(reason));
597       const TypeInstPtr* ex_con  = TypeInstPtr::make(ex_obj);
598       Node*              ex_node = _gvn.transform(ConNode::make(ex_con));
599 
600       // Clear the detail message of the preallocated exception object.
601       // Weblogic sometimes mutates the detail message of exceptions
602       // using reflection.
603       int offset = java_lang_Throwable::get_detailMessage_offset();
604       const TypePtr* adr_typ = ex_con->add_offset(offset);
605 
606       Node *adr = basic_plus_adr(ex_node, ex_node, offset);
607       const TypeOopPtr* val_type = TypeOopPtr::make_from_klass(env()->String_klass());
608       Node *store = access_store_at(control(), ex_node, adr, adr_typ, null(), val_type, T_OBJECT, IN_HEAP);

609 
610       add_exception_state(make_exception_state(ex_node));
611       return;
612     }
613   }
614 
615   // %%% Maybe add entry to OptoRuntime which directly throws the exc.?
616   // It won't be much cheaper than bailing to the interp., since we'll
617   // have to pass up all the debug-info, and the runtime will have to
618   // create the stack trace.
619 
620   // Usual case:  Bail to interpreter.
621   // Reserve the right to recompile if we haven't seen anything yet.
622 
623   ciMethod* m = Deoptimization::reason_is_speculate(reason) ? C->method() : NULL;
624   Deoptimization::DeoptAction action = Deoptimization::Action_maybe_recompile;
625   if (treat_throw_as_hot
626       && (method()->method_data()->trap_recompiled_at(bci(), m)
627           || C->too_many_traps(reason))) {

1533     st = StoreDNode::make_atomic(ctl, mem, adr, adr_type, val, mo);                                                                  
1534   } else {                                                                                                                           
1535     st = StoreNode::make(_gvn, ctl, mem, adr, adr_type, val, bt, mo);                                                                
1536   }                                                                                                                                  
1537   if (unaligned) {                                                                                                                   
1538     st->as_Store()->set_unaligned_access();                                                                                          
1539   }                                                                                                                                  
1540   if (mismatched) {                                                                                                                  
1541     st->as_Store()->set_mismatched_access();                                                                                         
1542   }                                                                                                                                  
1543   st = _gvn.transform(st);                                                                                                           
1544   set_memory(st, adr_idx);                                                                                                           
1545   // Back-to-back stores can only remove intermediate store with DU info                                                             
1546   // so push on worklist for optimizer.                                                                                              
1547   if (mem->req() > MemNode::Address && adr == mem->in(MemNode::Address))                                                             
1548     record_for_igvn(st);                                                                                                             
1549 
1550   return st;                                                                                                                         
1551 }                                                                                                                                    
1552 
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
1553 
1554 void GraphKit::pre_barrier(bool do_load,                                                                                             
1555                            Node* ctl,                                                                                                
1556                            Node* obj,                                                                                                
1557                            Node* adr,                                                                                                
1558                            uint  adr_idx,                                                                                            
1559                            Node* val,                                                                                                
1560                            const TypeOopPtr* val_type,                                                                               
1561                            Node* pre_val,                                                                                            
1562                            BasicType bt) {                                                                                           
1563                                                                                                                                      
1564   BarrierSet* bs = BarrierSet::barrier_set();                                                                                        
1565   set_control(ctl);                                                                                                                  
1566   switch (bs->kind()) {                                                                                                              
1567     case BarrierSet::G1BarrierSet:                                                                                                   
1568       g1_write_barrier_pre(do_load, obj, adr, adr_idx, val, val_type, pre_val, bt);                                                  
1569       break;                                                                                                                         
1570                                                                                                                                      
1571     case BarrierSet::CardTableBarrierSet:                                                                                            
1572       break;                                                                                                                         
1573 
1574     default      :                                                                                                                   
1575       ShouldNotReachHere();                                                                                                          
1576 
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
1577   }                                                                                                                                  
1578 }                                                                                                                                    
1579 
1580 bool GraphKit::can_move_pre_barrier() const {                                                                                        
1581   BarrierSet* bs = BarrierSet::barrier_set();                                                                                        
1582   switch (bs->kind()) {                                                                                                              
1583     case BarrierSet::G1BarrierSet:                                                                                                   
1584       return true; // Can move it if no safepoint                                                                                    
1585                                                                                                                                      
1586     case BarrierSet::CardTableBarrierSet:                                                                                            
1587       return true; // There is no pre-barrier                                                                                        
                                                                                                                                     
1588 
1589     default      :                                                                                                                   
1590       ShouldNotReachHere();                                                                                                          
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
1591   }                                                                                                                                  
1592   return false;                                                                                                                      
1593 }                                                                                                                                    
1594 
1595 void GraphKit::post_barrier(Node* ctl,                                                                                               
1596                             Node* store,                                                                                             
1597                             Node* obj,                                                                                               
1598                             Node* adr,                                                                                               
1599                             uint  adr_idx,                                                                                           
1600                             Node* val,                                                                                               
1601                             BasicType bt,                                                                                            
1602                             bool use_precise) {                                                                                      
1603   BarrierSet* bs = BarrierSet::barrier_set();                                                                                        
                                                                                                                                     
1604   set_control(ctl);                                                                                                                  
1605   switch (bs->kind()) {                                                                                                              
1606     case BarrierSet::G1BarrierSet:                                                                                                   
1607       g1_write_barrier_post(store, obj, adr, adr_idx, val, bt, use_precise);                                                         
1608       break;                                                                                                                         
1609                                                                                                                                      
1610     case BarrierSet::CardTableBarrierSet:                                                                                            
1611       write_barrier_post(store, obj, adr, adr_idx, val, use_precise);                                                                
1612       break;                                                                                                                         
1613                                                                                                                                      
1614     default      :                                                                                                                   
1615       ShouldNotReachHere();                                                                                                          
1616                                                                                                                                      
1617   }                                                                                                                                  
1618 }                                                                                                                                    
1619 
1620 Node* GraphKit::store_oop(Node* ctl,                                                                                                 
1621                           Node* obj,                                                                                                 
1622                           Node* adr,                                                                                                 
1623                           const TypePtr* adr_type,                                                                                   
1624                           Node* val,                                                                                                 
1625                           const TypeOopPtr* val_type,                                                                                
1626                           BasicType bt,                                                                                              
1627                           bool use_precise,                                                                                          
1628                           MemNode::MemOrd mo,                                                                                        
1629                           bool mismatched) {                                                                                         
1630   // Transformation of a value which could be NULL pointer (CastPP #NULL)                                                            
1631   // could be delayed during Parse (for example, in adjust_map_after_if()).                                                          
1632   // Execute transformation here to avoid barrier generation in such case.                                                           
1633   if (_gvn.type(val) == TypePtr::NULL_PTR)                                                                                           
1634     val = _gvn.makecon(TypePtr::NULL_PTR);                                                                                           
1635                                                                                                                                      
1636   set_control(ctl);                                                                                                                  
1637   if (stopped()) return top(); // Dead path ?                                                                                        
1638                                                                                                                                      
1639   assert(bt == T_OBJECT, "sanity");                                                                                                  
1640   assert(val != NULL, "not dead path");                                                                                              
1641   uint adr_idx = C->get_alias_index(adr_type);                                                                                       
1642   assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory" );                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
1643 
1644   pre_barrier(true /* do_load */,                                                                                                    
1645               control(), obj, adr, adr_idx, val, val_type,                                                                           
1646               NULL /* pre_val */,                                                                                                    
1647               bt);                                                                                                                   
1648                                                                                                                                      
1649   Node* store = store_to_memory(control(), adr, val, bt, adr_idx, mo, mismatched);                                                   
1650   post_barrier(control(), store, obj, adr, adr_idx, val, bt, use_precise);                                                           
1651   return store;                                                                                                                      
1652 }                                                                                                                                    
1653                                                                                                                                      
1654 // Could be an array or object we don't know at compile time (unsafe ref.)                                                           
1655 Node* GraphKit::store_oop_to_unknown(Node* ctl,                                                                                      
1656                              Node* obj,   // containing obj                                                                          
1657                              Node* adr,  // actual adress to store val at                                                            
1658                              const TypePtr* adr_type,                                                                                
1659                              Node* val,                                                                                              
1660                              BasicType bt,                                                                                           
1661                              MemNode::MemOrd mo,                                                                                     
1662                              bool mismatched) {                                                                                      
1663   Compile::AliasType* at = C->alias_type(adr_type);                                                                                  
1664   const TypeOopPtr* val_type = NULL;                                                                                                 
1665   if (adr_type->isa_instptr()) {                                                                                                     
1666     if (at->field() != NULL) {                                                                                                       
1667       // known field.  This code is a copy of the do_put_xxx logic.                                                                  
1668       ciField* field = at->field();                                                                                                  
1669       if (!field->type()->is_loaded()) {                                                                                             
1670         val_type = TypeInstPtr::BOTTOM;                                                                                              
1671       } else {                                                                                                                       
1672         val_type = TypeOopPtr::make_from_klass(field->type()->as_klass());                                                           
1673       }                                                                                                                              
1674     }                                                                                                                                
1675   } else if (adr_type->isa_aryptr()) {                                                                                               
1676     val_type = adr_type->is_aryptr()->elem()->make_oopptr();                                                                         
1677   }                                                                                                                                  
1678   if (val_type == NULL) {                                                                                                            
1679     val_type = TypeInstPtr::BOTTOM;                                                                                                  
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
1680   }                                                                                                                                  
1681   return store_oop(ctl, obj, adr, adr_type, val, val_type, bt, true, mo, mismatched);                                                
1682 }                                                                                                                                    
1683 
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
1684 
1685 //-------------------------array_element_address-------------------------                                                            
1686 Node* GraphKit::array_element_address(Node* ary, Node* idx, BasicType elembt,                                                        
1687                                       const TypeInt* sizetype, Node* ctrl) {                                                         
1688   uint shift  = exact_log2(type2aelembytes(elembt));                                                                                 
1689   uint header = arrayOopDesc::base_offset_in_bytes(elembt);                                                                          
1690 
1691   // short-circuit a common case (saves lots of confusing waste motion)                                                              
1692   jint idx_con = find_int_con(idx, -1);                                                                                              
1693   if (idx_con >= 0) {                                                                                                                
1694     intptr_t offset = header + ((intptr_t)idx_con << shift);                                                                         
1695     return basic_plus_adr(ary, offset);                                                                                              
1696   }                                                                                                                                  
1697 
1698   // must be correct type for alignment purposes                                                                                     
1699   Node* base  = basic_plus_adr(ary, header);                                                                                         
1700   idx = Compile::conv_I2X_index(&_gvn, idx, sizetype, ctrl);                                                                         
1701   Node* scale = _gvn.transform( new LShiftXNode(idx, intcon(shift)) );                                                               
1702   return basic_plus_adr(ary, base, scale);                                                                                           

1527     st = StoreDNode::make_atomic(ctl, mem, adr, adr_type, val, mo);
1528   } else {
1529     st = StoreNode::make(_gvn, ctl, mem, adr, adr_type, val, bt, mo);
1530   }
1531   if (unaligned) {
1532     st->as_Store()->set_unaligned_access();
1533   }
1534   if (mismatched) {
1535     st->as_Store()->set_mismatched_access();
1536   }
1537   st = _gvn.transform(st);
1538   set_memory(st, adr_idx);
1539   // Back-to-back stores can only remove intermediate store with DU info
1540   // so push on worklist for optimizer.
1541   if (mem->req() > MemNode::Address && adr == mem->in(MemNode::Address))
1542     record_for_igvn(st);
1543 
1544   return st;
1545 }
1546 
1547 Node* GraphKit::access_store_at(Node* ctl,
1548                                 Node* obj,
1549                                 Node* adr,
1550                                 const TypePtr* adr_type,
1551                                 Node* val,
1552                                 const Type* val_type,
1553                                 BasicType bt,
1554                                 DecoratorSet decorators) {
1555   // Transformation of a value which could be NULL pointer (CastPP #NULL)
1556   // could be delayed during Parse (for example, in adjust_map_after_if()).
1557   // Execute transformation here to avoid barrier generation in such case.
1558   if (_gvn.type(val) == TypePtr::NULL_PTR) {
1559     val = _gvn.makecon(TypePtr::NULL_PTR);
1560   }
1561 











1562   set_control(ctl);
1563   if (stopped()) {
1564     return top(); // Dead path ?
1565   }




1566 
1567   assert(val != NULL, "not dead path");

1568 
1569   C2AccessValuePtr addr(adr, adr_type);
1570   C2AccessValue value(val, val_type);
1571   C2Access access(this, decorators | C2_WRITE_ACCESS, bt, obj, addr);
1572   if (access.is_raw()) {
1573     return _barrier_set->BarrierSetC2::store_at(access, value);
1574   } else {
1575     return _barrier_set->store_at(access, value);
1576   }
1577 }
1578 
1579 Node* GraphKit::access_load_at(Node* obj,   // containing obj
1580                                Node* adr,   // actual adress to store val at
1581                                const TypePtr* adr_type,
1582                                const Type* val_type,
1583                                BasicType bt,
1584                                DecoratorSet decorators) {
1585   if (stopped()) {
1586     return top(); // Dead path ?
1587   }
1588 
1589   C2AccessValuePtr addr(adr, adr_type);
1590   C2Access access(this, decorators | C2_READ_ACCESS, bt, obj, addr);
1591   if (access.is_raw()) {
1592     return _barrier_set->BarrierSetC2::load_at(access, val_type);
1593   } else {
1594     return _barrier_set->load_at(access, val_type);
1595   }

1596 }
1597 
1598 Node* GraphKit::access_atomic_cmpxchg_val_at(Node* ctl,
1599                                              Node* obj,
1600                                              Node* adr,
1601                                              const TypePtr* adr_type,
1602                                              int alias_idx,
1603                                              Node* expected_val,
1604                                              Node* new_val,
1605                                              const Type* value_type,
1606                                              BasicType bt,
1607                                              DecoratorSet decorators) {
1608   set_control(ctl);
1609   C2AccessValuePtr addr(adr, adr_type);
1610   C2AtomicAccess access(this, decorators | C2_READ_ACCESS | C2_WRITE_ACCESS,
1611                         bt, obj, addr, alias_idx);
1612   if (access.is_raw()) {
1613     return _barrier_set->BarrierSetC2::atomic_cmpxchg_val_at(access, expected_val, new_val, value_type);
1614   } else {
1615     return _barrier_set->atomic_cmpxchg_val_at(access, expected_val, new_val, value_type);





1616   }
1617 }
1618 
1619 Node* GraphKit::access_atomic_cmpxchg_bool_at(Node* ctl,
1620                                               Node* obj,
1621                                               Node* adr,
1622                                               const TypePtr* adr_type,
1623                                               int alias_idx,
1624                                               Node* expected_val,
1625                                               Node* new_val,
1626                                               const Type* value_type,
1627                                               BasicType bt,
1628                                               DecoratorSet decorators) {






1629   set_control(ctl);
1630   C2AccessValuePtr addr(adr, adr_type);
1631   C2AtomicAccess access(this, decorators | C2_READ_ACCESS | C2_WRITE_ACCESS,
1632                         bt, obj, addr, alias_idx);
1633   if (access.is_raw()) {
1634     return _barrier_set->BarrierSetC2::atomic_cmpxchg_bool_at(access, expected_val, new_val, value_type);
1635   } else {
1636     return _barrier_set->atomic_cmpxchg_bool_at(access, expected_val, new_val, value_type);
1637   }
1638 }
1639 
1640 Node* GraphKit::access_atomic_xchg_at(Node* ctl,
1641                                       Node* obj,
1642                                       Node* adr,
1643                                       const TypePtr* adr_type,
1644                                       int alias_idx,
1645                                       Node* new_val,
1646                                       const Type* value_type,
1647                                       BasicType bt,
1648                                       DecoratorSet decorators) {
1649   set_control(ctl);
1650   C2AccessValuePtr addr(adr, adr_type);
1651   C2AtomicAccess access(this, decorators | C2_READ_ACCESS | C2_WRITE_ACCESS,
1652                         bt, obj, addr, alias_idx);
1653   if (access.is_raw()) {
1654     return _barrier_set->BarrierSetC2::atomic_xchg_at(access, new_val, value_type);
1655   } else {
1656     return _barrier_set->atomic_xchg_at(access, new_val, value_type);
















1657   }
1658 }
1659 
1660 Node* GraphKit::access_atomic_add_at(Node* ctl,
1661                                      Node* obj,
1662                                      Node* adr,
1663                                      const TypePtr* adr_type,
1664                                      int alias_idx,
1665                                      Node* new_val,
1666                                      const Type* value_type,
1667                                      BasicType bt,
1668                                      DecoratorSet decorators) {
1669   set_control(ctl);
1670   C2AccessValuePtr addr(adr, adr_type);
1671   C2AtomicAccess access(this, decorators | C2_READ_ACCESS | C2_WRITE_ACCESS, bt, obj, addr, alias_idx);
1672   if (access.is_raw()) {
1673     return _barrier_set->BarrierSetC2::atomic_add_at(access, new_val, value_type);
1674   } else {
1675     return _barrier_set->atomic_add_at(access, new_val, value_type);
1676   }

1677 }
1678 
1679 void GraphKit::access_clone(Node* ctl, Node* src, Node* dst, Node* size, bool is_array) {
1680   set_control(ctl);
1681   return _barrier_set->clone(this, src, dst, size, is_array);
1682 }
1683 
1684 //-------------------------array_element_address-------------------------
1685 Node* GraphKit::array_element_address(Node* ary, Node* idx, BasicType elembt,
1686                                       const TypeInt* sizetype, Node* ctrl) {
1687   uint shift  = exact_log2(type2aelembytes(elembt));
1688   uint header = arrayOopDesc::base_offset_in_bytes(elembt);
1689 
1690   // short-circuit a common case (saves lots of confusing waste motion)
1691   jint idx_con = find_int_con(idx, -1);
1692   if (idx_con >= 0) {
1693     intptr_t offset = header + ((intptr_t)idx_con << shift);
1694     return basic_plus_adr(ary, offset);
1695   }
1696 
1697   // must be correct type for alignment purposes
1698   Node* base  = basic_plus_adr(ary, header);
1699   idx = Compile::conv_I2X_index(&_gvn, idx, sizetype, ctrl);
1700   Node* scale = _gvn.transform( new LShiftXNode(idx, intcon(shift)) );
1701   return basic_plus_adr(ary, base, scale);

3792   C->add_predicate_opaq(opq);                                                                                                        
3793   {                                                                                                                                  
3794     PreserveJVMState pjvms(this);                                                                                                    
3795     set_control(iffalse);                                                                                                            
3796     inc_sp(nargs);                                                                                                                   
3797     uncommon_trap(reason, Deoptimization::Action_maybe_recompile);                                                                   
3798   }                                                                                                                                  
3799   Node* iftrue = _gvn.transform(new IfTrueNode(iff));                                                                                
3800   set_control(iftrue);                                                                                                               
3801 }                                                                                                                                    
3802 
3803 //------------------------------add_predicate---------------------------------                                                       
3804 void GraphKit::add_predicate(int nargs) {                                                                                            
3805   if (UseLoopPredicate) {                                                                                                            
3806     add_predicate_impl(Deoptimization::Reason_predicate, nargs);                                                                     
3807   }                                                                                                                                  
3808   // loop's limit check predicate should be near the loop.                                                                           
3809   add_predicate_impl(Deoptimization::Reason_loop_limit_check, nargs);                                                                
3810 }                                                                                                                                    
3811 
3812 //----------------------------- store barriers ----------------------------                                                          
3813 #define __ ideal.                                                                                                                    
3814                                                                                                                                      
3815 bool GraphKit::use_ReduceInitialCardMarks() {                                                                                        
3816   BarrierSet *bs = BarrierSet::barrier_set();                                                                                        
3817   return bs->is_a(BarrierSet::CardTableBarrierSet)                                                                                   
3818          && barrier_set_cast<CardTableBarrierSet>(bs)->can_elide_tlab_store_barriers()                                               
3819          && ReduceInitialCardMarks;                                                                                                  
3820 }                                                                                                                                    
3821                                                                                                                                      
3822 void GraphKit::sync_kit(IdealKit& ideal) {                                                                                           
3823   set_all_memory(__ merged_memory());                                                                                                
3824   set_i_o(__ i_o());                                                                                                                 
3825   set_control(__ ctrl());                                                                                                            
3826 }                                                                                                                                    
3827 
3828 void GraphKit::final_sync(IdealKit& ideal) {                                                                                         
3829   // Final sync IdealKit and graphKit.                                                                                               
3830   sync_kit(ideal);                                                                                                                   
3831 }                                                                                                                                    
3832 
3833 Node* GraphKit::byte_map_base_node() {                                                                                               
3834   // Get base of card map                                                                                                            
3835   jbyte* card_table_base = ci_card_table_address();                                                                                  
3836   if (card_table_base != NULL) {                                                                                                     
3837     return makecon(TypeRawPtr::make((address)card_table_base));                                                                      
3838   } else {                                                                                                                           
3839     return null();                                                                                                                   
3840   }                                                                                                                                  
3841 }                                                                                                                                    
3842                                                                                                                                      
3843 // vanilla/CMS post barrier                                                                                                          
3844 // Insert a write-barrier store.  This is to let generational GC work; we have                                                       
3845 // to flag all oop-stores before the next GC point.                                                                                  
3846 void GraphKit::write_barrier_post(Node* oop_store,                                                                                   
3847                                   Node* obj,                                                                                         
3848                                   Node* adr,                                                                                         
3849                                   uint  adr_idx,                                                                                     
3850                                   Node* val,                                                                                         
3851                                   bool use_precise) {                                                                                
3852   // No store check needed if we're storing a NULL or an old object                                                                  
3853   // (latter case is probably a string constant). The concurrent                                                                     
3854   // mark sweep garbage collector, however, needs to have all nonNull                                                                
3855   // oop updates flagged via card-marks.                                                                                             
3856   if (val != NULL && val->is_Con()) {                                                                                                
3857     // must be either an oop or NULL                                                                                                 
3858     const Type* t = val->bottom_type();                                                                                              
3859     if (t == TypePtr::NULL_PTR || t == Type::TOP)                                                                                    
3860       // stores of null never (?) need barriers                                                                                      
3861       return;                                                                                                                        
3862   }                                                                                                                                  
3863                                                                                                                                      
3864   if (use_ReduceInitialCardMarks()                                                                                                   
3865       && obj == just_allocated_object(control())) {                                                                                  
3866     // We can skip marks on a freshly-allocated object in Eden.                                                                      
3867     // Keep this code in sync with new_deferred_store_barrier() in runtime.cpp.                                                      
3868     // That routine informs GC to take appropriate compensating steps,                                                               
3869     // upon a slow-path allocation, so as to make this card-mark                                                                     
3870     // elision safe.                                                                                                                 
3871     return;                                                                                                                          
3872   }                                                                                                                                  
3873                                                                                                                                      
3874   if (!use_precise) {                                                                                                                
3875     // All card marks for a (non-array) instance are in one place:                                                                   
3876     adr = obj;                                                                                                                       
3877   }                                                                                                                                  
3878   // (Else it's an array (or unknown), and we want more precise card marks.)                                                         
3879   assert(adr != NULL, "");                                                                                                           
3880                                                                                                                                      
3881   IdealKit ideal(this, true);                                                                                                        
3882                                                                                                                                      
3883   // Convert the pointer to an int prior to doing math on it                                                                         
3884   Node* cast = __ CastPX(__ ctrl(), adr);                                                                                            
3885                                                                                                                                      
3886   // Divide by card size                                                                                                             
3887   assert(BarrierSet::barrier_set()->is_a(BarrierSet::CardTableBarrierSet),                                                           
3888          "Only one we handle so far.");                                                                                              
3889   Node* card_offset = __ URShiftX( cast, __ ConI(CardTable::card_shift) );                                                           
3890                                                                                                                                      
3891   // Combine card table base and card offset                                                                                         
3892   Node* card_adr = __ AddP(__ top(), byte_map_base_node(), card_offset );                                                            
3893                                                                                                                                      
3894   // Get the alias_index for raw card-mark memory                                                                                    
3895   int adr_type = Compile::AliasIdxRaw;                                                                                               
3896   Node*   zero = __ ConI(0); // Dirty card value                                                                                     
3897   BasicType bt = T_BYTE;                                                                                                             
3898                                                                                                                                      
3899   if (UseConcMarkSweepGC && UseCondCardMark) {                                                                                       
3900     insert_mem_bar(Op_MemBarVolatile);   // StoreLoad barrier                                                                        
3901     __ sync_kit(this);                                                                                                               
3902   }                                                                                                                                  
3903                                                                                                                                      
3904   if (UseCondCardMark) {                                                                                                             
3905     // The classic GC reference write barrier is typically implemented                                                               
3906     // as a store into the global card mark table.  Unfortunately                                                                    
3907     // unconditional stores can result in false sharing and excessive                                                                
3908     // coherence traffic as well as false transactional aborts.                                                                      
3909     // UseCondCardMark enables MP "polite" conditional card mark                                                                     
3910     // stores.  In theory we could relax the load from ctrl() to                                                                     
3911     // no_ctrl, but that doesn't buy much latitude.                                                                                  
3912     Node* card_val = __ load( __ ctrl(), card_adr, TypeInt::BYTE, bt, adr_type);                                                     
3913     __ if_then(card_val, BoolTest::ne, zero);                                                                                        
3914   }                                                                                                                                  
3915                                                                                                                                      
3916   // Smash zero into card                                                                                                            
3917   if( !UseConcMarkSweepGC ) {                                                                                                        
3918     __ store(__ ctrl(), card_adr, zero, bt, adr_type, MemNode::unordered);                                                           
3919   } else {                                                                                                                           
3920     // Specialized path for CM store barrier                                                                                         
3921     __ storeCM(__ ctrl(), card_adr, zero, oop_store, adr_idx, bt, adr_type);                                                         
3922   }                                                                                                                                  
3923                                                                                                                                      
3924   if (UseCondCardMark) {                                                                                                             
3925     __ end_if();                                                                                                                     
3926   }                                                                                                                                  
3927                                                                                                                                      
3928   // Final sync IdealKit and GraphKit.                                                                                               
3929   final_sync(ideal);                                                                                                                 
3930 }                                                                                                                                    
3931 /*                                                                                                                                   
3932  * Determine if the G1 pre-barrier can be removed. The pre-barrier is                                                                
3933  * required by SATB to make sure all objects live at the start of the                                                                
3934  * marking are kept alive, all reference updates need to any previous                                                                
3935  * reference stored before writing.                                                                                                  
3936  *                                                                                                                                   
3937  * If the previous value is NULL there is no need to save the old value.                                                             
3938  * References that are NULL are filtered during runtime by the barrier                                                               
3939  * code to avoid unnecessary queuing.                                                                                                
3940  *                                                                                                                                   
3941  * However in the case of newly allocated objects it might be possible to                                                            
3942  * prove that the reference about to be overwritten is NULL during compile                                                           
3943  * time and avoid adding the barrier code completely.                                                                                
3944  *                                                                                                                                   
3945  * The compiler needs to determine that the object in which a field is about                                                         
3946  * to be written is newly allocated, and that no prior store to the same field                                                       
3947  * has happened since the allocation.                                                                                                
3948  *                                                                                                                                   
3949  * Returns true if the pre-barrier can be removed                                                                                    
3950  */                                                                                                                                  
3951 bool GraphKit::g1_can_remove_pre_barrier(PhaseTransform* phase, Node* adr,                                                           
3952                                          BasicType bt, uint adr_idx) {                                                               
3953   intptr_t offset = 0;                                                                                                               
3954   Node* base = AddPNode::Ideal_base_and_offset(adr, phase, offset);                                                                  
3955   AllocateNode* alloc = AllocateNode::Ideal_allocation(base, phase);                                                                 
3956                                                                                                                                      
3957   if (offset == Type::OffsetBot) {                                                                                                   
3958     return false; // cannot unalias unless there are precise offsets                                                                 
3959   }                                                                                                                                  
3960                                                                                                                                      
3961   if (alloc == NULL) {                                                                                                               
3962     return false; // No allocation found                                                                                             
3963   }                                                                                                                                  
3964                                                                                                                                      
3965   intptr_t size_in_bytes = type2aelembytes(bt);                                                                                      
3966                                                                                                                                      
3967   Node* mem = memory(adr_idx); // start searching here...                                                                            
3968                                                                                                                                      
3969   for (int cnt = 0; cnt < 50; cnt++) {                                                                                               
3970                                                                                                                                      
3971     if (mem->is_Store()) {                                                                                                           
3972                                                                                                                                      
3973       Node* st_adr = mem->in(MemNode::Address);                                                                                      
3974       intptr_t st_offset = 0;                                                                                                        
3975       Node* st_base = AddPNode::Ideal_base_and_offset(st_adr, phase, st_offset);                                                     
3976                                                                                                                                      
3977       if (st_base == NULL) {                                                                                                         
3978         break; // inscrutable pointer                                                                                                
3979       }                                                                                                                              
3980                                                                                                                                      
3981       // Break we have found a store with same base and offset as ours so break                                                      
3982       if (st_base == base && st_offset == offset) {                                                                                  
3983         break;                                                                                                                       
3984       }                                                                                                                              
3985                                                                                                                                      
3986       if (st_offset != offset && st_offset != Type::OffsetBot) {                                                                     
3987         const int MAX_STORE = BytesPerLong;                                                                                          
3988         if (st_offset >= offset + size_in_bytes ||                                                                                   
3989             st_offset <= offset - MAX_STORE ||                                                                                       
3990             st_offset <= offset - mem->as_Store()->memory_size()) {                                                                  
3991           // Success:  The offsets are provably independent.                                                                         
3992           // (You may ask, why not just test st_offset != offset and be done?                                                        
3993           // The answer is that stores of different sizes can co-exist                                                               
3994           // in the same sequence of RawMem effects.  We sometimes initialize                                                        
3995           // a whole 'tile' of array elements with a single jint or jlong.)                                                          
3996           mem = mem->in(MemNode::Memory);                                                                                            
3997           continue; // advance through independent store memory                                                                      
3998         }                                                                                                                            
3999       }                                                                                                                              
4000                                                                                                                                      
4001       if (st_base != base                                                                                                            
4002           && MemNode::detect_ptr_independence(base, alloc, st_base,                                                                  
4003                                               AllocateNode::Ideal_allocation(st_base, phase),                                        
4004                                               phase)) {                                                                              
4005         // Success:  The bases are provably independent.                                                                             
4006         mem = mem->in(MemNode::Memory);                                                                                              
4007         continue; // advance through independent store memory                                                                        
4008       }                                                                                                                              
4009     } else if (mem->is_Proj() && mem->in(0)->is_Initialize()) {                                                                      
4010                                                                                                                                      
4011       InitializeNode* st_init = mem->in(0)->as_Initialize();                                                                         
4012       AllocateNode* st_alloc = st_init->allocation();                                                                                
4013                                                                                                                                      
4014       // Make sure that we are looking at the same allocation site.                                                                  
4015       // The alloc variable is guaranteed to not be null here from earlier check.                                                    
4016       if (alloc == st_alloc) {                                                                                                       
4017         // Check that the initialization is storing NULL so that no previous store                                                   
4018         // has been moved up and directly write a reference                                                                          
4019         Node* captured_store = st_init->find_captured_store(offset,                                                                  
4020                                                             type2aelembytes(T_OBJECT),                                               
4021                                                             phase);                                                                  
4022         if (captured_store == NULL || captured_store == st_init->zero_memory()) {                                                    
4023           return true;                                                                                                               
4024         }                                                                                                                            
4025       }                                                                                                                              
4026     }                                                                                                                                
4027                                                                                                                                      
4028     // Unless there is an explicit 'continue', we must bail out here,                                                                
4029     // because 'mem' is an inscrutable memory state (e.g., a call).                                                                  
4030     break;                                                                                                                           
4031   }                                                                                                                                  
4032                                                                                                                                      
4033   return false;                                                                                                                      
4034 }                                                                                                                                    
4035                                                                                                                                      
4036 // G1 pre/post barriers                                                                                                              
4037 void GraphKit::g1_write_barrier_pre(bool do_load,                                                                                    
4038                                     Node* obj,                                                                                       
4039                                     Node* adr,                                                                                       
4040                                     uint alias_idx,                                                                                  
4041                                     Node* val,                                                                                       
4042                                     const TypeOopPtr* val_type,                                                                      
4043                                     Node* pre_val,                                                                                   
4044                                     BasicType bt) {                                                                                  
4045                                                                                                                                      
4046   // Some sanity checks                                                                                                              
4047   // Note: val is unused in this routine.                                                                                            
4048                                                                                                                                      
4049   if (do_load) {                                                                                                                     
4050     // We need to generate the load of the previous value                                                                            
4051     assert(obj != NULL, "must have a base");                                                                                         
4052     assert(adr != NULL, "where are loading from?");                                                                                  
4053     assert(pre_val == NULL, "loaded already?");                                                                                      
4054     assert(val_type != NULL, "need a type");                                                                                         
4055                                                                                                                                      
4056     if (use_ReduceInitialCardMarks()                                                                                                 
4057         && g1_can_remove_pre_barrier(&_gvn, adr, bt, alias_idx)) {                                                                   
4058       return;                                                                                                                        
4059     }                                                                                                                                
4060                                                                                                                                      
4061   } else {                                                                                                                           
4062     // In this case both val_type and alias_idx are unused.                                                                          
4063     assert(pre_val != NULL, "must be loaded already");                                                                               
4064     // Nothing to be done if pre_val is null.                                                                                        
4065     if (pre_val->bottom_type() == TypePtr::NULL_PTR) return;                                                                         
4066     assert(pre_val->bottom_type()->basic_type() == T_OBJECT, "or we shouldn't be here");                                             
4067   }                                                                                                                                  
4068   assert(bt == T_OBJECT, "or we shouldn't be here");                                                                                 
4069                                                                                                                                      
4070   IdealKit ideal(this, true);                                                                                                        
4071                                                                                                                                      
4072   Node* tls = __ thread(); // ThreadLocalStorage                                                                                     
4073                                                                                                                                      
4074   Node* no_ctrl = NULL;                                                                                                              
4075   Node* no_base = __ top();                                                                                                          
4076   Node* zero  = __ ConI(0);                                                                                                          
4077   Node* zeroX = __ ConX(0);                                                                                                          
4078                                                                                                                                      
4079   float likely  = PROB_LIKELY(0.999);                                                                                                
4080   float unlikely  = PROB_UNLIKELY(0.999);                                                                                            
4081                                                                                                                                      
4082   BasicType active_type = in_bytes(SATBMarkQueue::byte_width_of_active()) == 4 ? T_INT : T_BYTE;                                     
4083   assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 4 || in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "flag width");
4084                                                                                                                                      
4085   // Offsets into the thread                                                                                                         
4086   const int marking_offset = in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset());                                           
4087   const int index_offset   = in_bytes(G1ThreadLocalData::satb_mark_queue_index_offset());                                            
4088   const int buffer_offset  = in_bytes(G1ThreadLocalData::satb_mark_queue_buffer_offset());                                           
4089                                                                                                                                      
4090   // Now the actual pointers into the thread                                                                                         
4091   Node* marking_adr = __ AddP(no_base, tls, __ ConX(marking_offset));                                                                
4092   Node* buffer_adr  = __ AddP(no_base, tls, __ ConX(buffer_offset));                                                                 
4093   Node* index_adr   = __ AddP(no_base, tls, __ ConX(index_offset));                                                                  
4094                                                                                                                                      
4095   // Now some of the values                                                                                                          
4096   Node* marking = __ load(__ ctrl(), marking_adr, TypeInt::INT, active_type, Compile::AliasIdxRaw);                                  
4097                                                                                                                                      
4098   // if (!marking)                                                                                                                   
4099   __ if_then(marking, BoolTest::ne, zero, unlikely); {                                                                               
4100     BasicType index_bt = TypeX_X->basic_type();                                                                                      
4101     assert(sizeof(size_t) == type2aelembytes(index_bt), "Loading G1 SATBMarkQueue::_index with wrong size.");                        
4102     Node* index   = __ load(__ ctrl(), index_adr, TypeX_X, index_bt, Compile::AliasIdxRaw);                                          
4103                                                                                                                                      
4104     if (do_load) {                                                                                                                   
4105       // load original value                                                                                                         
4106       // alias_idx correct??                                                                                                         
4107       pre_val = __ load(__ ctrl(), adr, val_type, bt, alias_idx);                                                                    
4108     }                                                                                                                                
4109                                                                                                                                      
4110     // if (pre_val != NULL)                                                                                                          
4111     __ if_then(pre_val, BoolTest::ne, null()); {                                                                                     
4112       Node* buffer  = __ load(__ ctrl(), buffer_adr, TypeRawPtr::NOTNULL, T_ADDRESS, Compile::AliasIdxRaw);                          
4113                                                                                                                                      
4114       // is the queue for this thread full?                                                                                          
4115       __ if_then(index, BoolTest::ne, zeroX, likely); {                                                                              
4116                                                                                                                                      
4117         // decrement the index                                                                                                       
4118         Node* next_index = _gvn.transform(new SubXNode(index, __ ConX(sizeof(intptr_t))));                                           
4119                                                                                                                                      
4120         // Now get the buffer location we will log the previous value into and store it                                              
4121         Node *log_addr = __ AddP(no_base, buffer, next_index);                                                                       
4122         __ store(__ ctrl(), log_addr, pre_val, T_OBJECT, Compile::AliasIdxRaw, MemNode::unordered);                                  
4123         // update the index                                                                                                          
4124         __ store(__ ctrl(), index_adr, next_index, index_bt, Compile::AliasIdxRaw, MemNode::unordered);                              
4125                                                                                                                                      
4126       } __ else_(); {                                                                                                                
4127                                                                                                                                      
4128         // logging buffer is full, call the runtime                                                                                  
4129         const TypeFunc *tf = OptoRuntime::g1_wb_pre_Type();                                                                          
4130         __ make_leaf_call(tf, CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_pre), "g1_wb_pre", pre_val, tls);                       
4131       } __ end_if();  // (!index)                                                                                                    
4132     } __ end_if();  // (pre_val != NULL)                                                                                             
4133   } __ end_if();  // (!marking)                                                                                                      
4134                                                                                                                                      
4135   // Final sync IdealKit and GraphKit.                                                                                               
4136   final_sync(ideal);                                                                                                                 
4137 }                                                                                                                                    
4138                                                                                                                                      
4139 /*                                                                                                                                   
4140  * G1 similar to any GC with a Young Generation requires a way to keep track of                                                      
4141  * references from Old Generation to Young Generation to make sure all live                                                          
4142  * objects are found. G1 also requires to keep track of object references                                                            
4143  * between different regions to enable evacuation of old regions, which is done                                                      
4144  * as part of mixed collections. References are tracked in remembered sets and                                                       
4145  * is continuously updated as reference are written to with the help of the                                                          
4146  * post-barrier.                                                                                                                     
4147  *                                                                                                                                   
4148  * To reduce the number of updates to the remembered set the post-barrier                                                            
4149  * filters updates to fields in objects located in the Young Generation,                                                             
4150  * the same region as the reference, when the NULL is being written or                                                               
4151  * if the card is already marked as dirty by an earlier write.                                                                       
4152  *                                                                                                                                   
4153  * Under certain circumstances it is possible to avoid generating the                                                                
4154  * post-barrier completely if it is possible during compile time to prove                                                            
4155  * the object is newly allocated and that no safepoint exists between the                                                            
4156  * allocation and the store.                                                                                                         
4157  *                                                                                                                                   
4158  * In the case of slow allocation the allocation code must handle the barrier                                                        
4159  * as part of the allocation in the case the allocated object is not located                                                         
4160  * in the nursery, this would happen for humongous objects. This is similar to                                                       
4161  * how CMS is required to handle this case, see the comments for the method                                                          
4162  * CardTableBarrierSet::on_allocation_slowpath_exit and OptoRuntime::new_deferred_store_barrier.                                     
4163  * A deferred card mark is required for these objects and handled in the above                                                       
4164  * mentioned methods.                                                                                                                
4165  *                                                                                                                                   
4166  * Returns true if the post barrier can be removed                                                                                   
4167  */                                                                                                                                  
4168 bool GraphKit::g1_can_remove_post_barrier(PhaseTransform* phase, Node* store,                                                        
4169                                           Node* adr) {                                                                               
4170   intptr_t      offset = 0;                                                                                                          
4171   Node*         base   = AddPNode::Ideal_base_and_offset(adr, phase, offset);                                                        
4172   AllocateNode* alloc  = AllocateNode::Ideal_allocation(base, phase);                                                                
4173                                                                                                                                      
4174   if (offset == Type::OffsetBot) {                                                                                                   
4175     return false; // cannot unalias unless there are precise offsets                                                                 
4176   }                                                                                                                                  
4177                                                                                                                                      
4178   if (alloc == NULL) {                                                                                                               
4179      return false; // No allocation found                                                                                            
4180   }                                                                                                                                  
4181                                                                                                                                      
4182   // Start search from Store node                                                                                                    
4183   Node* mem = store->in(MemNode::Control);                                                                                           
4184   if (mem->is_Proj() && mem->in(0)->is_Initialize()) {                                                                               
4185                                                                                                                                      
4186     InitializeNode* st_init = mem->in(0)->as_Initialize();                                                                           
4187     AllocateNode*  st_alloc = st_init->allocation();                                                                                 
4188                                                                                                                                      
4189     // Make sure we are looking at the same allocation                                                                               
4190     if (alloc == st_alloc) {                                                                                                         
4191       return true;                                                                                                                   
4192     }                                                                                                                                
4193   }                                                                                                                                  
4194                                                                                                                                      
4195   return false;                                                                                                                      
4196 }                                                                                                                                    
4197                                                                                                                                      
4198 //                                                                                                                                   
4199 // Update the card table and add card address to the queue                                                                           
4200 //                                                                                                                                   
4201 void GraphKit::g1_mark_card(IdealKit& ideal,                                                                                         
4202                             Node* card_adr,                                                                                          
4203                             Node* oop_store,                                                                                         
4204                             uint oop_alias_idx,                                                                                      
4205                             Node* index,                                                                                             
4206                             Node* index_adr,                                                                                         
4207                             Node* buffer,                                                                                            
4208                             const TypeFunc* tf) {                                                                                    
4209                                                                                                                                      
4210   Node* zero  = __ ConI(0);                                                                                                          
4211   Node* zeroX = __ ConX(0);                                                                                                          
4212   Node* no_base = __ top();                                                                                                          
4213   BasicType card_bt = T_BYTE;                                                                                                        
4214   // Smash zero into card. MUST BE ORDERED WRT TO STORE                                                                              
4215   __ storeCM(__ ctrl(), card_adr, zero, oop_store, oop_alias_idx, card_bt, Compile::AliasIdxRaw);                                    
4216                                                                                                                                      
4217   //  Now do the queue work                                                                                                          
4218   __ if_then(index, BoolTest::ne, zeroX); {                                                                                          
4219                                                                                                                                      
4220     Node* next_index = _gvn.transform(new SubXNode(index, __ ConX(sizeof(intptr_t))));                                               
4221     Node* log_addr = __ AddP(no_base, buffer, next_index);                                                                           
4222                                                                                                                                      
4223     // Order, see storeCM.                                                                                                           
4224     __ store(__ ctrl(), log_addr, card_adr, T_ADDRESS, Compile::AliasIdxRaw, MemNode::unordered);                                    
4225     __ store(__ ctrl(), index_adr, next_index, TypeX_X->basic_type(), Compile::AliasIdxRaw, MemNode::unordered);                     
4226                                                                                                                                      
4227   } __ else_(); {                                                                                                                    
4228     __ make_leaf_call(tf, CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_post), "g1_wb_post", card_adr, __ thread());                
4229   } __ end_if();                                                                                                                     
4230                                                                                                                                      
4231 }                                                                                                                                    
4232                                                                                                                                      
4233 void GraphKit::g1_write_barrier_post(Node* oop_store,                                                                                
4234                                      Node* obj,                                                                                      
4235                                      Node* adr,                                                                                      
4236                                      uint alias_idx,                                                                                 
4237                                      Node* val,                                                                                      
4238                                      BasicType bt,                                                                                   
4239                                      bool use_precise) {                                                                             
4240   // If we are writing a NULL then we need no post barrier                                                                           
4241                                                                                                                                      
4242   if (val != NULL && val->is_Con() && val->bottom_type() == TypePtr::NULL_PTR) {                                                     
4243     // Must be NULL                                                                                                                  
4244     const Type* t = val->bottom_type();                                                                                              
4245     assert(t == Type::TOP || t == TypePtr::NULL_PTR, "must be NULL");                                                                
4246     // No post barrier if writing NULLx                                                                                              
4247     return;                                                                                                                          
4248   }                                                                                                                                  
4249                                                                                                                                      
4250   if (use_ReduceInitialCardMarks() && obj == just_allocated_object(control())) {                                                     
4251     // We can skip marks on a freshly-allocated object in Eden.                                                                      
4252     // Keep this code in sync with new_deferred_store_barrier() in runtime.cpp.                                                      
4253     // That routine informs GC to take appropriate compensating steps,                                                               
4254     // upon a slow-path allocation, so as to make this card-mark                                                                     
4255     // elision safe.                                                                                                                 
4256     return;                                                                                                                          
4257   }                                                                                                                                  
4258                                                                                                                                      
4259   if (use_ReduceInitialCardMarks()                                                                                                   
4260       && g1_can_remove_post_barrier(&_gvn, oop_store, adr)) {                                                                        
4261     return;                                                                                                                          
4262   }                                                                                                                                  
4263                                                                                                                                      
4264   if (!use_precise) {                                                                                                                
4265     // All card marks for a (non-array) instance are in one place:                                                                   
4266     adr = obj;                                                                                                                       
4267   }                                                                                                                                  
4268   // (Else it's an array (or unknown), and we want more precise card marks.)                                                         
4269   assert(adr != NULL, "");                                                                                                           
4270                                                                                                                                      
4271   IdealKit ideal(this, true);                                                                                                        
4272                                                                                                                                      
4273   Node* tls = __ thread(); // ThreadLocalStorage                                                                                     
4274                                                                                                                                      
4275   Node* no_base = __ top();                                                                                                          
4276   float likely  = PROB_LIKELY(0.999);                                                                                                
4277   float unlikely  = PROB_UNLIKELY(0.999);                                                                                            
4278   Node* young_card = __ ConI((jint)G1CardTable::g1_young_card_val());                                                                
4279   Node* dirty_card = __ ConI((jint)CardTable::dirty_card_val());                                                                     
4280   Node* zeroX = __ ConX(0);                                                                                                          
4281                                                                                                                                      
4282   // Get the alias_index for raw card-mark memory                                                                                    
4283   const TypePtr* card_type = TypeRawPtr::BOTTOM;                                                                                     
4284                                                                                                                                      
4285   const TypeFunc *tf = OptoRuntime::g1_wb_post_Type();                                                                               
4286                                                                                                                                      
4287   // Offsets into the thread                                                                                                         
4288   const int index_offset  = in_bytes(G1ThreadLocalData::dirty_card_queue_index_offset());                                            
4289   const int buffer_offset = in_bytes(G1ThreadLocalData::dirty_card_queue_buffer_offset());                                           
4290                                                                                                                                      
4291   // Pointers into the thread                                                                                                        
4292                                                                                                                                      
4293   Node* buffer_adr = __ AddP(no_base, tls, __ ConX(buffer_offset));                                                                  
4294   Node* index_adr =  __ AddP(no_base, tls, __ ConX(index_offset));                                                                   
4295                                                                                                                                      
4296   // Now some values                                                                                                                 
4297   // Use ctrl to avoid hoisting these values past a safepoint, which could                                                           
4298   // potentially reset these fields in the JavaThread.                                                                               
4299   Node* index  = __ load(__ ctrl(), index_adr, TypeX_X, TypeX_X->basic_type(), Compile::AliasIdxRaw);                                
4300   Node* buffer = __ load(__ ctrl(), buffer_adr, TypeRawPtr::NOTNULL, T_ADDRESS, Compile::AliasIdxRaw);                               
4301                                                                                                                                      
4302   // Convert the store obj pointer to an int prior to doing math on it                                                               
4303   // Must use ctrl to prevent "integerized oop" existing across safepoint                                                            
4304   Node* cast =  __ CastPX(__ ctrl(), adr);                                                                                           
4305                                                                                                                                      
4306   // Divide pointer by card size                                                                                                     
4307   Node* card_offset = __ URShiftX( cast, __ ConI(CardTable::card_shift) );                                                           
4308                                                                                                                                      
4309   // Combine card table base and card offset                                                                                         
4310   Node* card_adr = __ AddP(no_base, byte_map_base_node(), card_offset );                                                             
4311                                                                                                                                      
4312   // If we know the value being stored does it cross regions?                                                                        
4313                                                                                                                                      
4314   if (val != NULL) {                                                                                                                 
4315     // Does the store cause us to cross regions?                                                                                     
4316                                                                                                                                      
4317     // Should be able to do an unsigned compare of region_size instead of                                                            
4318     // and extra shift. Do we have an unsigned compare??                                                                             
4319     // Node* region_size = __ ConI(1 << HeapRegion::LogOfHRGrainBytes);                                                              
4320     Node* xor_res =  __ URShiftX ( __ XorX( cast,  __ CastPX(__ ctrl(), val)), __ ConI(HeapRegion::LogOfHRGrainBytes));              
4321                                                                                                                                      
4322     // if (xor_res == 0) same region so skip                                                                                         
4323     __ if_then(xor_res, BoolTest::ne, zeroX); {                                                                                      
4324                                                                                                                                      
4325       // No barrier if we are storing a NULL                                                                                         
4326       __ if_then(val, BoolTest::ne, null(), unlikely); {                                                                             
4327                                                                                                                                      
4328         // Ok must mark the card if not already dirty                                                                                
4329                                                                                                                                      
4330         // load the original value of the card                                                                                       
4331         Node* card_val = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw);                                   
4332                                                                                                                                      
4333         __ if_then(card_val, BoolTest::ne, young_card); {                                                                            
4334           sync_kit(ideal);                                                                                                           
4335           // Use Op_MemBarVolatile to achieve the effect of a StoreLoad barrier.                                                     
4336           insert_mem_bar(Op_MemBarVolatile, oop_store);                                                                              
4337           __ sync_kit(this);                                                                                                         
4338                                                                                                                                      
4339           Node* card_val_reload = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw);                          
4340           __ if_then(card_val_reload, BoolTest::ne, dirty_card); {                                                                   
4341             g1_mark_card(ideal, card_adr, oop_store, alias_idx, index, index_adr, buffer, tf);                                       
4342           } __ end_if();                                                                                                             
4343         } __ end_if();                                                                                                               
4344       } __ end_if();                                                                                                                 
4345     } __ end_if();                                                                                                                   
4346   } else {                                                                                                                           
4347     // The Object.clone() intrinsic uses this path if !ReduceInitialCardMarks.                                                       
4348     // We don't need a barrier here if the destination is a newly allocated object                                                   
4349     // in Eden. Otherwise, GC verification breaks because we assume that cards in Eden                                               
4350     // are set to 'g1_young_gen' (see G1CardTable::verify_g1_young_region()).                                                        
4351     assert(!use_ReduceInitialCardMarks(), "can only happen with card marking");                                                      
4352     Node* card_val = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw);                                       
4353     __ if_then(card_val, BoolTest::ne, young_card); {                                                                                
4354       g1_mark_card(ideal, card_adr, oop_store, alias_idx, index, index_adr, buffer, tf);                                             
4355     } __ end_if();                                                                                                                   
4356   }                                                                                                                                  
4357                                                                                                                                      
4358   // Final sync IdealKit and GraphKit.                                                                                               
4359   final_sync(ideal);                                                                                                                 
4360 }                                                                                                                                    
4361 #undef __                                                                                                                            
4362                                                                                                                                      
4363                                                                                                                                      
4364 Node* GraphKit::load_String_length(Node* ctrl, Node* str) {                                                                          
4365   Node* len = load_array_length(load_String_value(ctrl, str));                                                                       
4366   Node* coder = load_String_coder(ctrl, str);                                                                                        
4367   // Divide length by 2 if coder is UTF16                                                                                            
4368   return _gvn.transform(new RShiftINode(len, coder));                                                                                
4369 }                                                                                                                                    
4370 
4371 Node* GraphKit::load_String_value(Node* ctrl, Node* str) {                                                                           
4372   int value_offset = java_lang_String::value_offset_in_bytes();                                                                      
4373   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),                                     
4374                                                      false, NULL, 0);                                                                
4375   const TypePtr* value_field_type = string_type->add_offset(value_offset);                                                           
4376   const TypeAryPtr* value_type = TypeAryPtr::make(TypePtr::NotNull,                                                                  
4377                                                   TypeAry::make(TypeInt::BYTE, TypeInt::POS),                                        
4378                                                   ciTypeArrayKlass::make(T_BYTE), true, 0);                                          
4379   int value_field_idx = C->get_alias_index(value_field_type);                                                                        
4380   Node* load = make_load(ctrl, basic_plus_adr(str, str, value_offset),                                                               
4381                          value_type, T_OBJECT, value_field_idx, MemNode::unordered);                                                 
4382   // String.value field is known to be @Stable.                                                                                      
4383   if (UseImplicitStableValues) {                                                                                                     
4384     load = cast_array_to_stable(load, value_type);                                                                                   
4385   }                                                                                                                                  
4386   return load;                                                                                                                       
4387 }                                                                                                                                    
4388 
4389 Node* GraphKit::load_String_coder(Node* ctrl, Node* str) {                                                                           
4390   if (!CompactStrings) {                                                                                                             
4391     return intcon(java_lang_String::CODER_UTF16);                                                                                    
4392   }                                                                                                                                  
4393   int coder_offset = java_lang_String::coder_offset_in_bytes();                                                                      
4394   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),                                     
4395                                                      false, NULL, 0);                                                                
4396   const TypePtr* coder_field_type = string_type->add_offset(coder_offset);                                                           
4397   int coder_field_idx = C->get_alias_index(coder_field_type);                                                                        
4398   return make_load(ctrl, basic_plus_adr(str, str, coder_offset),                                                                     
4399                    TypeInt::BYTE, T_BYTE, coder_field_idx, MemNode::unordered);                                                      
4400 }                                                                                                                                    
4401 
4402 void GraphKit::store_String_value(Node* ctrl, Node* str, Node* value) {                                                              
4403   int value_offset = java_lang_String::value_offset_in_bytes();                                                                      
4404   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),                                     
4405                                                      false, NULL, 0);                                                                
4406   const TypePtr* value_field_type = string_type->add_offset(value_offset);                                                           
4407   store_oop_to_object(ctrl, str,  basic_plus_adr(str, value_offset), value_field_type,                                               
4408       value, TypeAryPtr::BYTES, T_OBJECT, MemNode::unordered);                                                                       
4409 }                                                                                                                                    
4410 
4411 void GraphKit::store_String_coder(Node* ctrl, Node* str, Node* value) {                                                              
4412   int coder_offset = java_lang_String::coder_offset_in_bytes();                                                                      
4413   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),                                     
4414                                                      false, NULL, 0);                                                                
4415   const TypePtr* coder_field_type = string_type->add_offset(coder_offset);                                                           
4416   int coder_field_idx = C->get_alias_index(coder_field_type);                                                                        
4417   store_to_memory(ctrl, basic_plus_adr(str, coder_offset),                                                                           
4418                   value, T_BYTE, coder_field_idx, MemNode::unordered);                                                               
4419 }                                                                                                                                    
4420 
4421 // Capture src and dst memory state with a MergeMemNode                                                                              
4422 Node* GraphKit::capture_memory(const TypePtr* src_type, const TypePtr* dst_type) {                                                   
4423   if (src_type == dst_type) {                                                                                                        
4424     // Types are equal, we don't need a MergeMemNode                                                                                 
4425     return memory(src_type);                                                                                                         
4426   }                                                                                                                                  
4427   MergeMemNode* merge = MergeMemNode::make(map()->memory());                                                                         

3791   C->add_predicate_opaq(opq);
3792   {
3793     PreserveJVMState pjvms(this);
3794     set_control(iffalse);
3795     inc_sp(nargs);
3796     uncommon_trap(reason, Deoptimization::Action_maybe_recompile);
3797   }
3798   Node* iftrue = _gvn.transform(new IfTrueNode(iff));
3799   set_control(iftrue);
3800 }
3801 
3802 //------------------------------add_predicate---------------------------------
3803 void GraphKit::add_predicate(int nargs) {
3804   if (UseLoopPredicate) {
3805     add_predicate_impl(Deoptimization::Reason_predicate, nargs);
3806   }
3807   // loop's limit check predicate should be near the loop.
3808   add_predicate_impl(Deoptimization::Reason_loop_limit_check, nargs);
3809 }
3810 










3811 void GraphKit::sync_kit(IdealKit& ideal) {
3812   set_all_memory(ideal.merged_memory());
3813   set_i_o(ideal.i_o());
3814   set_control(ideal.ctrl());
3815 }
3816 
3817 void GraphKit::final_sync(IdealKit& ideal) {
3818   // Final sync IdealKit and graphKit.
3819   sync_kit(ideal);
3820 }
3821 



















































































































































































































































































































































































































































































































































3822 Node* GraphKit::load_String_length(Node* ctrl, Node* str) {
3823   Node* len = load_array_length(load_String_value(ctrl, str));
3824   Node* coder = load_String_coder(ctrl, str);
3825   // Divide length by 2 if coder is UTF16
3826   return _gvn.transform(new RShiftINode(len, coder));
3827 }
3828 
3829 Node* GraphKit::load_String_value(Node* ctrl, Node* str) {
3830   int value_offset = java_lang_String::value_offset_in_bytes();
3831   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),
3832                                                      false, NULL, 0);
3833   const TypePtr* value_field_type = string_type->add_offset(value_offset);
3834   const TypeAryPtr* value_type = TypeAryPtr::make(TypePtr::NotNull,
3835                                                   TypeAry::make(TypeInt::BYTE, TypeInt::POS),
3836                                                   ciTypeArrayKlass::make(T_BYTE), true, 0);
3837   Node* p = basic_plus_adr(str, str, value_offset);
3838   Node* load = access_load_at(str, p, value_field_type, value_type, T_OBJECT,
3839                               IN_HEAP | C2_CONTROL_DEPENDENT_LOAD);
3840   // String.value field is known to be @Stable.
3841   if (UseImplicitStableValues) {
3842     load = cast_array_to_stable(load, value_type);
3843   }
3844   return load;
3845 }
3846 
3847 Node* GraphKit::load_String_coder(Node* ctrl, Node* str) {
3848   if (!CompactStrings) {
3849     return intcon(java_lang_String::CODER_UTF16);
3850   }
3851   int coder_offset = java_lang_String::coder_offset_in_bytes();
3852   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),
3853                                                      false, NULL, 0);
3854   const TypePtr* coder_field_type = string_type->add_offset(coder_offset);
3855   int coder_field_idx = C->get_alias_index(coder_field_type);
3856   return make_load(ctrl, basic_plus_adr(str, str, coder_offset),
3857                    TypeInt::BYTE, T_BYTE, coder_field_idx, MemNode::unordered);
3858 }
3859 
3860 void GraphKit::store_String_value(Node* ctrl, Node* str, Node* value) {
3861   int value_offset = java_lang_String::value_offset_in_bytes();
3862   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),
3863                                                      false, NULL, 0);
3864   const TypePtr* value_field_type = string_type->add_offset(value_offset);
3865   access_store_at(ctrl, str,  basic_plus_adr(str, value_offset), value_field_type,
3866                   value, TypeAryPtr::BYTES, T_OBJECT, IN_HEAP);
3867 }
3868 
3869 void GraphKit::store_String_coder(Node* ctrl, Node* str, Node* value) {
3870   int coder_offset = java_lang_String::coder_offset_in_bytes();
3871   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),
3872                                                      false, NULL, 0);
3873   const TypePtr* coder_field_type = string_type->add_offset(coder_offset);
3874   int coder_field_idx = C->get_alias_index(coder_field_type);
3875   store_to_memory(ctrl, basic_plus_adr(str, coder_offset),
3876                   value, T_BYTE, coder_field_idx, MemNode::unordered);
3877 }
3878 
3879 // Capture src and dst memory state with a MergeMemNode
3880 Node* GraphKit::capture_memory(const TypePtr* src_type, const TypePtr* dst_type) {
3881   if (src_type == dst_type) {
3882     // Types are equal, we don't need a MergeMemNode
3883     return memory(src_type);
3884   }
3885   MergeMemNode* merge = MergeMemNode::make(map()->memory());
< prev index next >