46 #include "opto/valuetypenode.hpp" 47 #include "runtime/deoptimization.hpp" 48 #include "runtime/sharedRuntime.hpp" 49 50 #ifndef PRODUCT 51 extern int explicit_null_checks_inserted, 52 explicit_null_checks_elided; 53 #endif 54 55 //---------------------------------array_load---------------------------------- 56 void Parse::array_load(BasicType bt) { 57 const Type* elemtype = Type::TOP; 58 Node* adr = array_addressing(bt, 0, &elemtype); 59 if (stopped()) return; // guaranteed null or range check 60 61 Node* idx = pop(); 62 Node* ary = pop(); 63 64 // Handle value type arrays 65 const TypeOopPtr* elemptr = elemtype->make_oopptr(); 66 if (elemtype->isa_valuetype() != NULL) { 67 // Load from flattened value type array 68 ciValueKlass* vk = elemtype->is_valuetype()->value_klass(); 69 ValueTypeNode* vt = ValueTypeNode::make_from_flattened(this, vk, ary, adr); 70 push(vt); 71 return; 72 } else if (elemptr != NULL && elemptr->is_valuetypeptr()) { 73 // Load from non-flattened value type array (elements can never be null) 74 bt = T_VALUETYPE; 75 assert(elemptr->meet(TypePtr::NULL_PTR) != elemptr, "value type array elements should never be null"); 76 } else if (ValueArrayFlatten && elemptr != NULL && elemptr->can_be_value_type()) { 77 // Cannot statically determine if array is flattened, emit runtime check 78 gen_flattened_array_guard(ary, 2); 79 } 80 81 if (elemtype == TypeInt::BOOL) { 82 bt = T_BOOLEAN; 83 } else if (bt == T_OBJECT) { 84 elemtype = _gvn.type(ary)->is_aryptr()->elem()->make_oopptr(); 85 } 86 87 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt); 88 Node* ld = access_load_at(ary, adr, adr_type, elemtype, bt, 89 IN_HEAP | IS_ARRAY | C2_CONTROL_DEPENDENT_LOAD); 90 if (bt == T_VALUETYPE) { 91 // Loading a non-flattened (but flattenable) value type from an array 92 assert(!gvn().type(ld)->is_ptr()->maybe_null(), "value type array elements should never be null"); 93 ld = ValueTypeNode::make_from_oop(this, ld, elemptr->value_klass()); 94 } 95 96 push_node(bt, ld); 97 } 98 99 100 //--------------------------------array_store---------------------------------- 101 void Parse::array_store(BasicType bt) { 102 const Type* elemtype = Type::TOP; 103 Node* adr = array_addressing(bt, type2size[bt], &elemtype); 104 if (stopped()) return; // guaranteed null or range check 105 Node* cast_val = NULL; 106 if (bt == T_OBJECT) { 107 cast_val = array_store_check(); 108 if (stopped()) return; 109 } 110 Node* val = pop_node(bt); // Value to store 111 Node* idx = pop(); // Index in the array 112 Node* ary = pop(); // The array itself 113 114 if (bt == T_OBJECT) { 115 const TypeOopPtr* elemptr = elemtype->make_oopptr(); 116 if (elemtype->isa_valuetype() != NULL) { 117 // Store to flattened value type array 118 cast_val->as_ValueType()->store_flattened(this, ary, adr); 119 return; 120 } else if (elemptr->is_valuetypeptr()) { 121 // Store to non-flattened value type array 122 } else if (ValueArrayFlatten && elemptr->can_be_value_type() && val->is_ValueType()) { 123 IdealKit ideal(this); 124 Node* kls = load_object_klass(ary); 125 Node* lhp = basic_plus_adr(kls, in_bytes(Klass::layout_helper_offset())); 126 Node* layout_val = make_load(NULL, lhp, TypeInt::INT, T_INT, MemNode::unordered); 127 layout_val = _gvn.transform(new RShiftINode(layout_val, intcon(Klass::_lh_array_tag_shift))); 128 ideal.if_then(layout_val, BoolTest::ne, intcon(Klass::_lh_array_tag_vt_value)); { 129 // non flattened 130 sync_kit(ideal); 131 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt); 132 elemtype = _gvn.type(ary)->is_aryptr()->elem()->make_oopptr(); 133 access_store_at(control(), ary, adr, adr_type, val, elemtype, bt, MO_UNORDERED | IN_HEAP | IS_ARRAY); 134 ideal.sync_kit(this); 135 } ideal.else_(); { 136 // flattened 137 sync_kit(ideal); 138 // Object/interface array must be flattened, cast it 139 const TypeValueType* vt = _gvn.type(val)->is_valuetype(); 140 ciArrayKlass* array_klass = ciArrayKlass::make(vt->value_klass()); 141 const TypeAryPtr* arytype = TypeOopPtr::make_from_klass(array_klass)->isa_aryptr(); 142 ary = _gvn.transform(new CheckCastPPNode(control(), ary, arytype)); 143 adr = array_element_address(ary, idx, T_OBJECT, arytype->size(), control()); 144 val->as_ValueType()->store_flattened(this, ary, adr); 145 ideal.sync_kit(this); 146 } ideal.end_if(); 147 sync_kit(ideal); 148 return; 149 } 150 } 151 152 if (elemtype == TypeInt::BOOL) { 153 bt = T_BOOLEAN; 154 } else if (bt == T_OBJECT) { 155 elemtype = _gvn.type(ary)->is_aryptr()->elem()->make_oopptr(); 156 } 157 158 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt); 159 160 access_store_at(control(), ary, adr, adr_type, val, elemtype, bt, MO_UNORDERED | IN_HEAP | IS_ARRAY); 161 } 162 163 164 //------------------------------array_addressing------------------------------- 165 // Pull array and index from the stack. Compute pointer-to-element. 166 Node* Parse::array_addressing(BasicType type, int vals, const Type* *result2) { 167 Node *idx = peek(0+vals); // Get from stack without popping 168 Node *ary = peek(1+vals); // in case of exception 169 170 // Null check the array base, with correct stack contents 171 ary = null_check(ary, T_ARRAY); 172 // Compile-time detect of null-exception? 173 if (stopped()) return top(); 174 175 const TypeAryPtr* arytype = _gvn.type(ary)->is_aryptr(); | 46 #include "opto/valuetypenode.hpp" 47 #include "runtime/deoptimization.hpp" 48 #include "runtime/sharedRuntime.hpp" 49 50 #ifndef PRODUCT 51 extern int explicit_null_checks_inserted, 52 explicit_null_checks_elided; 53 #endif 54 55 //---------------------------------array_load---------------------------------- 56 void Parse::array_load(BasicType bt) { 57 const Type* elemtype = Type::TOP; 58 Node* adr = array_addressing(bt, 0, &elemtype); 59 if (stopped()) return; // guaranteed null or range check 60 61 Node* idx = pop(); 62 Node* ary = pop(); 63 64 // Handle value type arrays 65 const TypeOopPtr* elemptr = elemtype->make_oopptr(); 66 const TypeAryPtr* ary_t = _gvn.type(ary)->is_aryptr(); 67 if (elemtype->isa_valuetype() != NULL) { 68 // Load from flattened value type array 69 ciValueKlass* vk = elemtype->is_valuetype()->value_klass(); 70 ValueTypeNode* vt = ValueTypeNode::make_from_flattened(this, vk, ary, adr); 71 push(vt); 72 return; 73 } else if (elemptr != NULL && elemptr->is_valuetypeptr()) { 74 // Load from non-flattened value type array (elements can never be null) 75 bt = T_VALUETYPE; 76 assert(elemptr->meet(TypePtr::NULL_PTR) != elemptr, "value type array elements should never be null"); 77 } else if (ValueArrayFlatten && elemptr != NULL && elemptr->can_be_value_type() && 78 !ary_t->klass_is_exact()) { 79 // Cannot statically determine if array is flattened, emit runtime check 80 IdealKit ideal(this); 81 IdealVariable res(ideal); 82 ideal.declarations_done(); 83 Node* kls = load_object_klass(ary); 84 Node* tag = load_lh_array_tag(kls); 85 ideal.if_then(tag, BoolTest::ne, intcon(Klass::_lh_array_tag_vt_value)); { 86 // non flattened 87 sync_kit(ideal); 88 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt); 89 elemtype = ary_t->elem()->make_oopptr(); 90 Node* ld = access_load_at(ary, adr, adr_type, elemtype, bt, 91 IN_HEAP | IS_ARRAY | C2_CONTROL_DEPENDENT_LOAD); 92 ideal.sync_kit(this); 93 ideal.set(res, ld); 94 } ideal.else_(); { 95 // flattened 96 sync_kit(ideal); 97 Node* k_adr = basic_plus_adr(kls, in_bytes(ArrayKlass::element_klass_offset())); 98 Node* elem_klass = _gvn.transform(LoadKlassNode::make(_gvn, NULL, immutable_memory(), k_adr, TypeInstPtr::KLASS)); 99 Node* obj_size = NULL; 100 kill_dead_locals(); 101 inc_sp(2); 102 Node* alloc_obj = new_instance(elem_klass, NULL, &obj_size, /*deoptimize_on_exception=*/true); 103 dec_sp(2); 104 105 AllocateNode* alloc = AllocateNode::Ideal_allocation(alloc_obj, &_gvn); 106 assert(alloc->maybe_set_complete(&_gvn), ""); 107 alloc->initialization()->set_complete_with_arraycopy(); 108 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); 109 // Unknown value type so might have reference fields 110 if (!bs->array_copy_requires_gc_barriers(T_OBJECT)) { 111 int base_off = sizeof(instanceOopDesc); 112 Node* dst_base = basic_plus_adr(alloc_obj, base_off); 113 Node* countx = obj_size; 114 countx = _gvn.transform(new SubXNode(countx, MakeConX(base_off))); 115 countx = _gvn.transform(new URShiftXNode(countx, intcon(LogBytesPerLong))); 116 117 assert(Klass::_lh_log2_element_size_shift == 0, "use shift in place"); 118 Node* lhp = basic_plus_adr(kls, in_bytes(Klass::layout_helper_offset())); 119 Node* elem_shift = make_load(NULL, lhp, TypeInt::INT, T_INT, MemNode::unordered); 120 uint header = arrayOopDesc::base_offset_in_bytes(T_VALUETYPE); 121 Node* base = basic_plus_adr(ary, header); 122 idx = Compile::conv_I2X_index(&_gvn, idx, TypeInt::POS, control()); 123 Node* scale = _gvn.transform(new LShiftXNode(idx, elem_shift)); 124 Node* adr = basic_plus_adr(ary, base, scale); 125 126 access_clone(control(), adr, dst_base, countx, false); 127 } else { 128 ideal.sync_kit(this); 129 ideal.make_leaf_call(OptoRuntime::load_unknown_value_Type(), 130 CAST_FROM_FN_PTR(address, OptoRuntime::load_unknown_value), 131 "load_unknown_value", 132 ary, idx, alloc_obj); 133 sync_kit(ideal); 134 } 135 136 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress)); 137 138 ideal.sync_kit(this); 139 ideal.set(res, alloc_obj); 140 } ideal.end_if(); 141 sync_kit(ideal); 142 push_node(bt, ideal.value(res)); 143 return; 144 } 145 146 if (elemtype == TypeInt::BOOL) { 147 bt = T_BOOLEAN; 148 } else if (bt == T_OBJECT) { 149 elemtype = ary_t->elem()->make_oopptr(); 150 } 151 152 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt); 153 Node* ld = access_load_at(ary, adr, adr_type, elemtype, bt, 154 IN_HEAP | IS_ARRAY | C2_CONTROL_DEPENDENT_LOAD); 155 if (bt == T_VALUETYPE) { 156 // Loading a non-flattened (but flattenable) value type from an array 157 assert(!gvn().type(ld)->is_ptr()->maybe_null(), "value type array elements should never be null"); 158 ld = ValueTypeNode::make_from_oop(this, ld, elemptr->value_klass()); 159 } 160 161 push_node(bt, ld); 162 } 163 164 165 //--------------------------------array_store---------------------------------- 166 void Parse::array_store(BasicType bt) { 167 const Type* elemtype = Type::TOP; 168 Node* adr = array_addressing(bt, type2size[bt], &elemtype); 169 if (stopped()) return; // guaranteed null or range check 170 Node* cast_val = NULL; 171 if (bt == T_OBJECT) { 172 cast_val = array_store_check(); 173 if (stopped()) return; 174 } 175 Node* val = pop_node(bt); // Value to store 176 Node* idx = pop(); // Index in the array 177 Node* ary = pop(); // The array itself 178 179 const TypeAryPtr* ary_t = _gvn.type(ary)->is_aryptr(); 180 if (bt == T_OBJECT) { 181 const TypeOopPtr* elemptr = elemtype->make_oopptr(); 182 const Type* val_t = _gvn.type(val); 183 if (elemtype->isa_valuetype() != NULL) { 184 // Store to flattened value type array 185 if (!val->is_ValueType() && val_t == TypePtr::NULL_PTR) { 186 // Can not store null into a value type array 187 inc_sp(3); 188 uncommon_trap(Deoptimization::Reason_null_check, Deoptimization::Action_none); 189 return; 190 } 191 cast_val->as_ValueType()->store_flattened(this, ary, adr); 192 return; 193 } else if (elemptr->is_valuetypeptr()) { 194 // Store to non-flattened value type array 195 if (!val->is_ValueType() && val_t == TypePtr::NULL_PTR) { 196 // Can not store null into a value type array 197 inc_sp(3); 198 uncommon_trap(Deoptimization::Reason_null_check, Deoptimization::Action_none); 199 return; 200 } 201 } else if (elemptr->can_be_value_type() && !ary_t->klass_is_exact() && 202 (val->is_ValueType() || val_t == TypePtr::NULL_PTR || val_t->is_oopptr()->can_be_value_type())) { 203 if (ValueArrayFlatten) { 204 IdealKit ideal(this); 205 Node* kls = load_object_klass(ary); 206 Node* layout_val = load_lh_array_tag(kls); 207 ideal.if_then(layout_val, BoolTest::ne, intcon(Klass::_lh_array_tag_vt_value)); { 208 // non flattened 209 sync_kit(ideal); 210 211 if (!val->is_ValueType() && TypePtr::NULL_PTR->higher_equal(val_t)) { 212 gen_value_type_array_guard(ary, val, 3); 213 } 214 215 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt); 216 elemtype = ary_t->elem()->make_oopptr(); 217 access_store_at(control(), ary, adr, adr_type, val, elemtype, bt, MO_UNORDERED | IN_HEAP | IS_ARRAY); 218 ideal.sync_kit(this); 219 } ideal.else_(); { 220 // flattened 221 // Object/interface array must be flattened, cast it 222 if (val->is_ValueType()) { 223 sync_kit(ideal); 224 const TypeValueType* vt = _gvn.type(val)->is_valuetype(); 225 ciArrayKlass* array_klass = ciArrayKlass::make(vt->value_klass()); 226 const TypeAryPtr* arytype = TypeOopPtr::make_from_klass(array_klass)->isa_aryptr(); 227 ary = _gvn.transform(new CheckCastPPNode(control(), ary, arytype)); 228 adr = array_element_address(ary, idx, T_OBJECT, arytype->size(), control()); 229 val->as_ValueType()->store_flattened(this, ary, adr); 230 ideal.sync_kit(this); 231 } else { 232 if (TypePtr::NULL_PTR->higher_equal(val_t)) { 233 sync_kit(ideal); 234 Node* null_ctl = top(); 235 val = null_check_oop(val, &null_ctl); 236 { 237 assert(null_ctl != top(), "expected to possibly be null"); 238 PreserveJVMState pjvms(this); 239 set_control(null_ctl); 240 inc_sp(3); 241 uncommon_trap(Deoptimization::Reason_null_check, Deoptimization::Action_none); 242 } 243 ideal.sync_kit(this); 244 } 245 246 if (!ideal.ctrl()->is_top()) { 247 ideal.make_leaf_call(OptoRuntime::store_unknown_value_Type(), 248 CAST_FROM_FN_PTR(address, OptoRuntime::store_unknown_value), 249 "store_unknown_value", 250 val, ary, idx); 251 } 252 } 253 } ideal.end_if(); 254 sync_kit(ideal); 255 return; 256 } else { 257 if (!val->is_ValueType() && TypePtr::NULL_PTR->higher_equal(val_t)) { 258 gen_value_type_array_guard(ary, val, 3); 259 } 260 } 261 } 262 } 263 264 if (elemtype == TypeInt::BOOL) { 265 bt = T_BOOLEAN; 266 } else if (bt == T_OBJECT) { 267 elemtype = ary_t->elem()->make_oopptr(); 268 } 269 270 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt); 271 272 access_store_at(control(), ary, adr, adr_type, val, elemtype, bt, MO_UNORDERED | IN_HEAP | IS_ARRAY); 273 } 274 275 276 //------------------------------array_addressing------------------------------- 277 // Pull array and index from the stack. Compute pointer-to-element. 278 Node* Parse::array_addressing(BasicType type, int vals, const Type* *result2) { 279 Node *idx = peek(0+vals); // Get from stack without popping 280 Node *ary = peek(1+vals); // in case of exception 281 282 // Null check the array base, with correct stack contents 283 ary = null_check(ary, T_ARRAY); 284 // Compile-time detect of null-exception? 285 if (stopped()) return top(); 286 287 const TypeAryPtr* arytype = _gvn.type(ary)->is_aryptr(); |