3407 // references to it. FIX THIS WHEN UNION TYPES APPEAR! 3408 // replace_in_map( obj, res ); 3409 3410 // Return final merged results 3411 set_control( _gvn.transform(region) ); 3412 record_for_igvn(region); 3413 3414 bool not_null_free = !toop->can_be_value_type(); 3415 bool not_flattenable = !ValueArrayFlatten || not_null_free || (toop->is_valuetypeptr() && !toop->value_klass()->flatten_array()); 3416 if (EnableValhalla && not_flattenable) { 3417 // Check if obj has been loaded from an array 3418 obj = obj->isa_DecodeN() ? obj->in(1) : obj; 3419 Node* array = NULL; 3420 if (obj->isa_Load()) { 3421 Node* address = obj->in(MemNode::Address); 3422 if (address->isa_AddP()) { 3423 array = address->as_AddP()->in(AddPNode::Base); 3424 } 3425 } else if (obj->is_Phi()) { 3426 Node* region = obj->in(0); 3427 if (region->req() == 3 && region->in(2) != NULL) { 3428 IfNode* iff = region->in(2)->in(0)->isa_If(); 3429 if (iff != NULL) { 3430 iff->is_flattened_array_check(&_gvn, array); 3431 } 3432 } 3433 } 3434 if (array != NULL) { 3435 const TypeAryPtr* ary_t = _gvn.type(array)->isa_aryptr(); 3436 if (ary_t != NULL) { 3437 if (!ary_t->is_not_null_free() && not_null_free) { 3438 // Casting array element to a non-inline-type, mark array as not null-free. 3439 Node* cast = _gvn.transform(new CheckCastPPNode(control(), array, ary_t->cast_to_not_null_free())); 3440 replace_in_map(array, cast); 3441 } else if (!ary_t->is_not_flat()) { 3442 // Casting array element to a non-flattenable type, mark array as not flat. 3443 Node* cast = _gvn.transform(new CheckCastPPNode(control(), array, ary_t->cast_to_not_flat())); 3444 replace_in_map(array, cast); 3445 } 3446 } 3447 } 3448 } 3494 assert(EnableValhalla, "should only be used if value types are enabled"); 3495 // Extract null free property from klass pointer 3496 Node* k_adr = basic_plus_adr(ary, oopDesc::klass_offset_in_bytes()); 3497 const TypePtr* k_adr_type = k_adr->bottom_type()->isa_ptr(); 3498 Node* klass = NULL; 3499 if (k_adr_type->is_ptr_to_narrowklass()) { 3500 klass = _gvn.transform(new LoadNKlassNode(NULL, immutable_memory(), k_adr, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT->make_narrowklass(), MemNode::unordered)); 3501 } else { 3502 klass = _gvn.transform(new LoadKlassNode(NULL, immutable_memory(), k_adr, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT, MemNode::unordered)); 3503 } 3504 Node* null_free = _gvn.transform(new GetNullFreePropertyNode(klass)); 3505 Node* cmp = NULL; 3506 if (_gvn.type(klass)->isa_klassptr()) { 3507 cmp = _gvn.transform(new CmpLNode(null_free, zerocon(T_LONG))); 3508 } else { 3509 cmp = _gvn.transform(new CmpINode(null_free, zerocon(T_INT))); 3510 } 3511 return _gvn.transform(new BoolNode(cmp, BoolTest::eq)); 3512 } 3513 3514 // Deoptimize if 'ary' is a null-free value type array and 'val' is null 3515 Node* GraphKit::gen_value_array_null_guard(Node* ary, Node* val, int nargs, bool safe_for_replace) { 3516 const Type* val_t = _gvn.type(val); 3517 if (val->is_ValueType() || !TypePtr::NULL_PTR->higher_equal(val_t)) { 3518 return ary; // Never null 3519 } 3520 RegionNode* region = new RegionNode(3); 3521 Node* null_ctl = top(); 3522 null_check_oop(val, &null_ctl); 3523 if (null_ctl != top()) { 3524 PreserveJVMState pjvms(this); 3525 set_control(null_ctl); 3526 // Deoptimize if null-free array 3527 Node* bol = gen_null_free_array_check(ary); 3528 { BuildCutout unless(this, bol, PROB_MAX); 3529 inc_sp(nargs); 3530 uncommon_trap(Deoptimization::Reason_null_check, 3531 Deoptimization::Action_none); 3532 } 3533 region->init_req(1, control()); 4389 set_all_memory(ideal.merged_memory()); 4390 set_i_o(ideal.i_o()); 4391 set_control(ideal.ctrl()); 4392 } 4393 4394 void GraphKit::final_sync(IdealKit& ideal) { 4395 // Final sync IdealKit and graphKit. 4396 sync_kit(ideal); 4397 } 4398 4399 Node* GraphKit::load_String_length(Node* str, bool set_ctrl) { 4400 Node* len = load_array_length(load_String_value(str, set_ctrl)); 4401 Node* coder = load_String_coder(str, set_ctrl); 4402 // Divide length by 2 if coder is UTF16 4403 return _gvn.transform(new RShiftINode(len, coder)); 4404 } 4405 4406 Node* GraphKit::load_String_value(Node* str, bool set_ctrl) { 4407 int value_offset = java_lang_String::value_offset_in_bytes(); 4408 const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(), 4409 false, NULL, Type::Offset(0)); 4410 const TypePtr* value_field_type = string_type->add_offset(value_offset); 4411 const TypeAryPtr* value_type = TypeAryPtr::make(TypePtr::NotNull, 4412 TypeAry::make(TypeInt::BYTE, TypeInt::POS, false, true, true), 4413 ciTypeArrayKlass::make(T_BYTE), true, Type::Offset(0)); 4414 Node* p = basic_plus_adr(str, str, value_offset); 4415 Node* load = access_load_at(str, p, value_field_type, value_type, T_OBJECT, 4416 IN_HEAP | (set_ctrl ? C2_CONTROL_DEPENDENT_LOAD : 0) | MO_UNORDERED); 4417 return load; 4418 } 4419 4420 Node* GraphKit::load_String_coder(Node* str, bool set_ctrl) { 4421 if (!CompactStrings) { 4422 return intcon(java_lang_String::CODER_UTF16); 4423 } 4424 int coder_offset = java_lang_String::coder_offset_in_bytes(); 4425 const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(), 4426 false, NULL, Type::Offset(0)); 4427 const TypePtr* coder_field_type = string_type->add_offset(coder_offset); 4428 4429 Node* p = basic_plus_adr(str, str, coder_offset); 4430 Node* load = access_load_at(str, p, coder_field_type, TypeInt::BYTE, T_BYTE, 4431 IN_HEAP | (set_ctrl ? C2_CONTROL_DEPENDENT_LOAD : 0) | MO_UNORDERED); 4432 return load; 4433 } 4434 4435 void GraphKit::store_String_value(Node* str, Node* value) { 4436 int value_offset = java_lang_String::value_offset_in_bytes(); 4437 const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(), 4438 false, NULL, Type::Offset(0)); 4439 const TypePtr* value_field_type = string_type->add_offset(value_offset); 4440 4441 access_store_at(str, basic_plus_adr(str, value_offset), value_field_type, 4442 value, TypeAryPtr::BYTES, T_OBJECT, IN_HEAP | MO_UNORDERED); 4443 } 4444 4445 void GraphKit::store_String_coder(Node* str, Node* value) { 4446 int coder_offset = java_lang_String::coder_offset_in_bytes(); 4447 const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(), 4448 false, NULL, Type::Offset(0)); 4449 const TypePtr* coder_field_type = string_type->add_offset(coder_offset); 4450 4451 access_store_at(str, basic_plus_adr(str, coder_offset), coder_field_type, 4452 value, TypeInt::BYTE, T_BYTE, IN_HEAP | MO_UNORDERED); 4453 } 4454 4455 // Capture src and dst memory state with a MergeMemNode 4456 Node* GraphKit::capture_memory(const TypePtr* src_type, const TypePtr* dst_type) { 4457 if (src_type == dst_type) { 4458 // Types are equal, we don't need a MergeMemNode 4459 return memory(src_type); 4460 } 4461 MergeMemNode* merge = MergeMemNode::make(map()->memory()); 4462 record_for_igvn(merge); // fold it up later, if possible 4463 int src_idx = C->get_alias_index(src_type); 4464 int dst_idx = C->get_alias_index(dst_type); 4465 merge->set_memory_at(src_idx, memory(src_idx)); 4466 merge->set_memory_at(dst_idx, memory(dst_idx)); 4467 return merge; 4468 } | 3407 // references to it. FIX THIS WHEN UNION TYPES APPEAR! 3408 // replace_in_map( obj, res ); 3409 3410 // Return final merged results 3411 set_control( _gvn.transform(region) ); 3412 record_for_igvn(region); 3413 3414 bool not_null_free = !toop->can_be_value_type(); 3415 bool not_flattenable = !ValueArrayFlatten || not_null_free || (toop->is_valuetypeptr() && !toop->value_klass()->flatten_array()); 3416 if (EnableValhalla && not_flattenable) { 3417 // Check if obj has been loaded from an array 3418 obj = obj->isa_DecodeN() ? obj->in(1) : obj; 3419 Node* array = NULL; 3420 if (obj->isa_Load()) { 3421 Node* address = obj->in(MemNode::Address); 3422 if (address->isa_AddP()) { 3423 array = address->as_AddP()->in(AddPNode::Base); 3424 } 3425 } else if (obj->is_Phi()) { 3426 Node* region = obj->in(0); 3427 if (region->req() == 3 && region->in(1) != NULL) { 3428 IfNode* iff = region->in(1)->in(0)->isa_If(); 3429 if (iff != NULL) { 3430 iff->is_flattened_array_check(&_gvn, array); 3431 } 3432 } 3433 } 3434 if (array != NULL) { 3435 const TypeAryPtr* ary_t = _gvn.type(array)->isa_aryptr(); 3436 if (ary_t != NULL) { 3437 if (!ary_t->is_not_null_free() && not_null_free) { 3438 // Casting array element to a non-inline-type, mark array as not null-free. 3439 Node* cast = _gvn.transform(new CheckCastPPNode(control(), array, ary_t->cast_to_not_null_free())); 3440 replace_in_map(array, cast); 3441 } else if (!ary_t->is_not_flat()) { 3442 // Casting array element to a non-flattenable type, mark array as not flat. 3443 Node* cast = _gvn.transform(new CheckCastPPNode(control(), array, ary_t->cast_to_not_flat())); 3444 replace_in_map(array, cast); 3445 } 3446 } 3447 } 3448 } 3494 assert(EnableValhalla, "should only be used if value types are enabled"); 3495 // Extract null free property from klass pointer 3496 Node* k_adr = basic_plus_adr(ary, oopDesc::klass_offset_in_bytes()); 3497 const TypePtr* k_adr_type = k_adr->bottom_type()->isa_ptr(); 3498 Node* klass = NULL; 3499 if (k_adr_type->is_ptr_to_narrowklass()) { 3500 klass = _gvn.transform(new LoadNKlassNode(NULL, immutable_memory(), k_adr, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT->make_narrowklass(), MemNode::unordered)); 3501 } else { 3502 klass = _gvn.transform(new LoadKlassNode(NULL, immutable_memory(), k_adr, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT, MemNode::unordered)); 3503 } 3504 Node* null_free = _gvn.transform(new GetNullFreePropertyNode(klass)); 3505 Node* cmp = NULL; 3506 if (_gvn.type(klass)->isa_klassptr()) { 3507 cmp = _gvn.transform(new CmpLNode(null_free, zerocon(T_LONG))); 3508 } else { 3509 cmp = _gvn.transform(new CmpINode(null_free, zerocon(T_INT))); 3510 } 3511 return _gvn.transform(new BoolNode(cmp, BoolTest::eq)); 3512 } 3513 3514 Node* GraphKit::gen_flattened_array_test(Node* ary) { 3515 assert(EnableValhalla, "should only be used if value types are enabled"); 3516 // Extract flattened property from klass pointer 3517 Node* k_adr = basic_plus_adr(ary, oopDesc::klass_offset_in_bytes()); 3518 const TypePtr* k_adr_type = k_adr->bottom_type()->isa_ptr(); 3519 Node* klass = NULL; 3520 if (k_adr_type->is_ptr_to_narrowklass()) { 3521 klass = _gvn.transform(new LoadNKlassNode(NULL, immutable_memory(), k_adr, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT->make_narrowklass(), MemNode::unordered)); 3522 } else { 3523 klass = _gvn.transform(new LoadKlassNode(NULL, immutable_memory(), k_adr, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT, MemNode::unordered)); 3524 } 3525 return _gvn.transform(new GetFlattenedPropertyNode(klass)); 3526 } 3527 3528 // Deoptimize if 'ary' is a null-free value type array and 'val' is null 3529 Node* GraphKit::gen_value_array_null_guard(Node* ary, Node* val, int nargs, bool safe_for_replace) { 3530 const Type* val_t = _gvn.type(val); 3531 if (val->is_ValueType() || !TypePtr::NULL_PTR->higher_equal(val_t)) { 3532 return ary; // Never null 3533 } 3534 RegionNode* region = new RegionNode(3); 3535 Node* null_ctl = top(); 3536 null_check_oop(val, &null_ctl); 3537 if (null_ctl != top()) { 3538 PreserveJVMState pjvms(this); 3539 set_control(null_ctl); 3540 // Deoptimize if null-free array 3541 Node* bol = gen_null_free_array_check(ary); 3542 { BuildCutout unless(this, bol, PROB_MAX); 3543 inc_sp(nargs); 3544 uncommon_trap(Deoptimization::Reason_null_check, 3545 Deoptimization::Action_none); 3546 } 3547 region->init_req(1, control()); 4403 set_all_memory(ideal.merged_memory()); 4404 set_i_o(ideal.i_o()); 4405 set_control(ideal.ctrl()); 4406 } 4407 4408 void GraphKit::final_sync(IdealKit& ideal) { 4409 // Final sync IdealKit and graphKit. 4410 sync_kit(ideal); 4411 } 4412 4413 Node* GraphKit::load_String_length(Node* str, bool set_ctrl) { 4414 Node* len = load_array_length(load_String_value(str, set_ctrl)); 4415 Node* coder = load_String_coder(str, set_ctrl); 4416 // Divide length by 2 if coder is UTF16 4417 return _gvn.transform(new RShiftINode(len, coder)); 4418 } 4419 4420 Node* GraphKit::load_String_value(Node* str, bool set_ctrl) { 4421 int value_offset = java_lang_String::value_offset_in_bytes(); 4422 const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(), 4423 false, NULL, Type::Offset(0), false); 4424 const TypePtr* value_field_type = string_type->add_offset(value_offset); 4425 const TypeAryPtr* value_type = TypeAryPtr::make(TypePtr::NotNull, 4426 TypeAry::make(TypeInt::BYTE, TypeInt::POS, false, true, true), 4427 ciTypeArrayKlass::make(T_BYTE), true, Type::Offset(0)); 4428 Node* p = basic_plus_adr(str, str, value_offset); 4429 Node* load = access_load_at(str, p, value_field_type, value_type, T_OBJECT, 4430 IN_HEAP | (set_ctrl ? C2_CONTROL_DEPENDENT_LOAD : 0) | MO_UNORDERED); 4431 return load; 4432 } 4433 4434 Node* GraphKit::load_String_coder(Node* str, bool set_ctrl) { 4435 if (!CompactStrings) { 4436 return intcon(java_lang_String::CODER_UTF16); 4437 } 4438 int coder_offset = java_lang_String::coder_offset_in_bytes(); 4439 const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(), 4440 false, NULL, Type::Offset(0), false); 4441 const TypePtr* coder_field_type = string_type->add_offset(coder_offset); 4442 4443 Node* p = basic_plus_adr(str, str, coder_offset); 4444 Node* load = access_load_at(str, p, coder_field_type, TypeInt::BYTE, T_BYTE, 4445 IN_HEAP | (set_ctrl ? C2_CONTROL_DEPENDENT_LOAD : 0) | MO_UNORDERED); 4446 return load; 4447 } 4448 4449 void GraphKit::store_String_value(Node* str, Node* value) { 4450 int value_offset = java_lang_String::value_offset_in_bytes(); 4451 const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(), 4452 false, NULL, Type::Offset(0), false); 4453 const TypePtr* value_field_type = string_type->add_offset(value_offset); 4454 4455 access_store_at(str, basic_plus_adr(str, value_offset), value_field_type, 4456 value, TypeAryPtr::BYTES, T_OBJECT, IN_HEAP | MO_UNORDERED); 4457 } 4458 4459 void GraphKit::store_String_coder(Node* str, Node* value) { 4460 int coder_offset = java_lang_String::coder_offset_in_bytes(); 4461 const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(), 4462 false, NULL, Type::Offset(0), false); 4463 const TypePtr* coder_field_type = string_type->add_offset(coder_offset); 4464 4465 access_store_at(str, basic_plus_adr(str, coder_offset), coder_field_type, 4466 value, TypeInt::BYTE, T_BYTE, IN_HEAP | MO_UNORDERED); 4467 } 4468 4469 // Capture src and dst memory state with a MergeMemNode 4470 Node* GraphKit::capture_memory(const TypePtr* src_type, const TypePtr* dst_type) { 4471 if (src_type == dst_type) { 4472 // Types are equal, we don't need a MergeMemNode 4473 return memory(src_type); 4474 } 4475 MergeMemNode* merge = MergeMemNode::make(map()->memory()); 4476 record_for_igvn(merge); // fold it up later, if possible 4477 int src_idx = C->get_alias_index(src_type); 4478 int dst_idx = C->get_alias_index(dst_type); 4479 merge->set_memory_at(src_idx, memory(src_idx)); 4480 merge->set_memory_at(dst_idx, memory(dst_idx)); 4481 return merge; 4482 } |