41 // Create a new ValueTypeNode with default values 42 ValueTypeNode* vt = ValueTypeNode::make(gvn, vk); 43 for (uint i = 0; i < vt->field_count(); ++i) { 44 ciType* field_type = vt->field_type(i); 45 Node* value = NULL; 46 if (field_type->is_valuetype()) { 47 value = ValueTypeNode::make_default(gvn, field_type->as_value_klass()); 48 } else { 49 value = gvn.zerocon(field_type->basic_type()); 50 } 51 vt->set_field_value(i, value); 52 } 53 return gvn.transform(vt); 54 } 55 56 Node* ValueTypeNode::make(PhaseGVN& gvn, Node* mem, Node* oop) { 57 // Create and initialize a ValueTypeNode by loading all field 58 // values from a heap-allocated version and also save the oop. 59 const TypeValueType* type = gvn.type(oop)->is_valuetypeptr()->value_type(); 60 ValueTypeNode* vt = new ValueTypeNode(type, oop); 61 vt->load_values(gvn, mem, oop, oop, type->value_klass()); 62 return gvn.transform(vt); 63 } 64 65 Node* ValueTypeNode::make(PhaseGVN& gvn, ciValueKlass* vk, Node* mem, Node* obj, Node* ptr, ciInstanceKlass* holder, int holder_offset) { 66 // Create and initialize a ValueTypeNode by loading all field values from 67 // a flattened value type field at 'holder_offset' or from a value type array. 68 ValueTypeNode* vt = make(gvn, vk); 69 // The value type is flattened into the object without an oop header. Subtract the 70 // offset of the first field to account for the missing header when loading the values. 71 holder_offset -= vk->first_field_offset(); 72 vt->load_values(gvn, mem, obj, ptr, holder, holder_offset); 73 return gvn.transform(vt); 74 } 75 76 void ValueTypeNode::load_values(PhaseGVN& gvn, Node* mem, Node* base, Node* ptr, ciInstanceKlass* holder, int holder_offset) { 77 // Initialize the value type by loading its field values from 78 // memory and adding the values as input edges to the node. 79 for (uint i = 0; i < field_count(); ++i) { 80 int offset = holder_offset + field_offset(i); 81 ciType* ftype = field_type(i); 82 Node* value = NULL; 83 if (ftype->is_valuetype()) { 84 // Recursively load the flattened value type field 85 value = ValueTypeNode::make(gvn, ftype->as_value_klass(), mem, base, ptr, holder, offset); 86 } else { 87 const Type* con_type = NULL; 88 if (base->is_Con()) { 89 // If the oop to the value type is constant (static final field), we can 90 // also treat the fields as constants because the value type is immutable. 91 const TypeOopPtr* oop_ptr = base->bottom_type()->isa_oopptr(); 92 ciObject* constant_oop = oop_ptr->const_oop(); 93 ciField* field = holder->get_field_by_offset(offset, false); 94 ciConstant constant = constant_oop->as_instance()->field_value(field); 95 con_type = Type::make_from_constant(constant, /*require_const=*/ true); 96 } 101 // Load field value from memory 102 const Type* base_type = gvn.type(base); 103 const TypePtr* adr_type = NULL; 104 if (base_type->isa_aryptr()) { 105 // In the case of a flattened value type array, each field 106 // has its own slice 107 adr_type = base_type->is_aryptr()->with_field_offset(offset)->add_offset(Type::OffsetBot); 108 } else { 109 ciField* field = holder->get_field_by_offset(offset, false); 110 adr_type = gvn.C->alias_type(field)->adr_type(); 111 } 112 Node* adr = gvn.transform(new AddPNode(base, ptr, gvn.MakeConX(offset))); 113 BasicType bt = type2field[ftype->basic_type()]; 114 value = LoadNode::make(gvn, NULL, mem, adr, adr_type, Type::get_const_type(ftype), bt, MemNode::unordered); 115 } 116 } 117 set_field_value(i, gvn.transform(value)); 118 } 119 } 120 121 void ValueTypeNode::store(GraphKit* kit, Node* obj, Node* ptr, ciInstanceKlass* holder, int holder_offset) const { 122 // The value type is embedded into the object without an oop header. Subtract the 123 // offset of the first field to account for the missing header when storing the values. 124 holder_offset -= value_klass()->first_field_offset(); 125 store_values(kit, obj, ptr, holder, holder_offset); 126 } 127 128 void ValueTypeNode::store_values(GraphKit* kit, Node* base, Node* ptr, ciInstanceKlass* holder, int holder_offset) const { 129 // Write field values to memory 130 for (uint i = 0; i < field_count(); ++i) { 131 int offset = holder_offset + field_offset(i); 132 Node* value = field_value(i); 133 if (value->is_ValueType()) { 134 // Recursively store the flattened value type field 135 value->isa_ValueType()->store(kit, base, ptr, holder, offset); 136 } else { 137 const Type* base_type = kit->gvn().type(base); 138 const TypePtr* adr_type = NULL; 139 if (base_type->isa_aryptr()) { 140 // In the case of a flattened value type array, each field has its own slice 141 adr_type = base_type->is_aryptr()->with_field_offset(offset)->add_offset(Type::OffsetBot); 142 } else { 143 ciField* field = holder->get_field_by_offset(offset, false); 144 adr_type = kit->C->alias_type(field)->adr_type(); 145 } 146 Node* adr = kit->basic_plus_adr(base, ptr, offset); 147 BasicType bt = type2field[field_type(i)->basic_type()]; 148 if (is_java_primitive(bt)) { 149 kit->store_to_memory(kit->control(), adr, value, bt, adr_type, MemNode::unordered); 150 } else { 151 const TypeOopPtr* ft = TypeOopPtr::make_from_klass(field_type(i)->as_klass()); 152 assert(adr->bottom_type()->is_ptr_to_narrowoop() == UseCompressedOops, "inconsistent"); 153 bool is_array = base_type->isa_aryptr() != NULL; 154 kit->store_oop(kit->control(), base, adr, adr_type, value, ft, bt, is_array, MemNode::unordered); 155 } 156 157 } 158 } 159 } 160 161 Node* ValueTypeNode::store_to_memory(GraphKit* kit) { 162 Node* in_oop = get_oop(); 163 Node* null_ctl = kit->top(); 164 // Check if value type is already allocated 165 Node* not_null_oop = kit->null_check_oop(in_oop, &null_ctl); 166 if (null_ctl->is_top()) { 167 // Value type is allocated 168 return not_null_oop; 169 } 170 // Not able to prove that value type is allocated. 171 // Emit runtime check that may be folded later. 172 const Type* oop_type = kit->gvn().type(in_oop); 173 assert(TypePtr::NULL_PTR->higher_equal(oop_type), "should not be allocated"); 174 175 const TypeValueTypePtr* vtptr_type = TypeValueTypePtr::make(bottom_type()->isa_valuetype(), TypePtr::NotNull); 176 RegionNode* region = new RegionNode(3); 177 PhiNode* oop = new PhiNode(region, vtptr_type); 178 PhiNode* io = new PhiNode(region, Type::ABIO); 179 PhiNode* mem = new PhiNode(region, Type::MEMORY, TypePtr::BOTTOM); 180 181 // Oop is non-NULL, use it 182 region->init_req(1, kit->control()); 183 oop ->init_req(1, not_null_oop); 184 io ->init_req(1, kit->i_o()); 185 mem ->init_req(1, kit->merged_memory()); 186 187 // Oop is NULL, allocate value type 188 kit->set_control(null_ctl); 189 kit->kill_dead_locals(); 190 ciValueKlass* vk = value_klass(); 191 Node* klass_node = kit->makecon(TypeKlassPtr::make(vk)); 192 Node* alloc_oop = kit->new_instance(klass_node); 193 // Write field values to memory 194 store_values(kit, alloc_oop, alloc_oop, vk); 195 region->init_req(2, kit->control()); 196 oop ->init_req(2, alloc_oop); 197 io ->init_req(2, kit->i_o()); 198 mem ->init_req(2, kit->merged_memory()); 199 200 // Update GraphKit 201 kit->set_control(kit->gvn().transform(region)); 202 kit->set_i_o(kit->gvn().transform(io)); 203 kit->set_all_memory(kit->gvn().transform(mem)); 204 kit->record_for_igvn(region); 205 kit->record_for_igvn(oop); 206 kit->record_for_igvn(io); 207 kit->record_for_igvn(mem); 208 209 // Use cloned ValueTypeNode to propagate oop from now on 210 Node* res_oop = kit->gvn().transform(oop); 211 ValueTypeNode* vt = clone()->as_ValueType(); 212 vt->set_oop(res_oop); 213 kit->replace_in_map(this, kit->gvn().transform(vt)); 214 return res_oop; 215 } 216 217 // Clones the values type to handle control flow merges involving multiple value types. 218 // The inputs are replaced by PhiNodes to represent the merged values for the given region. 219 ValueTypeNode* ValueTypeNode::clone_with_phis(PhaseGVN* gvn, Node* region) { 220 assert(!has_phi_inputs(region), "already cloned with phis"); 221 ValueTypeNode* vt = clone()->as_ValueType(); 222 223 // Create a PhiNode for merging the oop values 224 const TypeValueTypePtr* vtptr = TypeValueTypePtr::make(vt->bottom_type()->isa_valuetype()); 225 PhiNode* oop = PhiNode::make(region, vt->get_oop(), vtptr); 226 gvn->set_type(oop, vtptr); 227 vt->set_oop(oop); 228 229 // Create a PhiNode each for merging the field values 230 for (uint i = 0; i < vt->field_count(); ++i) { 231 ciType* type = vt->field_type(i); 232 Node* value = vt->field_value(i); 233 if (type->is_valuetype()) { 234 // Handle flattened value type fields recursively 235 value = value->as_ValueType()->clone_with_phis(gvn, region); 236 } else { 398 break; 399 } 400 BasicType bt = f->type()->basic_type(); 401 if (bt == T_LONG || bt == T_DOUBLE) { 402 extra++; 403 } 404 } 405 n->init_req(base_input + j + extra, arg); 406 edges++; 407 BasicType bt = f_type->basic_type(); 408 if (bt == T_LONG || bt == T_DOUBLE) { 409 n->init_req(base_input + j + extra + 1, kit.top()); 410 edges++; 411 } 412 } 413 } 414 return edges; 415 } 416 417 Node* ValueTypeNode::Ideal(PhaseGVN* phase, bool can_reshape) { 418 if (can_reshape) { 419 PhaseIterGVN* igvn = phase->is_IterGVN(); 420 const Type* oop_type = igvn->type(get_oop()); 421 if (oop_type->meet(TypePtr::NULL_PTR) != oop_type) { 422 // Value type is heap allocated, search for safepoint uses 423 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) { 424 Node* out = fast_out(i); 425 if (out->is_SafePoint()) { 426 // Let SafePointNode::Ideal() take care of re-wiring the 427 // safepoint to the oop input instead of the value type node. 428 igvn->rehash_node_delayed(out); 429 } 430 } 431 } 432 } 433 434 return NULL; 435 } 436 437 // When a call returns multiple values, it has several result 438 // projections, one per field. Replacing the result of the call by a 439 // value type node (after late inlining) requires that for each result 440 // projection, we find the corresponding value type field. 441 void ValueTypeNode::replace_call_results(Node* call, Compile* C) { 442 ciValueKlass* vk = value_klass(); 443 for (DUIterator_Fast imax, i = call->fast_outs(imax); i < imax; i++) { 444 ProjNode *pn = call->fast_out(i)->as_Proj(); 445 uint con = pn->_con; 446 if (con >= TypeFunc::Parms+1) { 447 uint field_nb = con - (TypeFunc::Parms+1); 448 int extra = 0; 449 for (uint j = 0; j < field_nb - extra; j++) { 450 ciField* f = vk->nonstatic_field_at(j); 451 BasicType bt = f->type()->basic_type(); 452 if (bt == T_LONG || bt == T_DOUBLE) { 453 extra++; 454 } | 41 // Create a new ValueTypeNode with default values 42 ValueTypeNode* vt = ValueTypeNode::make(gvn, vk); 43 for (uint i = 0; i < vt->field_count(); ++i) { 44 ciType* field_type = vt->field_type(i); 45 Node* value = NULL; 46 if (field_type->is_valuetype()) { 47 value = ValueTypeNode::make_default(gvn, field_type->as_value_klass()); 48 } else { 49 value = gvn.zerocon(field_type->basic_type()); 50 } 51 vt->set_field_value(i, value); 52 } 53 return gvn.transform(vt); 54 } 55 56 Node* ValueTypeNode::make(PhaseGVN& gvn, Node* mem, Node* oop) { 57 // Create and initialize a ValueTypeNode by loading all field 58 // values from a heap-allocated version and also save the oop. 59 const TypeValueType* type = gvn.type(oop)->is_valuetypeptr()->value_type(); 60 ValueTypeNode* vt = new ValueTypeNode(type, oop); 61 vt->load(gvn, mem, oop, oop, type->value_klass()); 62 assert(vt->is_allocated(&gvn), "value type should be allocated"); 63 assert(oop->is_Con() || oop->is_CheckCastPP() || vt->is_loaded(&gvn, type) != NULL, "value type should be loaded"); 64 return gvn.transform(vt); 65 } 66 67 Node* ValueTypeNode::make(PhaseGVN& gvn, ciValueKlass* vk, Node* mem, Node* obj, Node* ptr, ciInstanceKlass* holder, int holder_offset) { 68 // Create and initialize a ValueTypeNode by loading all field values from 69 // a flattened value type field at 'holder_offset' or from a value type array. 70 ValueTypeNode* vt = make(gvn, vk); 71 // The value type is flattened into the object without an oop header. Subtract the 72 // offset of the first field to account for the missing header when loading the values. 73 holder_offset -= vk->first_field_offset(); 74 vt->load(gvn, mem, obj, ptr, holder, holder_offset); 75 vt = gvn.transform(vt)->as_ValueType(); 76 assert(!vt->is_allocated(&gvn), "value type should not be allocated"); 77 return vt; 78 } 79 80 void ValueTypeNode::load(PhaseGVN& gvn, Node* mem, Node* base, Node* ptr, ciInstanceKlass* holder, int holder_offset) { 81 // Initialize the value type by loading its field values from 82 // memory and adding the values as input edges to the node. 83 for (uint i = 0; i < field_count(); ++i) { 84 int offset = holder_offset + field_offset(i); 85 ciType* ftype = field_type(i); 86 Node* value = NULL; 87 if (ftype->is_valuetype()) { 88 // Recursively load the flattened value type field 89 value = ValueTypeNode::make(gvn, ftype->as_value_klass(), mem, base, ptr, holder, offset); 90 } else { 91 const Type* con_type = NULL; 92 if (base->is_Con()) { 93 // If the oop to the value type is constant (static final field), we can 94 // also treat the fields as constants because the value type is immutable. 95 const TypeOopPtr* oop_ptr = base->bottom_type()->isa_oopptr(); 96 ciObject* constant_oop = oop_ptr->const_oop(); 97 ciField* field = holder->get_field_by_offset(offset, false); 98 ciConstant constant = constant_oop->as_instance()->field_value(field); 99 con_type = Type::make_from_constant(constant, /*require_const=*/ true); 100 } 105 // Load field value from memory 106 const Type* base_type = gvn.type(base); 107 const TypePtr* adr_type = NULL; 108 if (base_type->isa_aryptr()) { 109 // In the case of a flattened value type array, each field 110 // has its own slice 111 adr_type = base_type->is_aryptr()->with_field_offset(offset)->add_offset(Type::OffsetBot); 112 } else { 113 ciField* field = holder->get_field_by_offset(offset, false); 114 adr_type = gvn.C->alias_type(field)->adr_type(); 115 } 116 Node* adr = gvn.transform(new AddPNode(base, ptr, gvn.MakeConX(offset))); 117 BasicType bt = type2field[ftype->basic_type()]; 118 value = LoadNode::make(gvn, NULL, mem, adr, adr_type, Type::get_const_type(ftype), bt, MemNode::unordered); 119 } 120 } 121 set_field_value(i, gvn.transform(value)); 122 } 123 } 124 125 Node* ValueTypeNode::is_loaded(PhaseGVN* phase, const TypeValueType* t, Node* base, int holder_offset) { 126 for (uint i = 0; i < field_count(); ++i) { 127 int offset = holder_offset + field_offset(i); 128 Node* value = field_value(i); 129 if (value->isa_DecodeN()) { 130 // Skip DecodeN 131 value = value->in(1); 132 } 133 if (value->isa_Load()) { 134 AddPNode* load_addr = value->in(MemNode::Address)->as_AddP(); 135 if (base == NULL) { 136 // Set base and check if pointer type matches 137 base = load_addr->base_node(); 138 const TypeValueTypePtr* vtptr = phase->type(base)->isa_valuetypeptr(); 139 if (vtptr == NULL || !vtptr->value_type()->eq(t)) { 140 return NULL; 141 } 142 } 143 // Check if base and offset of field load matches 144 Node* off = load_addr->in(AddPNode::Offset); 145 int load_offset = LP64_ONLY(off->get_long()) NOT_LP64(off->get_int()); 146 if (base != load_addr->base_node() || offset != load_offset) { 147 return NULL; 148 } 149 } else if (value->isa_ValueType()) { 150 // Check value type field load recursively 151 ValueTypeNode* vt = value->as_ValueType(); 152 base = vt->is_loaded(phase, t, base, offset - vt->value_klass()->first_field_offset()); 153 if (base == NULL) { 154 return NULL; 155 } 156 } else { 157 return NULL; 158 } 159 } 160 return base; 161 } 162 163 void ValueTypeNode::store_flattened(GraphKit* kit, Node* base, Node* ptr, ciInstanceKlass* holder, int holder_offset) const { 164 // The value type is embedded into the object without an oop header. Subtract the 165 // offset of the first field to account for the missing header when storing the values. 166 holder_offset -= value_klass()->first_field_offset(); 167 store(kit, base, ptr, holder, holder_offset); 168 } 169 170 void ValueTypeNode::store(GraphKit* kit, Node* base, Node* ptr, ciInstanceKlass* holder, int holder_offset) const { 171 // Write field values to memory 172 for (uint i = 0; i < field_count(); ++i) { 173 int offset = holder_offset + field_offset(i); 174 Node* value = field_value(i); 175 if (value->is_ValueType()) { 176 // Recursively store the flattened value type field 177 value->isa_ValueType()->store_flattened(kit, base, ptr, holder, offset); 178 } else { 179 const Type* base_type = kit->gvn().type(base); 180 const TypePtr* adr_type = NULL; 181 if (base_type->isa_aryptr()) { 182 // In the case of a flattened value type array, each field has its own slice 183 adr_type = base_type->is_aryptr()->with_field_offset(offset)->add_offset(Type::OffsetBot); 184 } else { 185 ciField* field = holder->get_field_by_offset(offset, false); 186 adr_type = kit->C->alias_type(field)->adr_type(); 187 } 188 Node* adr = kit->basic_plus_adr(base, ptr, offset); 189 BasicType bt = type2field[field_type(i)->basic_type()]; 190 if (is_java_primitive(bt)) { 191 kit->store_to_memory(kit->control(), adr, value, bt, adr_type, MemNode::unordered); 192 } else { 193 const TypeOopPtr* ft = TypeOopPtr::make_from_klass(field_type(i)->as_klass()); 194 assert(adr->bottom_type()->is_ptr_to_narrowoop() == UseCompressedOops, "inconsistent"); 195 bool is_array = base_type->isa_aryptr() != NULL; 196 kit->store_oop(kit->control(), base, adr, adr_type, value, ft, bt, is_array, MemNode::unordered); 197 } 198 } 199 } 200 } 201 202 Node* ValueTypeNode::allocate(GraphKit* kit) { 203 Node* in_oop = get_oop(); 204 Node* null_ctl = kit->top(); 205 // Check if value type is already allocated 206 Node* not_null_oop = kit->null_check_oop(in_oop, &null_ctl); 207 if (null_ctl->is_top()) { 208 // Value type is allocated 209 return not_null_oop; 210 } 211 // Not able to prove that value type is allocated. 212 // Emit runtime check that may be folded later. 213 assert(!is_allocated(&kit->gvn()), "should not be allocated"); 214 const TypeValueTypePtr* vtptr_type = TypeValueTypePtr::make(bottom_type()->isa_valuetype(), TypePtr::NotNull); 215 RegionNode* region = new RegionNode(3); 216 PhiNode* oop = new PhiNode(region, vtptr_type); 217 PhiNode* io = new PhiNode(region, Type::ABIO); 218 PhiNode* mem = new PhiNode(region, Type::MEMORY, TypePtr::BOTTOM); 219 220 // Oop is non-NULL, use it 221 region->init_req(1, kit->control()); 222 oop ->init_req(1, not_null_oop); 223 io ->init_req(1, kit->i_o()); 224 mem ->init_req(1, kit->merged_memory()); 225 226 // Oop is NULL, allocate value type 227 kit->set_control(null_ctl); 228 kit->kill_dead_locals(); 229 ciValueKlass* vk = value_klass(); 230 Node* klass_node = kit->makecon(TypeKlassPtr::make(vk)); 231 Node* alloc_oop = kit->new_instance(klass_node, NULL, NULL, false, this); 232 // Write field values to memory 233 store(kit, alloc_oop, alloc_oop, vk); 234 region->init_req(2, kit->control()); 235 oop ->init_req(2, alloc_oop); 236 io ->init_req(2, kit->i_o()); 237 mem ->init_req(2, kit->merged_memory()); 238 239 // Update GraphKit 240 kit->set_control(kit->gvn().transform(region)); 241 kit->set_i_o(kit->gvn().transform(io)); 242 kit->set_all_memory(kit->gvn().transform(mem)); 243 kit->record_for_igvn(region); 244 kit->record_for_igvn(oop); 245 kit->record_for_igvn(io); 246 kit->record_for_igvn(mem); 247 248 // Use cloned ValueTypeNode to propagate oop from now on 249 Node* res_oop = kit->gvn().transform(oop); 250 ValueTypeNode* vt = clone()->as_ValueType(); 251 vt->set_oop(res_oop); 252 kit->replace_in_map(this, kit->gvn().transform(vt)); 253 return res_oop; 254 } 255 256 bool ValueTypeNode::is_allocated(PhaseGVN* phase) const { 257 const Type* oop_type = phase->type(get_oop()); 258 return oop_type->meet(TypePtr::NULL_PTR) != oop_type; 259 } 260 261 // Clones the values type to handle control flow merges involving multiple value types. 262 // The inputs are replaced by PhiNodes to represent the merged values for the given region. 263 ValueTypeNode* ValueTypeNode::clone_with_phis(PhaseGVN* gvn, Node* region) { 264 assert(!has_phi_inputs(region), "already cloned with phis"); 265 ValueTypeNode* vt = clone()->as_ValueType(); 266 267 // Create a PhiNode for merging the oop values 268 const TypeValueTypePtr* vtptr = TypeValueTypePtr::make(vt->bottom_type()->isa_valuetype()); 269 PhiNode* oop = PhiNode::make(region, vt->get_oop(), vtptr); 270 gvn->set_type(oop, vtptr); 271 vt->set_oop(oop); 272 273 // Create a PhiNode each for merging the field values 274 for (uint i = 0; i < vt->field_count(); ++i) { 275 ciType* type = vt->field_type(i); 276 Node* value = vt->field_value(i); 277 if (type->is_valuetype()) { 278 // Handle flattened value type fields recursively 279 value = value->as_ValueType()->clone_with_phis(gvn, region); 280 } else { 442 break; 443 } 444 BasicType bt = f->type()->basic_type(); 445 if (bt == T_LONG || bt == T_DOUBLE) { 446 extra++; 447 } 448 } 449 n->init_req(base_input + j + extra, arg); 450 edges++; 451 BasicType bt = f_type->basic_type(); 452 if (bt == T_LONG || bt == T_DOUBLE) { 453 n->init_req(base_input + j + extra + 1, kit.top()); 454 edges++; 455 } 456 } 457 } 458 return edges; 459 } 460 461 Node* ValueTypeNode::Ideal(PhaseGVN* phase, bool can_reshape) { 462 if (!is_allocated(phase)) { 463 // Check if this value type is loaded from memory 464 Node* base = is_loaded(phase, type()->is_valuetype()); 465 if (base != NULL) { 466 // Save the oop 467 set_oop(base); 468 assert(is_allocated(phase), "should now be allocated"); 469 } 470 } 471 472 if (can_reshape) { 473 PhaseIterGVN* igvn = phase->is_IterGVN(); 474 if (is_allocated(igvn)) { 475 // Value type is heap allocated, search for safepoint uses 476 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) { 477 Node* out = fast_out(i); 478 if (out->is_SafePoint()) { 479 // Let SafePointNode::Ideal() take care of re-wiring the 480 // safepoint to the oop input instead of the value type node. 481 igvn->rehash_node_delayed(out); 482 } 483 } 484 } 485 } 486 return NULL; 487 } 488 489 // Search for multiple allocations of this value type 490 // and try to replace them by dominating allocations. 491 void ValueTypeNode::remove_redundant_allocations(PhaseIterGVN* igvn, PhaseIdealLoop* phase) { 492 assert(EliminateAllocations, "allocation elimination should be enabled"); 493 Node_List dead_allocations; 494 // Search for allocations of this value type 495 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) { 496 Node* out1 = fast_out(i); 497 if (out1->is_Allocate() && out1->in(AllocateNode::ValueNode) == this) { 498 AllocateNode* alloc = out1->as_Allocate(); 499 Node* res_dom = NULL; 500 if (is_allocated(igvn)) { 501 // The value type is already allocated but still connected to an AllocateNode. 502 // This can happen with late inlining when we first allocate a value type argument 503 // but later decide to inline the call with the callee code also allocating. 504 res_dom = get_oop(); 505 } else { 506 // Search for a dominating allocation of the same value type 507 for (DUIterator_Fast jmax, j = fast_outs(jmax); j < jmax; j++) { 508 Node* out2 = fast_out(j); 509 if (alloc != out2 && out2->is_Allocate() && out2->in(AllocateNode::ValueNode) == this && 510 phase->is_dominator(out2, alloc)) { 511 AllocateNode* alloc_dom = out2->as_Allocate(); 512 assert(alloc->in(AllocateNode::KlassNode) == alloc_dom->in(AllocateNode::KlassNode), "klasses should match"); 513 res_dom = alloc_dom->result_cast(); 514 break; 515 } 516 } 517 } 518 if (res_dom != NULL) { 519 // Found a dominating allocation 520 Node* res = alloc->result_cast(); 521 assert(res != NULL, "value type allocation should not be dead"); 522 // Move users to dominating allocation 523 igvn->replace_node(res, res_dom); 524 // The dominated allocation is now dead, remove the 525 // value type node connection and adjust the iterator. 526 dead_allocations.push(alloc); 527 igvn->replace_input_of(alloc, AllocateNode::ValueNode, NULL); 528 --i; --imax; 529 #ifdef ASSERT 530 if (PrintEliminateAllocations) { 531 tty->print("++++ Eliminated: %d Allocate ", alloc->_idx); 532 dump_spec(tty); 533 tty->cr(); 534 } 535 #endif 536 } 537 } 538 } 539 540 // Remove dead value type allocations by replacing the projection nodes 541 for (uint i = 0; i < dead_allocations.size(); ++i) { 542 CallProjections projs; 543 AllocateNode* alloc = dead_allocations.at(i)->as_Allocate(); 544 alloc->extract_projections(&projs, true); 545 // Use lazy_replace to avoid corrupting the dominator tree of PhaseIdealLoop 546 phase->lazy_replace(projs.fallthrough_catchproj, alloc->in(TypeFunc::Control)); 547 phase->lazy_replace(projs.fallthrough_memproj, alloc->in(TypeFunc::Memory)); 548 phase->lazy_replace(projs.catchall_memproj, phase->C->top()); 549 phase->lazy_replace(projs.fallthrough_ioproj, alloc->in(TypeFunc::I_O)); 550 phase->lazy_replace(projs.catchall_ioproj, phase->C->top()); 551 phase->lazy_replace(projs.catchall_catchproj, phase->C->top()); 552 phase->lazy_replace(projs.resproj, phase->C->top()); 553 } 554 } 555 556 // When a call returns multiple values, it has several result 557 // projections, one per field. Replacing the result of the call by a 558 // value type node (after late inlining) requires that for each result 559 // projection, we find the corresponding value type field. 560 void ValueTypeNode::replace_call_results(Node* call, Compile* C) { 561 ciValueKlass* vk = value_klass(); 562 for (DUIterator_Fast imax, i = call->fast_outs(imax); i < imax; i++) { 563 ProjNode *pn = call->fast_out(i)->as_Proj(); 564 uint con = pn->_con; 565 if (con >= TypeFunc::Parms+1) { 566 uint field_nb = con - (TypeFunc::Parms+1); 567 int extra = 0; 568 for (uint j = 0; j < field_nb - extra; j++) { 569 ciField* f = vk->nonstatic_field_at(j); 570 BasicType bt = f->type()->basic_type(); 571 if (bt == T_LONG || bt == T_DOUBLE) { 572 extra++; 573 } |