1476 // The field is Klass::_layout_helper. Return its constant value if known.
1477 assert(this->Opcode() == Op_LoadI, "must load an int from _layout_helper");
1478 return TypeInt::make(klass->layout_helper());
1479 }
1480
1481 // No match.
1482 return NULL;
1483 }
1484
1485 //------------------------------Value-----------------------------------------
1486 const Type *LoadNode::Value( PhaseTransform *phase ) const {
1487 // Either input is TOP ==> the result is TOP
1488 Node* mem = in(MemNode::Memory);
1489 const Type *t1 = phase->type(mem);
1490 if (t1 == Type::TOP) return Type::TOP;
1491 Node* adr = in(MemNode::Address);
1492 const TypePtr* tp = phase->type(adr)->isa_ptr();
1493 if (tp == NULL || tp->empty()) return Type::TOP;
1494 int off = tp->offset();
1495 assert(off != Type::OffsetTop, "case covered by TypePtr::empty");
1496
1497 // Try to guess loaded type from pointer type
1498 if (tp->base() == Type::AryPtr) {
1499 const Type *t = tp->is_aryptr()->elem();
1500 // Don't do this for integer types. There is only potential profit if
1501 // the element type t is lower than _type; that is, for int types, if _type is
1502 // more restrictive than t. This only happens here if one is short and the other
1503 // char (both 16 bits), and in those cases we've made an intentional decision
1504 // to use one kind of load over the other. See AndINode::Ideal and 4965907.
1505 // Also, do not try to narrow the type for a LoadKlass, regardless of offset.
1506 //
1507 // Yes, it is possible to encounter an expression like (LoadKlass p1:(AddP x x 8))
1508 // where the _gvn.type of the AddP is wider than 8. This occurs when an earlier
1509 // copy p0 of (AddP x x 8) has been proven equal to p1, and the p0 has been
1510 // subsumed by p1. If p1 is on the worklist but has not yet been re-transformed,
1511 // it is possible that p1 will have a type like Foo*[int+]:NotNull*+any.
1512 // In fact, that could have been the original type of p1, and p1 could have
1513 // had an original form like p1:(AddP x x (LShiftL quux 3)), where the
1514 // expression (LShiftL quux 3) independently optimized to the constant 8.
1515 if ((t->isa_int() == NULL) && (t->isa_long() == NULL)
1519 // Make sure the reference is not into the header, by comparing
1520 // the offset against the offset of the start of the array's data.
1521 // Different array types begin at slightly different offsets (12 vs. 16).
1522 // We choose T_BYTE as an example base type that is least restrictive
1523 // as to alignment, which will therefore produce the smallest
1524 // possible base offset.
1525 const int min_base_off = arrayOopDesc::base_offset_in_bytes(T_BYTE);
1526 if ((uint)off >= (uint)min_base_off) { // is the offset beyond the header?
1527 const Type* jt = t->join(_type);
1528 // In any case, do not allow the join, per se, to empty out the type.
1529 if (jt->empty() && !t->empty()) {
1530 // This can happen if a interface-typed array narrows to a class type.
1531 jt = _type;
1532 }
1533
1534 if (EliminateAutoBox && adr->is_AddP()) {
1535 // The pointers in the autobox arrays are always non-null
1536 Node* base = adr->in(AddPNode::Base);
1537 if (base != NULL &&
1538 !phase->type(base)->higher_equal(TypePtr::NULL_PTR)) {
1539 Compile::AliasType* atp = phase->C->alias_type(base->adr_type());
1540 if (is_autobox_cache(atp)) {
1541 return jt->join(TypePtr::NOTNULL)->is_ptr();
1542 }
1543 }
1544 }
1545 return jt;
1546 }
1547 }
1548 } else if (tp->base() == Type::InstPtr) {
1549 const TypeInstPtr* tinst = tp->is_instptr();
1550 ciKlass* klass = tinst->klass();
1551 assert( off != Type::OffsetBot ||
1552 // arrays can be cast to Objects
1553 tp->is_oopptr()->klass()->is_java_lang_Object() ||
1554 // unsafe field access may not have a constant offset
1555 phase->C->has_unsafe_access(),
1556 "Field accesses must be precise" );
1557 // For oop loads, we expect the _type to be precise
1558 if (klass == phase->C->env()->String_klass() &&
1559 adr->is_AddP() && off != Type::OffsetBot) {
1560 // For constant Strings treat the final fields as compile time constants.
1561 Node* base = adr->in(AddPNode::Base);
1562 const TypeOopPtr* t = phase->type(base)->isa_oopptr();
1563 if (t != NULL && t->singleton()) {
1564 ciField* field = phase->C->env()->String_klass()->get_field_by_offset(off, false);
1565 if (field != NULL && field->is_final()) {
1566 ciObject* string = t->const_oop();
1567 ciConstant constant = string->as_instance()->field_value(field);
1568 if (constant.basic_type() == T_INT) {
1569 return TypeInt::make(constant.as_int());
1570 } else if (constant.basic_type() == T_ARRAY) {
1571 if (adr->bottom_type()->is_ptr_to_narrowoop()) {
1572 return TypeNarrowOop::make_from_constant(constant.as_object(), true);
1573 } else {
1574 return TypeOopPtr::make_from_constant(constant.as_object(), true);
1575 }
1576 }
1577 }
1578 }
1579 }
1580 } else if (tp->base() == Type::KlassPtr) {
1581 assert( off != Type::OffsetBot ||
1582 // arrays can be cast to Objects
1583 tp->is_klassptr()->klass()->is_java_lang_Object() ||
1584 // also allow array-loading from the primary supertype
1585 // array during subtype checks
1586 Opcode() == Op_LoadKlass,
1587 "Field accesses must be precise" );
1588 // For klass/static loads, we expect the _type to be precise
1589 }
1590
1591 const TypeKlassPtr *tkls = tp->isa_klassptr();
1592 if (tkls != NULL && !StressReflectiveCode) {
1593 ciKlass* klass = tkls->klass();
1594 if (klass->is_loaded() && tkls->klass_is_exact()) {
1595 // We are loading a field from a Klass metaobject whose identity
1596 // is known at compile time (the type is "exact" or "precise").
1597 // Check for fields we know are maintained as constants by the VM.
1598 if (tkls->offset() == Klass::super_check_offset_offset_in_bytes() + (int)sizeof(oopDesc)) {
1599 // The field is Klass::_super_check_offset. Return its (constant) value.
|
1476 // The field is Klass::_layout_helper. Return its constant value if known.
1477 assert(this->Opcode() == Op_LoadI, "must load an int from _layout_helper");
1478 return TypeInt::make(klass->layout_helper());
1479 }
1480
1481 // No match.
1482 return NULL;
1483 }
1484
1485 //------------------------------Value-----------------------------------------
1486 const Type *LoadNode::Value( PhaseTransform *phase ) const {
1487 // Either input is TOP ==> the result is TOP
1488 Node* mem = in(MemNode::Memory);
1489 const Type *t1 = phase->type(mem);
1490 if (t1 == Type::TOP) return Type::TOP;
1491 Node* adr = in(MemNode::Address);
1492 const TypePtr* tp = phase->type(adr)->isa_ptr();
1493 if (tp == NULL || tp->empty()) return Type::TOP;
1494 int off = tp->offset();
1495 assert(off != Type::OffsetTop, "case covered by TypePtr::empty");
1496 Compile* C = phase->C;
1497
1498 // Try to guess loaded type from pointer type
1499 if (tp->base() == Type::AryPtr) {
1500 const Type *t = tp->is_aryptr()->elem();
1501 // Don't do this for integer types. There is only potential profit if
1502 // the element type t is lower than _type; that is, for int types, if _type is
1503 // more restrictive than t. This only happens here if one is short and the other
1504 // char (both 16 bits), and in those cases we've made an intentional decision
1505 // to use one kind of load over the other. See AndINode::Ideal and 4965907.
1506 // Also, do not try to narrow the type for a LoadKlass, regardless of offset.
1507 //
1508 // Yes, it is possible to encounter an expression like (LoadKlass p1:(AddP x x 8))
1509 // where the _gvn.type of the AddP is wider than 8. This occurs when an earlier
1510 // copy p0 of (AddP x x 8) has been proven equal to p1, and the p0 has been
1511 // subsumed by p1. If p1 is on the worklist but has not yet been re-transformed,
1512 // it is possible that p1 will have a type like Foo*[int+]:NotNull*+any.
1513 // In fact, that could have been the original type of p1, and p1 could have
1514 // had an original form like p1:(AddP x x (LShiftL quux 3)), where the
1515 // expression (LShiftL quux 3) independently optimized to the constant 8.
1516 if ((t->isa_int() == NULL) && (t->isa_long() == NULL)
1520 // Make sure the reference is not into the header, by comparing
1521 // the offset against the offset of the start of the array's data.
1522 // Different array types begin at slightly different offsets (12 vs. 16).
1523 // We choose T_BYTE as an example base type that is least restrictive
1524 // as to alignment, which will therefore produce the smallest
1525 // possible base offset.
1526 const int min_base_off = arrayOopDesc::base_offset_in_bytes(T_BYTE);
1527 if ((uint)off >= (uint)min_base_off) { // is the offset beyond the header?
1528 const Type* jt = t->join(_type);
1529 // In any case, do not allow the join, per se, to empty out the type.
1530 if (jt->empty() && !t->empty()) {
1531 // This can happen if a interface-typed array narrows to a class type.
1532 jt = _type;
1533 }
1534
1535 if (EliminateAutoBox && adr->is_AddP()) {
1536 // The pointers in the autobox arrays are always non-null
1537 Node* base = adr->in(AddPNode::Base);
1538 if (base != NULL &&
1539 !phase->type(base)->higher_equal(TypePtr::NULL_PTR)) {
1540 Compile::AliasType* atp = C->alias_type(base->adr_type());
1541 if (is_autobox_cache(atp)) {
1542 return jt->join(TypePtr::NOTNULL)->is_ptr();
1543 }
1544 }
1545 }
1546 return jt;
1547 }
1548 }
1549 } else if (tp->base() == Type::InstPtr) {
1550 ciEnv* env = C->env();
1551 const TypeInstPtr* tinst = tp->is_instptr();
1552 ciKlass* klass = tinst->klass();
1553 assert( off != Type::OffsetBot ||
1554 // arrays can be cast to Objects
1555 tp->is_oopptr()->klass()->is_java_lang_Object() ||
1556 // unsafe field access may not have a constant offset
1557 C->has_unsafe_access(),
1558 "Field accesses must be precise" );
1559 // For oop loads, we expect the _type to be precise
1560 if (klass == env->String_klass() &&
1561 adr->is_AddP() && off != Type::OffsetBot) {
1562 // For constant Strings treat the final fields as compile time constants.
1563 Node* base = adr->in(AddPNode::Base);
1564 const TypeOopPtr* t = phase->type(base)->isa_oopptr();
1565 if (t != NULL && t->singleton()) {
1566 ciField* field = env->String_klass()->get_field_by_offset(off, false);
1567 if (field != NULL && field->is_final()) {
1568 ciObject* string = t->const_oop();
1569 ciConstant constant = string->as_instance()->field_value(field);
1570 if (constant.basic_type() == T_INT) {
1571 return TypeInt::make(constant.as_int());
1572 } else if (constant.basic_type() == T_ARRAY) {
1573 if (adr->bottom_type()->is_ptr_to_narrowoop()) {
1574 return TypeNarrowOop::make_from_constant(constant.as_object(), true);
1575 } else {
1576 return TypeOopPtr::make_from_constant(constant.as_object(), true);
1577 }
1578 }
1579 }
1580 }
1581 }
1582 // Optimizations for constant objects
1583 ciObject* const_oop = tinst->const_oop();
1584 if (const_oop != NULL) {
1585 // For constant CallSites treat the target field as a compile time constant.
1586 if (const_oop->is_call_site()) {
1587 ciCallSite* call_site = const_oop->as_call_site();
1588 ciField* field = call_site->klass()->as_instance_klass()->get_field_by_offset(off, /*is_static=*/ false);
1589 if (field != NULL && field->is_call_site_target()) {
1590 ciMethodHandle* target = call_site->get_target();
1591 if (target != NULL) { // just in case
1592 ciConstant constant(T_OBJECT, target);
1593 const Type* t;
1594 if (adr->bottom_type()->is_ptr_to_narrowoop()) {
1595 t = TypeNarrowOop::make_from_constant(constant.as_object(), true);
1596 } else {
1597 t = TypeOopPtr::make_from_constant(constant.as_object(), true);
1598 }
1599 // Add a dependence for invalidation of the optimization.
1600 if (!call_site->is_constant_call_site()) {
1601 C->dependencies()->assert_call_site_target_value(call_site, target);
1602 }
1603 return t;
1604 }
1605 }
1606 }
1607 }
1608 } else if (tp->base() == Type::KlassPtr) {
1609 assert( off != Type::OffsetBot ||
1610 // arrays can be cast to Objects
1611 tp->is_klassptr()->klass()->is_java_lang_Object() ||
1612 // also allow array-loading from the primary supertype
1613 // array during subtype checks
1614 Opcode() == Op_LoadKlass,
1615 "Field accesses must be precise" );
1616 // For klass/static loads, we expect the _type to be precise
1617 }
1618
1619 const TypeKlassPtr *tkls = tp->isa_klassptr();
1620 if (tkls != NULL && !StressReflectiveCode) {
1621 ciKlass* klass = tkls->klass();
1622 if (klass->is_loaded() && tkls->klass_is_exact()) {
1623 // We are loading a field from a Klass metaobject whose identity
1624 // is known at compile time (the type is "exact" or "precise").
1625 // Check for fields we know are maintained as constants by the VM.
1626 if (tkls->offset() == Klass::super_check_offset_offset_in_bytes() + (int)sizeof(oopDesc)) {
1627 // The field is Klass::_super_check_offset. Return its (constant) value.
|