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