Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/vm/opto/memnode.cpp
          +++ new/src/share/vm/opto/memnode.cpp
↓ open down ↓ 1485 lines elided ↑ open up ↑
1486 1486  const Type *LoadNode::Value( PhaseTransform *phase ) const {
1487 1487    // Either input is TOP ==> the result is TOP
1488 1488    Node* mem = in(MemNode::Memory);
1489 1489    const Type *t1 = phase->type(mem);
1490 1490    if (t1 == Type::TOP)  return Type::TOP;
1491 1491    Node* adr = in(MemNode::Address);
1492 1492    const TypePtr* tp = phase->type(adr)->isa_ptr();
1493 1493    if (tp == NULL || tp->empty())  return Type::TOP;
1494 1494    int off = tp->offset();
1495 1495    assert(off != Type::OffsetTop, "case covered by TypePtr::empty");
     1496 +  Compile* C = phase->C;
1496 1497  
1497 1498    // Try to guess loaded type from pointer type
1498 1499    if (tp->base() == Type::AryPtr) {
1499 1500      const Type *t = tp->is_aryptr()->elem();
1500 1501      // Don't do this for integer types. There is only potential profit if
1501 1502      // the element type t is lower than _type; that is, for int types, if _type is
1502 1503      // more restrictive than t.  This only happens here if one is short and the other
1503 1504      // char (both 16 bits), and in those cases we've made an intentional decision
1504 1505      // to use one kind of load over the other. See AndINode::Ideal and 4965907.
1505 1506      // Also, do not try to narrow the type for a LoadKlass, regardless of offset.
↓ open down ↓ 23 lines elided ↑ open up ↑
1529 1530          if (jt->empty() && !t->empty()) {
1530 1531            // This can happen if a interface-typed array narrows to a class type.
1531 1532            jt = _type;
1532 1533          }
1533 1534  
1534 1535          if (EliminateAutoBox && adr->is_AddP()) {
1535 1536            // The pointers in the autobox arrays are always non-null
1536 1537            Node* base = adr->in(AddPNode::Base);
1537 1538            if (base != NULL &&
1538 1539                !phase->type(base)->higher_equal(TypePtr::NULL_PTR)) {
1539      -            Compile::AliasType* atp = phase->C->alias_type(base->adr_type());
     1540 +            Compile::AliasType* atp = C->alias_type(base->adr_type());
1540 1541              if (is_autobox_cache(atp)) {
1541 1542                return jt->join(TypePtr::NOTNULL)->is_ptr();
1542 1543              }
1543 1544            }
1544 1545          }
1545 1546          return jt;
1546 1547        }
1547 1548      }
1548 1549    } else if (tp->base() == Type::InstPtr) {
     1550 +    ciEnv* env = C->env();
1549 1551      const TypeInstPtr* tinst = tp->is_instptr();
1550 1552      ciKlass* klass = tinst->klass();
1551 1553      assert( off != Type::OffsetBot ||
1552 1554              // arrays can be cast to Objects
1553 1555              tp->is_oopptr()->klass()->is_java_lang_Object() ||
1554 1556              // unsafe field access may not have a constant offset
1555      -            phase->C->has_unsafe_access(),
     1557 +            C->has_unsafe_access(),
1556 1558              "Field accesses must be precise" );
1557 1559      // For oop loads, we expect the _type to be precise
1558      -    if (klass == phase->C->env()->String_klass() &&
     1560 +    if (klass == env->String_klass() &&
1559 1561          adr->is_AddP() && off != Type::OffsetBot) {
1560 1562        // For constant Strings treat the final fields as compile time constants.
1561 1563        Node* base = adr->in(AddPNode::Base);
1562 1564        const TypeOopPtr* t = phase->type(base)->isa_oopptr();
1563 1565        if (t != NULL && t->singleton()) {
1564      -        ciField* field = phase->C->env()->String_klass()->get_field_by_offset(off, false);
     1566 +        ciField* field = env->String_klass()->get_field_by_offset(off, false);
1565 1567          if (field != NULL && field->is_final()) {
1566 1568            ciObject* string = t->const_oop();
1567 1569            ciConstant constant = string->as_instance()->field_value(field);
1568 1570            if (constant.basic_type() == T_INT) {
1569 1571              return TypeInt::make(constant.as_int());
1570 1572            } else if (constant.basic_type() == T_ARRAY) {
1571 1573              if (adr->bottom_type()->is_ptr_to_narrowoop()) {
1572 1574                return TypeNarrowOop::make_from_constant(constant.as_object(), true);
1573 1575              } else {
1574 1576                return TypeOopPtr::make_from_constant(constant.as_object(), true);
1575 1577              }
1576 1578            }
1577 1579          }
1578 1580        }
1579 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 +    }
1580 1608    } else if (tp->base() == Type::KlassPtr) {
1581 1609      assert( off != Type::OffsetBot ||
1582 1610              // arrays can be cast to Objects
1583 1611              tp->is_klassptr()->klass()->is_java_lang_Object() ||
1584 1612              // also allow array-loading from the primary supertype
1585 1613              // array during subtype checks
1586 1614              Opcode() == Op_LoadKlass,
1587 1615              "Field accesses must be precise" );
1588 1616      // For klass/static loads, we expect the _type to be precise
1589 1617    }
↓ open down ↓ 2571 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX