src/share/vm/opto/type.cpp

changeset 5991
b2ee5dc63353
parent 5791
c9ccd7b85f20
child 5997
59e8ad757e19
     1.1 --- a/src/share/vm/opto/type.cpp	Wed Oct 23 10:00:39 2013 +0200
     1.2 +++ b/src/share/vm/opto/type.cpp	Wed Oct 23 12:40:23 2013 +0200
     1.3 @@ -358,7 +358,7 @@
     1.4                                             false, 0, oopDesc::mark_offset_in_bytes());
     1.5    TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
     1.6                                             false, 0, oopDesc::klass_offset_in_bytes());
     1.7 -  TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
     1.8 +  TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot, NULL);
     1.9  
    1.10    TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, OffsetBot);
    1.11  
    1.12 @@ -577,7 +577,7 @@
    1.13  
    1.14  //----------------------interface_vs_oop---------------------------------------
    1.15  #ifdef ASSERT
    1.16 -bool Type::interface_vs_oop(const Type *t) const {
    1.17 +bool Type::interface_vs_oop_helper(const Type *t) const {
    1.18    bool result = false;
    1.19  
    1.20    const TypePtr* this_ptr = this->make_ptr(); // In case it is narrow_oop
    1.21 @@ -595,6 +595,29 @@
    1.22  
    1.23    return result;
    1.24  }
    1.25 +
    1.26 +bool Type::interface_vs_oop(const Type *t) const {
    1.27 +  if (interface_vs_oop_helper(t)) {
    1.28 +    return true;
    1.29 +  }
    1.30 +  // Now check the speculative parts as well
    1.31 +  const TypeOopPtr* this_spec = isa_oopptr() != NULL ? isa_oopptr()->speculative() : NULL;
    1.32 +  const TypeOopPtr* t_spec = t->isa_oopptr() != NULL ? t->isa_oopptr()->speculative() : NULL;
    1.33 +  if (this_spec != NULL && t_spec != NULL) {
    1.34 +    if (this_spec->interface_vs_oop_helper(t_spec)) {
    1.35 +      return true;
    1.36 +    }
    1.37 +    return false;
    1.38 +  }
    1.39 +  if (this_spec != NULL && this_spec->interface_vs_oop_helper(t)) {
    1.40 +    return true;
    1.41 +  }
    1.42 +  if (t_spec != NULL && interface_vs_oop_helper(t_spec)) {
    1.43 +    return true;
    1.44 +  }
    1.45 +  return false;
    1.46 +}
    1.47 +
    1.48  #endif
    1.49  
    1.50  //------------------------------meet-------------------------------------------
    1.51 @@ -2407,14 +2430,15 @@
    1.52  const TypeOopPtr *TypeOopPtr::BOTTOM;
    1.53  
    1.54  //------------------------------TypeOopPtr-------------------------------------
    1.55 -TypeOopPtr::TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id )
    1.56 +TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative)
    1.57    : TypePtr(t, ptr, offset),
    1.58      _const_oop(o), _klass(k),
    1.59      _klass_is_exact(xk),
    1.60      _is_ptr_to_narrowoop(false),
    1.61      _is_ptr_to_narrowklass(false),
    1.62      _is_ptr_to_boxed_value(false),
    1.63 -    _instance_id(instance_id) {
    1.64 +    _instance_id(instance_id),
    1.65 +    _speculative(speculative) {
    1.66    if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
    1.67        (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
    1.68      _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
    1.69 @@ -2481,12 +2505,12 @@
    1.70  
    1.71  //------------------------------make-------------------------------------------
    1.72  const TypeOopPtr *TypeOopPtr::make(PTR ptr,
    1.73 -                                   int offset, int instance_id) {
    1.74 +                                   int offset, int instance_id, const TypeOopPtr* speculative) {
    1.75    assert(ptr != Constant, "no constant generic pointers");
    1.76    ciKlass*  k = Compile::current()->env()->Object_klass();
    1.77    bool      xk = false;
    1.78    ciObject* o = NULL;
    1.79 -  return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id))->hashcons();
    1.80 +  return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative))->hashcons();
    1.81  }
    1.82  
    1.83  
    1.84 @@ -2494,7 +2518,7 @@
    1.85  const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
    1.86    assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
    1.87    if( ptr == _ptr ) return this;
    1.88 -  return make(ptr, _offset, _instance_id);
    1.89 +  return make(ptr, _offset, _instance_id, _speculative);
    1.90  }
    1.91  
    1.92  //-----------------------------cast_to_instance_id----------------------------
    1.93 @@ -2524,10 +2548,31 @@
    1.94      return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
    1.95  }
    1.96  
    1.97 +const Type *TypeOopPtr::xmeet(const Type *t) const {
    1.98 +  const Type* res = xmeet_helper(t);
    1.99 +  if (res->isa_oopptr() == NULL) {
   1.100 +    return res;
   1.101 +  }
   1.102 +
   1.103 +  if (res->isa_oopptr() != NULL) {
   1.104 +    // type->speculative() == NULL means that speculation is no better
   1.105 +    // than type, i.e. type->speculative() == type. So there are 2
   1.106 +    // ways to represent the fact that we have no useful speculative
   1.107 +    // data and we should use a single one to be able to test for
   1.108 +    // equality between types. Check whether type->speculative() ==
   1.109 +    // type and set speculative to NULL if it is the case.
   1.110 +    const TypeOopPtr* res_oopptr = res->is_oopptr();
   1.111 +    if (res_oopptr->remove_speculative() == res_oopptr->speculative()) {
   1.112 +      return res_oopptr->remove_speculative();
   1.113 +    }
   1.114 +  }
   1.115 +
   1.116 +  return res;
   1.117 +}
   1.118  
   1.119  //------------------------------meet-------------------------------------------
   1.120  // Compute the MEET of two types.  It returns a new Type object.
   1.121 -const Type *TypeOopPtr::xmeet( const Type *t ) const {
   1.122 +const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
   1.123    // Perform a fast test for common case; meeting the same types together.
   1.124    if( this == t ) return this;  // Meeting same type-rep?
   1.125  
   1.126 @@ -2569,7 +2614,8 @@
   1.127      case TopPTR:
   1.128      case AnyNull: {
   1.129        int instance_id = meet_instance_id(InstanceTop);
   1.130 -      return make(ptr, offset, instance_id);
   1.131 +      const TypeOopPtr* speculative = _speculative;
   1.132 +      return make(ptr, offset, instance_id, speculative);
   1.133      }
   1.134      case BotPTR:
   1.135      case NotNull:
   1.136 @@ -2581,7 +2627,8 @@
   1.137    case OopPtr: {                 // Meeting to other OopPtrs
   1.138      const TypeOopPtr *tp = t->is_oopptr();
   1.139      int instance_id = meet_instance_id(tp->instance_id());
   1.140 -    return make( meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id );
   1.141 +    const TypeOopPtr* speculative = meet_speculative(tp);
   1.142 +    return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative);
   1.143    }
   1.144  
   1.145    case InstPtr:                  // For these, flip the call around to cut down
   1.146 @@ -2598,7 +2645,7 @@
   1.147  const Type *TypeOopPtr::xdual() const {
   1.148    assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
   1.149    assert(const_oop() == NULL,             "no constants here");
   1.150 -  return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id()  );
   1.151 +  return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative());
   1.152  }
   1.153  
   1.154  //--------------------------make_from_klass_common-----------------------------
   1.155 @@ -2689,7 +2736,7 @@
   1.156      } else if (!o->should_be_constant()) {
   1.157        return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
   1.158      }
   1.159 -    const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0, InstanceBot, is_autobox_cache);
   1.160 +    const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0, InstanceBot, NULL, is_autobox_cache);
   1.161      return arr;
   1.162    } else if (klass->is_type_array_klass()) {
   1.163      // Element is an typeArray
   1.164 @@ -2789,7 +2836,8 @@
   1.165  bool TypeOopPtr::eq( const Type *t ) const {
   1.166    const TypeOopPtr *a = (const TypeOopPtr*)t;
   1.167    if (_klass_is_exact != a->_klass_is_exact ||
   1.168 -      _instance_id != a->_instance_id)  return false;
   1.169 +      _instance_id != a->_instance_id ||
   1.170 +      !eq_speculative(a))  return false;
   1.171    ciObject* one = const_oop();
   1.172    ciObject* two = a->const_oop();
   1.173    if (one == NULL || two == NULL) {
   1.174 @@ -2806,6 +2854,7 @@
   1.175      (const_oop() ? const_oop()->hash() : 0) +
   1.176      _klass_is_exact +
   1.177      _instance_id +
   1.178 +    hash_speculative() +
   1.179      TypePtr::hash();
   1.180  }
   1.181  
   1.182 @@ -2825,6 +2874,19 @@
   1.183      st->print(",iid=top");
   1.184    else if (_instance_id != InstanceBot)
   1.185      st->print(",iid=%d",_instance_id);
   1.186 +
   1.187 +  dump_speculative(st);
   1.188 +}
   1.189 +
   1.190 +/**
   1.191 + *dump the speculative part of the type
   1.192 + */
   1.193 +void TypeOopPtr::dump_speculative(outputStream *st) const {
   1.194 +  if (_speculative != NULL) {
   1.195 +    st->print(" (speculative=");
   1.196 +    _speculative->dump_on(st);
   1.197 +    st->print(")");
   1.198 +  }
   1.199  }
   1.200  #endif
   1.201  
   1.202 @@ -2838,8 +2900,15 @@
   1.203  }
   1.204  
   1.205  //------------------------------add_offset-------------------------------------
   1.206 -const TypePtr *TypeOopPtr::add_offset( intptr_t offset ) const {
   1.207 -  return make( _ptr, xadd_offset(offset), _instance_id);
   1.208 +const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
   1.209 +  return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset));
   1.210 +}
   1.211 +
   1.212 +/**
   1.213 + * Return same type without a speculative part
   1.214 + */
   1.215 +const TypeOopPtr* TypeOopPtr::remove_speculative() const {
   1.216 +  return make(_ptr, _offset, _instance_id, NULL);
   1.217  }
   1.218  
   1.219  //------------------------------meet_instance_id--------------------------------
   1.220 @@ -2859,6 +2928,89 @@
   1.221    return _instance_id;              // Map everything else into self
   1.222  }
   1.223  
   1.224 +/**
   1.225 + * meet of the speculative parts of 2 types
   1.226 + *
   1.227 + * @param other  type to meet with
   1.228 + */
   1.229 +const TypeOopPtr* TypeOopPtr::meet_speculative(const TypeOopPtr* other) const {
   1.230 +  bool this_has_spec = (_speculative != NULL);
   1.231 +  bool other_has_spec = (other->speculative() != NULL);
   1.232 +
   1.233 +  if (!this_has_spec && !other_has_spec) {
   1.234 +    return NULL;
   1.235 +  }
   1.236 +
   1.237 +  // If we are at a point where control flow meets and one branch has
   1.238 +  // a speculative type and the other has not, we meet the speculative
   1.239 +  // type of one branch with the actual type of the other. If the
   1.240 +  // actual type is exact and the speculative is as well, then the
   1.241 +  // result is a speculative type which is exact and we can continue
   1.242 +  // speculation further.
   1.243 +  const TypeOopPtr* this_spec = _speculative;
   1.244 +  const TypeOopPtr* other_spec = other->speculative();
   1.245 +
   1.246 +  if (!this_has_spec) {
   1.247 +    this_spec = this;
   1.248 +  }
   1.249 +
   1.250 +  if (!other_has_spec) {
   1.251 +    other_spec = other;
   1.252 +  }
   1.253 +
   1.254 +  return this_spec->meet(other_spec)->is_oopptr();
   1.255 +}
   1.256 +
   1.257 +/**
   1.258 + * dual of the speculative part of the type
   1.259 + */
   1.260 +const TypeOopPtr* TypeOopPtr::dual_speculative() const {
   1.261 +  if (_speculative == NULL) {
   1.262 +    return NULL;
   1.263 +  }
   1.264 +  return _speculative->dual()->is_oopptr();
   1.265 +}
   1.266 +
   1.267 +/**
   1.268 + * add offset to the speculative part of the type
   1.269 + *
   1.270 + * @param offset  offset to add
   1.271 + */
   1.272 +const TypeOopPtr* TypeOopPtr::add_offset_speculative(intptr_t offset) const {
   1.273 +  if (_speculative == NULL) {
   1.274 +    return NULL;
   1.275 +  }
   1.276 +  return _speculative->add_offset(offset)->is_oopptr();
   1.277 +}
   1.278 +
   1.279 +/**
   1.280 + * Are the speculative parts of 2 types equal?
   1.281 + *
   1.282 + * @param other  type to compare this one to
   1.283 + */
   1.284 +bool TypeOopPtr::eq_speculative(const TypeOopPtr* other) const {
   1.285 +  if (_speculative == NULL || other->speculative() == NULL) {
   1.286 +    return _speculative == other->speculative();
   1.287 +  }
   1.288 +
   1.289 +  if (_speculative->base() != other->speculative()->base()) {
   1.290 +    return false;
   1.291 +  }
   1.292 +
   1.293 +  return _speculative->eq(other->speculative());
   1.294 +}
   1.295 +
   1.296 +/**
   1.297 + * Hash of the speculative part of the type
   1.298 + */
   1.299 +int TypeOopPtr::hash_speculative() const {
   1.300 +  if (_speculative == NULL) {
   1.301 +    return 0;
   1.302 +  }
   1.303 +
   1.304 +  return _speculative->hash();
   1.305 +}
   1.306 +
   1.307  
   1.308  //=============================================================================
   1.309  // Convenience common pre-built types.
   1.310 @@ -2869,8 +3021,8 @@
   1.311  const TypeInstPtr *TypeInstPtr::KLASS;
   1.312  
   1.313  //------------------------------TypeInstPtr-------------------------------------
   1.314 -TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id)
   1.315 - : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id), _name(k->name()) {
   1.316 +TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id, const TypeOopPtr* speculative)
   1.317 +  : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative), _name(k->name()) {
   1.318     assert(k != NULL &&
   1.319            (k->is_loaded() || o == NULL),
   1.320            "cannot have constants with non-loaded klass");
   1.321 @@ -2882,7 +3034,8 @@
   1.322                                       bool xk,
   1.323                                       ciObject* o,
   1.324                                       int offset,
   1.325 -                                     int instance_id) {
   1.326 +                                     int instance_id,
   1.327 +                                     const TypeOopPtr* speculative) {
   1.328    assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
   1.329    // Either const_oop() is NULL or else ptr is Constant
   1.330    assert( (!o && ptr != Constant) || (o && ptr == Constant),
   1.331 @@ -2903,7 +3056,7 @@
   1.332  
   1.333    // Now hash this baby
   1.334    TypeInstPtr *result =
   1.335 -    (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id))->hashcons();
   1.336 +    (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative))->hashcons();
   1.337  
   1.338    return result;
   1.339  }
   1.340 @@ -2936,7 +3089,7 @@
   1.341    if( ptr == _ptr ) return this;
   1.342    // Reconstruct _sig info here since not a problem with later lazy
   1.343    // construction, _sig will show up on demand.
   1.344 -  return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id);
   1.345 +  return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative);
   1.346  }
   1.347  
   1.348  
   1.349 @@ -2948,13 +3101,13 @@
   1.350    ciInstanceKlass* ik = _klass->as_instance_klass();
   1.351    if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
   1.352    if( ik->is_interface() )              return this;  // cannot set xk
   1.353 -  return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id);
   1.354 +  return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative);
   1.355  }
   1.356  
   1.357  //-----------------------------cast_to_instance_id----------------------------
   1.358  const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
   1.359    if( instance_id == _instance_id ) return this;
   1.360 -  return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id);
   1.361 +  return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative);
   1.362  }
   1.363  
   1.364  //------------------------------xmeet_unloaded---------------------------------
   1.365 @@ -2964,6 +3117,7 @@
   1.366      int off = meet_offset(tinst->offset());
   1.367      PTR ptr = meet_ptr(tinst->ptr());
   1.368      int instance_id = meet_instance_id(tinst->instance_id());
   1.369 +    const TypeOopPtr* speculative = meet_speculative(tinst);
   1.370  
   1.371      const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
   1.372      const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
   1.373 @@ -2984,7 +3138,7 @@
   1.374        assert(loaded->ptr() != TypePtr::Null, "insanity check");
   1.375        //
   1.376        if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
   1.377 -      else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make( ptr, unloaded->klass(), false, NULL, off, instance_id ); }
   1.378 +      else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative); }
   1.379        else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
   1.380        else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
   1.381          if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
   1.382 @@ -3006,7 +3160,7 @@
   1.383  
   1.384  //------------------------------meet-------------------------------------------
   1.385  // Compute the MEET of two types.  It returns a new Type object.
   1.386 -const Type *TypeInstPtr::xmeet( const Type *t ) const {
   1.387 +const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
   1.388    // Perform a fast test for common case; meeting the same types together.
   1.389    if( this == t ) return this;  // Meeting same type-rep?
   1.390  
   1.391 @@ -3040,16 +3194,20 @@
   1.392      int offset = meet_offset(tp->offset());
   1.393      PTR ptr = meet_ptr(tp->ptr());
   1.394      int instance_id = meet_instance_id(tp->instance_id());
   1.395 +    const TypeOopPtr* speculative = meet_speculative(tp);
   1.396      switch (ptr) {
   1.397      case TopPTR:
   1.398      case AnyNull:                // Fall 'down' to dual of object klass
   1.399 -      if (klass()->equals(ciEnv::current()->Object_klass())) {
   1.400 -        return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);
   1.401 +      // For instances when a subclass meets a superclass we fall
   1.402 +      // below the centerline when the superclass is exact. We need to
   1.403 +      // do the same here.
   1.404 +      if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
   1.405 +        return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative);
   1.406        } else {
   1.407          // cannot subclass, so the meet has to fall badly below the centerline
   1.408          ptr = NotNull;
   1.409          instance_id = InstanceBot;
   1.410 -        return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id);
   1.411 +        return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative);
   1.412        }
   1.413      case Constant:
   1.414      case NotNull:
   1.415 @@ -3058,10 +3216,13 @@
   1.416        if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
   1.417          // If 'this' (InstPtr) is above the centerline and it is Object class
   1.418          // then we can subclass in the Java class hierarchy.
   1.419 -        if (klass()->equals(ciEnv::current()->Object_klass())) {
   1.420 +        // For instances when a subclass meets a superclass we fall
   1.421 +        // below the centerline when the superclass is exact. We need
   1.422 +        // to do the same here.
   1.423 +        if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
   1.424            // that is, tp's array type is a subtype of my klass
   1.425            return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
   1.426 -                                  tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);
   1.427 +                                  tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative);
   1.428          }
   1.429        }
   1.430        // The other case cannot happen, since I cannot be a subtype of an array.
   1.431 @@ -3069,7 +3230,7 @@
   1.432        if( ptr == Constant )
   1.433           ptr = NotNull;
   1.434        instance_id = InstanceBot;
   1.435 -      return make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id );
   1.436 +      return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative);
   1.437      default: typerr(t);
   1.438      }
   1.439    }
   1.440 @@ -3083,13 +3244,15 @@
   1.441      case TopPTR:
   1.442      case AnyNull: {
   1.443        int instance_id = meet_instance_id(InstanceTop);
   1.444 +      const TypeOopPtr* speculative = meet_speculative(tp);
   1.445        return make(ptr, klass(), klass_is_exact(),
   1.446 -                  (ptr == Constant ? const_oop() : NULL), offset, instance_id);
   1.447 +                  (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative);
   1.448      }
   1.449      case NotNull:
   1.450      case BotPTR: {
   1.451        int instance_id = meet_instance_id(tp->instance_id());
   1.452 -      return TypeOopPtr::make(ptr, offset, instance_id);
   1.453 +      const TypeOopPtr* speculative = meet_speculative(tp);
   1.454 +      return TypeOopPtr::make(ptr, offset, instance_id, speculative);
   1.455      }
   1.456      default: typerr(t);
   1.457      }
   1.458 @@ -3102,17 +3265,18 @@
   1.459      PTR ptr = meet_ptr(tp->ptr());
   1.460      switch (tp->ptr()) {
   1.461      case Null:
   1.462 -      if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
   1.463 +      if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
   1.464        // else fall through to AnyNull
   1.465      case TopPTR:
   1.466      case AnyNull: {
   1.467        int instance_id = meet_instance_id(InstanceTop);
   1.468 -      return make( ptr, klass(), klass_is_exact(),
   1.469 -                   (ptr == Constant ? const_oop() : NULL), offset, instance_id);
   1.470 +      const TypeOopPtr* speculative = _speculative;
   1.471 +      return make(ptr, klass(), klass_is_exact(),
   1.472 +                  (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative);
   1.473      }
   1.474      case NotNull:
   1.475      case BotPTR:
   1.476 -      return TypePtr::make( AnyPtr, ptr, offset );
   1.477 +      return TypePtr::make(AnyPtr, ptr, offset);
   1.478      default: typerr(t);
   1.479      }
   1.480    }
   1.481 @@ -3139,13 +3303,14 @@
   1.482      int off = meet_offset( tinst->offset() );
   1.483      PTR ptr = meet_ptr( tinst->ptr() );
   1.484      int instance_id = meet_instance_id(tinst->instance_id());
   1.485 +    const TypeOopPtr* speculative = meet_speculative(tinst);
   1.486  
   1.487      // Check for easy case; klasses are equal (and perhaps not loaded!)
   1.488      // If we have constants, then we created oops so classes are loaded
   1.489      // and we can handle the constants further down.  This case handles
   1.490      // both-not-loaded or both-loaded classes
   1.491      if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
   1.492 -      return make( ptr, klass(), klass_is_exact(), NULL, off, instance_id );
   1.493 +      return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative);
   1.494      }
   1.495  
   1.496      // Classes require inspection in the Java klass hierarchy.  Must be loaded.
   1.497 @@ -3167,7 +3332,8 @@
   1.498      }
   1.499  
   1.500      // Handle mixing oops and interfaces first.
   1.501 -    if( this_klass->is_interface() && !tinst_klass->is_interface() ) {
   1.502 +    if( this_klass->is_interface() && !(tinst_klass->is_interface() ||
   1.503 +                                        tinst_klass == ciEnv::current()->Object_klass())) {
   1.504        ciKlass *tmp = tinst_klass; // Swap interface around
   1.505        tinst_klass = this_klass;
   1.506        this_klass = tmp;
   1.507 @@ -3208,7 +3374,7 @@
   1.508          // Find out which constant.
   1.509          o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
   1.510        }
   1.511 -      return make( ptr, k, xk, o, off, instance_id );
   1.512 +      return make(ptr, k, xk, o, off, instance_id, speculative);
   1.513      }
   1.514  
   1.515      // Either oop vs oop or interface vs interface or interface vs Object
   1.516 @@ -3285,7 +3451,7 @@
   1.517          else
   1.518            ptr = NotNull;
   1.519        }
   1.520 -      return make( ptr, this_klass, this_xk, o, off, instance_id );
   1.521 +      return make(ptr, this_klass, this_xk, o, off, instance_id, speculative);
   1.522      } // Else classes are not equal
   1.523  
   1.524      // Since klasses are different, we require a LCA in the Java
   1.525 @@ -3296,7 +3462,7 @@
   1.526  
   1.527      // Now we find the LCA of Java classes
   1.528      ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
   1.529 -    return make( ptr, k, false, NULL, off, instance_id );
   1.530 +    return make(ptr, k, false, NULL, off, instance_id, speculative);
   1.531    } // End of case InstPtr
   1.532  
   1.533    } // End of switch
   1.534 @@ -3320,7 +3486,7 @@
   1.535  // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
   1.536  // inheritance mechanism.
   1.537  const Type *TypeInstPtr::xdual() const {
   1.538 -  return new TypeInstPtr( dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id()  );
   1.539 +  return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative());
   1.540  }
   1.541  
   1.542  //------------------------------eq---------------------------------------------
   1.543 @@ -3376,12 +3542,18 @@
   1.544      st->print(",iid=top");
   1.545    else if (_instance_id != InstanceBot)
   1.546      st->print(",iid=%d",_instance_id);
   1.547 +
   1.548 +  dump_speculative(st);
   1.549  }
   1.550  #endif
   1.551  
   1.552  //------------------------------add_offset-------------------------------------
   1.553 -const TypePtr *TypeInstPtr::add_offset( intptr_t offset ) const {
   1.554 -  return make( _ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id );
   1.555 +const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
   1.556 +  return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id, add_offset_speculative(offset));
   1.557 +}
   1.558 +
   1.559 +const TypeOopPtr *TypeInstPtr::remove_speculative() const {
   1.560 +  return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, NULL);
   1.561  }
   1.562  
   1.563  //=============================================================================
   1.564 @@ -3398,30 +3570,30 @@
   1.565  const TypeAryPtr *TypeAryPtr::DOUBLES;
   1.566  
   1.567  //------------------------------make-------------------------------------------
   1.568 -const TypeAryPtr *TypeAryPtr::make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) {
   1.569 +const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, const TypeOopPtr* speculative) {
   1.570    assert(!(k == NULL && ary->_elem->isa_int()),
   1.571           "integral arrays must be pre-equipped with a class");
   1.572    if (!xk)  xk = ary->ary_must_be_exact();
   1.573    assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
   1.574    if (!UseExactTypes)  xk = (ptr == Constant);
   1.575 -  return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false))->hashcons();
   1.576 +  return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative))->hashcons();
   1.577  }
   1.578  
   1.579  //------------------------------make-------------------------------------------
   1.580 -const TypeAryPtr *TypeAryPtr::make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, bool is_autobox_cache) {
   1.581 +const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, const TypeOopPtr* speculative, bool is_autobox_cache) {
   1.582    assert(!(k == NULL && ary->_elem->isa_int()),
   1.583           "integral arrays must be pre-equipped with a class");
   1.584    assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
   1.585    if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
   1.586    assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
   1.587    if (!UseExactTypes)  xk = (ptr == Constant);
   1.588 -  return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache))->hashcons();
   1.589 +  return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative))->hashcons();
   1.590  }
   1.591  
   1.592  //------------------------------cast_to_ptr_type-------------------------------
   1.593  const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
   1.594    if( ptr == _ptr ) return this;
   1.595 -  return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id);
   1.596 +  return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative);
   1.597  }
   1.598  
   1.599  
   1.600 @@ -3430,13 +3602,13 @@
   1.601    if( klass_is_exact == _klass_is_exact ) return this;
   1.602    if (!UseExactTypes)  return this;
   1.603    if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
   1.604 -  return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id);
   1.605 +  return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative);
   1.606  }
   1.607  
   1.608  //-----------------------------cast_to_instance_id----------------------------
   1.609  const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
   1.610    if( instance_id == _instance_id ) return this;
   1.611 -  return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id);
   1.612 +  return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative);
   1.613  }
   1.614  
   1.615  //-----------------------------narrow_size_type-------------------------------
   1.616 @@ -3499,7 +3671,7 @@
   1.617    new_size = narrow_size_type(new_size);
   1.618    if (new_size == size())  return this;
   1.619    const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
   1.620 -  return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
   1.621 +  return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative);
   1.622  }
   1.623  
   1.624  
   1.625 @@ -3548,7 +3720,7 @@
   1.626  
   1.627  //------------------------------meet-------------------------------------------
   1.628  // Compute the MEET of two types.  It returns a new Type object.
   1.629 -const Type *TypeAryPtr::xmeet( const Type *t ) const {
   1.630 +const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
   1.631    // Perform a fast test for common case; meeting the same types together.
   1.632    if( this == t ) return this;  // Meeting same type-rep?
   1.633    // Current "this->_base" is Pointer
   1.634 @@ -3582,13 +3754,15 @@
   1.635      case TopPTR:
   1.636      case AnyNull: {
   1.637        int instance_id = meet_instance_id(InstanceTop);
   1.638 +      const TypeOopPtr* speculative = meet_speculative(tp);
   1.639        return make(ptr, (ptr == Constant ? const_oop() : NULL),
   1.640 -                  _ary, _klass, _klass_is_exact, offset, instance_id);
   1.641 +                  _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
   1.642      }
   1.643      case BotPTR:
   1.644      case NotNull: {
   1.645        int instance_id = meet_instance_id(tp->instance_id());
   1.646 -      return TypeOopPtr::make(ptr, offset, instance_id);
   1.647 +      const TypeOopPtr* speculative = meet_speculative(tp);
   1.648 +      return TypeOopPtr::make(ptr, offset, instance_id, speculative);
   1.649      }
   1.650      default: ShouldNotReachHere();
   1.651      }
   1.652 @@ -3610,8 +3784,9 @@
   1.653        // else fall through to AnyNull
   1.654      case AnyNull: {
   1.655        int instance_id = meet_instance_id(InstanceTop);
   1.656 -      return make( ptr, (ptr == Constant ? const_oop() : NULL),
   1.657 -                  _ary, _klass, _klass_is_exact, offset, instance_id);
   1.658 +      const TypeOopPtr* speculative = _speculative;
   1.659 +      return make(ptr, (ptr == Constant ? const_oop() : NULL),
   1.660 +                  _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
   1.661      }
   1.662      default: ShouldNotReachHere();
   1.663      }
   1.664 @@ -3627,6 +3802,7 @@
   1.665      const TypeAry *tary = _ary->meet(tap->_ary)->is_ary();
   1.666      PTR ptr = meet_ptr(tap->ptr());
   1.667      int instance_id = meet_instance_id(tap->instance_id());
   1.668 +    const TypeOopPtr* speculative = meet_speculative(tap);
   1.669      ciKlass* lazy_klass = NULL;
   1.670      if (tary->_elem->isa_int()) {
   1.671        // Integral array element types have irrelevant lattice relations.
   1.672 @@ -3654,7 +3830,7 @@
   1.673           // 'this' is exact and super or unrelated:
   1.674           (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
   1.675        tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
   1.676 -      return make( NotNull, NULL, tary, lazy_klass, false, off, InstanceBot );
   1.677 +      return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot);
   1.678      }
   1.679  
   1.680      bool xk = false;
   1.681 @@ -3662,8 +3838,12 @@
   1.682      case AnyNull:
   1.683      case TopPTR:
   1.684        // Compute new klass on demand, do not use tap->_klass
   1.685 -      xk = (tap->_klass_is_exact | this->_klass_is_exact);
   1.686 -      return make( ptr, const_oop(), tary, lazy_klass, xk, off, instance_id );
   1.687 +      if (below_centerline(this->_ptr)) {
   1.688 +        xk = this->_klass_is_exact;
   1.689 +      } else {
   1.690 +        xk = (tap->_klass_is_exact | this->_klass_is_exact);
   1.691 +      }
   1.692 +      return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative);
   1.693      case Constant: {
   1.694        ciObject* o = const_oop();
   1.695        if( _ptr == Constant ) {
   1.696 @@ -3675,25 +3855,23 @@
   1.697          } else {
   1.698            xk = true;
   1.699          }
   1.700 -      } else if( above_centerline(_ptr) ) {
   1.701 +      } else if(above_centerline(_ptr)) {
   1.702          o = tap->const_oop();
   1.703          xk = true;
   1.704        } else {
   1.705          // Only precise for identical arrays
   1.706          xk = this->_klass_is_exact && (klass() == tap->klass());
   1.707        }
   1.708 -      return TypeAryPtr::make( ptr, o, tary, lazy_klass, xk, off, instance_id );
   1.709 +      return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, instance_id, speculative);
   1.710      }
   1.711      case NotNull:
   1.712      case BotPTR:
   1.713        // Compute new klass on demand, do not use tap->_klass
   1.714        if (above_centerline(this->_ptr))
   1.715              xk = tap->_klass_is_exact;
   1.716 -      else if (above_centerline(tap->_ptr))
   1.717 -            xk = this->_klass_is_exact;
   1.718        else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
   1.719                (klass() == tap->klass()); // Only precise for identical arrays
   1.720 -      return TypeAryPtr::make( ptr, NULL, tary, lazy_klass, xk, off, instance_id );
   1.721 +      return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, instance_id, speculative);
   1.722      default: ShouldNotReachHere();
   1.723      }
   1.724    }
   1.725 @@ -3704,16 +3882,20 @@
   1.726      int offset = meet_offset(tp->offset());
   1.727      PTR ptr = meet_ptr(tp->ptr());
   1.728      int instance_id = meet_instance_id(tp->instance_id());
   1.729 +    const TypeOopPtr* speculative = meet_speculative(tp);
   1.730      switch (ptr) {
   1.731      case TopPTR:
   1.732      case AnyNull:                // Fall 'down' to dual of object klass
   1.733 -      if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
   1.734 -        return TypeAryPtr::make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id );
   1.735 +      // For instances when a subclass meets a superclass we fall
   1.736 +      // below the centerline when the superclass is exact. We need to
   1.737 +      // do the same here.
   1.738 +      if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
   1.739 +        return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
   1.740        } else {
   1.741          // cannot subclass, so the meet has to fall badly below the centerline
   1.742          ptr = NotNull;
   1.743          instance_id = InstanceBot;
   1.744 -        return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id);
   1.745 +        return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative);
   1.746        }
   1.747      case Constant:
   1.748      case NotNull:
   1.749 @@ -3722,10 +3904,13 @@
   1.750        if (above_centerline(tp->ptr())) {
   1.751          // If 'tp'  is above the centerline and it is Object class
   1.752          // then we can subclass in the Java class hierarchy.
   1.753 -        if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
   1.754 +        // For instances when a subclass meets a superclass we fall
   1.755 +        // below the centerline when the superclass is exact. We need
   1.756 +        // to do the same here.
   1.757 +        if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
   1.758            // that is, my array type is a subtype of 'tp' klass
   1.759 -          return make( ptr, (ptr == Constant ? const_oop() : NULL),
   1.760 -                       _ary, _klass, _klass_is_exact, offset, instance_id );
   1.761 +          return make(ptr, (ptr == Constant ? const_oop() : NULL),
   1.762 +                      _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
   1.763          }
   1.764        }
   1.765        // The other case cannot happen, since t cannot be a subtype of an array.
   1.766 @@ -3733,7 +3918,7 @@
   1.767        if( ptr == Constant )
   1.768           ptr = NotNull;
   1.769        instance_id = InstanceBot;
   1.770 -      return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id);
   1.771 +      return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative);
   1.772      default: typerr(t);
   1.773      }
   1.774    }
   1.775 @@ -3744,7 +3929,7 @@
   1.776  //------------------------------xdual------------------------------------------
   1.777  // Dual: compute field-by-field dual
   1.778  const Type *TypeAryPtr::xdual() const {
   1.779 -  return new TypeAryPtr( dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id(), is_autobox_cache() );
   1.780 +  return new TypeAryPtr(dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id(), is_autobox_cache(), dual_speculative());
   1.781  }
   1.782  
   1.783  //----------------------interface_vs_oop---------------------------------------
   1.784 @@ -3796,6 +3981,8 @@
   1.785      st->print(",iid=top");
   1.786    else if (_instance_id != InstanceBot)
   1.787      st->print(",iid=%d",_instance_id);
   1.788 +
   1.789 +  dump_speculative(st);
   1.790  }
   1.791  #endif
   1.792  
   1.793 @@ -3805,10 +3992,13 @@
   1.794  }
   1.795  
   1.796  //------------------------------add_offset-------------------------------------
   1.797 -const TypePtr *TypeAryPtr::add_offset( intptr_t offset ) const {
   1.798 -  return make( _ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id );
   1.799 -}
   1.800 -
   1.801 +const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
   1.802 +  return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset));
   1.803 +}
   1.804 +
   1.805 +const TypeOopPtr *TypeAryPtr::remove_speculative() const {
   1.806 +  return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, _offset, _instance_id, NULL);
   1.807 +}
   1.808  
   1.809  //=============================================================================
   1.810  

mercurial