< prev index next >

src/hotspot/share/opto/type.cpp

Print this page




 577 
 578   TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, Offset(0));
 579   TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, Offset::bottom);
 580   TypePtr::BOTTOM  = TypePtr::make(AnyPtr, TypePtr::BotPTR, Offset::bottom);
 581 
 582   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
 583   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
 584 
 585   const Type **fmembar = TypeTuple::fields(0);
 586   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
 587 
 588   const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
 589   fsc[0] = TypeInt::CC;
 590   fsc[1] = Type::MEMORY;
 591   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
 592 
 593   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
 594   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
 595   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
 596   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 597                                            false, 0, Offset(oopDesc::mark_offset_in_bytes()));
 598   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 599                                            false, 0, Offset(oopDesc::klass_offset_in_bytes()));
 600   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
 601 
 602   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, Offset::bottom);
 603 
 604   TypeValueType::BOTTOM = TypeValueType::make(NULL);
 605 
 606   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
 607   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
 608 
 609   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
 610 
 611   mreg2type[Op_Node] = Type::BOTTOM;
 612   mreg2type[Op_Set ] = 0;
 613   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
 614   mreg2type[Op_RegI] = TypeInt::INT;
 615   mreg2type[Op_RegP] = TypePtr::BOTTOM;
 616   mreg2type[Op_RegF] = Type::FLOAT;
 617   mreg2type[Op_RegD] = Type::DOUBLE;
 618   mreg2type[Op_RegL] = TypeLong::LONG;
 619   mreg2type[Op_RegFlags] = TypeInt::CC;


 638   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Offset::bottom);
 639   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Offset::bottom);
 640   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Offset::bottom);
 641   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Offset::bottom);
 642   TypeAryPtr::VALUES  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeValueType::BOTTOM,TypeInt::POS), NULL, false,  Offset::bottom);
 643 
 644   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
 645   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
 646   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
 647   TypeAryPtr::_array_body_type[T_VALUETYPE] = TypeAryPtr::OOPS;
 648   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
 649   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
 650   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
 651   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
 652   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
 653   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
 654   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
 655   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
 656   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
 657 
 658   TypeKlassPtr::OBJECT = TypeKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), Offset(0) );
 659   TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), Offset(0) );
 660 
 661   const Type **fi2c = TypeTuple::fields(2);
 662   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
 663   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
 664   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
 665 
 666   const Type **intpair = TypeTuple::fields(2);
 667   intpair[0] = TypeInt::INT;
 668   intpair[1] = TypeInt::INT;
 669   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
 670 
 671   const Type **longpair = TypeTuple::fields(2);
 672   longpair[0] = TypeLong::LONG;
 673   longpair[1] = TypeLong::LONG;
 674   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
 675 
 676   const Type **intccpair = TypeTuple::fields(2);
 677   intccpair[0] = TypeInt::INT;
 678   intccpair[1] = TypeInt::CC;
 679   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);


3331   return this;
3332 }
3333 
3334 //-----------------------------cast_to_exactness-------------------------------
3335 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3336   // There is no such thing as an exact general oop.
3337   // Return self unchanged.
3338   return this;
3339 }
3340 
3341 
3342 //------------------------------as_klass_type----------------------------------
3343 // Return the klass type corresponding to this instance or array type.
3344 // It is the type that is loaded from an object of this type.
3345 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
3346   ciKlass* k = klass();
3347   bool    xk = klass_is_exact();
3348   if (k == NULL)
3349     return TypeKlassPtr::OBJECT;
3350   else
3351     return TypeKlassPtr::make(xk? Constant: NotNull, k, Offset(0));
3352 }
3353 
3354 //------------------------------meet-------------------------------------------
3355 // Compute the MEET of two types.  It returns a new Type object.
3356 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3357   // Perform a fast test for common case; meeting the same types together.
3358   if( this == t ) return this;  // Meeting same type-rep?
3359 
3360   // Current "this->_base" is OopPtr
3361   switch (t->base()) {          // switch on original type
3362 
3363   case Int:                     // Mixing ints & oops happens when javac
3364   case Long:                    // reuses local variables
3365   case FloatTop:
3366   case FloatCon:
3367   case FloatBot:
3368   case DoubleTop:
3369   case DoubleCon:
3370   case DoubleBot:
3371   case NarrowOop:


3445       ciInstanceKlass* ik = klass->as_instance_klass();
3446       klass_is_exact = ik->is_final();
3447       if (!klass_is_exact && klass_change
3448           && deps != NULL && UseUniqueSubclasses) {
3449         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3450         if (sub != NULL) {
3451           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3452           klass = ik = sub;
3453           klass_is_exact = sub->is_final();
3454         }
3455       }
3456       if (!klass_is_exact && try_for_exact
3457           && deps != NULL && UseExactTypes) {
3458         if (!ik->is_interface() && !ik->has_subklass()) {
3459           // Add a dependence; if concrete subclass added we need to recompile
3460           deps->assert_leaf_type(ik);
3461           klass_is_exact = true;
3462         }
3463       }
3464     }
3465     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, Offset(0));
3466   } else if (klass->is_obj_array_klass()) {
3467     // Element is an object or value array. Recursively call ourself.
3468     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), false, try_for_exact);
3469     bool null_free = klass->is_loaded() && klass->as_array_klass()->storage_properties().is_null_free();
3470     if (null_free) {
3471       assert(etype->is_valuetypeptr(), "must be a valuetypeptr");
3472       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3473     }
3474     // [V? has a subtype: [V. So even though V is final, [V? is not exact.
3475     bool xk = etype->klass_is_exact() && (!etype->is_valuetypeptr() || null_free);
3476     bool not_null_free = !etype->can_be_value_type() || xk;
3477     bool not_flat = !ValueArrayFlatten || not_null_free || (etype->is_valuetypeptr() && !etype->value_klass()->flatten_array());
3478     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, false, not_flat, not_null_free);
3479     // We used to pass NotNull in here, asserting that the sub-arrays
3480     // are all not-null.  This is not true in generally, as code can
3481     // slam NULLs down in the subarrays.
3482     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0));
3483     return arr;
3484   } else if (klass->is_type_array_klass()) {
3485     // Element is an typeArray


3497     return arr;
3498   } else {
3499     ShouldNotReachHere();
3500     return NULL;
3501   }
3502 }
3503 
3504 //------------------------------make_from_constant-----------------------------
3505 // Make a java pointer from an oop constant
3506 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3507   assert(!o->is_null_object(), "null object not yet handled here.");
3508 
3509   const bool make_constant = require_constant || o->should_be_constant();
3510 
3511   ciKlass* klass = o->klass();
3512   if (klass->is_instance_klass() || klass->is_valuetype()) {
3513     // Element is an instance or value type
3514     if (make_constant) {
3515       return TypeInstPtr::make(o);
3516     } else {
3517       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0));
3518     }
3519   } else if (klass->is_obj_array_klass()) {
3520     // Element is an object array. Recursively call ourself.
3521     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass());
3522     bool null_free = klass->is_loaded() && klass->as_array_klass()->storage_properties().is_null_free();
3523     if (null_free) {
3524       assert(etype->is_valuetypeptr(), "must be a valuetypeptr");
3525       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3526     }
3527     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3528                                         /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ !null_free);
3529     // We used to pass NotNull in here, asserting that the sub-arrays
3530     // are all not-null.  This is not true in generally, as code can
3531     // slam NULLs down in the subarrays.
3532     if (make_constant) {
3533       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3534     } else {
3535       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3536     }
3537   } else if (klass->is_type_array_klass()) {


3754  * @return  true if type profile is valuable
3755  */
3756 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3757   // no way to improve an already exact type
3758   if (klass_is_exact()) {
3759     return false;
3760   }
3761   return TypePtr::would_improve_type(exact_kls, inline_depth);
3762 }
3763 
3764 //=============================================================================
3765 // Convenience common pre-built types.
3766 const TypeInstPtr *TypeInstPtr::NOTNULL;
3767 const TypeInstPtr *TypeInstPtr::BOTTOM;
3768 const TypeInstPtr *TypeInstPtr::MIRROR;
3769 const TypeInstPtr *TypeInstPtr::MARK;
3770 const TypeInstPtr *TypeInstPtr::KLASS;
3771 
3772 //------------------------------TypeInstPtr-------------------------------------
3773 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset off,
3774                          int instance_id, const TypePtr* speculative, int inline_depth)

3775   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
3776     _name(k->name()) {
3777    assert(k != NULL &&
3778           (k->is_loaded() || o == NULL),
3779           "cannot have constants with non-loaded klass");


3780 };
3781 
3782 //------------------------------make-------------------------------------------
3783 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3784                                      ciKlass* k,
3785                                      bool xk,
3786                                      ciObject* o,
3787                                      Offset offset,

3788                                      int instance_id,
3789                                      const TypePtr* speculative,
3790                                      int inline_depth) {
3791   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3792   // Either const_oop() is NULL or else ptr is Constant
3793   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3794           "constant pointers must have a value supplied" );
3795   // Ptr is never Null
3796   assert( ptr != Null, "NULL pointers are not typed" );
3797 
3798   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3799   if (!UseExactTypes)  xk = false;
3800   if (ptr == Constant) {
3801     // Note:  This case includes meta-object constants, such as methods.
3802     xk = true;
3803   } else if (k->is_loaded()) {
3804     ciInstanceKlass* ik = k->as_instance_klass();
3805     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3806     if (xk && ik->is_interface())  xk = false;  // no exact interface
3807   }
3808 
3809   // Now hash this baby
3810   TypeInstPtr *result =
3811     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
3812 
3813   return result;
3814 }
3815 
3816 /**
3817  *  Create constant type for a constant boxed value
3818  */
3819 const Type* TypeInstPtr::get_const_boxed_value() const {
3820   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3821   assert((const_oop() != NULL), "should be called only for constant object");
3822   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3823   BasicType bt = constant.basic_type();
3824   switch (bt) {
3825     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
3826     case T_INT:      return TypeInt::make(constant.as_int());
3827     case T_CHAR:     return TypeInt::make(constant.as_char());
3828     case T_BYTE:     return TypeInt::make(constant.as_byte());
3829     case T_SHORT:    return TypeInt::make(constant.as_short());
3830     case T_FLOAT:    return TypeF::make(constant.as_float());
3831     case T_DOUBLE:   return TypeD::make(constant.as_double());
3832     case T_LONG:     return TypeLong::make(constant.as_long());
3833     default:         break;
3834   }
3835   fatal("Invalid boxed value type '%s'", type2name(bt));
3836   return NULL;
3837 }
3838 
3839 //------------------------------cast_to_ptr_type-------------------------------
3840 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3841   if( ptr == _ptr ) return this;
3842   // Reconstruct _sig info here since not a problem with later lazy
3843   // construction, _sig will show up on demand.
3844   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3845 }
3846 
3847 
3848 //-----------------------------cast_to_exactness-------------------------------
3849 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3850   if( klass_is_exact == _klass_is_exact ) return this;
3851   if (!UseExactTypes)  return this;
3852   if (!_klass->is_loaded())  return this;
3853   ciInstanceKlass* ik = _klass->as_instance_klass();
3854   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3855   if( ik->is_interface() )              return this;  // cannot set xk
3856   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3857 }
3858 
3859 //-----------------------------cast_to_instance_id----------------------------
3860 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3861   if( instance_id == _instance_id ) return this;
3862   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3863 }
3864 
3865 const TypeOopPtr *TypeInstPtr::cast_to_nonconst() const {
3866   if (const_oop() == NULL) return this;
3867   return make(NotNull, klass(), _klass_is_exact, NULL, _offset, _instance_id, _speculative, _inline_depth);
3868 }
3869 
3870 //------------------------------xmeet_unloaded---------------------------------
3871 // Compute the MEET of two InstPtrs when at least one is unloaded.
3872 // Assume classes are different since called after check for same name/class-loader
3873 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3874     Offset off = meet_offset(tinst->offset());
3875     PTR ptr = meet_ptr(tinst->ptr());
3876     int instance_id = meet_instance_id(tinst->instance_id());
3877     const TypePtr* speculative = xmeet_speculative(tinst);
3878     int depth = meet_inline_depth(tinst->inline_depth());
3879 
3880     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3881     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3882     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3883       //
3884       // Meet unloaded class with java/lang/Object
3885       //
3886       // Meet
3887       //          |                     Unloaded Class
3888       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3889       //  ===================================================================
3890       //   TOP    | ..........................Unloaded......................|
3891       //  AnyNull |  U-AN    |................Unloaded......................|
3892       // Constant | ... O-NN .................................. |   O-BOT   |
3893       //  NotNull | ... O-NN .................................. |   O-BOT   |
3894       //  BOTTOM  | ........................Object-BOTTOM ..................|
3895       //
3896       assert(loaded->ptr() != TypePtr::Null, "insanity check");
3897       //
3898       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
3899       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative, depth); }
3900       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
3901       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
3902         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
3903         else                                      { return TypeInstPtr::NOTNULL; }
3904       }
3905       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
3906 
3907       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
3908     }
3909 
3910     // Both are unloaded, not the same class, not Object
3911     // Or meet unloaded with a different loaded class, not java/lang/Object
3912     if( ptr != TypePtr::BotPTR ) {
3913       return TypeInstPtr::NOTNULL;
3914     }
3915     return TypeInstPtr::BOTTOM;
3916 }
3917 
3918 
3919 //------------------------------meet-------------------------------------------


3949 
3950   case AryPtr: {                // All arrays inherit from Object class
3951     const TypeAryPtr *tp = t->is_aryptr();
3952     Offset offset = meet_offset(tp->offset());
3953     PTR ptr = meet_ptr(tp->ptr());
3954     int instance_id = meet_instance_id(tp->instance_id());
3955     const TypePtr* speculative = xmeet_speculative(tp);
3956     int depth = meet_inline_depth(tp->inline_depth());
3957     switch (ptr) {
3958     case TopPTR:
3959     case AnyNull:                // Fall 'down' to dual of object klass
3960       // For instances when a subclass meets a superclass we fall
3961       // below the centerline when the superclass is exact. We need to
3962       // do the same here.
3963       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3964         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->field_offset(), instance_id, speculative, depth);
3965       } else {
3966         // cannot subclass, so the meet has to fall badly below the centerline
3967         ptr = NotNull;
3968         instance_id = InstanceBot;
3969         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3970       }
3971     case Constant:
3972     case NotNull:
3973     case BotPTR:                // Fall down to object klass
3974       // LCA is object_klass, but if we subclass from the top we can do better
3975       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
3976         // If 'this' (InstPtr) is above the centerline and it is Object class
3977         // then we can subclass in the Java class hierarchy.
3978         // For instances when a subclass meets a superclass we fall
3979         // below the centerline when the superclass is exact. We need
3980         // to do the same here.
3981         if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3982           // that is, tp's array type is a subtype of my klass
3983           return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
3984                                   tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->field_offset(), instance_id, speculative, depth);
3985         }
3986       }
3987       // The other case cannot happen, since I cannot be a subtype of an array.
3988       // The meet falls down to Object class below centerline.
3989       if( ptr == Constant )
3990          ptr = NotNull;
3991       instance_id = InstanceBot;
3992       return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3993     default: typerr(t);
3994     }
3995   }
3996 
3997   case OopPtr: {                // Meeting to OopPtrs
3998     // Found a OopPtr type vs self-InstPtr type
3999     const TypeOopPtr *tp = t->is_oopptr();
4000     Offset offset = meet_offset(tp->offset());
4001     PTR ptr = meet_ptr(tp->ptr());
4002     switch (tp->ptr()) {
4003     case TopPTR:
4004     case AnyNull: {
4005       int instance_id = meet_instance_id(InstanceTop);
4006       const TypePtr* speculative = xmeet_speculative(tp);
4007       int depth = meet_inline_depth(tp->inline_depth());
4008       return make(ptr, klass(), klass_is_exact(),
4009                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
4010     }
4011     case NotNull:
4012     case BotPTR: {
4013       int instance_id = meet_instance_id(tp->instance_id());
4014       const TypePtr* speculative = xmeet_speculative(tp);
4015       int depth = meet_inline_depth(tp->inline_depth());
4016       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4017     }
4018     default: typerr(t);
4019     }
4020   }
4021 
4022   case AnyPtr: {                // Meeting to AnyPtrs
4023     // Found an AnyPtr type vs self-InstPtr type
4024     const TypePtr *tp = t->is_ptr();
4025     Offset offset = meet_offset(tp->offset());
4026     PTR ptr = meet_ptr(tp->ptr());
4027     int instance_id = meet_instance_id(InstanceTop);
4028     const TypePtr* speculative = xmeet_speculative(tp);
4029     int depth = meet_inline_depth(tp->inline_depth());
4030     switch (tp->ptr()) {
4031     case Null:
4032       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4033       // else fall through to AnyNull
4034     case TopPTR:
4035     case AnyNull: {
4036       return make(ptr, klass(), klass_is_exact(),
4037                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
4038     }
4039     case NotNull:
4040     case BotPTR:
4041       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4042     default: typerr(t);
4043     }
4044   }
4045 
4046   /*
4047                  A-top         }
4048                /   |   \       }  Tops
4049            B-top A-any C-top   }
4050               | /  |  \ |      }  Any-nulls
4051            B-any   |   C-any   }
4052               |    |    |
4053            B-con A-con C-con   } constants; not comparable across classes
4054               |    |    |
4055            B-not   |   C-not   }
4056               | \  |  / |      }  not-nulls
4057            B-bot A-not C-bot   }
4058                \   |   /       }  Bottoms
4059                  A-bot         }
4060   */
4061 
4062   case InstPtr: {                // Meeting 2 Oops?
4063     // Found an InstPtr sub-type vs self-InstPtr type
4064     const TypeInstPtr *tinst = t->is_instptr();
4065     Offset off = meet_offset( tinst->offset() );
4066     PTR ptr = meet_ptr( tinst->ptr() );
4067     int instance_id = meet_instance_id(tinst->instance_id());
4068     const TypePtr* speculative = xmeet_speculative(tinst);
4069     int depth = meet_inline_depth(tinst->inline_depth());
4070 
4071     // Check for easy case; klasses are equal (and perhaps not loaded!)
4072     // If we have constants, then we created oops so classes are loaded
4073     // and we can handle the constants further down.  This case handles
4074     // both-not-loaded or both-loaded classes
4075     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
4076       return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth);

4077     }
4078 
4079     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4080     ciKlass* tinst_klass = tinst->klass();
4081     ciKlass* this_klass  = this->klass();
4082     bool tinst_xk = tinst->klass_is_exact();
4083     bool this_xk  = this->klass_is_exact();


4084     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
4085       // One of these classes has not been loaded
4086       const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
4087 #ifndef PRODUCT
4088       if( PrintOpto && Verbose ) {
4089         tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
4090         tty->print("  this == "); this->dump(); tty->cr();
4091         tty->print(" tinst == "); tinst->dump(); tty->cr();
4092       }
4093 #endif
4094       return unloaded_meet;
4095     }
4096 
4097     // Handle mixing oops and interfaces first.
4098     if( this_klass->is_interface() && !(tinst_klass->is_interface() ||
4099                                         tinst_klass == ciEnv::current()->Object_klass())) {
4100       ciKlass *tmp = tinst_klass; // Swap interface around
4101       tinst_klass = this_klass;
4102       this_klass = tmp;
4103       bool tmp2 = tinst_xk;
4104       tinst_xk = this_xk;
4105       this_xk = tmp2;



4106     }
4107     if (tinst_klass->is_interface() &&
4108         !(this_klass->is_interface() ||
4109           // Treat java/lang/Object as an honorary interface,
4110           // because we need a bottom for the interface hierarchy.
4111           this_klass == ciEnv::current()->Object_klass())) {
4112       // Oop meets interface!
4113 
4114       // See if the oop subtypes (implements) interface.
4115       ciKlass *k;
4116       bool xk;

4117       if( this_klass->is_subtype_of( tinst_klass ) ) {
4118         // Oop indeed subtypes.  Now keep oop or interface depending
4119         // on whether we are both above the centerline or either is
4120         // below the centerline.  If we are on the centerline
4121         // (e.g., Constant vs. AnyNull interface), use the constant.
4122         k  = below_centerline(ptr) ? tinst_klass : this_klass;
4123         // If we are keeping this_klass, keep its exactness too.
4124         xk = below_centerline(ptr) ? tinst_xk    : this_xk;

4125       } else {                  // Does not implement, fall to Object
4126         // Oop does not implement interface, so mixing falls to Object
4127         // just like the verifier does (if both are above the
4128         // centerline fall to interface)
4129         k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
4130         xk = above_centerline(ptr) ? tinst_xk : false;

4131         // Watch out for Constant vs. AnyNull interface.
4132         if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
4133         instance_id = InstanceBot;
4134       }
4135       ciObject* o = NULL;  // the Constant value, if any
4136       if (ptr == Constant) {
4137         // Find out which constant.
4138         o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
4139       }
4140       return make(ptr, k, xk, o, off, instance_id, speculative, depth);
4141     }
4142 
4143     // Either oop vs oop or interface vs interface or interface vs Object
4144 
4145     // !!! Here's how the symmetry requirement breaks down into invariants:
4146     // If we split one up & one down AND they subtype, take the down man.
4147     // If we split one up & one down AND they do NOT subtype, "fall hard".
4148     // If both are up and they subtype, take the subtype class.
4149     // If both are up and they do NOT subtype, "fall hard".
4150     // If both are down and they subtype, take the supertype class.
4151     // If both are down and they do NOT subtype, "fall hard".
4152     // Constants treated as down.
4153 
4154     // Now, reorder the above list; observe that both-down+subtype is also
4155     // "fall hard"; "fall hard" becomes the default case:
4156     // If we split one up & one down AND they subtype, take the down man.
4157     // If both are up and they subtype, take the subtype class.
4158 
4159     // If both are down and they subtype, "fall hard".
4160     // If both are down and they do NOT subtype, "fall hard".
4161     // If both are up and they do NOT subtype, "fall hard".
4162     // If we split one up & one down AND they do NOT subtype, "fall hard".
4163 
4164     // If a proper subtype is exact, and we return it, we return it exactly.
4165     // If a proper supertype is exact, there can be no subtyping relationship!
4166     // If both types are equal to the subtype, exactness is and-ed below the
4167     // centerline and or-ed above it.  (N.B. Constants are always exact.)
4168 
4169     // Check for subtyping:
4170     ciKlass *subtype = NULL;
4171     bool subtype_exact = false;

4172     if( tinst_klass->equals(this_klass) ) {
4173       subtype = this_klass;
4174       subtype_exact = below_centerline(ptr) ? (this_xk && tinst_xk) : (this_xk || tinst_xk);

4175     } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
4176       subtype = this_klass;     // Pick subtyping class
4177       subtype_exact = this_xk;

4178     } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
4179       subtype = tinst_klass;    // Pick subtyping class
4180       subtype_exact = tinst_xk;

4181     }
4182 
4183     if( subtype ) {
4184       if( above_centerline(ptr) ) { // both are up?
4185         this_klass = tinst_klass = subtype;
4186         this_xk = tinst_xk = subtype_exact;

4187       } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
4188         this_klass = tinst_klass; // tinst is down; keep down man
4189         this_xk = tinst_xk;

4190       } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
4191         tinst_klass = this_klass; // this is down; keep down man
4192         tinst_xk = this_xk;

4193       } else {
4194         this_xk = subtype_exact;  // either they are equal, or we'll do an LCA

4195       }
4196     }
4197 
4198     // Check for classes now being equal
4199     if (tinst_klass->equals(this_klass)) {
4200       // If the klasses are equal, the constants may still differ.  Fall to
4201       // NotNull if they do (neither constant is NULL; that is a special case
4202       // handled elsewhere).
4203       ciObject* o = NULL;             // Assume not constant when done
4204       ciObject* this_oop  = const_oop();
4205       ciObject* tinst_oop = tinst->const_oop();
4206       if( ptr == Constant ) {
4207         if (this_oop != NULL && tinst_oop != NULL &&
4208             this_oop->equals(tinst_oop) )
4209           o = this_oop;
4210         else if (above_centerline(this ->_ptr))
4211           o = tinst_oop;
4212         else if (above_centerline(tinst ->_ptr))
4213           o = this_oop;
4214         else
4215           ptr = NotNull;
4216       }
4217       return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth);
4218     } // Else classes are not equal
4219 
4220     // Since klasses are different, we require a LCA in the Java
4221     // class hierarchy - which means we have to fall to at least NotNull.
4222     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
4223       ptr = NotNull;
4224 
4225     instance_id = InstanceBot;
4226 
4227     // Now we find the LCA of Java classes
4228     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
4229     return make(ptr, k, false, NULL, off, instance_id, speculative, depth);
4230   } // End of case InstPtr
4231 
4232   case ValueType: {
4233     const TypeValueType* tv = t->is_valuetype();
4234     if (above_centerline(ptr())) {
4235       if (tv->value_klass()->is_subtype_of(_klass)) {
4236         return t;
4237       } else {
4238         return TypeInstPtr::make(NotNull, _klass);
4239       }
4240     } else {
4241       PTR ptr = this->_ptr;
4242       if (ptr == Constant) {
4243         ptr = NotNull;
4244       }
4245       if (tv->value_klass()->is_subtype_of(_klass)) {
4246         return TypeInstPtr::make(ptr, _klass);
4247       } else {
4248         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass());
4249       }


4254   return this;                  // Return the double constant
4255 }
4256 
4257 
4258 //------------------------java_mirror_type--------------------------------------
4259 ciType* TypeInstPtr::java_mirror_type(bool* is_indirect_type) const {
4260   // must be a singleton type
4261   if( const_oop() == NULL )  return NULL;
4262 
4263   // must be of type java.lang.Class
4264   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
4265 
4266   return const_oop()->as_instance()->java_mirror_type(is_indirect_type);
4267 }
4268 
4269 
4270 //------------------------------xdual------------------------------------------
4271 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4272 // inheritance mechanism.
4273 const Type *TypeInstPtr::xdual() const {
4274   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4275 }
4276 
4277 //------------------------------eq---------------------------------------------
4278 // Structural equality check for Type representations
4279 bool TypeInstPtr::eq( const Type *t ) const {
4280   const TypeInstPtr *p = t->is_instptr();
4281   return
4282     klass()->equals(p->klass()) &&

4283     TypeOopPtr::eq(p);          // Check sub-type stuff
4284 }
4285 
4286 //------------------------------hash-------------------------------------------
4287 // Type-specific hashing function.
4288 int TypeInstPtr::hash(void) const {
4289   int hash = java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash());
4290   return hash;
4291 }
4292 
4293 //------------------------------dump2------------------------------------------
4294 // Dump oop Type
4295 #ifndef PRODUCT
4296 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4297   // Print the name of the klass.
4298   klass()->print_name_on(st);
4299 
4300   switch( _ptr ) {
4301   case Constant:
4302     // TO DO: Make CI print the hex address of the underlying oop.
4303     if (WizardMode || Verbose) {
4304       const_oop()->print_oop(st);
4305     }
4306   case BotPTR:
4307     if (!WizardMode && !Verbose) {
4308       if( _klass_is_exact ) st->print(":exact");
4309       break;
4310     }
4311   case TopPTR:
4312   case AnyNull:
4313   case NotNull:
4314     st->print(":%s", ptr_msg[_ptr]);
4315     if( _klass_is_exact ) st->print(":exact");
4316     break;
4317   default:
4318     break;
4319   }
4320 
4321   _offset.dump2(st);
4322 
4323   st->print(" *");





4324   if (_instance_id == InstanceTop)
4325     st->print(",iid=top");
4326   else if (_instance_id != InstanceBot)
4327     st->print(",iid=%d",_instance_id);
4328 
4329   dump_inline_depth(st);
4330   dump_speculative(st);
4331 }
4332 #endif
4333 
4334 //------------------------------add_offset-------------------------------------
4335 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
4336   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset),
4337               _instance_id, add_offset_speculative(offset), _inline_depth);
4338 }
4339 
4340 const Type *TypeInstPtr::remove_speculative() const {
4341   if (_speculative == NULL) {
4342     return this;
4343   }
4344   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4345   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset,
4346               _instance_id, NULL, _inline_depth);
4347 }
4348 
4349 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
4350   if (!UseInlineDepthForSpeculativeTypes) {
4351     return this;
4352   }
4353   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4354 }
4355 
4356 const TypePtr *TypeInstPtr::with_instance_id(int instance_id) const {
4357   assert(is_known_instance(), "should be known");
4358   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4359 }
4360 





4361 //=============================================================================
4362 // Convenience common pre-built types.
4363 const TypeAryPtr *TypeAryPtr::RANGE;
4364 const TypeAryPtr *TypeAryPtr::OOPS;
4365 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4366 const TypeAryPtr *TypeAryPtr::BYTES;
4367 const TypeAryPtr *TypeAryPtr::SHORTS;
4368 const TypeAryPtr *TypeAryPtr::CHARS;
4369 const TypeAryPtr *TypeAryPtr::INTS;
4370 const TypeAryPtr *TypeAryPtr::LONGS;
4371 const TypeAryPtr *TypeAryPtr::FLOATS;
4372 const TypeAryPtr *TypeAryPtr::DOUBLES;
4373 const TypeAryPtr *TypeAryPtr::VALUES;
4374 
4375 //------------------------------make-------------------------------------------
4376 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4377                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4378   assert(!(k == NULL && ary->_elem->isa_int()),
4379          "integral arrays must be pre-equipped with a class");
4380   if (!xk) xk = ary->ary_must_be_exact();


4748   // All arrays inherit from Object class
4749   case InstPtr: {
4750     const TypeInstPtr *tp = t->is_instptr();
4751     Offset offset = meet_offset(tp->offset());
4752     PTR ptr = meet_ptr(tp->ptr());
4753     int instance_id = meet_instance_id(tp->instance_id());
4754     const TypePtr* speculative = xmeet_speculative(tp);
4755     int depth = meet_inline_depth(tp->inline_depth());
4756     switch (ptr) {
4757     case TopPTR:
4758     case AnyNull:                // Fall 'down' to dual of object klass
4759       // For instances when a subclass meets a superclass we fall
4760       // below the centerline when the superclass is exact. We need to
4761       // do the same here.
4762       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4763         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4764       } else {
4765         // cannot subclass, so the meet has to fall badly below the centerline
4766         ptr = NotNull;
4767         instance_id = InstanceBot;
4768         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
4769       }
4770     case Constant:
4771     case NotNull:
4772     case BotPTR:                // Fall down to object klass
4773       // LCA is object_klass, but if we subclass from the top we can do better
4774       if (above_centerline(tp->ptr())) {
4775         // If 'tp'  is above the centerline and it is Object class
4776         // then we can subclass in the Java class hierarchy.
4777         // For instances when a subclass meets a superclass we fall
4778         // below the centerline when the superclass is exact. We need
4779         // to do the same here.
4780         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4781           // that is, my array type is a subtype of 'tp' klass
4782           return make(ptr, (ptr == Constant ? const_oop() : NULL),
4783                       _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4784         }
4785       }
4786       // The other case cannot happen, since t cannot be a subtype of an array.
4787       // The meet falls down to Object class below centerline.
4788       if( ptr == Constant )
4789          ptr = NotNull;
4790       instance_id = InstanceBot;
4791       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
4792     default: typerr(t);
4793     }
4794   }
4795 
4796   case ValueType: {
4797     // All value types inherit from Object
4798     PTR ptr = this->_ptr;
4799     if (ptr == Constant) {
4800       ptr = NotNull;
4801     }
4802     return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass());
4803   }
4804 
4805   }
4806   return this;                  // Lint noise
4807 }
4808 
4809 //------------------------------xdual------------------------------------------
4810 // Dual: compute field-by-field dual
4811 const Type *TypeAryPtr::xdual() const {


5309 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5310   return make(Constant, m, Offset(0));
5311 }
5312 
5313 //------------------------------make-------------------------------------------
5314 // Create a meta data constant
5315 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
5316   assert(m == NULL || !m->is_klass(), "wrong type");
5317   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5318 }
5319 
5320 
5321 //=============================================================================
5322 // Convenience common pre-built types.
5323 
5324 // Not-null object klass or below
5325 const TypeKlassPtr *TypeKlassPtr::OBJECT;
5326 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
5327 
5328 //------------------------------TypeKlassPtr-----------------------------------
5329 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, Offset offset )
5330   : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) {


5331 }
5332 
5333 //------------------------------make-------------------------------------------
5334 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
5335 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* k, Offset offset) {
5336   assert(k == NULL || k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
5337   return (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
5338 }
5339 
5340 //------------------------------eq---------------------------------------------
5341 // Structural equality check for Type representations
5342 bool TypeKlassPtr::eq( const Type *t ) const {
5343   const TypeKlassPtr *p = t->is_klassptr();
5344   return klass() == p->klass() && TypePtr::eq(p);
5345 }
5346 
5347 //------------------------------hash-------------------------------------------
5348 // Type-specific hashing function.
5349 int TypeKlassPtr::hash(void) const {
5350   return java_add(klass() != NULL ? klass()->hash() : (jint)0, (jint)TypePtr::hash());
5351 }
5352 
5353 //------------------------------singleton--------------------------------------
5354 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5355 // constants
5356 bool TypeKlassPtr::singleton(void) const {
5357   // detune optimizer to not generate constant klass + constant offset as a constant!
5358   // TopPTR, Null, AnyNull, Constant are all singletons
5359   return (offset() == 0) && !below_centerline(_ptr);
5360 }
5361 
5362 // Do not allow interface-vs.-noninterface joins to collapse to top.
5363 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5364   // logic here mirrors the one from TypeOopPtr::filter. See comments
5365   // there.
5366   const Type* ft = join_helper(kills, include_speculative);
5367   const TypeKlassPtr* ftkp = ft->isa_klassptr();
5368   const TypeKlassPtr* ktkp = kills->isa_klassptr();
5369 
5370   if (ft->empty()) {


5464     // active compilations.  However, the ciKlass which represents
5465     // this Type is *not* shared between compilations, so caching
5466     // this value would result in fetching a dangling pointer.
5467     //
5468     // Recomputing the underlying ciKlass for each request is
5469     // a bit less efficient than caching, but calls to
5470     // TypeAryPtr::OOPS->klass() are not common enough to matter.
5471     ((TypeAryPtr*)this)->_klass = k_ary;
5472     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
5473         offset() != 0 && offset() != arrayOopDesc::length_offset_in_bytes()) {
5474       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
5475     }
5476   }
5477   return k_ary;
5478 }
5479 
5480 
5481 //------------------------------add_offset-------------------------------------
5482 // Access internals of klass object
5483 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
5484   return make( _ptr, klass(), xadd_offset(offset) );
5485 }
5486 
5487 //------------------------------cast_to_ptr_type-------------------------------
5488 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
5489   assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
5490   if( ptr == _ptr ) return this;
5491   return make(ptr, _klass, _offset);
5492 }
5493 
5494 
5495 //-----------------------------cast_to_exactness-------------------------------
5496 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5497   if( klass_is_exact == _klass_is_exact ) return this;
5498   if (!UseExactTypes)  return this;
5499   return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
5500 }
5501 
5502 
5503 //-----------------------------as_instance_type--------------------------------
5504 // Corresponding type for an instance of the given class.
5505 // It will be NotNull, and exact if and only if the klass type is exact.
5506 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
5507   ciKlass* k = klass();
5508   assert(k != NULL, "klass should not be NULL");
5509   bool    xk = klass_is_exact();
5510   //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
5511   const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
5512   guarantee(toop != NULL, "need type for given klass");
5513   toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();



5514   return toop->cast_to_exactness(xk)->is_oopptr();
5515 }
5516 
5517 
5518 //------------------------------xmeet------------------------------------------
5519 // Compute the MEET of two types, return a new Type object.
5520 const Type    *TypeKlassPtr::xmeet( const Type *t ) const {
5521   // Perform a fast test for common case; meeting the same types together.
5522   if( this == t ) return this;  // Meeting same type-rep?
5523 
5524   // Current "this->_base" is Pointer
5525   switch (t->base()) {          // switch on original type
5526 
5527   case Int:                     // Mixing ints & oops happens when javac
5528   case Long:                    // reuses local variables
5529   case FloatTop:
5530   case FloatCon:
5531   case FloatBot:
5532   case DoubleTop:
5533   case DoubleCon:


5536   case NarrowKlass:
5537   case Bottom:                  // Ye Olde Default
5538     return Type::BOTTOM;
5539   case Top:
5540     return this;
5541 
5542   default:                      // All else is a mistake
5543     typerr(t);
5544 
5545   case AnyPtr: {                // Meeting to AnyPtrs
5546     // Found an AnyPtr type vs self-KlassPtr type
5547     const TypePtr *tp = t->is_ptr();
5548     Offset offset = meet_offset(tp->offset());
5549     PTR ptr = meet_ptr(tp->ptr());
5550     switch (tp->ptr()) {
5551     case TopPTR:
5552       return this;
5553     case Null:
5554       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5555     case AnyNull:
5556       return make( ptr, klass(), offset );
5557     case BotPTR:
5558     case NotNull:
5559       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5560     default: typerr(t);
5561     }
5562   }
5563 
5564   case RawPtr:
5565   case MetadataPtr:
5566   case OopPtr:
5567   case AryPtr:                  // Meet with AryPtr
5568   case InstPtr:                 // Meet with InstPtr
5569     return TypePtr::BOTTOM;
5570 
5571   //
5572   //             A-top         }
5573   //           /   |   \       }  Tops
5574   //       B-top A-any C-top   }
5575   //          | /  |  \ |      }  Any-nulls
5576   //       B-any   |   C-any   }
5577   //          |    |    |
5578   //       B-con A-con C-con   } constants; not comparable across classes
5579   //          |    |    |
5580   //       B-not   |   C-not   }
5581   //          | \  |  / |      }  not-nulls
5582   //       B-bot A-not C-bot   }
5583   //           \   |   /       }  Bottoms
5584   //             A-bot         }
5585   //
5586 
5587   case KlassPtr: {  // Meet two KlassPtr types
5588     const TypeKlassPtr *tkls = t->is_klassptr();
5589     Offset  off  = meet_offset(tkls->offset());
5590     PTR  ptr     = meet_ptr(tkls->ptr());
5591 
5592     if (klass() == NULL || tkls->klass() == NULL) {
5593       ciKlass* k = NULL;
5594       if (ptr == Constant) {
5595         k = (klass() == NULL) ? tkls->klass() : klass();
5596       }
5597       return make(ptr, k, off);
5598     }
5599 
5600     // Check for easy case; klasses are equal (and perhaps not loaded!)
5601     // If we have constants, then we created oops so classes are loaded
5602     // and we can handle the constants further down.  This case handles
5603     // not-loaded classes
5604     if( ptr != Constant && tkls->klass()->equals(klass()) ) {
5605       return make( ptr, klass(), off );
5606     }
5607 
5608     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
5609     ciKlass* tkls_klass = tkls->klass();
5610     ciKlass* this_klass = this->klass();
5611     assert( tkls_klass->is_loaded(), "This class should have been loaded.");
5612     assert( this_klass->is_loaded(), "This class should have been loaded.");



5613 
5614     // If 'this' type is above the centerline and is a superclass of the
5615     // other, we can treat 'this' as having the same type as the other.
5616     if ((above_centerline(this->ptr())) &&
5617         tkls_klass->is_subtype_of(this_klass)) {
5618       this_klass = tkls_klass;
5619     }
5620     // If 'tinst' type is above the centerline and is a superclass of the
5621     // other, we can treat 'tinst' as having the same type as the other.
5622     if ((above_centerline(tkls->ptr())) &&
5623         this_klass->is_subtype_of(tkls_klass)) {
5624       tkls_klass = this_klass;
5625     }
5626 
5627     // Check for classes now being equal
5628     if (tkls_klass->equals(this_klass)) {
5629       // If the klasses are equal, the constants may still differ.  Fall to
5630       // NotNull if they do (neither constant is NULL; that is a special case
5631       // handled elsewhere).
5632       if( ptr == Constant ) {
5633         if (this->_ptr == Constant && tkls->_ptr == Constant &&
5634             this->klass()->equals(tkls->klass()));
5635         else if (above_centerline(this->ptr()));
5636         else if (above_centerline(tkls->ptr()));
5637         else
5638           ptr = NotNull;
5639       }
5640       return make( ptr, this_klass, off );
5641     } // Else classes are not equal
5642 
5643     // Since klasses are different, we require the LCA in the Java
5644     // class hierarchy - which means we have to fall to at least NotNull.
5645     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
5646       ptr = NotNull;
5647     // Now we find the LCA of Java classes
5648     ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
5649     return   make( ptr, k, off );
5650   } // End of case KlassPtr
5651 
5652   } // End of switch
5653   return this;                  // Return the double constant
5654 }
5655 
5656 //------------------------------xdual------------------------------------------
5657 // Dual: compute field-by-field dual
5658 const Type    *TypeKlassPtr::xdual() const {
5659   return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
5660 }
5661 
5662 //------------------------------get_con----------------------------------------
5663 intptr_t TypeKlassPtr::get_con() const {
5664   assert( _ptr == Null || _ptr == Constant, "" );
5665   assert(offset() >= 0, "");
5666 
5667   if (offset() != 0) {
5668     // After being ported to the compiler interface, the compiler no longer
5669     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5670     // to a handle at compile time.  This handle is embedded in the generated
5671     // code and dereferenced at the time the nmethod is made.  Until that time,
5672     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5673     // have access to the addresses!).  This does not seem to currently happen,
5674     // but this assertion here is to help prevent its occurence.
5675     tty->print_cr("Found oop constant with non-zero offset");
5676     ShouldNotReachHere();
5677   }
5678 
5679   return (intptr_t)klass()->constant_encoding();




 577 
 578   TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, Offset(0));
 579   TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, Offset::bottom);
 580   TypePtr::BOTTOM  = TypePtr::make(AnyPtr, TypePtr::BotPTR, Offset::bottom);
 581 
 582   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
 583   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
 584 
 585   const Type **fmembar = TypeTuple::fields(0);
 586   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
 587 
 588   const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
 589   fsc[0] = TypeInt::CC;
 590   fsc[1] = Type::MEMORY;
 591   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
 592 
 593   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
 594   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
 595   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
 596   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 597                                            false, 0, Offset(oopDesc::mark_offset_in_bytes()), false);
 598   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 599                                            false, 0, Offset(oopDesc::klass_offset_in_bytes()), false);
 600   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
 601 
 602   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, Offset::bottom);
 603 
 604   TypeValueType::BOTTOM = TypeValueType::make(NULL);
 605 
 606   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
 607   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
 608 
 609   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
 610 
 611   mreg2type[Op_Node] = Type::BOTTOM;
 612   mreg2type[Op_Set ] = 0;
 613   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
 614   mreg2type[Op_RegI] = TypeInt::INT;
 615   mreg2type[Op_RegP] = TypePtr::BOTTOM;
 616   mreg2type[Op_RegF] = Type::FLOAT;
 617   mreg2type[Op_RegD] = Type::DOUBLE;
 618   mreg2type[Op_RegL] = TypeLong::LONG;
 619   mreg2type[Op_RegFlags] = TypeInt::CC;


 638   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Offset::bottom);
 639   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Offset::bottom);
 640   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Offset::bottom);
 641   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Offset::bottom);
 642   TypeAryPtr::VALUES  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeValueType::BOTTOM,TypeInt::POS), NULL, false,  Offset::bottom);
 643 
 644   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
 645   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
 646   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
 647   TypeAryPtr::_array_body_type[T_VALUETYPE] = TypeAryPtr::OOPS;
 648   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
 649   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
 650   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
 651   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
 652   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
 653   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
 654   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
 655   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
 656   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
 657 
 658   TypeKlassPtr::OBJECT = TypeKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), Offset(0), false);
 659   TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), Offset(0), false );
 660 
 661   const Type **fi2c = TypeTuple::fields(2);
 662   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
 663   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
 664   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
 665 
 666   const Type **intpair = TypeTuple::fields(2);
 667   intpair[0] = TypeInt::INT;
 668   intpair[1] = TypeInt::INT;
 669   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
 670 
 671   const Type **longpair = TypeTuple::fields(2);
 672   longpair[0] = TypeLong::LONG;
 673   longpair[1] = TypeLong::LONG;
 674   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
 675 
 676   const Type **intccpair = TypeTuple::fields(2);
 677   intccpair[0] = TypeInt::INT;
 678   intccpair[1] = TypeInt::CC;
 679   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);


3331   return this;
3332 }
3333 
3334 //-----------------------------cast_to_exactness-------------------------------
3335 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3336   // There is no such thing as an exact general oop.
3337   // Return self unchanged.
3338   return this;
3339 }
3340 
3341 
3342 //------------------------------as_klass_type----------------------------------
3343 // Return the klass type corresponding to this instance or array type.
3344 // It is the type that is loaded from an object of this type.
3345 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
3346   ciKlass* k = klass();
3347   bool    xk = klass_is_exact();
3348   if (k == NULL)
3349     return TypeKlassPtr::OBJECT;
3350   else
3351     return TypeKlassPtr::make(xk? Constant: NotNull, k, Offset(0), isa_instptr() && is_instptr()->flat_array());
3352 }
3353 
3354 //------------------------------meet-------------------------------------------
3355 // Compute the MEET of two types.  It returns a new Type object.
3356 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3357   // Perform a fast test for common case; meeting the same types together.
3358   if( this == t ) return this;  // Meeting same type-rep?
3359 
3360   // Current "this->_base" is OopPtr
3361   switch (t->base()) {          // switch on original type
3362 
3363   case Int:                     // Mixing ints & oops happens when javac
3364   case Long:                    // reuses local variables
3365   case FloatTop:
3366   case FloatCon:
3367   case FloatBot:
3368   case DoubleTop:
3369   case DoubleCon:
3370   case DoubleBot:
3371   case NarrowOop:


3445       ciInstanceKlass* ik = klass->as_instance_klass();
3446       klass_is_exact = ik->is_final();
3447       if (!klass_is_exact && klass_change
3448           && deps != NULL && UseUniqueSubclasses) {
3449         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3450         if (sub != NULL) {
3451           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3452           klass = ik = sub;
3453           klass_is_exact = sub->is_final();
3454         }
3455       }
3456       if (!klass_is_exact && try_for_exact
3457           && deps != NULL && UseExactTypes) {
3458         if (!ik->is_interface() && !ik->has_subklass()) {
3459           // Add a dependence; if concrete subclass added we need to recompile
3460           deps->assert_leaf_type(ik);
3461           klass_is_exact = true;
3462         }
3463       }
3464     }
3465     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, Offset(0), klass->flatten_array());
3466   } else if (klass->is_obj_array_klass()) {
3467     // Element is an object or value array. Recursively call ourself.
3468     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), false, try_for_exact);
3469     bool null_free = klass->is_loaded() && klass->as_array_klass()->storage_properties().is_null_free();
3470     if (null_free) {
3471       assert(etype->is_valuetypeptr(), "must be a valuetypeptr");
3472       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3473     }
3474     // [V? has a subtype: [V. So even though V is final, [V? is not exact.
3475     bool xk = etype->klass_is_exact() && (!etype->is_valuetypeptr() || null_free);
3476     bool not_null_free = !etype->can_be_value_type() || xk;
3477     bool not_flat = !ValueArrayFlatten || not_null_free || (etype->is_valuetypeptr() && !etype->value_klass()->flatten_array());
3478     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, false, not_flat, not_null_free);
3479     // We used to pass NotNull in here, asserting that the sub-arrays
3480     // are all not-null.  This is not true in generally, as code can
3481     // slam NULLs down in the subarrays.
3482     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0));
3483     return arr;
3484   } else if (klass->is_type_array_klass()) {
3485     // Element is an typeArray


3497     return arr;
3498   } else {
3499     ShouldNotReachHere();
3500     return NULL;
3501   }
3502 }
3503 
3504 //------------------------------make_from_constant-----------------------------
3505 // Make a java pointer from an oop constant
3506 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3507   assert(!o->is_null_object(), "null object not yet handled here.");
3508 
3509   const bool make_constant = require_constant || o->should_be_constant();
3510 
3511   ciKlass* klass = o->klass();
3512   if (klass->is_instance_klass() || klass->is_valuetype()) {
3513     // Element is an instance or value type
3514     if (make_constant) {
3515       return TypeInstPtr::make(o);
3516     } else {
3517       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0), klass->flatten_array());
3518     }
3519   } else if (klass->is_obj_array_klass()) {
3520     // Element is an object array. Recursively call ourself.
3521     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass());
3522     bool null_free = klass->is_loaded() && klass->as_array_klass()->storage_properties().is_null_free();
3523     if (null_free) {
3524       assert(etype->is_valuetypeptr(), "must be a valuetypeptr");
3525       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3526     }
3527     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3528                                         /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ !null_free);
3529     // We used to pass NotNull in here, asserting that the sub-arrays
3530     // are all not-null.  This is not true in generally, as code can
3531     // slam NULLs down in the subarrays.
3532     if (make_constant) {
3533       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3534     } else {
3535       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3536     }
3537   } else if (klass->is_type_array_klass()) {


3754  * @return  true if type profile is valuable
3755  */
3756 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3757   // no way to improve an already exact type
3758   if (klass_is_exact()) {
3759     return false;
3760   }
3761   return TypePtr::would_improve_type(exact_kls, inline_depth);
3762 }
3763 
3764 //=============================================================================
3765 // Convenience common pre-built types.
3766 const TypeInstPtr *TypeInstPtr::NOTNULL;
3767 const TypeInstPtr *TypeInstPtr::BOTTOM;
3768 const TypeInstPtr *TypeInstPtr::MIRROR;
3769 const TypeInstPtr *TypeInstPtr::MARK;
3770 const TypeInstPtr *TypeInstPtr::KLASS;
3771 
3772 //------------------------------TypeInstPtr-------------------------------------
3773 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset off,
3774                          bool flat_array, int instance_id, const TypePtr* speculative,
3775                          int inline_depth)
3776   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
3777     _name(k->name()), _flat_array(flat_array) {
3778    assert(k != NULL &&
3779           (k->is_loaded() || o == NULL),
3780           "cannot have constants with non-loaded klass");
3781    assert(!klass()->is_valuetype() || !klass()->flatten_array() || flat_array, "incorrect flatten array bit");
3782    assert(!flat_array || can_be_value_type(), "incorrect flatten array bit");
3783 };
3784 
3785 //------------------------------make-------------------------------------------
3786 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3787                                      ciKlass* k,
3788                                      bool xk,
3789                                      ciObject* o,
3790                                      Offset offset,
3791                                      bool flat_array,
3792                                      int instance_id,
3793                                      const TypePtr* speculative,
3794                                      int inline_depth) {
3795   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3796   // Either const_oop() is NULL or else ptr is Constant
3797   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3798           "constant pointers must have a value supplied" );
3799   // Ptr is never Null
3800   assert( ptr != Null, "NULL pointers are not typed" );
3801 
3802   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3803   if (!UseExactTypes)  xk = false;
3804   if (ptr == Constant) {
3805     // Note:  This case includes meta-object constants, such as methods.
3806     xk = true;
3807   } else if (k->is_loaded()) {
3808     ciInstanceKlass* ik = k->as_instance_klass();
3809     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3810     if (xk && ik->is_interface())  xk = false;  // no exact interface
3811   }
3812 
3813   // Now hash this baby
3814   TypeInstPtr *result =
3815     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, flat_array, instance_id, speculative, inline_depth))->hashcons();
3816 
3817   return result;
3818 }
3819 
3820 /**
3821  *  Create constant type for a constant boxed value
3822  */
3823 const Type* TypeInstPtr::get_const_boxed_value() const {
3824   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3825   assert((const_oop() != NULL), "should be called only for constant object");
3826   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3827   BasicType bt = constant.basic_type();
3828   switch (bt) {
3829     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
3830     case T_INT:      return TypeInt::make(constant.as_int());
3831     case T_CHAR:     return TypeInt::make(constant.as_char());
3832     case T_BYTE:     return TypeInt::make(constant.as_byte());
3833     case T_SHORT:    return TypeInt::make(constant.as_short());
3834     case T_FLOAT:    return TypeF::make(constant.as_float());
3835     case T_DOUBLE:   return TypeD::make(constant.as_double());
3836     case T_LONG:     return TypeLong::make(constant.as_long());
3837     default:         break;
3838   }
3839   fatal("Invalid boxed value type '%s'", type2name(bt));
3840   return NULL;
3841 }
3842 
3843 //------------------------------cast_to_ptr_type-------------------------------
3844 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3845   if( ptr == _ptr ) return this;
3846   // Reconstruct _sig info here since not a problem with later lazy
3847   // construction, _sig will show up on demand.
3848   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _flat_array, _instance_id, _speculative, _inline_depth);
3849 }
3850 
3851 
3852 //-----------------------------cast_to_exactness-------------------------------
3853 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3854   if( klass_is_exact == _klass_is_exact ) return this;
3855   if (!UseExactTypes)  return this;
3856   if (!_klass->is_loaded())  return this;
3857   ciInstanceKlass* ik = _klass->as_instance_klass();
3858   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3859   if( ik->is_interface() )              return this;  // cannot set xk
3860   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _flat_array, _instance_id, _speculative, _inline_depth);
3861 }
3862 
3863 //-----------------------------cast_to_instance_id----------------------------
3864 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3865   if( instance_id == _instance_id ) return this;
3866   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, _flat_array, instance_id, _speculative, _inline_depth);
3867 }
3868 
3869 const TypeOopPtr *TypeInstPtr::cast_to_nonconst() const {
3870   if (const_oop() == NULL) return this;
3871   return make(NotNull, klass(), _klass_is_exact, NULL, _offset, _flat_array, _instance_id, _speculative, _inline_depth);
3872 }
3873 
3874 //------------------------------xmeet_unloaded---------------------------------
3875 // Compute the MEET of two InstPtrs when at least one is unloaded.
3876 // Assume classes are different since called after check for same name/class-loader
3877 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3878     Offset off = meet_offset(tinst->offset());
3879     PTR ptr = meet_ptr(tinst->ptr());
3880     int instance_id = meet_instance_id(tinst->instance_id());
3881     const TypePtr* speculative = xmeet_speculative(tinst);
3882     int depth = meet_inline_depth(tinst->inline_depth());
3883 
3884     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3885     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3886     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3887       //
3888       // Meet unloaded class with java/lang/Object
3889       //
3890       // Meet
3891       //          |                     Unloaded Class
3892       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3893       //  ===================================================================
3894       //   TOP    | ..........................Unloaded......................|
3895       //  AnyNull |  U-AN    |................Unloaded......................|
3896       // Constant | ... O-NN .................................. |   O-BOT   |
3897       //  NotNull | ... O-NN .................................. |   O-BOT   |
3898       //  BOTTOM  | ........................Object-BOTTOM ..................|
3899       //
3900       assert(loaded->ptr() != TypePtr::Null, "insanity check");
3901       //
3902       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
3903       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, false, instance_id, speculative, depth); }
3904       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
3905       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
3906         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
3907         else                                      { return TypeInstPtr::NOTNULL; }
3908       }
3909       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
3910 
3911       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
3912     }
3913 
3914     // Both are unloaded, not the same class, not Object
3915     // Or meet unloaded with a different loaded class, not java/lang/Object
3916     if( ptr != TypePtr::BotPTR ) {
3917       return TypeInstPtr::NOTNULL;
3918     }
3919     return TypeInstPtr::BOTTOM;
3920 }
3921 
3922 
3923 //------------------------------meet-------------------------------------------


3953 
3954   case AryPtr: {                // All arrays inherit from Object class
3955     const TypeAryPtr *tp = t->is_aryptr();
3956     Offset offset = meet_offset(tp->offset());
3957     PTR ptr = meet_ptr(tp->ptr());
3958     int instance_id = meet_instance_id(tp->instance_id());
3959     const TypePtr* speculative = xmeet_speculative(tp);
3960     int depth = meet_inline_depth(tp->inline_depth());
3961     switch (ptr) {
3962     case TopPTR:
3963     case AnyNull:                // Fall 'down' to dual of object klass
3964       // For instances when a subclass meets a superclass we fall
3965       // below the centerline when the superclass is exact. We need to
3966       // do the same here.
3967       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3968         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->field_offset(), instance_id, speculative, depth);
3969       } else {
3970         // cannot subclass, so the meet has to fall badly below the centerline
3971         ptr = NotNull;
3972         instance_id = InstanceBot;
3973         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, false, instance_id, speculative, depth);
3974       }
3975     case Constant:
3976     case NotNull:
3977     case BotPTR:                // Fall down to object klass
3978       // LCA is object_klass, but if we subclass from the top we can do better
3979       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
3980         // If 'this' (InstPtr) is above the centerline and it is Object class
3981         // then we can subclass in the Java class hierarchy.
3982         // For instances when a subclass meets a superclass we fall
3983         // below the centerline when the superclass is exact. We need
3984         // to do the same here.
3985         if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3986           // that is, tp's array type is a subtype of my klass
3987           return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
3988                                   tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->field_offset(), instance_id, speculative, depth);
3989         }
3990       }
3991       // The other case cannot happen, since I cannot be a subtype of an array.
3992       // The meet falls down to Object class below centerline.
3993       if( ptr == Constant )
3994          ptr = NotNull;
3995       instance_id = InstanceBot;
3996       return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, false, instance_id, speculative, depth);
3997     default: typerr(t);
3998     }
3999   }
4000 
4001   case OopPtr: {                // Meeting to OopPtrs
4002     // Found a OopPtr type vs self-InstPtr type
4003     const TypeOopPtr *tp = t->is_oopptr();
4004     Offset offset = meet_offset(tp->offset());
4005     PTR ptr = meet_ptr(tp->ptr());
4006     switch (tp->ptr()) {
4007     case TopPTR:
4008     case AnyNull: {
4009       int instance_id = meet_instance_id(InstanceTop);
4010       const TypePtr* speculative = xmeet_speculative(tp);
4011       int depth = meet_inline_depth(tp->inline_depth());
4012       return make(ptr, klass(), klass_is_exact(),
4013                   (ptr == Constant ? const_oop() : NULL), offset, flat_array(), instance_id, speculative, depth);
4014     }
4015     case NotNull:
4016     case BotPTR: {
4017       int instance_id = meet_instance_id(tp->instance_id());
4018       const TypePtr* speculative = xmeet_speculative(tp);
4019       int depth = meet_inline_depth(tp->inline_depth());
4020       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4021     }
4022     default: typerr(t);
4023     }
4024   }
4025 
4026   case AnyPtr: {                // Meeting to AnyPtrs
4027     // Found an AnyPtr type vs self-InstPtr type
4028     const TypePtr *tp = t->is_ptr();
4029     Offset offset = meet_offset(tp->offset());
4030     PTR ptr = meet_ptr(tp->ptr());
4031     int instance_id = meet_instance_id(InstanceTop);
4032     const TypePtr* speculative = xmeet_speculative(tp);
4033     int depth = meet_inline_depth(tp->inline_depth());
4034     switch (tp->ptr()) {
4035     case Null:
4036       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4037       // else fall through to AnyNull
4038     case TopPTR:
4039     case AnyNull: {
4040       return make(ptr, klass(), klass_is_exact(),
4041                   (ptr == Constant ? const_oop() : NULL), offset, flat_array(), instance_id, speculative, depth);
4042     }
4043     case NotNull:
4044     case BotPTR:
4045       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4046     default: typerr(t);
4047     }
4048   }
4049 
4050   /*
4051                  A-top         }
4052                /   |   \       }  Tops
4053            B-top A-any C-top   }
4054               | /  |  \ |      }  Any-nulls
4055            B-any   |   C-any   }
4056               |    |    |
4057            B-con A-con C-con   } constants; not comparable across classes
4058               |    |    |
4059            B-not   |   C-not   }
4060               | \  |  / |      }  not-nulls
4061            B-bot A-not C-bot   }
4062                \   |   /       }  Bottoms
4063                  A-bot         }
4064   */
4065 
4066   case InstPtr: {                // Meeting 2 Oops?
4067     // Found an InstPtr sub-type vs self-InstPtr type
4068     const TypeInstPtr *tinst = t->is_instptr();
4069     Offset off = meet_offset( tinst->offset() );
4070     PTR ptr = meet_ptr( tinst->ptr() );
4071     int instance_id = meet_instance_id(tinst->instance_id());
4072     const TypePtr* speculative = xmeet_speculative(tinst);
4073     int depth = meet_inline_depth(tinst->inline_depth());
4074 
4075     // Check for easy case; klasses are equal (and perhaps not loaded!)
4076     // If we have constants, then we created oops so classes are loaded
4077     // and we can handle the constants further down.  This case handles
4078     // both-not-loaded or both-loaded classes
4079     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact() &&
4080         flat_array() == tinst->flat_array()) {
4081       return make(ptr, klass(), klass_is_exact(), NULL, off, flat_array(), instance_id, speculative, depth);
4082     }
4083 
4084     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4085     ciKlass* tinst_klass = tinst->klass();
4086     ciKlass* this_klass  = this->klass();
4087     bool tinst_xk = tinst->klass_is_exact();
4088     bool this_xk  = this->klass_is_exact();
4089     bool tinst_flat_array = tinst->flat_array();
4090     bool this_flat_array  = this->flat_array();
4091     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
4092       // One of these classes has not been loaded
4093       const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
4094 #ifndef PRODUCT
4095       if( PrintOpto && Verbose ) {
4096         tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
4097         tty->print("  this == "); this->dump(); tty->cr();
4098         tty->print(" tinst == "); tinst->dump(); tty->cr();
4099       }
4100 #endif
4101       return unloaded_meet;
4102     }
4103 
4104     // Handle mixing oops and interfaces first.
4105     if( this_klass->is_interface() && !(tinst_klass->is_interface() ||
4106                                         tinst_klass == ciEnv::current()->Object_klass())) {
4107       ciKlass *tmp = tinst_klass; // Swap interface around
4108       tinst_klass = this_klass;
4109       this_klass = tmp;
4110       bool tmp2 = tinst_xk;
4111       tinst_xk = this_xk;
4112       this_xk = tmp2;
4113       tmp2 = tinst_flat_array;
4114       tinst_flat_array = this_flat_array;
4115       this_flat_array = tmp2;
4116     }
4117     if (tinst_klass->is_interface() &&
4118         !(this_klass->is_interface() ||
4119           // Treat java/lang/Object as an honorary interface,
4120           // because we need a bottom for the interface hierarchy.
4121           this_klass == ciEnv::current()->Object_klass())) {
4122       // Oop meets interface!
4123 
4124       // See if the oop subtypes (implements) interface.
4125       ciKlass *k;
4126       bool xk;
4127       bool flat_array;
4128       if( this_klass->is_subtype_of( tinst_klass ) ) {
4129         // Oop indeed subtypes.  Now keep oop or interface depending
4130         // on whether we are both above the centerline or either is
4131         // below the centerline.  If we are on the centerline
4132         // (e.g., Constant vs. AnyNull interface), use the constant.
4133         k  = below_centerline(ptr) ? tinst_klass : this_klass;
4134         // If we are keeping this_klass, keep its exactness too.
4135         xk = below_centerline(ptr) ? tinst_xk    : this_xk;
4136         flat_array = below_centerline(ptr) ? tinst_flat_array    : this_flat_array;
4137       } else {                  // Does not implement, fall to Object
4138         // Oop does not implement interface, so mixing falls to Object
4139         // just like the verifier does (if both are above the
4140         // centerline fall to interface)
4141         k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
4142         xk = above_centerline(ptr) ? tinst_xk : false;
4143         flat_array = above_centerline(ptr) ? tinst_flat_array : false;
4144         // Watch out for Constant vs. AnyNull interface.
4145         if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
4146         instance_id = InstanceBot;
4147       }
4148       ciObject* o = NULL;  // the Constant value, if any
4149       if (ptr == Constant) {
4150         // Find out which constant.
4151         o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
4152       }
4153       return make(ptr, k, xk, o, off, flat_array, instance_id, speculative, depth);
4154     }
4155 
4156     // Either oop vs oop or interface vs interface or interface vs Object
4157 
4158     // !!! Here's how the symmetry requirement breaks down into invariants:
4159     // If we split one up & one down AND they subtype, take the down man.
4160     // If we split one up & one down AND they do NOT subtype, "fall hard".
4161     // If both are up and they subtype, take the subtype class.
4162     // If both are up and they do NOT subtype, "fall hard".
4163     // If both are down and they subtype, take the supertype class.
4164     // If both are down and they do NOT subtype, "fall hard".
4165     // Constants treated as down.
4166 
4167     // Now, reorder the above list; observe that both-down+subtype is also
4168     // "fall hard"; "fall hard" becomes the default case:
4169     // If we split one up & one down AND they subtype, take the down man.
4170     // If both are up and they subtype, take the subtype class.
4171 
4172     // If both are down and they subtype, "fall hard".
4173     // If both are down and they do NOT subtype, "fall hard".
4174     // If both are up and they do NOT subtype, "fall hard".
4175     // If we split one up & one down AND they do NOT subtype, "fall hard".
4176 
4177     // If a proper subtype is exact, and we return it, we return it exactly.
4178     // If a proper supertype is exact, there can be no subtyping relationship!
4179     // If both types are equal to the subtype, exactness is and-ed below the
4180     // centerline and or-ed above it.  (N.B. Constants are always exact.)
4181 
4182     // Check for subtyping:
4183     ciKlass *subtype = NULL;
4184     bool subtype_exact = false;
4185     bool flat_array = false;
4186     if( tinst_klass->equals(this_klass) ) {
4187       subtype = this_klass;
4188       subtype_exact = below_centerline(ptr) ? (this_xk && tinst_xk) : (this_xk || tinst_xk);
4189       flat_array = below_centerline(ptr) ? (this_flat_array && tinst_flat_array) : (this_flat_array || tinst_flat_array);
4190     } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
4191       subtype = this_klass;     // Pick subtyping class
4192       subtype_exact = this_xk;
4193       flat_array = this_flat_array;
4194     } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
4195       subtype = tinst_klass;    // Pick subtyping class
4196       subtype_exact = tinst_xk;
4197       flat_array = tinst_flat_array;
4198     }
4199 
4200     if( subtype ) {
4201       if( above_centerline(ptr) ) { // both are up?
4202         this_klass = tinst_klass = subtype;
4203         this_xk = tinst_xk = subtype_exact;
4204         this_flat_array = tinst_flat_array = flat_array;
4205       } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
4206         this_klass = tinst_klass; // tinst is down; keep down man
4207         this_xk = tinst_xk;
4208         this_flat_array = tinst_flat_array;
4209       } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
4210         tinst_klass = this_klass; // this is down; keep down man
4211         tinst_xk = this_xk;
4212         tinst_flat_array = this_flat_array;
4213       } else {
4214         this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4215         this_flat_array = flat_array;
4216       }
4217     }
4218 
4219     // Check for classes now being equal
4220     if (tinst_klass->equals(this_klass)) {
4221       // If the klasses are equal, the constants may still differ.  Fall to
4222       // NotNull if they do (neither constant is NULL; that is a special case
4223       // handled elsewhere).
4224       ciObject* o = NULL;             // Assume not constant when done
4225       ciObject* this_oop  = const_oop();
4226       ciObject* tinst_oop = tinst->const_oop();
4227       if( ptr == Constant ) {
4228         if (this_oop != NULL && tinst_oop != NULL &&
4229             this_oop->equals(tinst_oop) )
4230           o = this_oop;
4231         else if (above_centerline(this ->_ptr))
4232           o = tinst_oop;
4233         else if (above_centerline(tinst ->_ptr))
4234           o = this_oop;
4235         else
4236           ptr = NotNull;
4237       }
4238       return make(ptr, this_klass, this_xk, o, off, this_flat_array, instance_id, speculative, depth);
4239     } // Else classes are not equal
4240 
4241     // Since klasses are different, we require a LCA in the Java
4242     // class hierarchy - which means we have to fall to at least NotNull.
4243     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
4244       ptr = NotNull;
4245 
4246     instance_id = InstanceBot;
4247 
4248     // Now we find the LCA of Java classes
4249     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
4250     return make(ptr, k, false, NULL, off, false, instance_id, speculative, depth);
4251   } // End of case InstPtr
4252 
4253   case ValueType: {
4254     const TypeValueType* tv = t->is_valuetype();
4255     if (above_centerline(ptr())) {
4256       if (tv->value_klass()->is_subtype_of(_klass)) {
4257         return t;
4258       } else {
4259         return TypeInstPtr::make(NotNull, _klass);
4260       }
4261     } else {
4262       PTR ptr = this->_ptr;
4263       if (ptr == Constant) {
4264         ptr = NotNull;
4265       }
4266       if (tv->value_klass()->is_subtype_of(_klass)) {
4267         return TypeInstPtr::make(ptr, _klass);
4268       } else {
4269         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass());
4270       }


4275   return this;                  // Return the double constant
4276 }
4277 
4278 
4279 //------------------------java_mirror_type--------------------------------------
4280 ciType* TypeInstPtr::java_mirror_type(bool* is_indirect_type) const {
4281   // must be a singleton type
4282   if( const_oop() == NULL )  return NULL;
4283 
4284   // must be of type java.lang.Class
4285   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
4286 
4287   return const_oop()->as_instance()->java_mirror_type(is_indirect_type);
4288 }
4289 
4290 
4291 //------------------------------xdual------------------------------------------
4292 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4293 // inheritance mechanism.
4294 const Type *TypeInstPtr::xdual() const {
4295   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), flat_array(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4296 }
4297 
4298 //------------------------------eq---------------------------------------------
4299 // Structural equality check for Type representations
4300 bool TypeInstPtr::eq( const Type *t ) const {
4301   const TypeInstPtr *p = t->is_instptr();
4302   return
4303     klass()->equals(p->klass()) &&
4304     flat_array() == p->flat_array() &&
4305     TypeOopPtr::eq(p);          // Check sub-type stuff
4306 }
4307 
4308 //------------------------------hash-------------------------------------------
4309 // Type-specific hashing function.
4310 int TypeInstPtr::hash(void) const {
4311   int hash = java_add(java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash()), (jint)flat_array());
4312   return hash;
4313 }
4314 
4315 //------------------------------dump2------------------------------------------
4316 // Dump oop Type
4317 #ifndef PRODUCT
4318 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4319   // Print the name of the klass.
4320   klass()->print_name_on(st);
4321 
4322   switch( _ptr ) {
4323   case Constant:
4324     // TO DO: Make CI print the hex address of the underlying oop.
4325     if (WizardMode || Verbose) {
4326       const_oop()->print_oop(st);
4327     }
4328   case BotPTR:
4329     if (!WizardMode && !Verbose) {
4330       if( _klass_is_exact ) st->print(":exact");
4331       break;
4332     }
4333   case TopPTR:
4334   case AnyNull:
4335   case NotNull:
4336     st->print(":%s", ptr_msg[_ptr]);
4337     if( _klass_is_exact ) st->print(":exact");
4338     break;
4339   default:
4340     break;
4341   }
4342 
4343   _offset.dump2(st);
4344 
4345   st->print(" *");
4346   
4347   if (flat_array() && !klass()->is_valuetype()) {
4348     st->print(" (flatten array)");
4349   }
4350   
4351   if (_instance_id == InstanceTop)
4352     st->print(",iid=top");
4353   else if (_instance_id != InstanceBot)
4354     st->print(",iid=%d",_instance_id);
4355 
4356   dump_inline_depth(st);
4357   dump_speculative(st);
4358 }
4359 #endif
4360 
4361 //------------------------------add_offset-------------------------------------
4362 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
4363   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), flat_array(), 
4364               _instance_id, add_offset_speculative(offset), _inline_depth);
4365 }
4366 
4367 const Type *TypeInstPtr::remove_speculative() const {
4368   if (_speculative == NULL) {
4369     return this;
4370   }
4371   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4372   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flat_array(),
4373               _instance_id, NULL, _inline_depth);
4374 }
4375 
4376 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
4377   if (!UseInlineDepthForSpeculativeTypes) {
4378     return this;
4379   }
4380   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flat_array(), _instance_id, _speculative, depth);
4381 }
4382 
4383 const TypePtr *TypeInstPtr::with_instance_id(int instance_id) const {
4384   assert(is_known_instance(), "should be known");
4385   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flat_array(), instance_id, _speculative, _inline_depth);
4386 }
4387 
4388 const TypeInstPtr *TypeInstPtr::cast_to_flat_array() const {
4389   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, true, _instance_id, _speculative, _inline_depth);
4390 }
4391 
4392 
4393 //=============================================================================
4394 // Convenience common pre-built types.
4395 const TypeAryPtr *TypeAryPtr::RANGE;
4396 const TypeAryPtr *TypeAryPtr::OOPS;
4397 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4398 const TypeAryPtr *TypeAryPtr::BYTES;
4399 const TypeAryPtr *TypeAryPtr::SHORTS;
4400 const TypeAryPtr *TypeAryPtr::CHARS;
4401 const TypeAryPtr *TypeAryPtr::INTS;
4402 const TypeAryPtr *TypeAryPtr::LONGS;
4403 const TypeAryPtr *TypeAryPtr::FLOATS;
4404 const TypeAryPtr *TypeAryPtr::DOUBLES;
4405 const TypeAryPtr *TypeAryPtr::VALUES;
4406 
4407 //------------------------------make-------------------------------------------
4408 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4409                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4410   assert(!(k == NULL && ary->_elem->isa_int()),
4411          "integral arrays must be pre-equipped with a class");
4412   if (!xk) xk = ary->ary_must_be_exact();


4780   // All arrays inherit from Object class
4781   case InstPtr: {
4782     const TypeInstPtr *tp = t->is_instptr();
4783     Offset offset = meet_offset(tp->offset());
4784     PTR ptr = meet_ptr(tp->ptr());
4785     int instance_id = meet_instance_id(tp->instance_id());
4786     const TypePtr* speculative = xmeet_speculative(tp);
4787     int depth = meet_inline_depth(tp->inline_depth());
4788     switch (ptr) {
4789     case TopPTR:
4790     case AnyNull:                // Fall 'down' to dual of object klass
4791       // For instances when a subclass meets a superclass we fall
4792       // below the centerline when the superclass is exact. We need to
4793       // do the same here.
4794       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4795         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4796       } else {
4797         // cannot subclass, so the meet has to fall badly below the centerline
4798         ptr = NotNull;
4799         instance_id = InstanceBot;
4800         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, false, instance_id, speculative, depth);
4801       }
4802     case Constant:
4803     case NotNull:
4804     case BotPTR:                // Fall down to object klass
4805       // LCA is object_klass, but if we subclass from the top we can do better
4806       if (above_centerline(tp->ptr())) {
4807         // If 'tp'  is above the centerline and it is Object class
4808         // then we can subclass in the Java class hierarchy.
4809         // For instances when a subclass meets a superclass we fall
4810         // below the centerline when the superclass is exact. We need
4811         // to do the same here.
4812         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4813           // that is, my array type is a subtype of 'tp' klass
4814           return make(ptr, (ptr == Constant ? const_oop() : NULL),
4815                       _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4816         }
4817       }
4818       // The other case cannot happen, since t cannot be a subtype of an array.
4819       // The meet falls down to Object class below centerline.
4820       if( ptr == Constant )
4821          ptr = NotNull;
4822       instance_id = InstanceBot;
4823       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, false, instance_id, speculative, depth);
4824     default: typerr(t);
4825     }
4826   }
4827 
4828   case ValueType: {
4829     // All value types inherit from Object
4830     PTR ptr = this->_ptr;
4831     if (ptr == Constant) {
4832       ptr = NotNull;
4833     }
4834     return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass());
4835   }
4836 
4837   }
4838   return this;                  // Lint noise
4839 }
4840 
4841 //------------------------------xdual------------------------------------------
4842 // Dual: compute field-by-field dual
4843 const Type *TypeAryPtr::xdual() const {


5341 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5342   return make(Constant, m, Offset(0));
5343 }
5344 
5345 //------------------------------make-------------------------------------------
5346 // Create a meta data constant
5347 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
5348   assert(m == NULL || !m->is_klass(), "wrong type");
5349   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5350 }
5351 
5352 
5353 //=============================================================================
5354 // Convenience common pre-built types.
5355 
5356 // Not-null object klass or below
5357 const TypeKlassPtr *TypeKlassPtr::OBJECT;
5358 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
5359 
5360 //------------------------------TypeKlassPtr-----------------------------------
5361 TypeKlassPtr::TypeKlassPtr(PTR ptr, ciKlass* klass, Offset offset, bool flat_array)
5362   : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant), _flat_array(flat_array) {
5363    assert(!klass->is_valuetype() || !klass->flatten_array() || flat_array, "incorrect flatten array bit");
5364    assert(!flat_array || can_be_value_type(), "incorrect flatten array bit");
5365 }
5366 
5367 //------------------------------make-------------------------------------------
5368 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
5369 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, bool value) {
5370   assert(k == NULL || k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
5371   return (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset, value))->hashcons();
5372 }
5373 
5374 //------------------------------eq---------------------------------------------
5375 // Structural equality check for Type representations
5376 bool TypeKlassPtr::eq( const Type *t ) const {
5377   const TypeKlassPtr *p = t->is_klassptr();
5378   return klass() == p->klass() && TypePtr::eq(p) && flat_array() == p->flat_array();
5379 }
5380 
5381 //------------------------------hash-------------------------------------------
5382 // Type-specific hashing function.
5383 int TypeKlassPtr::hash(void) const {
5384   return java_add(java_add(klass() != NULL ? klass()->hash() : (jint)0, (jint)TypePtr::hash()), (jint)flat_array());
5385 }
5386 
5387 //------------------------------singleton--------------------------------------
5388 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5389 // constants
5390 bool TypeKlassPtr::singleton(void) const {
5391   // detune optimizer to not generate constant klass + constant offset as a constant!
5392   // TopPTR, Null, AnyNull, Constant are all singletons
5393   return (offset() == 0) && !below_centerline(_ptr);
5394 }
5395 
5396 // Do not allow interface-vs.-noninterface joins to collapse to top.
5397 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5398   // logic here mirrors the one from TypeOopPtr::filter. See comments
5399   // there.
5400   const Type* ft = join_helper(kills, include_speculative);
5401   const TypeKlassPtr* ftkp = ft->isa_klassptr();
5402   const TypeKlassPtr* ktkp = kills->isa_klassptr();
5403 
5404   if (ft->empty()) {


5498     // active compilations.  However, the ciKlass which represents
5499     // this Type is *not* shared between compilations, so caching
5500     // this value would result in fetching a dangling pointer.
5501     //
5502     // Recomputing the underlying ciKlass for each request is
5503     // a bit less efficient than caching, but calls to
5504     // TypeAryPtr::OOPS->klass() are not common enough to matter.
5505     ((TypeAryPtr*)this)->_klass = k_ary;
5506     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
5507         offset() != 0 && offset() != arrayOopDesc::length_offset_in_bytes()) {
5508       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
5509     }
5510   }
5511   return k_ary;
5512 }
5513 
5514 
5515 //------------------------------add_offset-------------------------------------
5516 // Access internals of klass object
5517 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
5518   return make(_ptr, klass(), xadd_offset(offset), flat_array());
5519 }
5520 
5521 //------------------------------cast_to_ptr_type-------------------------------
5522 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
5523   assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
5524   if( ptr == _ptr ) return this;
5525   return make(ptr, _klass, _offset, _flat_array);
5526 }
5527 
5528 
5529 //-----------------------------cast_to_exactness-------------------------------
5530 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5531   if( klass_is_exact == _klass_is_exact ) return this;
5532   if (!UseExactTypes)  return this;
5533   return make(klass_is_exact ? Constant : NotNull, _klass, _offset, _flat_array);
5534 }
5535 
5536 
5537 //-----------------------------as_instance_type--------------------------------
5538 // Corresponding type for an instance of the given class.
5539 // It will be NotNull, and exact if and only if the klass type is exact.
5540 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
5541   ciKlass* k = klass();
5542   assert(k != NULL, "klass should not be NULL");
5543   bool    xk = klass_is_exact();
5544   //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
5545   const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
5546   guarantee(toop != NULL, "need type for given klass");
5547   toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5548   if (flat_array() && !klass()->is_valuetype()) {
5549     toop = toop->is_instptr()->cast_to_flat_array();
5550   }
5551   return toop->cast_to_exactness(xk)->is_oopptr();
5552 }
5553 
5554 
5555 //------------------------------xmeet------------------------------------------
5556 // Compute the MEET of two types, return a new Type object.
5557 const Type    *TypeKlassPtr::xmeet( const Type *t ) const {
5558   // Perform a fast test for common case; meeting the same types together.
5559   if( this == t ) return this;  // Meeting same type-rep?
5560 
5561   // Current "this->_base" is Pointer
5562   switch (t->base()) {          // switch on original type
5563 
5564   case Int:                     // Mixing ints & oops happens when javac
5565   case Long:                    // reuses local variables
5566   case FloatTop:
5567   case FloatCon:
5568   case FloatBot:
5569   case DoubleTop:
5570   case DoubleCon:


5573   case NarrowKlass:
5574   case Bottom:                  // Ye Olde Default
5575     return Type::BOTTOM;
5576   case Top:
5577     return this;
5578 
5579   default:                      // All else is a mistake
5580     typerr(t);
5581 
5582   case AnyPtr: {                // Meeting to AnyPtrs
5583     // Found an AnyPtr type vs self-KlassPtr type
5584     const TypePtr *tp = t->is_ptr();
5585     Offset offset = meet_offset(tp->offset());
5586     PTR ptr = meet_ptr(tp->ptr());
5587     switch (tp->ptr()) {
5588     case TopPTR:
5589       return this;
5590     case Null:
5591       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5592     case AnyNull:
5593       return make(ptr, klass(), offset, flat_array());
5594     case BotPTR:
5595     case NotNull:
5596       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5597     default: typerr(t);
5598     }
5599   }
5600 
5601   case RawPtr:
5602   case MetadataPtr:
5603   case OopPtr:
5604   case AryPtr:                  // Meet with AryPtr
5605   case InstPtr:                 // Meet with InstPtr
5606     return TypePtr::BOTTOM;
5607 
5608   //
5609   //             A-top         }
5610   //           /   |   \       }  Tops
5611   //       B-top A-any C-top   }
5612   //          | /  |  \ |      }  Any-nulls
5613   //       B-any   |   C-any   }
5614   //          |    |    |
5615   //       B-con A-con C-con   } constants; not comparable across classes
5616   //          |    |    |
5617   //       B-not   |   C-not   }
5618   //          | \  |  / |      }  not-nulls
5619   //       B-bot A-not C-bot   }
5620   //           \   |   /       }  Bottoms
5621   //             A-bot         }
5622   //
5623 
5624   case KlassPtr: {  // Meet two KlassPtr types
5625     const TypeKlassPtr *tkls = t->is_klassptr();
5626     Offset  off  = meet_offset(tkls->offset());
5627     PTR  ptr     = meet_ptr(tkls->ptr());
5628 
5629     if (klass() == NULL || tkls->klass() == NULL) {
5630       ciKlass* k = NULL;
5631       if (ptr == Constant) {
5632         k = (klass() == NULL) ? tkls->klass() : klass();
5633       }
5634       return make(ptr, k, off, false);
5635     }
5636 
5637     // Check for easy case; klasses are equal (and perhaps not loaded!)
5638     // If we have constants, then we created oops so classes are loaded
5639     // and we can handle the constants further down.  This case handles
5640     // not-loaded classes
5641     if (ptr != Constant && tkls->klass()->equals(klass()) && flat_array() == tkls->flat_array()) {
5642       return make(ptr, klass(), off, flat_array());
5643     }
5644 
5645     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
5646     ciKlass* tkls_klass = tkls->klass();
5647     ciKlass* this_klass = this->klass();
5648     assert( tkls_klass->is_loaded(), "This class should have been loaded.");
5649     assert( this_klass->is_loaded(), "This class should have been loaded.");
5650     bool tkls_flat_array = tkls->flat_array();
5651     bool this_flat_array  = this->flat_array();
5652     bool flat_array = below_centerline(ptr) ? (this_flat_array && tkls_flat_array) : (this_flat_array || tkls_flat_array);
5653 
5654     // If 'this' type is above the centerline and is a superclass of the
5655     // other, we can treat 'this' as having the same type as the other.
5656     if ((above_centerline(this->ptr())) &&
5657         tkls_klass->is_subtype_of(this_klass)) {
5658       this_klass = tkls_klass;
5659     }
5660     // If 'tinst' type is above the centerline and is a superclass of the
5661     // other, we can treat 'tinst' as having the same type as the other.
5662     if ((above_centerline(tkls->ptr())) &&
5663         this_klass->is_subtype_of(tkls_klass)) {
5664       tkls_klass = this_klass;
5665     }
5666 
5667     // Check for classes now being equal
5668     if (tkls_klass->equals(this_klass)) {
5669       // If the klasses are equal, the constants may still differ.  Fall to
5670       // NotNull if they do (neither constant is NULL; that is a special case
5671       // handled elsewhere).
5672       if( ptr == Constant ) {
5673         if (this->_ptr == Constant && tkls->_ptr == Constant &&
5674             this->klass()->equals(tkls->klass()));
5675         else if (above_centerline(this->ptr()));
5676         else if (above_centerline(tkls->ptr()));
5677         else
5678           ptr = NotNull;
5679       }
5680       return make(ptr, this_klass, off, flat_array);
5681     } // Else classes are not equal
5682 
5683     // Since klasses are different, we require the LCA in the Java
5684     // class hierarchy - which means we have to fall to at least NotNull.
5685     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
5686       ptr = NotNull;
5687     // Now we find the LCA of Java classes
5688     ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
5689     return   make(ptr, k, off, k->is_valuetype() && k->flatten_array());
5690   } // End of case KlassPtr
5691 
5692   } // End of switch
5693   return this;                  // Return the double constant
5694 }
5695 
5696 //------------------------------xdual------------------------------------------
5697 // Dual: compute field-by-field dual
5698 const Type    *TypeKlassPtr::xdual() const {
5699   return new TypeKlassPtr(dual_ptr(), klass(), dual_offset(), flat_array());
5700 }
5701 
5702 //------------------------------get_con----------------------------------------
5703 intptr_t TypeKlassPtr::get_con() const {
5704   assert( _ptr == Null || _ptr == Constant, "" );
5705   assert(offset() >= 0, "");
5706 
5707   if (offset() != 0) {
5708     // After being ported to the compiler interface, the compiler no longer
5709     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5710     // to a handle at compile time.  This handle is embedded in the generated
5711     // code and dereferenced at the time the nmethod is made.  Until that time,
5712     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5713     // have access to the addresses!).  This does not seem to currently happen,
5714     // but this assertion here is to help prevent its occurence.
5715     tty->print_cr("Found oop constant with non-zero offset");
5716     ShouldNotReachHere();
5717   }
5718 
5719   return (intptr_t)klass()->constant_encoding();


< prev index next >