< prev index next >

src/hotspot/share/c1/c1_LIRGenerator.cpp

BarrierSetC1_v3

BarrierSetC1_v2

BarrierSetC1

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 "c1/c1_Compilation.hpp"                                                                                                     
26 #include "c1/c1_Defs.hpp"                                                                                                            
27 #include "c1/c1_FrameMap.hpp"                                                                                                        
28 #include "c1/c1_Instruction.hpp"                                                                                                     
29 #include "c1/c1_LIRAssembler.hpp"                                                                                                    
30 #include "c1/c1_LIRGenerator.hpp"                                                                                                    
31 #include "c1/c1_ValueStack.hpp"                                                                                                      
32 #include "ci/ciArrayKlass.hpp"                                                                                                       
33 #include "ci/ciInstance.hpp"                                                                                                         
34 #include "ci/ciObjArray.hpp"                                                                                                         
35 #include "ci/ciUtilities.hpp"                                                                                                        
36 #include "gc/shared/cardTable.hpp"                                                                                                   
37 #include "gc/shared/cardTableBarrierSet.hpp"                                                                                         
38 #include "gc/shared/collectedHeap.hpp"                                                                                               
39 #include "runtime/arguments.hpp"                                                                                                     
40 #include "runtime/sharedRuntime.hpp"                                                                                                 
41 #include "runtime/stubRoutines.hpp"                                                                                                  
42 #include "runtime/vm_version.hpp"                                                                                                    
43 #include "utilities/bitMap.inline.hpp"                                                                                               
44 #include "utilities/macros.hpp"                                                                                                      
45 #if INCLUDE_ALL_GCS                                                                                                                  
46 #include "gc/g1/g1ThreadLocalData.hpp"                                                                                               
47 #include "gc/g1/heapRegion.hpp"                                                                                                      
48 #endif // INCLUDE_ALL_GCS                                                                                                            
49 #ifdef TRACE_HAVE_INTRINSICS                                                                                                         
50 #include "trace/traceMacros.hpp"                                                                                                     
51 #endif                                                                                                                               
52 
53 #ifdef ASSERT                                                                                                                        
54 #define __ gen()->lir(__FILE__, __LINE__)->                                                                                          
55 #else                                                                                                                                
56 #define __ gen()->lir()->                                                                                                            
57 #endif                                                                                                                               
58 
59 #ifndef PATCHED_ADDR                                                                                                                 
60 #define PATCHED_ADDR  (max_jint)                                                                                                     
61 #endif                                                                                                                               
62 
63 void PhiResolverState::reset(int max_vregs) {                                                                                        
64   // Initialize array sizes                                                                                                          
65   _virtual_operands.at_put_grow(max_vregs - 1, NULL, NULL);                                                                          
66   _virtual_operands.trunc_to(0);                                                                                                     
67   _other_operands.at_put_grow(max_vregs - 1, NULL, NULL);                                                                            

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 "c1/c1_Compilation.hpp"
26 #include "c1/c1_Defs.hpp"
27 #include "c1/c1_FrameMap.hpp"
28 #include "c1/c1_Instruction.hpp"
29 #include "c1/c1_LIRAssembler.hpp"
30 #include "c1/c1_LIRGenerator.hpp"
31 #include "c1/c1_ValueStack.hpp"
32 #include "ci/ciArrayKlass.hpp"
33 #include "ci/ciInstance.hpp"
34 #include "ci/ciObjArray.hpp"
35 #include "ci/ciUtilities.hpp"
36 #include "gc/shared/barrierSet.hpp"
37 #include "gc/shared/c1/barrierSetC1.hpp"

38 #include "runtime/arguments.hpp"
39 #include "runtime/sharedRuntime.hpp"
40 #include "runtime/stubRoutines.hpp"
41 #include "runtime/vm_version.hpp"
42 #include "utilities/bitMap.inline.hpp"
43 #include "utilities/macros.hpp"




44 #ifdef TRACE_HAVE_INTRINSICS
45 #include "trace/traceMacros.hpp"
46 #endif
47 
48 #ifdef ASSERT
49 #define __ gen()->lir(__FILE__, __LINE__)->
50 #else
51 #define __ gen()->lir()->
52 #endif
53 
54 #ifndef PATCHED_ADDR
55 #define PATCHED_ADDR  (max_jint)
56 #endif
57 
58 void PhiResolverState::reset(int max_vregs) {
59   // Initialize array sizes
60   _virtual_operands.at_put_grow(max_vregs - 1, NULL, NULL);
61   _virtual_operands.trunc_to(0);
62   _other_operands.at_put_grow(max_vregs - 1, NULL, NULL);

295 
296 
297 jdouble LIRItem::get_jdouble_constant() const {                                                                                      
298   assert(is_constant() && value() != NULL, "");                                                                                      
299   assert(type()->as_DoubleConstant() != NULL, "type check");                                                                         
300   return type()->as_DoubleConstant()->value();                                                                                       
301 }                                                                                                                                    
302 
303 
304 jlong LIRItem::get_jlong_constant() const {                                                                                          
305   assert(is_constant() && value() != NULL, "");                                                                                      
306   assert(type()->as_LongConstant() != NULL, "type check");                                                                           
307   return type()->as_LongConstant()->value();                                                                                         
308 }                                                                                                                                    
309 
310 
311 
312 //--------------------------------------------------------------                                                                     
313 
314 
315 void LIRGenerator::init() {                                                                                                          
316   _bs = BarrierSet::barrier_set();                                                                                                   
317 }                                                                                                                                    
318                                                                                                                                      
319                                                                                                                                      
320 void LIRGenerator::block_do_prolog(BlockBegin* block) {                                                                              
321 #ifndef PRODUCT                                                                                                                      
322   if (PrintIRWithLIR) {                                                                                                              
323     block->print();                                                                                                                  
324   }                                                                                                                                  
325 #endif                                                                                                                               
326 
327   // set up the list of LIR instructions                                                                                             
328   assert(block->lir() == NULL, "LIR list already computed for this block");                                                          
329   _lir = new LIR_List(compilation(), block);                                                                                         
330   block->set_lir(_lir);                                                                                                              
331 
332   __ branch_destination(block->label());                                                                                             
333 
334   if (LIRTraceExecution &&                                                                                                           
335       Compilation::current()->hir()->start()->block_id() != block->block_id() &&                                                     
336       !block->is_set(BlockBegin::exception_entry_flag)) {                                                                            
337     assert(block->lir()->instructions_list()->length() == 1, "should come right after br_dst");                                      
338     trace_block_entry(block);                                                                                                        

290 
291 
292 jdouble LIRItem::get_jdouble_constant() const {
293   assert(is_constant() && value() != NULL, "");
294   assert(type()->as_DoubleConstant() != NULL, "type check");
295   return type()->as_DoubleConstant()->value();
296 }
297 
298 
299 jlong LIRItem::get_jlong_constant() const {
300   assert(is_constant() && value() != NULL, "");
301   assert(type()->as_LongConstant() != NULL, "type check");
302   return type()->as_LongConstant()->value();
303 }
304 
305 
306 
307 //--------------------------------------------------------------
308 
309 





310 void LIRGenerator::block_do_prolog(BlockBegin* block) {
311 #ifndef PRODUCT
312   if (PrintIRWithLIR) {
313     block->print();
314   }
315 #endif
316 
317   // set up the list of LIR instructions
318   assert(block->lir() == NULL, "LIR list already computed for this block");
319   _lir = new LIR_List(compilation(), block);
320   block->set_lir(_lir);
321 
322   __ branch_destination(block->label());
323 
324   if (LIRTraceExecution &&
325       Compilation::current()->hir()->start()->block_id() != block->block_id() &&
326       !block->is_set(BlockBegin::exception_entry_flag)) {
327     assert(block->lir()->instructions_list()->length() == 1, "should come right after br_dst");
328     trace_block_entry(block);

1227 }                                                                                                                                    
1228 
1229 // Examble: ref.get()                                                                                                                
1230 // Combination of LoadField and g1 pre-write barrier                                                                                 
1231 void LIRGenerator::do_Reference_get(Intrinsic* x) {                                                                                  
1232 
1233   const int referent_offset = java_lang_ref_Reference::referent_offset;                                                              
1234   guarantee(referent_offset > 0, "referent offset not initialized");                                                                 
1235 
1236   assert(x->number_of_arguments() == 1, "wrong type");                                                                               
1237 
1238   LIRItem reference(x->argument_at(0), this);                                                                                        
1239   reference.load_item();                                                                                                             
1240 
1241   // need to perform the null check on the reference objecy                                                                          
1242   CodeEmitInfo* info = NULL;                                                                                                         
1243   if (x->needs_null_check()) {                                                                                                       
1244     info = state_for(x);                                                                                                             
1245   }                                                                                                                                  
1246 
1247   LIR_Address* referent_field_adr =                                                                                                  
1248     new LIR_Address(reference.result(), referent_offset, T_OBJECT);                                                                  
1249                                                                                                                                      
1250   LIR_Opr result = rlock_result(x);                                                                                                  
1251                                                                                                                                      
1252   __ load(referent_field_adr, result, info);                                                                                         
1253                                                                                                                                      
1254   // Register the value in the referent field with the pre-barrier                                                                   
1255   pre_barrier(LIR_OprFact::illegalOpr /* addr_opr */,                                                                                
1256               result /* pre_val */,                                                                                                  
1257               false  /* do_load */,                                                                                                  
1258               false  /* patch */,                                                                                                    
1259               NULL   /* info */);                                                                                                    
1260 }                                                                                                                                    
1261 
1262 // Example: clazz.isInstance(object)                                                                                                 
1263 void LIRGenerator::do_isInstance(Intrinsic* x) {                                                                                     
1264   assert(x->number_of_arguments() == 2, "wrong type");                                                                               
1265 
1266   // TODO could try to substitute this node with an equivalent InstanceOf                                                            
1267   // if clazz is known to be a constant Class. This will pick up newly found                                                         
1268   // constants after HIR construction. I'll leave this to a future change.                                                           
1269 
1270   // as a first cut, make a simple leaf call to runtime to stay platform independent.                                                
1271   // could follow the aastore example in a future change.                                                                            
1272 
1273   LIRItem clazz(x->argument_at(0), this);                                                                                            
1274   LIRItem object(x->argument_at(1), this);                                                                                           
1275   clazz.load_item();                                                                                                                 
1276   object.load_item();                                                                                                                
1277   LIR_Opr result = rlock_result(x);                                                                                                  
1278 

1217 }
1218 
1219 // Examble: ref.get()
1220 // Combination of LoadField and g1 pre-write barrier
1221 void LIRGenerator::do_Reference_get(Intrinsic* x) {
1222 
1223   const int referent_offset = java_lang_ref_Reference::referent_offset;
1224   guarantee(referent_offset > 0, "referent offset not initialized");
1225 
1226   assert(x->number_of_arguments() == 1, "wrong type");
1227 
1228   LIRItem reference(x->argument_at(0), this);
1229   reference.load_item();
1230 
1231   // need to perform the null check on the reference objecy
1232   CodeEmitInfo* info = NULL;
1233   if (x->needs_null_check()) {
1234     info = state_for(x);
1235   }
1236 
1237   LIR_Opr result = rlock_result(x, T_OBJECT);
1238   access_load_at(IN_HEAP | ON_WEAK_OOP_REF, T_OBJECT,
1239                  reference, LIR_OprFact::intConst(referent_offset), result);










1240 }
1241 
1242 // Example: clazz.isInstance(object)
1243 void LIRGenerator::do_isInstance(Intrinsic* x) {
1244   assert(x->number_of_arguments() == 2, "wrong type");
1245 
1246   // TODO could try to substitute this node with an equivalent InstanceOf
1247   // if clazz is known to be a constant Class. This will pick up newly found
1248   // constants after HIR construction. I'll leave this to a future change.
1249 
1250   // as a first cut, make a simple leaf call to runtime to stay platform independent.
1251   // could follow the aastore example in a future change.
1252 
1253   LIRItem clazz(x->argument_at(0), this);
1254   LIRItem object(x->argument_at(1), this);
1255   clazz.load_item();
1256   object.load_item();
1257   LIR_Opr result = rlock_result(x);
1258 

1436         if (c->as_jint_hi_bits() != other->as_jint_hi_bits()) continue;                                                              
1437         if (c->as_jint_lo_bits() != other->as_jint_lo_bits()) continue;                                                              
1438         break;                                                                                                                       
1439       case T_OBJECT:                                                                                                                 
1440         if (c->as_jobject() != other->as_jobject()) continue;                                                                        
1441         break;                                                                                                                       
1442       default:                                                                                                                       
1443         break;                                                                                                                       
1444       }                                                                                                                              
1445       return _reg_for_constants.at(i);                                                                                               
1446     }                                                                                                                                
1447   }                                                                                                                                  
1448 
1449   LIR_Opr result = new_register(t);                                                                                                  
1450   __ move((LIR_Opr)c, result);                                                                                                       
1451   _constants.append(c);                                                                                                              
1452   _reg_for_constants.append(result);                                                                                                 
1453   return result;                                                                                                                     
1454 }                                                                                                                                    
1455 
1456 // Various barriers                                                                                                                  
1457                                                                                                                                      
1458 void LIRGenerator::pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val,                                                                    
1459                                bool do_load, bool patch, CodeEmitInfo* info) {                                                       
1460   // Do the pre-write barrier, if any.                                                                                               
1461   switch (_bs->kind()) {                                                                                                             
1462 #if INCLUDE_ALL_GCS                                                                                                                  
1463     case BarrierSet::G1BarrierSet:                                                                                                   
1464       G1BarrierSet_pre_barrier(addr_opr, pre_val, do_load, patch, info);                                                             
1465       break;                                                                                                                         
1466 #endif // INCLUDE_ALL_GCS                                                                                                            
1467     case BarrierSet::CardTableBarrierSet:                                                                                            
1468       // No pre barriers                                                                                                             
1469       break;                                                                                                                         
1470     default      :                                                                                                                   
1471       ShouldNotReachHere();                                                                                                          
1472                                                                                                                                      
1473   }                                                                                                                                  
1474 }                                                                                                                                    
1475                                                                                                                                      
1476 void LIRGenerator::post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) {                                                           
1477   switch (_bs->kind()) {                                                                                                             
1478 #if INCLUDE_ALL_GCS                                                                                                                  
1479     case BarrierSet::G1BarrierSet:                                                                                                   
1480       G1BarrierSet_post_barrier(addr,  new_val);                                                                                     
1481       break;                                                                                                                         
1482 #endif // INCLUDE_ALL_GCS                                                                                                            
1483     case BarrierSet::CardTableBarrierSet:                                                                                            
1484       CardTableBarrierSet_post_barrier(addr,  new_val);                                                                              
1485       break;                                                                                                                         
1486     default      :                                                                                                                   
1487       ShouldNotReachHere();                                                                                                          
1488     }                                                                                                                                
1489 }                                                                                                                                    
1490                                                                                                                                      
1491 ////////////////////////////////////////////////////////////////////////                                                             
1492 #if INCLUDE_ALL_GCS                                                                                                                  
1493                                                                                                                                      
1494 void LIRGenerator::G1BarrierSet_pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val,                                                       
1495                                             bool do_load, bool patch, CodeEmitInfo* info) {                                          
1496   // First we test whether marking is in progress.                                                                                   
1497   BasicType flag_type;                                                                                                               
1498   if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) {                                                                        
1499     flag_type = T_INT;                                                                                                               
1500   } else {                                                                                                                           
1501     guarantee(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1,                                                                  
1502               "Assumption");                                                                                                         
1503     // Use unsigned type T_BOOLEAN here rather than signed T_BYTE since some platforms, eg. ARM,                                     
1504     // need to use unsigned instructions to use the large offset to load the satb_mark_queue.                                        
1505     flag_type = T_BOOLEAN;                                                                                                           
1506   }                                                                                                                                  
1507   LIR_Opr thrd = getThreadPointer();                                                                                                 
1508   LIR_Address* mark_active_flag_addr =                                                                                               
1509     new LIR_Address(thrd, in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset()), flag_type);                                  
1510   // Read the marking-in-progress flag.                                                                                              
1511   LIR_Opr flag_val = new_register(T_INT);                                                                                            
1512   __ load(mark_active_flag_addr, flag_val);                                                                                          
1513   __ cmp(lir_cond_notEqual, flag_val, LIR_OprFact::intConst(0));                                                                     
1514                                                                                                                                      
1515   LIR_PatchCode pre_val_patch_code = lir_patch_none;                                                                                 
1516                                                                                                                                      
1517   CodeStub* slow;                                                                                                                    
1518                                                                                                                                      
1519   if (do_load) {                                                                                                                     
1520     assert(pre_val == LIR_OprFact::illegalOpr, "sanity");                                                                            
1521     assert(addr_opr != LIR_OprFact::illegalOpr, "sanity");                                                                           
1522                                                                                                                                      
1523     if (patch)                                                                                                                       
1524       pre_val_patch_code = lir_patch_normal;                                                                                         
1525                                                                                                                                      
1526     pre_val = new_register(T_OBJECT);                                                                                                
1527                                                                                                                                      
1528     if (!addr_opr->is_address()) {                                                                                                   
1529       assert(addr_opr->is_register(), "must be");                                                                                    
1530       addr_opr = LIR_OprFact::address(new LIR_Address(addr_opr, T_OBJECT));                                                          
1531     }                                                                                                                                
1532     slow = new G1PreBarrierStub(addr_opr, pre_val, pre_val_patch_code, info);                                                        
1533   } else {                                                                                                                           
1534     assert(addr_opr == LIR_OprFact::illegalOpr, "sanity");                                                                           
1535     assert(pre_val->is_register(), "must be");                                                                                       
1536     assert(pre_val->type() == T_OBJECT, "must be an object");                                                                        
1537     assert(info == NULL, "sanity");                                                                                                  
1538                                                                                                                                      
1539     slow = new G1PreBarrierStub(pre_val);                                                                                            
1540   }                                                                                                                                  
1541                                                                                                                                      
1542   __ branch(lir_cond_notEqual, T_INT, slow);                                                                                         
1543   __ branch_destination(slow->continuation());                                                                                       
1544 }                                                                                                                                    
1545                                                                                                                                      
1546 void LIRGenerator::G1BarrierSet_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) {                                              
1547   // If the "new_val" is a constant NULL, no barrier is necessary.                                                                   
1548   if (new_val->is_constant() &&                                                                                                      
1549       new_val->as_constant_ptr()->as_jobject() == NULL) return;                                                                      
1550                                                                                                                                      
1551   if (!new_val->is_register()) {                                                                                                     
1552     LIR_Opr new_val_reg = new_register(T_OBJECT);                                                                                    
1553     if (new_val->is_constant()) {                                                                                                    
1554       __ move(new_val, new_val_reg);                                                                                                 
1555     } else {                                                                                                                         
1556       __ leal(new_val, new_val_reg);                                                                                                 
1557     }                                                                                                                                
1558     new_val = new_val_reg;                                                                                                           
1559   }                                                                                                                                  
1560   assert(new_val->is_register(), "must be a register at this point");                                                                
1561                                                                                                                                      
1562   if (addr->is_address()) {                                                                                                          
1563     LIR_Address* address = addr->as_address_ptr();                                                                                   
1564     LIR_Opr ptr = new_pointer_register();                                                                                            
1565     if (!address->index()->is_valid() && address->disp() == 0) {                                                                     
1566       __ move(address->base(), ptr);                                                                                                 
1567     } else {                                                                                                                         
1568       assert(address->disp() != max_jint, "lea doesn't support patched addresses!");                                                 
1569       __ leal(addr, ptr);                                                                                                            
1570     }                                                                                                                                
1571     addr = ptr;                                                                                                                      
1572   }                                                                                                                                  
1573   assert(addr->is_register(), "must be a register at this point");                                                                   
1574                                                                                                                                      
1575   LIR_Opr xor_res = new_pointer_register();                                                                                          
1576   LIR_Opr xor_shift_res = new_pointer_register();                                                                                    
1577   if (TwoOperandLIRForm ) {                                                                                                          
1578     __ move(addr, xor_res);                                                                                                          
1579     __ logical_xor(xor_res, new_val, xor_res);                                                                                       
1580     __ move(xor_res, xor_shift_res);                                                                                                 
1581     __ unsigned_shift_right(xor_shift_res,                                                                                           
1582                             LIR_OprFact::intConst(HeapRegion::LogOfHRGrainBytes),                                                    
1583                             xor_shift_res,                                                                                           
1584                             LIR_OprDesc::illegalOpr());                                                                              
1585   } else {                                                                                                                           
1586     __ logical_xor(addr, new_val, xor_res);                                                                                          
1587     __ unsigned_shift_right(xor_res,                                                                                                 
1588                             LIR_OprFact::intConst(HeapRegion::LogOfHRGrainBytes),                                                    
1589                             xor_shift_res,                                                                                           
1590                             LIR_OprDesc::illegalOpr());                                                                              
1591   }                                                                                                                                  
1592                                                                                                                                      
1593   if (!new_val->is_register()) {                                                                                                     
1594     LIR_Opr new_val_reg = new_register(T_OBJECT);                                                                                    
1595     __ leal(new_val, new_val_reg);                                                                                                   
1596     new_val = new_val_reg;                                                                                                           
1597   }                                                                                                                                  
1598   assert(new_val->is_register(), "must be a register at this point");                                                                
1599                                                                                                                                      
1600   __ cmp(lir_cond_notEqual, xor_shift_res, LIR_OprFact::intptrConst(NULL_WORD));                                                     
1601                                                                                                                                      
1602   CodeStub* slow = new G1PostBarrierStub(addr, new_val);                                                                             
1603   __ branch(lir_cond_notEqual, LP64_ONLY(T_LONG) NOT_LP64(T_INT), slow);                                                             
1604   __ branch_destination(slow->continuation());                                                                                       
1605 }                                                                                                                                    
1606                                                                                                                                      
1607 #endif // INCLUDE_ALL_GCS                                                                                                            
1608 ////////////////////////////////////////////////////////////////////////                                                             
1609                                                                                                                                      
1610 void LIRGenerator::CardTableBarrierSet_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) {                                       
1611   LIR_Const* card_table_base = new LIR_Const(ci_card_table_address());                                                               
1612   if (addr->is_address()) {                                                                                                          
1613     LIR_Address* address = addr->as_address_ptr();                                                                                   
1614     // ptr cannot be an object because we use this barrier for array card marks                                                      
1615     // and addr can point in the middle of an array.                                                                                 
1616     LIR_Opr ptr = new_pointer_register();                                                                                            
1617     if (!address->index()->is_valid() && address->disp() == 0) {                                                                     
1618       __ move(address->base(), ptr);                                                                                                 
1619     } else {                                                                                                                         
1620       assert(address->disp() != max_jint, "lea doesn't support patched addresses!");                                                 
1621       __ leal(addr, ptr);                                                                                                            
1622     }                                                                                                                                
1623     addr = ptr;                                                                                                                      
1624   }                                                                                                                                  
1625   assert(addr->is_register(), "must be a register at this point");                                                                   
1626 
1627 #ifdef CARDTABLEBARRIERSET_POST_BARRIER_HELPER                                                                                       
1628   CardTableBarrierSet_post_barrier_helper(addr, card_table_base);                                                                    
1629 #else                                                                                                                                
1630   LIR_Opr tmp = new_pointer_register();                                                                                              
1631   if (TwoOperandLIRForm) {                                                                                                           
1632     __ move(addr, tmp);                                                                                                              
1633     __ unsigned_shift_right(tmp, CardTable::card_shift, tmp);                                                                        
1634   } else {                                                                                                                           
1635     __ unsigned_shift_right(addr, CardTable::card_shift, tmp);                                                                       
1636   }                                                                                                                                  
1637 
1638   LIR_Address* card_addr;                                                                                                            
1639   if (can_inline_as_constant(card_table_base)) {                                                                                     
1640     card_addr = new LIR_Address(tmp, card_table_base->as_jint(), T_BYTE);                                                            
1641   } else {                                                                                                                           
1642     card_addr = new LIR_Address(tmp, load_constant(card_table_base), T_BYTE);                                                        
1643   }                                                                                                                                  
1644 
1645   LIR_Opr dirty = LIR_OprFact::intConst(CardTable::dirty_card_val());                                                                
1646   if (UseCondCardMark) {                                                                                                             
1647     LIR_Opr cur_value = new_register(T_INT);                                                                                         
1648     if (UseConcMarkSweepGC) {                                                                                                        
1649       __ membar_storeload();                                                                                                         
1650     }                                                                                                                                
1651     __ move(card_addr, cur_value);                                                                                                   
1652 
1653     LabelObj* L_already_dirty = new LabelObj();                                                                                      
1654     __ cmp(lir_cond_equal, cur_value, dirty);                                                                                        
1655     __ branch(lir_cond_equal, T_BYTE, L_already_dirty->label());                                                                     
1656     __ move(dirty, card_addr);                                                                                                       
1657     __ branch_destination(L_already_dirty->label());                                                                                 
1658   } else {                                                                                                                           
1659 #if INCLUDE_ALL_GCS                                                                                                                  
1660     if (UseConcMarkSweepGC && CMSPrecleaningEnabled) {                                                                               
1661       __ membar_storestore();                                                                                                        
1662     }                                                                                                                                
1663 #endif                                                                                                                               
1664     __ move(dirty, card_addr);                                                                                                       
1665   }                                                                                                                                  
1666 #endif                                                                                                                               
1667 }                                                                                                                                    
1668 
1669                                                                                                                                      
1670 //------------------------field access--------------------------------------                                                         
1671                                                                                                                                      
1672 // Comment copied form templateTable_i486.cpp                                                                                        
1673 // ----------------------------------------------------------------------------                                                      
1674 // Volatile variables demand their effects be made known to all CPU's in                                                             
1675 // order.  Store buffers on most chips allow reads & writes to reorder; the                                                          
1676 // JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of                                                           
1677 // memory barrier (i.e., it's not sufficient that the interpreter does not                                                           
1678 // reorder volatile references, the hardware also must not reorder them).                                                            
1679 //                                                                                                                                   
1680 // According to the new Java Memory Model (JMM):                                                                                     
1681 // (1) All volatiles are serialized wrt to each other.                                                                               
1682 // ALSO reads & writes act as aquire & release, so:                                                                                  
1683 // (2) A read cannot let unrelated NON-volatile memory refs that happen after                                                        
1684 // the read float up to before the read.  It's OK for non-volatile memory refs                                                       
1685 // that happen before the volatile read to float down below it.                                                                      
1686 // (3) Similar a volatile write cannot let unrelated NON-volatile memory refs                                                        
1687 // that happen BEFORE the write float down to after the write.  It's OK for                                                          
1688 // non-volatile memory refs that happen after the volatile write to float up                                                         
1689 // before it.                                                                                                                        
1690 //                                                                                                                                   
1691 // We only put in barriers around volatile refs (they are expensive), not                                                            
1692 // _between_ memory refs (that would require us to track the flavor of the                                                           
1693 // previous memory refs).  Requirements (2) and (3) require some barriers                                                            
1694 // before volatile stores and after volatile loads.  These nearly cover                                                              
1695 // requirement (1) but miss the volatile-store-volatile-load case.  This final                                                       
1696 // case is placed after volatile-stores although it could just as well go                                                            
1697 // before volatile-loads.                                                                                                            
1698 
1699 
1700 void LIRGenerator::do_StoreField(StoreField* x) {                                                                                    
1701   bool needs_patching = x->needs_patching();                                                                                         
1702   bool is_volatile = x->field()->is_volatile();                                                                                      
1703   BasicType field_type = x->field_type();                                                                                            
1704   bool is_oop = (field_type == T_ARRAY || field_type == T_OBJECT);                                                                   
1705 
1706   CodeEmitInfo* info = NULL;                                                                                                         
1707   if (needs_patching) {                                                                                                              
1708     assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access");                                    
1709     info = state_for(x, x->state_before());                                                                                          
1710   } else if (x->needs_null_check()) {                                                                                                
1711     NullCheck* nc = x->explicit_null_check();                                                                                        
1712     if (nc == NULL) {                                                                                                                
1713       info = state_for(x);                                                                                                           
1714     } else {                                                                                                                         
1715       info = state_for(nc);                                                                                                          
1716     }                                                                                                                                
1717   }                                                                                                                                  
1718 
1719                                                                                                                                      
1720   LIRItem object(x->obj(), this);                                                                                                    
1721   LIRItem value(x->value(),  this);                                                                                                  
1722 
1723   object.load_item();                                                                                                                
1724 
1725   if (is_volatile || needs_patching) {                                                                                               
1726     // load item if field is volatile (fewer special cases for volatiles)                                                            
1727     // load item if field not initialized                                                                                            
1728     // load item if field not constant                                                                                               
1729     // because of code patching we cannot inline constants                                                                           
1730     if (field_type == T_BYTE || field_type == T_BOOLEAN) {                                                                           
1731       value.load_byte_item();                                                                                                        
1732     } else  {                                                                                                                        
1733       value.load_item();                                                                                                             
1734     }                                                                                                                                
1735   } else {                                                                                                                           
1736     value.load_for_store(field_type);                                                                                                
1737   }                                                                                                                                  
1738 
1739   set_no_result(x);                                                                                                                  
1740 
1741 #ifndef PRODUCT                                                                                                                      
1742   if (PrintNotLoaded && needs_patching) {                                                                                            
1743     tty->print_cr("   ###class not loaded at store_%s bci %d",                                                                       
1744                   x->is_static() ?  "static" : "field", x->printable_bci());                                                         
1745   }                                                                                                                                  
1746 #endif                                                                                                                               
1747 
1748   if (x->needs_null_check() &&                                                                                                       
1749       (needs_patching ||                                                                                                             
1750        MacroAssembler::needs_explicit_null_check(x->offset()))) {                                                                    
1751     // Emit an explicit null check because the offset is too large.                                                                  
1752     // If the class is not loaded and the object is NULL, we need to deoptimize to throw a                                           
1753     // NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.                                        
1754     __ null_check(object.result(), new CodeEmitInfo(info), /* deoptimize */ needs_patching);                                         
1755   }                                                                                                                                  
1756 
1757   LIR_Address* address;                                                                                                              
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
1758   if (needs_patching) {                                                                                                              
1759     // we need to patch the offset in the instruction so don't allow                                                                 
1760     // generate_address to try to be smart about emitting the -1.                                                                    
1761     // Otherwise the patching code won't know how to find the                                                                        
1762     // instruction to patch.                                                                                                         
1763     address = new LIR_Address(object.result(), PATCHED_ADDR, field_type);                                                            
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
1764   } else {                                                                                                                           
1765     address = generate_address(object.result(), x->offset(), field_type);                                                            
1766   }                                                                                                                                  
1767 
1768   if (is_volatile && os::is_MP()) {                                                                                                  
1769     __ membar_release();                                                                                                             
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
1770   }                                                                                                                                  
1771 
1772   if (is_oop) {                                                                                                                      
1773     // Do the pre-write barrier, if any.                                                                                             
1774     pre_barrier(LIR_OprFact::address(address),                                                                                       
1775                 LIR_OprFact::illegalOpr /* pre_val */,                                                                               
1776                 true /* do_load*/,                                                                                                   
1777                 needs_patching,                                                                                                      
1778                 (info ? new CodeEmitInfo(info) : NULL));                                                                             
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
1779   }                                                                                                                                  
                                                                                                                                     
1780 
1781   bool needs_atomic_access = is_volatile || AlwaysAtomicAccesses;                                                                    
1782   if (needs_atomic_access && !needs_patching) {                                                                                      
1783     volatile_field_store(value.result(), address, info);                                                                             
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
1784   } else {                                                                                                                           
1785     LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none;                                                   
1786     __ store(value.result(), address, info, patch_code);                                                                             
1787   }                                                                                                                                  
                                                                                                                                     
1788 
1789   if (is_oop) {                                                                                                                      
1790     // Store to object so mark the card of the header                                                                                
1791     post_barrier(object.result(), value.result());                                                                                   
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
1792   }                                                                                                                                  
                                                                                                                                     
1793 
1794   if (!support_IRIW_for_not_multiple_copy_atomic_cpu && is_volatile && os::is_MP()) {                                                
1795     __ membar();                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
1796   }                                                                                                                                  
1797 }                                                                                                                                    
1798 
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
1799 
1800 void LIRGenerator::do_LoadField(LoadField* x) {                                                                                      
1801   bool needs_patching = x->needs_patching();                                                                                         
1802   bool is_volatile = x->field()->is_volatile();                                                                                      
1803   BasicType field_type = x->field_type();                                                                                            
1804 
1805   CodeEmitInfo* info = NULL;                                                                                                         
1806   if (needs_patching) {                                                                                                              
1807     assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access");                                    
1808     info = state_for(x, x->state_before());                                                                                          
1809   } else if (x->needs_null_check()) {                                                                                                
1810     NullCheck* nc = x->explicit_null_check();                                                                                        
1811     if (nc == NULL) {                                                                                                                
1812       info = state_for(x);                                                                                                           
1813     } else {                                                                                                                         
1814       info = state_for(nc);                                                                                                          
1815     }                                                                                                                                
1816   }                                                                                                                                  
1817 

1416         if (c->as_jint_hi_bits() != other->as_jint_hi_bits()) continue;
1417         if (c->as_jint_lo_bits() != other->as_jint_lo_bits()) continue;
1418         break;
1419       case T_OBJECT:
1420         if (c->as_jobject() != other->as_jobject()) continue;
1421         break;
1422       default:
1423         break;
1424       }
1425       return _reg_for_constants.at(i);
1426     }
1427   }
1428 
1429   LIR_Opr result = new_register(t);
1430   __ move((LIR_Opr)c, result);
1431   _constants.append(c);
1432   _reg_for_constants.append(result);
1433   return result;
1434 }
1435 
1436 //------------------------field access--------------------------------------









































































































































































1437 
1438 void LIRGenerator::do_CompareAndSwap(Intrinsic* x, ValueType* type) {
1439   assert(x->number_of_arguments() == 4, "wrong type");
1440   LIRItem obj   (x->argument_at(0), this);  // object
1441   LIRItem offset(x->argument_at(1), this);  // offset of field
1442   LIRItem cmp   (x->argument_at(2), this);  // value to compare with field
1443   LIRItem val   (x->argument_at(3), this);  // replace field with val if matches cmp
1444   assert(obj.type()->tag() == objectTag, "invalid type");



1445 
1446   // In 64bit the type can be long, sparc doesn't have this assert
1447   // assert(offset.type()->tag() == intTag, "invalid type");




1448 
1449   assert(cmp.type()->tag() == type->tag(), "invalid type");
1450   assert(val.type()->tag() == type->tag(), "invalid type");





1451 
1452   LIR_Opr result = access_atomic_cmpxchg_at(IN_HEAP, as_BasicType(type),
1453                                             obj, offset, cmp, val);
1454   set_result(x, result);











1455 }
1456 



1457 // Comment copied form templateTable_i486.cpp
1458 // ----------------------------------------------------------------------------
1459 // Volatile variables demand their effects be made known to all CPU's in
1460 // order.  Store buffers on most chips allow reads & writes to reorder; the
1461 // JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of
1462 // memory barrier (i.e., it's not sufficient that the interpreter does not
1463 // reorder volatile references, the hardware also must not reorder them).
1464 //
1465 // According to the new Java Memory Model (JMM):
1466 // (1) All volatiles are serialized wrt to each other.
1467 // ALSO reads & writes act as aquire & release, so:
1468 // (2) A read cannot let unrelated NON-volatile memory refs that happen after
1469 // the read float up to before the read.  It's OK for non-volatile memory refs
1470 // that happen before the volatile read to float down below it.
1471 // (3) Similar a volatile write cannot let unrelated NON-volatile memory refs
1472 // that happen BEFORE the write float down to after the write.  It's OK for
1473 // non-volatile memory refs that happen after the volatile write to float up
1474 // before it.
1475 //
1476 // We only put in barriers around volatile refs (they are expensive), not
1477 // _between_ memory refs (that would require us to track the flavor of the
1478 // previous memory refs).  Requirements (2) and (3) require some barriers
1479 // before volatile stores and after volatile loads.  These nearly cover
1480 // requirement (1) but miss the volatile-store-volatile-load case.  This final
1481 // case is placed after volatile-stores although it could just as well go
1482 // before volatile-loads.
1483 
1484 
1485 void LIRGenerator::do_StoreField(StoreField* x) {
1486   bool needs_patching = x->needs_patching();
1487   bool is_volatile = x->field()->is_volatile();
1488   BasicType field_type = x->field_type();

1489 
1490   CodeEmitInfo* info = NULL;
1491   if (needs_patching) {
1492     assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access");
1493     info = state_for(x, x->state_before());
1494   } else if (x->needs_null_check()) {
1495     NullCheck* nc = x->explicit_null_check();
1496     if (nc == NULL) {
1497       info = state_for(x);
1498     } else {
1499       info = state_for(nc);
1500     }
1501   }
1502 

1503   LIRItem object(x->obj(), this);
1504   LIRItem value(x->value(),  this);
1505 
1506   object.load_item();
1507 
1508   if (is_volatile || needs_patching) {
1509     // load item if field is volatile (fewer special cases for volatiles)
1510     // load item if field not initialized
1511     // load item if field not constant
1512     // because of code patching we cannot inline constants
1513     if (field_type == T_BYTE || field_type == T_BOOLEAN) {
1514       value.load_byte_item();
1515     } else  {
1516       value.load_item();
1517     }
1518   } else {
1519     value.load_for_store(field_type);
1520   }
1521 
1522   set_no_result(x);
1523 
1524 #ifndef PRODUCT
1525   if (PrintNotLoaded && needs_patching) {
1526     tty->print_cr("   ###class not loaded at store_%s bci %d",
1527                   x->is_static() ?  "static" : "field", x->printable_bci());
1528   }
1529 #endif
1530 
1531   if (x->needs_null_check() &&
1532       (needs_patching ||
1533        MacroAssembler::needs_explicit_null_check(x->offset()))) {
1534     // Emit an explicit null check because the offset is too large.
1535     // If the class is not loaded and the object is NULL, we need to deoptimize to throw a
1536     // NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.
1537     __ null_check(object.result(), new CodeEmitInfo(info), /* deoptimize */ needs_patching);
1538   }
1539 
1540   DecoratorSet decorators = IN_HEAP;
1541   if (is_volatile) {
1542     decorators |= MO_SEQ_CST;
1543   }
1544   if (needs_patching) {
1545     decorators |= C1_NEEDS_PATCHING;
1546   }
1547 
1548   access_store_at(decorators, field_type, object, LIR_OprFact::intConst(x->offset()),
1549                   value.result(), info != NULL ? new CodeEmitInfo(info) : NULL, info);
1550 }
1551 
1552 void LIRGenerator::do_StoreIndexed(StoreIndexed* x) {
1553   assert(x->is_pinned(),"");
1554   bool needs_range_check = x->compute_needs_range_check();
1555   bool use_length = x->length() != NULL;
1556   bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT;
1557   bool needs_store_check = obj_store && (x->value()->as_Constant() == NULL ||
1558                                          !get_jobject_constant(x->value())->is_null_object() ||
1559                                          x->should_profile());
1560 
1561   LIRItem array(x->array(), this);
1562   LIRItem index(x->index(), this);
1563   LIRItem value(x->value(), this);
1564   LIRItem length(this);
1565 
1566   array.load_item();
1567   index.load_nonconstant();
1568 
1569   if (use_length && needs_range_check) {
1570     length.set_instruction(x->length());
1571     length.load_item();
1572 
1573   }
1574   if (needs_store_check || x->check_boolean()) {
1575     value.load_item();
1576   } else {
1577     value.load_for_store(x->elt_type());
1578   }
1579 
1580   set_no_result(x);
1581 
1582   // the CodeEmitInfo must be duplicated for each different
1583   // LIR-instruction because spilling can occur anywhere between two
1584   // instructions and so the debug information must be different
1585   CodeEmitInfo* range_check_info = state_for(x);
1586   CodeEmitInfo* null_check_info = NULL;
1587   if (x->needs_null_check()) {
1588     null_check_info = new CodeEmitInfo(range_check_info);
1589   }
1590 
1591   if (GenerateRangeChecks && needs_range_check) {
1592     if (use_length) {
1593       __ cmp(lir_cond_belowEqual, length.result(), index.result());
1594       __ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result()));
1595     } else {
1596       array_range_check(array.result(), index.result(), null_check_info, range_check_info);
1597       // range_check also does the null check
1598       null_check_info = NULL;
1599     }
1600   }
1601 
1602   if (GenerateArrayStoreCheck && needs_store_check) {
1603     CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info);
1604     array_store_check(value.result(), array.result(), store_check_info, x->profiled_method(), x->profiled_bci());
1605   }
1606 
1607   DecoratorSet decorators = IN_HEAP | IN_HEAP_ARRAY;
1608   if (x->check_boolean()) {
1609     decorators |= C1_MASK_BOOLEAN;
1610   }
1611 
1612   access_store_at(decorators, x->elt_type(), array, index.result(), value.result(),
1613                   NULL, null_check_info);
1614 }
1615 
1616 void LIRGenerator::access_load_at(DecoratorSet decorators, BasicType type,
1617                                   LIRItem& base, LIR_Opr offset, LIR_Opr result,
1618                                   CodeEmitInfo* patch_info, CodeEmitInfo* load_emit_info) {
1619   LIRAccess access(this, decorators, base, offset, type, patch_info, load_emit_info);
1620   if (access.is_raw()) {
1621     _barrier_set->BarrierSetC1::load_at(access, result);
1622   } else {
1623     _barrier_set->load_at(access, result);
1624   }
1625 }
1626 
1627 void LIRGenerator::access_store_at(DecoratorSet decorators, BasicType type,
1628                                    LIRItem& base, LIR_Opr offset, LIR_Opr value,
1629                                    CodeEmitInfo* patch_info, CodeEmitInfo* store_emit_info) {
1630   LIRAccess access(this, decorators, base, offset, type, patch_info, store_emit_info);
1631   if (access.is_raw()) {
1632     _barrier_set->BarrierSetC1::store_at(access, value);
1633   } else {
1634     _barrier_set->store_at(access, value);

1635   }
1636 }
1637 
1638 LIR_Opr LIRGenerator::access_atomic_cmpxchg_at(DecoratorSet decorators, BasicType type,
1639                                                LIRItem& base, LIRItem& offset, LIRItem& cmp_value, LIRItem& new_value) {
1640   // Atomic operations are SEQ_CST by default
1641   decorators |= ((decorators & MO_DECORATOR_MASK) != 0) ? MO_SEQ_CST : 0;
1642   LIRAccess access(this, decorators, base, offset, type);
1643   if (access.is_raw()) {
1644     return _barrier_set->BarrierSetC1::atomic_cmpxchg_at(access, cmp_value, new_value);
1645   } else {
1646     return _barrier_set->atomic_cmpxchg_at(access, cmp_value, new_value);
1647   }
1648 }
1649 
1650 LIR_Opr LIRGenerator::access_atomic_xchg_at(DecoratorSet decorators, BasicType type,
1651                                             LIRItem& base, LIRItem& offset, LIRItem& value) {
1652   // Atomic operations are SEQ_CST by default
1653   decorators |= ((decorators & MO_DECORATOR_MASK) != 0) ? MO_SEQ_CST : 0;
1654   LIRAccess access(this, decorators, base, offset, type);
1655   if (access.is_raw()) {
1656     return _barrier_set->BarrierSetC1::atomic_xchg(access, value);
1657   } else {
1658     return _barrier_set->atomic_xchg(access, value);
1659   }
1660 }
1661 
1662 LIR_Opr LIRGenerator::access_atomic_add_at(DecoratorSet decorators, BasicType type,
1663                                            LIRItem& base, LIRItem& offset, LIRItem& value) {
1664   // Atomic operations are SEQ_CST by default
1665   decorators |= ((decorators & MO_DECORATOR_MASK) != 0) ? MO_SEQ_CST : 0;
1666   LIRAccess access(this, decorators, base, offset, type);
1667   if (access.is_raw()) {
1668     return _barrier_set->BarrierSetC1::atomic_add_at(access, value);
1669   } else {
1670     return _barrier_set->atomic_add_at(access, value);
1671   }
1672 }
1673 
1674 void LIRGenerator::do_LoadField(LoadField* x) {
1675   bool needs_patching = x->needs_patching();
1676   bool is_volatile = x->field()->is_volatile();
1677   BasicType field_type = x->field_type();
1678 
1679   CodeEmitInfo* info = NULL;
1680   if (needs_patching) {
1681     assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access");
1682     info = state_for(x, x->state_before());
1683   } else if (x->needs_null_check()) {
1684     NullCheck* nc = x->explicit_null_check();
1685     if (nc == NULL) {
1686       info = state_for(x);
1687     } else {
1688       info = state_for(nc);
1689     }
1690   }
1691 

1825                   x->is_static() ?  "static" : "field", x->printable_bci());                                                         
1826   }                                                                                                                                  
1827 #endif                                                                                                                               
1828 
1829   bool stress_deopt = StressLoopInvariantCodeMotion && info && info->deoptimize_on_exception();                                      
1830   if (x->needs_null_check() &&                                                                                                       
1831       (needs_patching ||                                                                                                             
1832        MacroAssembler::needs_explicit_null_check(x->offset()) ||                                                                     
1833        stress_deopt)) {                                                                                                              
1834     LIR_Opr obj = object.result();                                                                                                   
1835     if (stress_deopt) {                                                                                                              
1836       obj = new_register(T_OBJECT);                                                                                                  
1837       __ move(LIR_OprFact::oopConst(NULL), obj);                                                                                     
1838     }                                                                                                                                
1839     // Emit an explicit null check because the offset is too large.                                                                  
1840     // If the class is not loaded and the object is NULL, we need to deoptimize to throw a                                           
1841     // NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.                                        
1842     __ null_check(obj, new CodeEmitInfo(info), /* deoptimize */ needs_patching);                                                     
1843   }                                                                                                                                  
1844 
1845   LIR_Opr reg = rlock_result(x, field_type);                                                                                         
1846   LIR_Address* address;                                                                                                              
1847   if (needs_patching) {                                                                                                              
1848     // we need to patch the offset in the instruction so don't allow                                                                 
1849     // generate_address to try to be smart about emitting the -1.                                                                    
1850     // Otherwise the patching code won't know how to find the                                                                        
1851     // instruction to patch.                                                                                                         
1852     address = new LIR_Address(object.result(), PATCHED_ADDR, field_type);                                                            
1853   } else {                                                                                                                           
1854     address = generate_address(object.result(), x->offset(), field_type);                                                            
1855   }                                                                                                                                  
1856                                                                                                                                      
1857   if (support_IRIW_for_not_multiple_copy_atomic_cpu && is_volatile && os::is_MP()) {                                                 
1858     __ membar();                                                                                                                     
1859   }                                                                                                                                  
1860                                                                                                                                      
1861   bool needs_atomic_access = is_volatile || AlwaysAtomicAccesses;                                                                    
1862   if (needs_atomic_access && !needs_patching) {                                                                                      
1863     volatile_field_load(address, reg, info);                                                                                         
1864   } else {                                                                                                                           
1865     LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none;                                                   
1866     __ load(address, reg, info, patch_code);                                                                                         
1867   }                                                                                                                                  
1868 
1869   if (is_volatile && os::is_MP()) {                                                                                                  
1870     __ membar_acquire();                                                                                                             
1871   }                                                                                                                                  
                                                                                                                                     
1872 }                                                                                                                                    
1873 
1874 
1875 //------------------------java.nio.Buffer.checkIndex------------------------                                                         
1876 
1877 // int java.nio.Buffer.checkIndex(int)                                                                                               
1878 void LIRGenerator::do_NIOCheckIndex(Intrinsic* x) {                                                                                  
1879   // NOTE: by the time we are in checkIndex() we are guaranteed that                                                                 
1880   // the buffer is non-null (because checkIndex is package-private and                                                               
1881   // only called from within other methods in the buffer).                                                                           
1882   assert(x->number_of_arguments() == 2, "wrong type");                                                                               
1883   LIRItem buf  (x->argument_at(0), this);                                                                                            
1884   LIRItem index(x->argument_at(1), this);                                                                                            
1885   buf.load_item();                                                                                                                   
1886   index.load_item();                                                                                                                 
1887 
1888   LIR_Opr result = rlock_result(x);                                                                                                  
1889   if (GenerateRangeChecks) {                                                                                                         
1890     CodeEmitInfo* info = state_for(x);                                                                                               

1699                   x->is_static() ?  "static" : "field", x->printable_bci());
1700   }
1701 #endif
1702 
1703   bool stress_deopt = StressLoopInvariantCodeMotion && info && info->deoptimize_on_exception();
1704   if (x->needs_null_check() &&
1705       (needs_patching ||
1706        MacroAssembler::needs_explicit_null_check(x->offset()) ||
1707        stress_deopt)) {
1708     LIR_Opr obj = object.result();
1709     if (stress_deopt) {
1710       obj = new_register(T_OBJECT);
1711       __ move(LIR_OprFact::oopConst(NULL), obj);
1712     }
1713     // Emit an explicit null check because the offset is too large.
1714     // If the class is not loaded and the object is NULL, we need to deoptimize to throw a
1715     // NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.
1716     __ null_check(obj, new CodeEmitInfo(info), /* deoptimize */ needs_patching);
1717   }
1718 
1719   DecoratorSet decorators = IN_HEAP;
1720   if (is_volatile) {
1721     decorators |= MO_SEQ_CST;











1722   }
1723   if (needs_patching) {
1724     decorators |= C1_NEEDS_PATCHING;





1725   }
1726 
1727   LIR_Opr result = rlock_result(x, field_type);
1728   access_load_at(decorators, field_type,
1729                  object, LIR_OprFact::intConst(x->offset()), result,
1730                  info ? new CodeEmitInfo(info) : NULL, info);
1731 }
1732 
1733 
1734 //------------------------java.nio.Buffer.checkIndex------------------------
1735 
1736 // int java.nio.Buffer.checkIndex(int)
1737 void LIRGenerator::do_NIOCheckIndex(Intrinsic* x) {
1738   // NOTE: by the time we are in checkIndex() we are guaranteed that
1739   // the buffer is non-null (because checkIndex is package-private and
1740   // only called from within other methods in the buffer).
1741   assert(x->number_of_arguments() == 2, "wrong type");
1742   LIRItem buf  (x->argument_at(0), this);
1743   LIRItem index(x->argument_at(1), this);
1744   buf.load_item();
1745   index.load_item();
1746 
1747   LIR_Opr result = rlock_result(x);
1748   if (GenerateRangeChecks) {
1749     CodeEmitInfo* info = state_for(x);

1950   } else {                                                                                                                           
1951     index.load_item();                                                                                                               
1952   }                                                                                                                                  
1953 
1954   CodeEmitInfo* range_check_info = state_for(x);                                                                                     
1955   CodeEmitInfo* null_check_info = NULL;                                                                                              
1956   if (x->needs_null_check()) {                                                                                                       
1957     NullCheck* nc = x->explicit_null_check();                                                                                        
1958     if (nc != NULL) {                                                                                                                
1959       null_check_info = state_for(nc);                                                                                               
1960     } else {                                                                                                                         
1961       null_check_info = range_check_info;                                                                                            
1962     }                                                                                                                                
1963     if (StressLoopInvariantCodeMotion && null_check_info->deoptimize_on_exception()) {                                               
1964       LIR_Opr obj = new_register(T_OBJECT);                                                                                          
1965       __ move(LIR_OprFact::oopConst(NULL), obj);                                                                                     
1966       __ null_check(obj, new CodeEmitInfo(null_check_info));                                                                         
1967     }                                                                                                                                
1968   }                                                                                                                                  
1969 
1970   // emit array address setup early so it schedules better                                                                           
1971   LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), false);                                
1972                                                                                                                                      
1973   if (GenerateRangeChecks && needs_range_check) {                                                                                    
1974     if (StressLoopInvariantCodeMotion && range_check_info->deoptimize_on_exception()) {                                              
1975       __ branch(lir_cond_always, T_ILLEGAL, new RangeCheckStub(range_check_info, index.result()));                                   
1976     } else if (use_length) {                                                                                                         
1977       // TODO: use a (modified) version of array_range_check that does not require a                                                 
1978       //       constant length to be loaded to a register                                                                            
1979       __ cmp(lir_cond_belowEqual, length.result(), index.result());                                                                  
1980       __ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result()));                                   
1981     } else {                                                                                                                         
1982       array_range_check(array.result(), index.result(), null_check_info, range_check_info);                                          
1983       // The range check performs the null check, so clear it out for the load                                                       
1984       null_check_info = NULL;                                                                                                        
1985     }                                                                                                                                
1986   }                                                                                                                                  
1987 
1988   __ move(array_addr, rlock_result(x, x->elt_type()), null_check_info);                                                              
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
1989 }                                                                                                                                    
1990 
1991 
1992 void LIRGenerator::do_NullCheck(NullCheck* x) {                                                                                      
1993   if (x->can_trap()) {                                                                                                               
1994     LIRItem value(x->obj(), this);                                                                                                   
1995     value.load_item();                                                                                                               
1996     CodeEmitInfo* info = state_for(x);                                                                                               
1997     __ null_check(value.result(), info);                                                                                             
1998   }                                                                                                                                  
1999 }                                                                                                                                    
2000 
2001 
2002 void LIRGenerator::do_TypeCast(TypeCast* x) {                                                                                        
2003   LIRItem value(x->obj(), this);                                                                                                     
2004   value.load_item();                                                                                                                 
2005   // the result is the same as from the node we are casting                                                                          
2006   set_result(x, value.result());                                                                                                     
2007 }                                                                                                                                    

1809   } else {
1810     index.load_item();
1811   }
1812 
1813   CodeEmitInfo* range_check_info = state_for(x);
1814   CodeEmitInfo* null_check_info = NULL;
1815   if (x->needs_null_check()) {
1816     NullCheck* nc = x->explicit_null_check();
1817     if (nc != NULL) {
1818       null_check_info = state_for(nc);
1819     } else {
1820       null_check_info = range_check_info;
1821     }
1822     if (StressLoopInvariantCodeMotion && null_check_info->deoptimize_on_exception()) {
1823       LIR_Opr obj = new_register(T_OBJECT);
1824       __ move(LIR_OprFact::oopConst(NULL), obj);
1825       __ null_check(obj, new CodeEmitInfo(null_check_info));
1826     }
1827   }
1828 



1829   if (GenerateRangeChecks && needs_range_check) {
1830     if (StressLoopInvariantCodeMotion && range_check_info->deoptimize_on_exception()) {
1831       __ branch(lir_cond_always, T_ILLEGAL, new RangeCheckStub(range_check_info, index.result()));
1832     } else if (use_length) {
1833       // TODO: use a (modified) version of array_range_check that does not require a
1834       //       constant length to be loaded to a register
1835       __ cmp(lir_cond_belowEqual, length.result(), index.result());
1836       __ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result()));
1837     } else {
1838       array_range_check(array.result(), index.result(), null_check_info, range_check_info);
1839       // The range check performs the null check, so clear it out for the load
1840       null_check_info = NULL;
1841     }
1842   }
1843 
1844   DecoratorSet decorators = IN_HEAP | IN_HEAP_ARRAY;
1845 
1846   LIR_Opr result = rlock_result(x, x->elt_type());
1847   access_load_at(decorators, x->elt_type(),
1848                  array, index.result(), result,
1849                  NULL, null_check_info);
1850 }
1851 
1852 
1853 void LIRGenerator::do_NullCheck(NullCheck* x) {
1854   if (x->can_trap()) {
1855     LIRItem value(x->obj(), this);
1856     value.load_item();
1857     CodeEmitInfo* info = state_for(x);
1858     __ null_check(value.result(), info);
1859   }
1860 }
1861 
1862 
1863 void LIRGenerator::do_TypeCast(TypeCast* x) {
1864   LIRItem value(x->obj(), this);
1865   value.load_item();
1866   // the result is the same as from the node we are casting
1867   set_result(x, value.result());
1868 }

2254     __ shift_left(index_op, log2_scale, tmp);                                                                                        
2255     if (!TwoOperandLIRForm) {                                                                                                        
2256       index_op = tmp;                                                                                                                
2257     }                                                                                                                                
2258   }                                                                                                                                  
2259 
2260   LIR_Address* addr = new LIR_Address(base_op, index_op, x->basic_type());                                                           
2261 #endif // !GENERATE_ADDRESS_IS_PREFERRED                                                                                             
2262   __ move(value.result(), addr);                                                                                                     
2263 }                                                                                                                                    
2264 
2265 
2266 void LIRGenerator::do_UnsafeGetObject(UnsafeGetObject* x) {                                                                          
2267   BasicType type = x->basic_type();                                                                                                  
2268   LIRItem src(x->object(), this);                                                                                                    
2269   LIRItem off(x->offset(), this);                                                                                                    
2270 
2271   off.load_item();                                                                                                                   
2272   src.load_item();                                                                                                                   
2273 
2274   LIR_Opr value = rlock_result(x, x->basic_type());                                                                                  
2275 
2276   if (support_IRIW_for_not_multiple_copy_atomic_cpu && x->is_volatile() && os::is_MP()) {                                            
2277     __ membar();                                                                                                                     
2278   }                                                                                                                                  
2279                                                                                                                                      
2280   get_Object_unsafe(value, src.result(), off.result(), type, x->is_volatile());                                                      
2281                                                                                                                                      
2282 #if INCLUDE_ALL_GCS                                                                                                                  
2283   // We might be reading the value of the referent field of a                                                                        
2284   // Reference object in order to attach it back to the live                                                                         
2285   // object graph. If G1 is enabled then we need to record                                                                           
2286   // the value that is being returned in an SATB log buffer.                                                                         
2287   //                                                                                                                                 
2288   // We need to generate code similar to the following...                                                                            
2289   //                                                                                                                                 
2290   // if (offset == java_lang_ref_Reference::referent_offset) {                                                                       
2291   //   if (src != NULL) {                                                                                                            
2292   //     if (klass(src)->reference_type() != REF_NONE) {                                                                             
2293   //       pre_barrier(..., value, ...);                                                                                             
2294   //     }                                                                                                                           
2295   //   }                                                                                                                             
2296   // }                                                                                                                               
2297                                                                                                                                      
2298   if (UseG1GC && type == T_OBJECT) {                                                                                                 
2299     bool gen_pre_barrier = true;     // Assume we need to generate pre_barrier.                                                      
2300     bool gen_offset_check = true;    // Assume we need to generate the offset guard.                                                 
2301     bool gen_source_check = true;    // Assume we need to check the src object for null.                                             
2302     bool gen_type_check = true;      // Assume we need to check the reference_type.                                                  
2303                                                                                                                                      
2304     if (off.is_constant()) {                                                                                                         
2305       jlong off_con = (off.type()->is_int() ?                                                                                        
2306                         (jlong) off.get_jint_constant() :                                                                            
2307                         off.get_jlong_constant());                                                                                   
2308                                                                                                                                      
2309                                                                                                                                      
2310       if (off_con != (jlong) java_lang_ref_Reference::referent_offset) {                                                             
2311         // The constant offset is something other than referent_offset.                                                              
2312         // We can skip generating/checking the remaining guards and                                                                  
2313         // skip generation of the code stub.                                                                                         
2314         gen_pre_barrier = false;                                                                                                     
2315       } else {                                                                                                                       
2316         // The constant offset is the same as referent_offset -                                                                      
2317         // we do not need to generate a runtime offset check.                                                                        
2318         gen_offset_check = false;                                                                                                    
2319       }                                                                                                                              
2320     }                                                                                                                                
2321                                                                                                                                      
2322     // We don't need to generate stub if the source object is an array                                                               
2323     if (gen_pre_barrier && src.type()->is_array()) {                                                                                 
2324       gen_pre_barrier = false;                                                                                                       
2325     }                                                                                                                                
2326                                                                                                                                      
2327     if (gen_pre_barrier) {                                                                                                           
2328       // We still need to continue with the checks.                                                                                  
2329       if (src.is_constant()) {                                                                                                       
2330         ciObject* src_con = src.get_jobject_constant();                                                                              
2331         guarantee(src_con != NULL, "no source constant");                                                                            
2332                                                                                                                                      
2333         if (src_con->is_null_object()) {                                                                                             
2334           // The constant src object is null - We can skip                                                                           
2335           // generating the code stub.                                                                                               
2336           gen_pre_barrier = false;                                                                                                   
2337         } else {                                                                                                                     
2338           // Non-null constant source object. We still have to generate                                                              
2339           // the slow stub - but we don't need to generate the runtime                                                               
2340           // null object check.                                                                                                      
2341           gen_source_check = false;                                                                                                  
2342         }                                                                                                                            
2343       }                                                                                                                              
2344     }                                                                                                                                
2345     if (gen_pre_barrier && !PatchALot) {                                                                                             
2346       // Can the klass of object be statically determined to be                                                                      
2347       // a sub-class of Reference?                                                                                                   
2348       ciType* type = src.value()->declared_type();                                                                                   
2349       if ((type != NULL) && type->is_loaded()) {                                                                                     
2350         if (type->is_subtype_of(compilation()->env()->Reference_klass())) {                                                          
2351           gen_type_check = false;                                                                                                    
2352         } else if (type->is_klass() &&                                                                                               
2353                    !compilation()->env()->Object_klass()->is_subtype_of(type->as_klass())) {                                         
2354           // Not Reference and not Object klass.                                                                                     
2355           gen_pre_barrier = false;                                                                                                   
2356         }                                                                                                                            
2357       }                                                                                                                              
2358     }                                                                                                                                
2359                                                                                                                                      
2360     if (gen_pre_barrier) {                                                                                                           
2361       LabelObj* Lcont = new LabelObj();                                                                                              
2362                                                                                                                                      
2363       // We can have generate one runtime check here. Let's start with                                                               
2364       // the offset check.                                                                                                           
2365       if (gen_offset_check) {                                                                                                        
2366         // if (offset != referent_offset) -> continue                                                                                
2367         // If offset is an int then we can do the comparison with the                                                                
2368         // referent_offset constant; otherwise we need to move                                                                       
2369         // referent_offset into a temporary register and generate                                                                    
2370         // a reg-reg compare.                                                                                                        
2371                                                                                                                                      
2372         LIR_Opr referent_off;                                                                                                        
2373                                                                                                                                      
2374         if (off.type()->is_int()) {                                                                                                  
2375           referent_off = LIR_OprFact::intConst(java_lang_ref_Reference::referent_offset);                                            
2376         } else {                                                                                                                     
2377           assert(off.type()->is_long(), "what else?");                                                                               
2378           referent_off = new_register(T_LONG);                                                                                       
2379           __ move(LIR_OprFact::longConst(java_lang_ref_Reference::referent_offset), referent_off);                                   
2380         }                                                                                                                            
2381         __ cmp(lir_cond_notEqual, off.result(), referent_off);                                                                       
2382         __ branch(lir_cond_notEqual, as_BasicType(off.type()), Lcont->label());                                                      
2383       }                                                                                                                              
2384       if (gen_source_check) {                                                                                                        
2385         // offset is a const and equals referent offset                                                                              
2386         // if (source == null) -> continue                                                                                           
2387         __ cmp(lir_cond_equal, src.result(), LIR_OprFact::oopConst(NULL));                                                           
2388         __ branch(lir_cond_equal, T_OBJECT, Lcont->label());                                                                         
2389       }                                                                                                                              
2390       LIR_Opr src_klass = new_register(T_OBJECT);                                                                                    
2391       if (gen_type_check) {                                                                                                          
2392         // We have determined that offset == referent_offset && src != null.                                                         
2393         // if (src->_klass->_reference_type == REF_NONE) -> continue                                                                 
2394         __ move(new LIR_Address(src.result(), oopDesc::klass_offset_in_bytes(), T_ADDRESS), src_klass);                              
2395         LIR_Address* reference_type_addr = new LIR_Address(src_klass, in_bytes(InstanceKlass::reference_type_offset()), T_BYTE);     
2396         LIR_Opr reference_type = new_register(T_INT);                                                                                
2397         __ move(reference_type_addr, reference_type);                                                                                
2398         __ cmp(lir_cond_equal, reference_type, LIR_OprFact::intConst(REF_NONE));                                                     
2399         __ branch(lir_cond_equal, T_INT, Lcont->label());                                                                            
2400       }                                                                                                                              
2401       {                                                                                                                              
2402         // We have determined that src->_klass->_reference_type != REF_NONE                                                          
2403         // so register the value in the referent field with the pre-barrier.                                                         
2404         pre_barrier(LIR_OprFact::illegalOpr /* addr_opr */,                                                                          
2405                     value  /* pre_val */,                                                                                            
2406                     false  /* do_load */,                                                                                            
2407                     false  /* patch */,                                                                                              
2408                     NULL   /* info */);                                                                                              
2409       }                                                                                                                              
2410       __ branch_destination(Lcont->label());                                                                                         
2411     }                                                                                                                                
2412   }                                                                                                                                  
2413 #endif // INCLUDE_ALL_GCS                                                                                                            
2414                                                                                                                                      
2415   if (x->is_volatile() && os::is_MP()) __ membar_acquire();                                                                          
2416                                                                                                                                      
2417   /* Normalize boolean value returned by unsafe operation, i.e., value  != 0 ? value = true : value false. */                        
2418   if (type == T_BOOLEAN) {                                                                                                           
2419     LabelObj* equalZeroLabel = new LabelObj();                                                                                       
2420     __ cmp(lir_cond_equal, value, 0);                                                                                                
2421     __ branch(lir_cond_equal, T_BOOLEAN, equalZeroLabel->label());                                                                   
2422     __ move(LIR_OprFact::intConst(1), value);                                                                                        
2423     __ branch_destination(equalZeroLabel->label());                                                                                  
2424   }                                                                                                                                  
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
2425 }                                                                                                                                    
2426 
2427 
2428 void LIRGenerator::do_UnsafePutObject(UnsafePutObject* x) {                                                                          
2429   BasicType type = x->basic_type();                                                                                                  
2430   LIRItem src(x->object(), this);                                                                                                    
2431   LIRItem off(x->offset(), this);                                                                                                    
2432   LIRItem data(x->value(), this);                                                                                                    
2433 
2434   src.load_item();                                                                                                                   
2435   if (type == T_BOOLEAN || type == T_BYTE) {                                                                                         
2436     data.load_byte_item();                                                                                                           
2437   } else {                                                                                                                           
2438     data.load_item();                                                                                                                
2439   }                                                                                                                                  
2440   off.load_item();                                                                                                                   
2441 
2442   set_no_result(x);                                                                                                                  
2443 
2444   if (x->is_volatile() && os::is_MP()) __ membar_release();                                                                          
2445   put_Object_unsafe(src.result(), off.result(), data.result(), type, x->is_volatile());                                              
2446   if (!support_IRIW_for_not_multiple_copy_atomic_cpu && x->is_volatile() && os::is_MP()) __ membar();                                
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
2447 }                                                                                                                                    
2448 
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
2449 
2450 void LIRGenerator::do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux) {                                    
2451   int lng = x->length();                                                                                                             
2452 
2453   for (int i = 0; i < lng; i++) {                                                                                                    
2454     SwitchRange* one_range = x->at(i);                                                                                               
2455     int low_key = one_range->low_key();                                                                                              
2456     int high_key = one_range->high_key();                                                                                            
2457     BlockBegin* dest = one_range->sux();                                                                                             
2458     if (low_key == high_key) {                                                                                                       
2459       __ cmp(lir_cond_equal, value, low_key);                                                                                        
2460       __ branch(lir_cond_equal, T_INT, dest);                                                                                        
2461     } else if (high_key - low_key == 1) {                                                                                            
2462       __ cmp(lir_cond_equal, value, low_key);                                                                                        
2463       __ branch(lir_cond_equal, T_INT, dest);                                                                                        
2464       __ cmp(lir_cond_equal, value, high_key);                                                                                       
2465       __ branch(lir_cond_equal, T_INT, dest);                                                                                        
2466     } else {                                                                                                                         
2467       LabelObj* L = new LabelObj();                                                                                                  

2115     __ shift_left(index_op, log2_scale, tmp);
2116     if (!TwoOperandLIRForm) {
2117       index_op = tmp;
2118     }
2119   }
2120 
2121   LIR_Address* addr = new LIR_Address(base_op, index_op, x->basic_type());
2122 #endif // !GENERATE_ADDRESS_IS_PREFERRED
2123   __ move(value.result(), addr);
2124 }
2125 
2126 
2127 void LIRGenerator::do_UnsafeGetObject(UnsafeGetObject* x) {
2128   BasicType type = x->basic_type();
2129   LIRItem src(x->object(), this);
2130   LIRItem off(x->offset(), this);
2131 
2132   off.load_item();
2133   src.load_item();
2134 
2135   DecoratorSet decorators = IN_HEAP;
2136 
2137   if (x->is_volatile()) {
2138     decorators |= MO_SEQ_CST;
2139   }











































































































































2140   if (type == T_BOOLEAN) {
2141     decorators |= C1_MASK_BOOLEAN;
2142   }
2143   if (type == T_ARRAY || type == T_OBJECT) {
2144     decorators |= ON_UNKNOWN_OOP_REF;

2145   }
2146 
2147   LIR_Opr result = rlock_result(x, type);
2148   access_load_at(decorators, type,
2149                  src, off.result(), result);
2150 }
2151 
2152 
2153 void LIRGenerator::do_UnsafePutObject(UnsafePutObject* x) {
2154   BasicType type = x->basic_type();
2155   LIRItem src(x->object(), this);
2156   LIRItem off(x->offset(), this);
2157   LIRItem data(x->value(), this);
2158 
2159   src.load_item();
2160   if (type == T_BOOLEAN || type == T_BYTE) {
2161     data.load_byte_item();
2162   } else {
2163     data.load_item();
2164   }
2165   off.load_item();
2166 
2167   set_no_result(x);
2168 
2169   DecoratorSet decorators = IN_HEAP;
2170   if (type == T_ARRAY || type == T_OBJECT) {
2171     decorators |= ON_UNKNOWN_OOP_REF;
2172   }
2173   if (x->is_volatile()) {
2174     decorators |= MO_SEQ_CST;
2175   }
2176   access_store_at(decorators, type, src, off.result(), data.result());
2177 }
2178 
2179 void LIRGenerator::do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) {
2180   BasicType type = x->basic_type();
2181   LIRItem src(x->object(), this);
2182   LIRItem off(x->offset(), this);
2183   LIRItem value(x->value(), this);
2184 
2185   DecoratorSet decorators = IN_HEAP | MO_SEQ_CST;
2186 
2187   if (type == T_ARRAY || type == T_OBJECT) {
2188     decorators |= ON_UNKNOWN_OOP_REF;
2189   }
2190 
2191   LIR_Opr result;
2192   if (x->is_add()) {
2193     result = access_atomic_add_at(decorators, type, src, off, value);
2194   } else {
2195     result = access_atomic_xchg_at(decorators, type, src, off, value);
2196   }
2197   set_result(x, result);
2198 }
2199 
2200 void LIRGenerator::do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux) {
2201   int lng = x->length();
2202 
2203   for (int i = 0; i < lng; i++) {
2204     SwitchRange* one_range = x->at(i);
2205     int low_key = one_range->low_key();
2206     int high_key = one_range->high_key();
2207     BlockBegin* dest = one_range->sux();
2208     if (low_key == high_key) {
2209       __ cmp(lir_cond_equal, value, low_key);
2210       __ branch(lir_cond_equal, T_INT, dest);
2211     } else if (high_key - low_key == 1) {
2212       __ cmp(lir_cond_equal, value, low_key);
2213       __ branch(lir_cond_equal, T_INT, dest);
2214       __ cmp(lir_cond_equal, value, high_key);
2215       __ branch(lir_cond_equal, T_INT, dest);
2216     } else {
2217       LabelObj* L = new LabelObj();

3747   }                                                                                                                                  
3748   return result;                                                                                                                     
3749 }                                                                                                                                    
3750 
3751 void LIRGenerator::do_MemBar(MemBar* x) {                                                                                            
3752   if (os::is_MP()) {                                                                                                                 
3753     LIR_Code code = x->code();                                                                                                       
3754     switch(code) {                                                                                                                   
3755       case lir_membar_acquire   : __ membar_acquire(); break;                                                                        
3756       case lir_membar_release   : __ membar_release(); break;                                                                        
3757       case lir_membar           : __ membar(); break;                                                                                
3758       case lir_membar_loadload  : __ membar_loadload(); break;                                                                       
3759       case lir_membar_storestore: __ membar_storestore(); break;                                                                     
3760       case lir_membar_loadstore : __ membar_loadstore(); break;                                                                      
3761       case lir_membar_storeload : __ membar_storeload(); break;                                                                      
3762       default                   : ShouldNotReachHere(); break;                                                                       
3763     }                                                                                                                                
3764   }                                                                                                                                  
3765 }                                                                                                                                    
3766 
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
3767 LIR_Opr LIRGenerator::maybe_mask_boolean(StoreIndexed* x, LIR_Opr array, LIR_Opr value, CodeEmitInfo*& null_check_info) {            
3768   if (x->check_boolean()) {                                                                                                          
3769     LIR_Opr value_fixed = rlock_byte(T_BYTE);                                                                                        
3770     if (TwoOperandLIRForm) {                                                                                                         
3771       __ move(value, value_fixed);                                                                                                   
3772       __ logical_and(value_fixed, LIR_OprFact::intConst(1), value_fixed);                                                            
3773     } else {                                                                                                                         
3774       __ logical_and(value, LIR_OprFact::intConst(1), value_fixed);                                                                  
3775     }                                                                                                                                
3776     LIR_Opr klass = new_register(T_METADATA);                                                                                        
3777     __ move(new LIR_Address(array, oopDesc::klass_offset_in_bytes(), T_ADDRESS), klass, null_check_info);                            
3778     null_check_info = NULL;                                                                                                          
3779     LIR_Opr layout = new_register(T_INT);                                                                                            
3780     __ move(new LIR_Address(klass, in_bytes(Klass::layout_helper_offset()), T_INT), layout);                                         
3781     int diffbit = Klass::layout_helper_boolean_diffbit();                                                                            
3782     __ logical_and(layout, LIR_OprFact::intConst(diffbit), layout);                                                                  
3783     __ cmp(lir_cond_notEqual, layout, LIR_OprFact::intConst(0));                                                                     
3784     __ cmove(lir_cond_notEqual, value_fixed, value, value_fixed, T_BYTE);                                                            
3785     value = value_fixed;                                                                                                             
3786   }                                                                                                                                  
3787   return value;                                                                                                                      
3788 }                                                                                                                                    

3497   }
3498   return result;
3499 }
3500 
3501 void LIRGenerator::do_MemBar(MemBar* x) {
3502   if (os::is_MP()) {
3503     LIR_Code code = x->code();
3504     switch(code) {
3505       case lir_membar_acquire   : __ membar_acquire(); break;
3506       case lir_membar_release   : __ membar_release(); break;
3507       case lir_membar           : __ membar(); break;
3508       case lir_membar_loadload  : __ membar_loadload(); break;
3509       case lir_membar_storestore: __ membar_storestore(); break;
3510       case lir_membar_loadstore : __ membar_loadstore(); break;
3511       case lir_membar_storeload : __ membar_storeload(); break;
3512       default                   : ShouldNotReachHere(); break;
3513     }
3514   }
3515 }
3516 
3517 LIR_Opr LIRGenerator::mask_boolean(LIR_Opr array, LIR_Opr value, CodeEmitInfo*& null_check_info) {
3518   LIR_Opr value_fixed = rlock_byte(T_BYTE);
3519   if (TwoOperandLIRForm) {
3520     __ move(value, value_fixed);
3521     __ logical_and(value_fixed, LIR_OprFact::intConst(1), value_fixed);
3522   } else {
3523     __ logical_and(value, LIR_OprFact::intConst(1), value_fixed);
3524   }
3525   LIR_Opr klass = new_register(T_METADATA);
3526   __ move(new LIR_Address(array, oopDesc::klass_offset_in_bytes(), T_ADDRESS), klass, null_check_info);
3527   null_check_info = NULL;
3528   LIR_Opr layout = new_register(T_INT);
3529   __ move(new LIR_Address(klass, in_bytes(Klass::layout_helper_offset()), T_INT), layout);
3530   int diffbit = Klass::layout_helper_boolean_diffbit();
3531   __ logical_and(layout, LIR_OprFact::intConst(diffbit), layout);
3532   __ cmp(lir_cond_notEqual, layout, LIR_OprFact::intConst(0));
3533   __ cmove(lir_cond_notEqual, value_fixed, value, value_fixed, T_BYTE);
3534   value = value_fixed;
3535   return value;
3536 }
3537 
3538 LIR_Opr LIRGenerator::maybe_mask_boolean(StoreIndexed* x, LIR_Opr array, LIR_Opr value, CodeEmitInfo*& null_check_info) {
3539   if (x->check_boolean()) {
3540     value = mask_boolean(array, value, null_check_info);
















3541   }
3542   return value;
3543 }
< prev index next >