src/share/vm/opto/type.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/opto

src/share/vm/opto/type.cpp

Print this page
rev 5771 : 8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
Summary: type methods shouldn't always operate on speculative part
Reviewed-by:
rev 5772 : imported patch typefixes-8027422-chris
rev 5777 : 8031754: Type speculation should favor profile data from outermost inlined method
Summary: favor profile data coming from outer most method
Reviewed-by:


2436 // Type-specific hashing function.
2437 int TypeRawPtr::hash(void) const {
2438   return (intptr_t)_bits + TypePtr::hash();
2439 }
2440 
2441 //------------------------------dump2------------------------------------------
2442 #ifndef PRODUCT
2443 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2444   if( _ptr == Constant )
2445     st->print(INTPTR_FORMAT, _bits);
2446   else
2447     st->print("rawptr:%s", ptr_msg[_ptr]);
2448 }
2449 #endif
2450 
2451 //=============================================================================
2452 // Convenience common pre-built type.
2453 const TypeOopPtr *TypeOopPtr::BOTTOM;
2454 
2455 //------------------------------TypeOopPtr-------------------------------------
2456 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative)
2457   : TypePtr(t, ptr, offset),
2458     _const_oop(o), _klass(k),
2459     _klass_is_exact(xk),
2460     _is_ptr_to_narrowoop(false),
2461     _is_ptr_to_narrowklass(false),
2462     _is_ptr_to_boxed_value(false),
2463     _instance_id(instance_id),
2464     _speculative(speculative) {

2465   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
2466       (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
2467     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
2468   }
2469 #ifdef _LP64
2470   if (_offset != 0) {
2471     if (_offset == oopDesc::klass_offset_in_bytes()) {
2472       _is_ptr_to_narrowklass = UseCompressedClassPointers;
2473     } else if (klass() == NULL) {
2474       // Array with unknown body type
2475       assert(this->isa_aryptr(), "only arrays without klass");
2476       _is_ptr_to_narrowoop = UseCompressedOops;
2477     } else if (this->isa_aryptr()) {
2478       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
2479                              _offset != arrayOopDesc::length_offset_in_bytes());
2480     } else if (klass()->is_instance_klass()) {
2481       ciInstanceKlass* ik = klass()->as_instance_klass();
2482       ciField* field = NULL;
2483       if (this->isa_klassptr()) {
2484         // Perm objects don't use compressed references


2511             BasicType basic_elem_type = field->layout_type();
2512             _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
2513                                                          basic_elem_type == T_ARRAY);
2514           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
2515             // Compile::find_alias_type() cast exactness on all types to verify
2516             // that it does not affect alias type.
2517             _is_ptr_to_narrowoop = UseCompressedOops;
2518           } else {
2519             // Type for the copy start in LibraryCallKit::inline_native_clone().
2520             _is_ptr_to_narrowoop = UseCompressedOops;
2521           }
2522         }
2523       }
2524     }
2525   }
2526 #endif
2527 }
2528 
2529 //------------------------------make-------------------------------------------
2530 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
2531                                    int offset, int instance_id, const TypeOopPtr* speculative) {
2532   assert(ptr != Constant, "no constant generic pointers");
2533   ciKlass*  k = Compile::current()->env()->Object_klass();
2534   bool      xk = false;
2535   ciObject* o = NULL;
2536   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative))->hashcons();
2537 }
2538 
2539 
2540 //------------------------------cast_to_ptr_type-------------------------------
2541 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
2542   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
2543   if( ptr == _ptr ) return this;
2544   return make(ptr, _offset, _instance_id, _speculative);
2545 }
2546 
2547 //-----------------------------cast_to_instance_id----------------------------
2548 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
2549   // There are no instances of a general oop.
2550   // Return self unchanged.
2551   return this;
2552 }
2553 
2554 //-----------------------------cast_to_exactness-------------------------------
2555 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
2556   // There is no such thing as an exact general oop.
2557   // Return self unchanged.
2558   return this;
2559 }
2560 
2561 
2562 //------------------------------as_klass_type----------------------------------
2563 // Return the klass type corresponding to this instance or array type.
2564 // It is the type that is loaded from an object of this type.


2621     typerr(t);
2622 
2623   case RawPtr:
2624   case MetadataPtr:
2625   case KlassPtr:
2626     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
2627 
2628   case AnyPtr: {
2629     // Found an AnyPtr type vs self-OopPtr type
2630     const TypePtr *tp = t->is_ptr();
2631     int offset = meet_offset(tp->offset());
2632     PTR ptr = meet_ptr(tp->ptr());
2633     switch (tp->ptr()) {
2634     case Null:
2635       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset);
2636       // else fall through:
2637     case TopPTR:
2638     case AnyNull: {
2639       int instance_id = meet_instance_id(InstanceTop);
2640       const TypeOopPtr* speculative = _speculative;
2641       return make(ptr, offset, instance_id, speculative);
2642     }
2643     case BotPTR:
2644     case NotNull:
2645       return TypePtr::make(AnyPtr, ptr, offset);
2646     default: typerr(t);
2647     }
2648   }
2649 
2650   case OopPtr: {                 // Meeting to other OopPtrs
2651     const TypeOopPtr *tp = t->is_oopptr();
2652     int instance_id = meet_instance_id(tp->instance_id());
2653     const TypeOopPtr* speculative = xmeet_speculative(tp);
2654     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative);

2655   }
2656 
2657   case InstPtr:                  // For these, flip the call around to cut down
2658   case AryPtr:
2659     return t->xmeet(this);      // Call in reverse direction
2660 
2661   } // End of switch
2662   return this;                  // Return the double constant
2663 }
2664 
2665 
2666 //------------------------------xdual------------------------------------------
2667 // Dual of a pure heap pointer.  No relevant klass or oop information.
2668 const Type *TypeOopPtr::xdual() const {
2669   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
2670   assert(const_oop() == NULL,             "no constants here");
2671   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative());
2672 }
2673 
2674 //--------------------------make_from_klass_common-----------------------------
2675 // Computes the element-type given a klass.
2676 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
2677   if (klass->is_instance_klass()) {
2678     Compile* C = Compile::current();
2679     Dependencies* deps = C->dependencies();
2680     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
2681     // Element is an instance
2682     bool klass_is_exact = false;
2683     if (klass->is_loaded()) {
2684       // Try to set klass_is_exact.
2685       ciInstanceKlass* ik = klass->as_instance_klass();
2686       klass_is_exact = ik->is_final();
2687       if (!klass_is_exact && klass_change
2688           && deps != NULL && UseUniqueSubclasses) {
2689         ciInstanceKlass* sub = ik->unique_concrete_subklass();
2690         if (sub != NULL) {
2691           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);


2831   // class-typed Phi and an interface flows in, it's possible that the meet &
2832   // join report an interface back out.  This isn't possible but happens
2833   // because the type system doesn't interact well with interfaces.
2834   if (ftip != NULL && ktip != NULL &&
2835       ftip->is_loaded() &&  ftip->klass()->is_interface() &&
2836       ktip->is_loaded() && !ktip->klass()->is_interface()) {
2837     // Happens in a CTW of rt.jar, 320-341, no extra flags
2838     assert(!ftip->klass_is_exact(), "interface could not be exact");
2839     return ktip->cast_to_ptr_type(ftip->ptr());
2840   }
2841 
2842   return ft;
2843 }
2844 
2845 //------------------------------eq---------------------------------------------
2846 // Structural equality check for Type representations
2847 bool TypeOopPtr::eq( const Type *t ) const {
2848   const TypeOopPtr *a = (const TypeOopPtr*)t;
2849   if (_klass_is_exact != a->_klass_is_exact ||
2850       _instance_id != a->_instance_id ||
2851       !eq_speculative(a))  return false;

2852   ciObject* one = const_oop();
2853   ciObject* two = a->const_oop();
2854   if (one == NULL || two == NULL) {
2855     return (one == two) && TypePtr::eq(t);
2856   } else {
2857     return one->equals(two) && TypePtr::eq(t);
2858   }
2859 }
2860 
2861 //------------------------------hash-------------------------------------------
2862 // Type-specific hashing function.
2863 int TypeOopPtr::hash(void) const {
2864   return
2865     (const_oop() ? const_oop()->hash() : 0) +
2866     _klass_is_exact +
2867     _instance_id +
2868     hash_speculative() +

2869     TypePtr::hash();
2870 }
2871 
2872 //------------------------------dump2------------------------------------------
2873 #ifndef PRODUCT
2874 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2875   st->print("oopptr:%s", ptr_msg[_ptr]);
2876   if( _klass_is_exact ) st->print(":exact");
2877   if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
2878   switch( _offset ) {
2879   case OffsetTop: st->print("+top"); break;
2880   case OffsetBot: st->print("+any"); break;
2881   case         0: break;
2882   default:        st->print("+%d",_offset); break;
2883   }
2884   if (_instance_id == InstanceTop)
2885     st->print(",iid=top");
2886   else if (_instance_id != InstanceBot)
2887     st->print(",iid=%d",_instance_id);
2888 

2889   dump_speculative(st);
2890 }
2891 
2892 /**
2893  *dump the speculative part of the type
2894  */
2895 void TypeOopPtr::dump_speculative(outputStream *st) const {
2896   if (_speculative != NULL) {
2897     st->print(" (speculative=");
2898     _speculative->dump_on(st);
2899     st->print(")");
2900   }
2901 }










2902 #endif
2903 
2904 //------------------------------singleton--------------------------------------
2905 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2906 // constants
2907 bool TypeOopPtr::singleton(void) const {
2908   // detune optimizer to not generate constant oop + constant offset as a constant!
2909   // TopPTR, Null, AnyNull, Constant are all singletons
2910   return (_offset == 0) && !below_centerline(_ptr);
2911 }
2912 
2913 //------------------------------add_offset-------------------------------------
2914 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
2915   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset));
2916 }
2917 
2918 /**
2919  * Return same type without a speculative part
2920  */
2921 const Type* TypeOopPtr::remove_speculative() const {
2922   if (_speculative == NULL) {
2923     return this;
2924   }
2925   return make(_ptr, _offset, _instance_id, NULL);









2926 }
2927 
2928 //------------------------------meet_instance_id--------------------------------
2929 int TypeOopPtr::meet_instance_id( int instance_id ) const {
2930   // Either is 'TOP' instance?  Return the other instance!
2931   if( _instance_id == InstanceTop ) return  instance_id;
2932   if(  instance_id == InstanceTop ) return _instance_id;
2933   // If either is different, return 'BOTTOM' instance
2934   if( _instance_id != instance_id ) return InstanceBot;
2935   return _instance_id;
2936 }
2937 
2938 //------------------------------dual_instance_id--------------------------------
2939 int TypeOopPtr::dual_instance_id( ) const {
2940   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
2941   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
2942   return _instance_id;              // Map everything else into self
2943 }
2944 
2945 /**


3008   }
3009 
3010   if (_speculative->base() != other->speculative()->base()) {
3011     return false;
3012   }
3013 
3014   return _speculative->eq(other->speculative());
3015 }
3016 
3017 /**
3018  * Hash of the speculative part of the type
3019  */
3020 int TypeOopPtr::hash_speculative() const {
3021   if (_speculative == NULL) {
3022     return 0;
3023   }
3024 
3025   return _speculative->hash();
3026 }
3027 















3028 
3029 //=============================================================================
3030 // Convenience common pre-built types.
3031 const TypeInstPtr *TypeInstPtr::NOTNULL;
3032 const TypeInstPtr *TypeInstPtr::BOTTOM;
3033 const TypeInstPtr *TypeInstPtr::MIRROR;
3034 const TypeInstPtr *TypeInstPtr::MARK;
3035 const TypeInstPtr *TypeInstPtr::KLASS;
3036 
3037 //------------------------------TypeInstPtr-------------------------------------
3038 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id, const TypeOopPtr* speculative)
3039   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative), _name(k->name()) {
3040    assert(k != NULL &&
3041           (k->is_loaded() || o == NULL),
3042           "cannot have constants with non-loaded klass");
3043 };
3044 
3045 //------------------------------make-------------------------------------------
3046 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3047                                      ciKlass* k,
3048                                      bool xk,
3049                                      ciObject* o,
3050                                      int offset,
3051                                      int instance_id,
3052                                      const TypeOopPtr* speculative) {

3053   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3054   // Either const_oop() is NULL or else ptr is Constant
3055   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3056           "constant pointers must have a value supplied" );
3057   // Ptr is never Null
3058   assert( ptr != Null, "NULL pointers are not typed" );
3059 
3060   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3061   if (!UseExactTypes)  xk = false;
3062   if (ptr == Constant) {
3063     // Note:  This case includes meta-object constants, such as methods.
3064     xk = true;
3065   } else if (k->is_loaded()) {
3066     ciInstanceKlass* ik = k->as_instance_klass();
3067     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3068     if (xk && ik->is_interface())  xk = false;  // no exact interface
3069   }
3070 
3071   // Now hash this baby
3072   TypeInstPtr *result =
3073     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative))->hashcons();
3074 
3075   return result;
3076 }
3077 
3078 /**
3079  *  Create constant type for a constant boxed value
3080  */
3081 const Type* TypeInstPtr::get_const_boxed_value() const {
3082   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3083   assert((const_oop() != NULL), "should be called only for constant object");
3084   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3085   BasicType bt = constant.basic_type();
3086   switch (bt) {
3087     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
3088     case T_INT:      return TypeInt::make(constant.as_int());
3089     case T_CHAR:     return TypeInt::make(constant.as_char());
3090     case T_BYTE:     return TypeInt::make(constant.as_byte());
3091     case T_SHORT:    return TypeInt::make(constant.as_short());
3092     case T_FLOAT:    return TypeF::make(constant.as_float());
3093     case T_DOUBLE:   return TypeD::make(constant.as_double());
3094     case T_LONG:     return TypeLong::make(constant.as_long());
3095     default:         break;
3096   }
3097   fatal(err_msg_res("Invalid boxed value type '%s'", type2name(bt)));
3098   return NULL;
3099 }
3100 
3101 //------------------------------cast_to_ptr_type-------------------------------
3102 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3103   if( ptr == _ptr ) return this;
3104   // Reconstruct _sig info here since not a problem with later lazy
3105   // construction, _sig will show up on demand.
3106   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative);
3107 }
3108 
3109 
3110 //-----------------------------cast_to_exactness-------------------------------
3111 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3112   if( klass_is_exact == _klass_is_exact ) return this;
3113   if (!UseExactTypes)  return this;
3114   if (!_klass->is_loaded())  return this;
3115   ciInstanceKlass* ik = _klass->as_instance_klass();
3116   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3117   if( ik->is_interface() )              return this;  // cannot set xk
3118   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative);
3119 }
3120 
3121 //-----------------------------cast_to_instance_id----------------------------
3122 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3123   if( instance_id == _instance_id ) return this;
3124   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative);
3125 }
3126 
3127 //------------------------------xmeet_unloaded---------------------------------
3128 // Compute the MEET of two InstPtrs when at least one is unloaded.
3129 // Assume classes are different since called after check for same name/class-loader
3130 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3131     int off = meet_offset(tinst->offset());
3132     PTR ptr = meet_ptr(tinst->ptr());
3133     int instance_id = meet_instance_id(tinst->instance_id());
3134     const TypeOopPtr* speculative = xmeet_speculative(tinst);

3135 
3136     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3137     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3138     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3139       //
3140       // Meet unloaded class with java/lang/Object
3141       //
3142       // Meet
3143       //          |                     Unloaded Class
3144       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3145       //  ===================================================================
3146       //   TOP    | ..........................Unloaded......................|
3147       //  AnyNull |  U-AN    |................Unloaded......................|
3148       // Constant | ... O-NN .................................. |   O-BOT   |
3149       //  NotNull | ... O-NN .................................. |   O-BOT   |
3150       //  BOTTOM  | ........................Object-BOTTOM ..................|
3151       //
3152       assert(loaded->ptr() != TypePtr::Null, "insanity check");
3153       //
3154       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
3155       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative); }
3156       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
3157       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
3158         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
3159         else                                      { return TypeInstPtr::NOTNULL; }
3160       }
3161       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
3162 
3163       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
3164     }
3165 
3166     // Both are unloaded, not the same class, not Object
3167     // Or meet unloaded with a different loaded class, not java/lang/Object
3168     if( ptr != TypePtr::BotPTR ) {
3169       return TypeInstPtr::NOTNULL;
3170     }
3171     return TypeInstPtr::BOTTOM;
3172 }
3173 
3174 
3175 //------------------------------meet-------------------------------------------


3192   case NarrowOop:
3193   case NarrowKlass:
3194   case Bottom:                  // Ye Olde Default
3195     return Type::BOTTOM;
3196   case Top:
3197     return this;
3198 
3199   default:                      // All else is a mistake
3200     typerr(t);
3201 
3202   case MetadataPtr:
3203   case KlassPtr:
3204   case RawPtr: return TypePtr::BOTTOM;
3205 
3206   case AryPtr: {                // All arrays inherit from Object class
3207     const TypeAryPtr *tp = t->is_aryptr();
3208     int offset = meet_offset(tp->offset());
3209     PTR ptr = meet_ptr(tp->ptr());
3210     int instance_id = meet_instance_id(tp->instance_id());
3211     const TypeOopPtr* speculative = xmeet_speculative(tp);

3212     switch (ptr) {
3213     case TopPTR:
3214     case AnyNull:                // Fall 'down' to dual of object klass
3215       // For instances when a subclass meets a superclass we fall
3216       // below the centerline when the superclass is exact. We need to
3217       // do the same here.
3218       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3219         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative);
3220       } else {
3221         // cannot subclass, so the meet has to fall badly below the centerline
3222         ptr = NotNull;
3223         instance_id = InstanceBot;
3224         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative);
3225       }
3226     case Constant:
3227     case NotNull:
3228     case BotPTR:                // Fall down to object klass
3229       // LCA is object_klass, but if we subclass from the top we can do better
3230       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
3231         // If 'this' (InstPtr) is above the centerline and it is Object class
3232         // then we can subclass in the Java class hierarchy.
3233         // For instances when a subclass meets a superclass we fall
3234         // below the centerline when the superclass is exact. We need
3235         // to do the same here.
3236         if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3237           // that is, tp's array type is a subtype of my klass
3238           return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
3239                                   tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative);
3240         }
3241       }
3242       // The other case cannot happen, since I cannot be a subtype of an array.
3243       // The meet falls down to Object class below centerline.
3244       if( ptr == Constant )
3245          ptr = NotNull;
3246       instance_id = InstanceBot;
3247       return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative);
3248     default: typerr(t);
3249     }
3250   }
3251 
3252   case OopPtr: {                // Meeting to OopPtrs
3253     // Found a OopPtr type vs self-InstPtr type
3254     const TypeOopPtr *tp = t->is_oopptr();
3255     int offset = meet_offset(tp->offset());
3256     PTR ptr = meet_ptr(tp->ptr());
3257     switch (tp->ptr()) {
3258     case TopPTR:
3259     case AnyNull: {
3260       int instance_id = meet_instance_id(InstanceTop);
3261       const TypeOopPtr* speculative = xmeet_speculative(tp);

3262       return make(ptr, klass(), klass_is_exact(),
3263                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative);
3264     }
3265     case NotNull:
3266     case BotPTR: {
3267       int instance_id = meet_instance_id(tp->instance_id());
3268       const TypeOopPtr* speculative = xmeet_speculative(tp);
3269       return TypeOopPtr::make(ptr, offset, instance_id, speculative);

3270     }
3271     default: typerr(t);
3272     }
3273   }
3274 
3275   case AnyPtr: {                // Meeting to AnyPtrs
3276     // Found an AnyPtr type vs self-InstPtr type
3277     const TypePtr *tp = t->is_ptr();
3278     int offset = meet_offset(tp->offset());
3279     PTR ptr = meet_ptr(tp->ptr());
3280     switch (tp->ptr()) {
3281     case Null:
3282       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
3283       // else fall through to AnyNull
3284     case TopPTR:
3285     case AnyNull: {
3286       int instance_id = meet_instance_id(InstanceTop);
3287       const TypeOopPtr* speculative = _speculative;
3288       return make(ptr, klass(), klass_is_exact(),
3289                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative);
3290     }
3291     case NotNull:
3292     case BotPTR:
3293       return TypePtr::make(AnyPtr, ptr, offset);
3294     default: typerr(t);
3295     }
3296   }
3297 
3298   /*
3299                  A-top         }
3300                /   |   \       }  Tops
3301            B-top A-any C-top   }
3302               | /  |  \ |      }  Any-nulls
3303            B-any   |   C-any   }
3304               |    |    |
3305            B-con A-con C-con   } constants; not comparable across classes
3306               |    |    |
3307            B-not   |   C-not   }
3308               | \  |  / |      }  not-nulls
3309            B-bot A-not C-bot   }
3310                \   |   /       }  Bottoms
3311                  A-bot         }
3312   */
3313 
3314   case InstPtr: {                // Meeting 2 Oops?
3315     // Found an InstPtr sub-type vs self-InstPtr type
3316     const TypeInstPtr *tinst = t->is_instptr();
3317     int off = meet_offset( tinst->offset() );
3318     PTR ptr = meet_ptr( tinst->ptr() );
3319     int instance_id = meet_instance_id(tinst->instance_id());
3320     const TypeOopPtr* speculative = xmeet_speculative(tinst);

3321 
3322     // Check for easy case; klasses are equal (and perhaps not loaded!)
3323     // If we have constants, then we created oops so classes are loaded
3324     // and we can handle the constants further down.  This case handles
3325     // both-not-loaded or both-loaded classes
3326     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
3327       return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative);
3328     }
3329 
3330     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
3331     ciKlass* tinst_klass = tinst->klass();
3332     ciKlass* this_klass  = this->klass();
3333     bool tinst_xk = tinst->klass_is_exact();
3334     bool this_xk  = this->klass_is_exact();
3335     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
3336       // One of these classes has not been loaded
3337       const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
3338 #ifndef PRODUCT
3339       if( PrintOpto && Verbose ) {
3340         tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
3341         tty->print("  this == "); this->dump(); tty->cr();
3342         tty->print(" tinst == "); tinst->dump(); tty->cr();
3343       }
3344 #endif
3345       return unloaded_meet;
3346     }
3347 


3371         // below the centerline.  If we are on the centerline
3372         // (e.g., Constant vs. AnyNull interface), use the constant.
3373         k  = below_centerline(ptr) ? tinst_klass : this_klass;
3374         // If we are keeping this_klass, keep its exactness too.
3375         xk = below_centerline(ptr) ? tinst_xk    : this_xk;
3376       } else {                  // Does not implement, fall to Object
3377         // Oop does not implement interface, so mixing falls to Object
3378         // just like the verifier does (if both are above the
3379         // centerline fall to interface)
3380         k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
3381         xk = above_centerline(ptr) ? tinst_xk : false;
3382         // Watch out for Constant vs. AnyNull interface.
3383         if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
3384         instance_id = InstanceBot;
3385       }
3386       ciObject* o = NULL;  // the Constant value, if any
3387       if (ptr == Constant) {
3388         // Find out which constant.
3389         o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
3390       }
3391       return make(ptr, k, xk, o, off, instance_id, speculative);
3392     }
3393 
3394     // Either oop vs oop or interface vs interface or interface vs Object
3395 
3396     // !!! Here's how the symmetry requirement breaks down into invariants:
3397     // If we split one up & one down AND they subtype, take the down man.
3398     // If we split one up & one down AND they do NOT subtype, "fall hard".
3399     // If both are up and they subtype, take the subtype class.
3400     // If both are up and they do NOT subtype, "fall hard".
3401     // If both are down and they subtype, take the supertype class.
3402     // If both are down and they do NOT subtype, "fall hard".
3403     // Constants treated as down.
3404 
3405     // Now, reorder the above list; observe that both-down+subtype is also
3406     // "fall hard"; "fall hard" becomes the default case:
3407     // If we split one up & one down AND they subtype, take the down man.
3408     // If both are up and they subtype, take the subtype class.
3409 
3410     // If both are down and they subtype, "fall hard".
3411     // If both are down and they do NOT subtype, "fall hard".


3448 
3449     // Check for classes now being equal
3450     if (tinst_klass->equals(this_klass)) {
3451       // If the klasses are equal, the constants may still differ.  Fall to
3452       // NotNull if they do (neither constant is NULL; that is a special case
3453       // handled elsewhere).
3454       ciObject* o = NULL;             // Assume not constant when done
3455       ciObject* this_oop  = const_oop();
3456       ciObject* tinst_oop = tinst->const_oop();
3457       if( ptr == Constant ) {
3458         if (this_oop != NULL && tinst_oop != NULL &&
3459             this_oop->equals(tinst_oop) )
3460           o = this_oop;
3461         else if (above_centerline(this ->_ptr))
3462           o = tinst_oop;
3463         else if (above_centerline(tinst ->_ptr))
3464           o = this_oop;
3465         else
3466           ptr = NotNull;
3467       }
3468       return make(ptr, this_klass, this_xk, o, off, instance_id, speculative);
3469     } // Else classes are not equal
3470 
3471     // Since klasses are different, we require a LCA in the Java
3472     // class hierarchy - which means we have to fall to at least NotNull.
3473     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3474       ptr = NotNull;
3475     instance_id = InstanceBot;
3476 
3477     // Now we find the LCA of Java classes
3478     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
3479     return make(ptr, k, false, NULL, off, instance_id, speculative);
3480   } // End of case InstPtr
3481 
3482   } // End of switch
3483   return this;                  // Return the double constant
3484 }
3485 
3486 
3487 //------------------------java_mirror_type--------------------------------------
3488 ciType* TypeInstPtr::java_mirror_type() const {
3489   // must be a singleton type
3490   if( const_oop() == NULL )  return NULL;
3491 
3492   // must be of type java.lang.Class
3493   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
3494 
3495   return const_oop()->as_instance()->java_mirror_type();
3496 }
3497 
3498 
3499 //------------------------------xdual------------------------------------------
3500 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
3501 // inheritance mechanism.
3502 const Type *TypeInstPtr::xdual() const {
3503   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative());
3504 }
3505 
3506 //------------------------------eq---------------------------------------------
3507 // Structural equality check for Type representations
3508 bool TypeInstPtr::eq( const Type *t ) const {
3509   const TypeInstPtr *p = t->is_instptr();
3510   return
3511     klass()->equals(p->klass()) &&
3512     TypeOopPtr::eq(p);          // Check sub-type stuff
3513 }
3514 
3515 //------------------------------hash-------------------------------------------
3516 // Type-specific hashing function.
3517 int TypeInstPtr::hash(void) const {
3518   int hash = klass()->hash() + TypeOopPtr::hash();
3519   return hash;
3520 }
3521 
3522 //------------------------------dump2------------------------------------------
3523 // Dump oop Type


3540   case TopPTR:
3541   case AnyNull:
3542   case NotNull:
3543     st->print(":%s", ptr_msg[_ptr]);
3544     if( _klass_is_exact ) st->print(":exact");
3545     break;
3546   }
3547 
3548   if( _offset ) {               // Dump offset, if any
3549     if( _offset == OffsetBot )      st->print("+any");
3550     else if( _offset == OffsetTop ) st->print("+unknown");
3551     else st->print("+%d", _offset);
3552   }
3553 
3554   st->print(" *");
3555   if (_instance_id == InstanceTop)
3556     st->print(",iid=top");
3557   else if (_instance_id != InstanceBot)
3558     st->print(",iid=%d",_instance_id);
3559 

3560   dump_speculative(st);
3561 }
3562 #endif
3563 
3564 //------------------------------add_offset-------------------------------------
3565 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
3566   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id, add_offset_speculative(offset));
3567 }
3568 
3569 const Type *TypeInstPtr::remove_speculative() const {
3570   if (_speculative == NULL) {
3571     return this;
3572   }
3573   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, NULL);




3574 }
3575 
3576 //=============================================================================
3577 // Convenience common pre-built types.
3578 const TypeAryPtr *TypeAryPtr::RANGE;
3579 const TypeAryPtr *TypeAryPtr::OOPS;
3580 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
3581 const TypeAryPtr *TypeAryPtr::BYTES;
3582 const TypeAryPtr *TypeAryPtr::SHORTS;
3583 const TypeAryPtr *TypeAryPtr::CHARS;
3584 const TypeAryPtr *TypeAryPtr::INTS;
3585 const TypeAryPtr *TypeAryPtr::LONGS;
3586 const TypeAryPtr *TypeAryPtr::FLOATS;
3587 const TypeAryPtr *TypeAryPtr::DOUBLES;
3588 
3589 //------------------------------make-------------------------------------------
3590 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, const TypeOopPtr* speculative) {
3591   assert(!(k == NULL && ary->_elem->isa_int()),
3592          "integral arrays must be pre-equipped with a class");
3593   if (!xk)  xk = ary->ary_must_be_exact();
3594   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3595   if (!UseExactTypes)  xk = (ptr == Constant);
3596   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative))->hashcons();
3597 }
3598 
3599 //------------------------------make-------------------------------------------
3600 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) {
3601   assert(!(k == NULL && ary->_elem->isa_int()),
3602          "integral arrays must be pre-equipped with a class");
3603   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
3604   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
3605   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3606   if (!UseExactTypes)  xk = (ptr == Constant);
3607   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative))->hashcons();
3608 }
3609 
3610 //------------------------------cast_to_ptr_type-------------------------------
3611 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
3612   if( ptr == _ptr ) return this;
3613   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative);
3614 }
3615 
3616 
3617 //-----------------------------cast_to_exactness-------------------------------
3618 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
3619   if( klass_is_exact == _klass_is_exact ) return this;
3620   if (!UseExactTypes)  return this;
3621   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
3622   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative);
3623 }
3624 
3625 //-----------------------------cast_to_instance_id----------------------------
3626 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
3627   if( instance_id == _instance_id ) return this;
3628   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative);
3629 }
3630 
3631 //-----------------------------narrow_size_type-------------------------------
3632 // Local cache for arrayOopDesc::max_array_length(etype),
3633 // which is kind of slow (and cached elsewhere by other users).
3634 static jint max_array_length_cache[T_CONFLICT+1];
3635 static jint max_array_length(BasicType etype) {
3636   jint& cache = max_array_length_cache[etype];
3637   jint res = cache;
3638   if (res == 0) {
3639     switch (etype) {
3640     case T_NARROWOOP:
3641       etype = T_OBJECT;
3642       break;
3643     case T_NARROWKLASS:
3644     case T_CONFLICT:
3645     case T_ILLEGAL:
3646     case T_VOID:
3647       etype = T_BYTE;           // will produce conservatively high value
3648     }


3671     hi = max_hi;
3672     if (size->is_con()) {
3673       lo = hi;
3674     }
3675     chg = true;
3676   }
3677   // Negative length arrays will produce weird intermediate dead fast-path code
3678   if (lo > hi)
3679     return TypeInt::ZERO;
3680   if (!chg)
3681     return size;
3682   return TypeInt::make(lo, hi, Type::WidenMin);
3683 }
3684 
3685 //-------------------------------cast_to_size----------------------------------
3686 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
3687   assert(new_size != NULL, "");
3688   new_size = narrow_size_type(new_size);
3689   if (new_size == size())  return this;
3690   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
3691   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative);
3692 }
3693 
3694 
3695 //------------------------------cast_to_stable---------------------------------
3696 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
3697   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
3698     return this;
3699 
3700   const Type* elem = this->elem();
3701   const TypePtr* elem_ptr = elem->make_ptr();
3702 
3703   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
3704     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
3705     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
3706   }
3707 
3708   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
3709 
3710   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
3711 }


3750   case FloatCon:
3751   case FloatBot:
3752   case DoubleTop:
3753   case DoubleCon:
3754   case DoubleBot:
3755   case NarrowOop:
3756   case NarrowKlass:
3757   case Bottom:                  // Ye Olde Default
3758     return Type::BOTTOM;
3759   case Top:
3760     return this;
3761 
3762   default:                      // All else is a mistake
3763     typerr(t);
3764 
3765   case OopPtr: {                // Meeting to OopPtrs
3766     // Found a OopPtr type vs self-AryPtr type
3767     const TypeOopPtr *tp = t->is_oopptr();
3768     int offset = meet_offset(tp->offset());
3769     PTR ptr = meet_ptr(tp->ptr());

3770     switch (tp->ptr()) {
3771     case TopPTR:
3772     case AnyNull: {
3773       int instance_id = meet_instance_id(InstanceTop);
3774       const TypeOopPtr* speculative = xmeet_speculative(tp);
3775       return make(ptr, (ptr == Constant ? const_oop() : NULL),
3776                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
3777     }
3778     case BotPTR:
3779     case NotNull: {
3780       int instance_id = meet_instance_id(tp->instance_id());
3781       const TypeOopPtr* speculative = xmeet_speculative(tp);
3782       return TypeOopPtr::make(ptr, offset, instance_id, speculative);
3783     }
3784     default: ShouldNotReachHere();
3785     }
3786   }
3787 
3788   case AnyPtr: {                // Meeting two AnyPtrs
3789     // Found an AnyPtr type vs self-AryPtr type
3790     const TypePtr *tp = t->is_ptr();
3791     int offset = meet_offset(tp->offset());
3792     PTR ptr = meet_ptr(tp->ptr());
3793     switch (tp->ptr()) {
3794     case TopPTR:
3795       return this;
3796     case BotPTR:
3797     case NotNull:
3798       return TypePtr::make(AnyPtr, ptr, offset);
3799     case Null:
3800       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
3801       // else fall through to AnyNull
3802     case AnyNull: {
3803       int instance_id = meet_instance_id(InstanceTop);
3804       const TypeOopPtr* speculative = _speculative;
3805       return make(ptr, (ptr == Constant ? const_oop() : NULL),
3806                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
3807     }
3808     default: ShouldNotReachHere();
3809     }
3810   }
3811 
3812   case MetadataPtr:
3813   case KlassPtr:
3814   case RawPtr: return TypePtr::BOTTOM;
3815 
3816   case AryPtr: {                // Meeting 2 references?
3817     const TypeAryPtr *tap = t->is_aryptr();
3818     int off = meet_offset(tap->offset());
3819     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
3820     PTR ptr = meet_ptr(tap->ptr());
3821     int instance_id = meet_instance_id(tap->instance_id());
3822     const TypeOopPtr* speculative = xmeet_speculative(tap);

3823     ciKlass* lazy_klass = NULL;
3824     if (tary->_elem->isa_int()) {
3825       // Integral array element types have irrelevant lattice relations.
3826       // It is the klass that determines array layout, not the element type.
3827       if (_klass == NULL)
3828         lazy_klass = tap->_klass;
3829       else if (tap->_klass == NULL || tap->_klass == _klass) {
3830         lazy_klass = _klass;
3831       } else {
3832         // Something like byte[int+] meets char[int+].
3833         // This must fall to bottom, not (int[-128..65535])[int+].
3834         instance_id = InstanceBot;
3835         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
3836       }
3837     } else // Non integral arrays.
3838       // Must fall to bottom if exact klasses in upper lattice
3839       // are not equal or super klass is exact.
3840       if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
3841           // meet with top[] and bottom[] are processed further down:
3842           tap->_klass != NULL  && this->_klass != NULL   &&
3843           // both are exact and not equal:
3844           ((tap->_klass_is_exact && this->_klass_is_exact) ||
3845            // 'tap'  is exact and super or unrelated:
3846            (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
3847            // 'this' is exact and super or unrelated:
3848            (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
3849       tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
3850       return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot);
3851     }
3852 
3853     bool xk = false;
3854     switch (tap->ptr()) {
3855     case AnyNull:
3856     case TopPTR:
3857       // Compute new klass on demand, do not use tap->_klass
3858       if (below_centerline(this->_ptr)) {
3859         xk = this->_klass_is_exact;
3860       } else {
3861         xk = (tap->_klass_is_exact | this->_klass_is_exact);
3862       }
3863       return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative);
3864     case Constant: {
3865       ciObject* o = const_oop();
3866       if( _ptr == Constant ) {
3867         if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
3868           xk = (klass() == tap->klass());
3869           ptr = NotNull;
3870           o = NULL;
3871           instance_id = InstanceBot;
3872         } else {
3873           xk = true;
3874         }
3875       } else if(above_centerline(_ptr)) {
3876         o = tap->const_oop();
3877         xk = true;
3878       } else {
3879         // Only precise for identical arrays
3880         xk = this->_klass_is_exact && (klass() == tap->klass());
3881       }
3882       return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, instance_id, speculative);
3883     }
3884     case NotNull:
3885     case BotPTR:
3886       // Compute new klass on demand, do not use tap->_klass
3887       if (above_centerline(this->_ptr))
3888             xk = tap->_klass_is_exact;
3889       else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
3890               (klass() == tap->klass()); // Only precise for identical arrays
3891       return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, instance_id, speculative);
3892     default: ShouldNotReachHere();
3893     }
3894   }
3895 
3896   // All arrays inherit from Object class
3897   case InstPtr: {
3898     const TypeInstPtr *tp = t->is_instptr();
3899     int offset = meet_offset(tp->offset());
3900     PTR ptr = meet_ptr(tp->ptr());
3901     int instance_id = meet_instance_id(tp->instance_id());
3902     const TypeOopPtr* speculative = xmeet_speculative(tp);

3903     switch (ptr) {
3904     case TopPTR:
3905     case AnyNull:                // Fall 'down' to dual of object klass
3906       // For instances when a subclass meets a superclass we fall
3907       // below the centerline when the superclass is exact. We need to
3908       // do the same here.
3909       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
3910         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
3911       } else {
3912         // cannot subclass, so the meet has to fall badly below the centerline
3913         ptr = NotNull;
3914         instance_id = InstanceBot;
3915         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative);
3916       }
3917     case Constant:
3918     case NotNull:
3919     case BotPTR:                // Fall down to object klass
3920       // LCA is object_klass, but if we subclass from the top we can do better
3921       if (above_centerline(tp->ptr())) {
3922         // If 'tp'  is above the centerline and it is Object class
3923         // then we can subclass in the Java class hierarchy.
3924         // For instances when a subclass meets a superclass we fall
3925         // below the centerline when the superclass is exact. We need
3926         // to do the same here.
3927         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
3928           // that is, my array type is a subtype of 'tp' klass
3929           return make(ptr, (ptr == Constant ? const_oop() : NULL),
3930                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
3931         }
3932       }
3933       // The other case cannot happen, since t cannot be a subtype of an array.
3934       // The meet falls down to Object class below centerline.
3935       if( ptr == Constant )
3936          ptr = NotNull;
3937       instance_id = InstanceBot;
3938       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative);
3939     default: typerr(t);
3940     }
3941   }
3942   }
3943   return this;                  // Lint noise
3944 }
3945 
3946 //------------------------------xdual------------------------------------------
3947 // Dual: compute field-by-field dual
3948 const Type *TypeAryPtr::xdual() const {
3949   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());
3950 }
3951 
3952 //----------------------interface_vs_oop---------------------------------------
3953 #ifdef ASSERT
3954 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
3955   const TypeAryPtr* t_aryptr = t->isa_aryptr();
3956   if (t_aryptr) {
3957     return _ary->interface_vs_oop(t_aryptr->_ary);
3958   }
3959   return false;
3960 }
3961 #endif
3962 
3963 //------------------------------dump2------------------------------------------
3964 #ifndef PRODUCT
3965 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3966   _ary->dump2(d,depth,st);
3967   switch( _ptr ) {
3968   case Constant:
3969     const_oop()->print(st);


3982   }
3983 
3984   if( _offset != 0 ) {
3985     int header_size = objArrayOopDesc::header_size() * wordSize;
3986     if( _offset == OffsetTop )       st->print("+undefined");
3987     else if( _offset == OffsetBot )  st->print("+any");
3988     else if( _offset < header_size ) st->print("+%d", _offset);
3989     else {
3990       BasicType basic_elem_type = elem()->basic_type();
3991       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
3992       int elem_size = type2aelembytes(basic_elem_type);
3993       st->print("[%d]", (_offset - array_base)/elem_size);
3994     }
3995   }
3996   st->print(" *");
3997   if (_instance_id == InstanceTop)
3998     st->print(",iid=top");
3999   else if (_instance_id != InstanceBot)
4000     st->print(",iid=%d",_instance_id);
4001 

4002   dump_speculative(st);
4003 }
4004 #endif
4005 
4006 bool TypeAryPtr::empty(void) const {
4007   if (_ary->empty())       return true;
4008   return TypeOopPtr::empty();
4009 }
4010 
4011 //------------------------------add_offset-------------------------------------
4012 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4013   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset));
4014 }
4015 
4016 const Type *TypeAryPtr::remove_speculative() const {
4017   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL);







4018 }
4019 
4020 //=============================================================================
4021 
4022 //------------------------------hash-------------------------------------------
4023 // Type-specific hashing function.
4024 int TypeNarrowPtr::hash(void) const {
4025   return _ptrtype->hash() + 7;
4026 }
4027 
4028 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
4029   return _ptrtype->singleton();
4030 }
4031 
4032 bool TypeNarrowPtr::empty(void) const {
4033   return _ptrtype->empty();
4034 }
4035 
4036 intptr_t TypeNarrowPtr::get_con() const {
4037   return _ptrtype->get_con();




2436 // Type-specific hashing function.
2437 int TypeRawPtr::hash(void) const {
2438   return (intptr_t)_bits + TypePtr::hash();
2439 }
2440 
2441 //------------------------------dump2------------------------------------------
2442 #ifndef PRODUCT
2443 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2444   if( _ptr == Constant )
2445     st->print(INTPTR_FORMAT, _bits);
2446   else
2447     st->print("rawptr:%s", ptr_msg[_ptr]);
2448 }
2449 #endif
2450 
2451 //=============================================================================
2452 // Convenience common pre-built type.
2453 const TypeOopPtr *TypeOopPtr::BOTTOM;
2454 
2455 //------------------------------TypeOopPtr-------------------------------------
2456 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth)
2457   : TypePtr(t, ptr, offset),
2458     _const_oop(o), _klass(k),
2459     _klass_is_exact(xk),
2460     _is_ptr_to_narrowoop(false),
2461     _is_ptr_to_narrowklass(false),
2462     _is_ptr_to_boxed_value(false),
2463     _instance_id(instance_id),
2464     _speculative(speculative),
2465     _inline_depth(inline_depth){
2466   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
2467       (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
2468     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
2469   }
2470 #ifdef _LP64
2471   if (_offset != 0) {
2472     if (_offset == oopDesc::klass_offset_in_bytes()) {
2473       _is_ptr_to_narrowklass = UseCompressedClassPointers;
2474     } else if (klass() == NULL) {
2475       // Array with unknown body type
2476       assert(this->isa_aryptr(), "only arrays without klass");
2477       _is_ptr_to_narrowoop = UseCompressedOops;
2478     } else if (this->isa_aryptr()) {
2479       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
2480                              _offset != arrayOopDesc::length_offset_in_bytes());
2481     } else if (klass()->is_instance_klass()) {
2482       ciInstanceKlass* ik = klass()->as_instance_klass();
2483       ciField* field = NULL;
2484       if (this->isa_klassptr()) {
2485         // Perm objects don't use compressed references


2512             BasicType basic_elem_type = field->layout_type();
2513             _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
2514                                                          basic_elem_type == T_ARRAY);
2515           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
2516             // Compile::find_alias_type() cast exactness on all types to verify
2517             // that it does not affect alias type.
2518             _is_ptr_to_narrowoop = UseCompressedOops;
2519           } else {
2520             // Type for the copy start in LibraryCallKit::inline_native_clone().
2521             _is_ptr_to_narrowoop = UseCompressedOops;
2522           }
2523         }
2524       }
2525     }
2526   }
2527 #endif
2528 }
2529 
2530 //------------------------------make-------------------------------------------
2531 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
2532                                    int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth) {
2533   assert(ptr != Constant, "no constant generic pointers");
2534   ciKlass*  k = Compile::current()->env()->Object_klass();
2535   bool      xk = false;
2536   ciObject* o = NULL;
2537   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
2538 }
2539 
2540 
2541 //------------------------------cast_to_ptr_type-------------------------------
2542 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
2543   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
2544   if( ptr == _ptr ) return this;
2545   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
2546 }
2547 
2548 //-----------------------------cast_to_instance_id----------------------------
2549 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
2550   // There are no instances of a general oop.
2551   // Return self unchanged.
2552   return this;
2553 }
2554 
2555 //-----------------------------cast_to_exactness-------------------------------
2556 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
2557   // There is no such thing as an exact general oop.
2558   // Return self unchanged.
2559   return this;
2560 }
2561 
2562 
2563 //------------------------------as_klass_type----------------------------------
2564 // Return the klass type corresponding to this instance or array type.
2565 // It is the type that is loaded from an object of this type.


2622     typerr(t);
2623 
2624   case RawPtr:
2625   case MetadataPtr:
2626   case KlassPtr:
2627     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
2628 
2629   case AnyPtr: {
2630     // Found an AnyPtr type vs self-OopPtr type
2631     const TypePtr *tp = t->is_ptr();
2632     int offset = meet_offset(tp->offset());
2633     PTR ptr = meet_ptr(tp->ptr());
2634     switch (tp->ptr()) {
2635     case Null:
2636       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset);
2637       // else fall through:
2638     case TopPTR:
2639     case AnyNull: {
2640       int instance_id = meet_instance_id(InstanceTop);
2641       const TypeOopPtr* speculative = _speculative;
2642       return make(ptr, offset, instance_id, speculative, _inline_depth);
2643     }
2644     case BotPTR:
2645     case NotNull:
2646       return TypePtr::make(AnyPtr, ptr, offset);
2647     default: typerr(t);
2648     }
2649   }
2650 
2651   case OopPtr: {                 // Meeting to other OopPtrs
2652     const TypeOopPtr *tp = t->is_oopptr();
2653     int instance_id = meet_instance_id(tp->instance_id());
2654     const TypeOopPtr* speculative = xmeet_speculative(tp);
2655     int depth = meet_inline_depth(tp->inline_depth());
2656     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
2657   }
2658 
2659   case InstPtr:                  // For these, flip the call around to cut down
2660   case AryPtr:
2661     return t->xmeet(this);      // Call in reverse direction
2662 
2663   } // End of switch
2664   return this;                  // Return the double constant
2665 }
2666 
2667 
2668 //------------------------------xdual------------------------------------------
2669 // Dual of a pure heap pointer.  No relevant klass or oop information.
2670 const Type *TypeOopPtr::xdual() const {
2671   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
2672   assert(const_oop() == NULL,             "no constants here");
2673   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
2674 }
2675 
2676 //--------------------------make_from_klass_common-----------------------------
2677 // Computes the element-type given a klass.
2678 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
2679   if (klass->is_instance_klass()) {
2680     Compile* C = Compile::current();
2681     Dependencies* deps = C->dependencies();
2682     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
2683     // Element is an instance
2684     bool klass_is_exact = false;
2685     if (klass->is_loaded()) {
2686       // Try to set klass_is_exact.
2687       ciInstanceKlass* ik = klass->as_instance_klass();
2688       klass_is_exact = ik->is_final();
2689       if (!klass_is_exact && klass_change
2690           && deps != NULL && UseUniqueSubclasses) {
2691         ciInstanceKlass* sub = ik->unique_concrete_subklass();
2692         if (sub != NULL) {
2693           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);


2833   // class-typed Phi and an interface flows in, it's possible that the meet &
2834   // join report an interface back out.  This isn't possible but happens
2835   // because the type system doesn't interact well with interfaces.
2836   if (ftip != NULL && ktip != NULL &&
2837       ftip->is_loaded() &&  ftip->klass()->is_interface() &&
2838       ktip->is_loaded() && !ktip->klass()->is_interface()) {
2839     // Happens in a CTW of rt.jar, 320-341, no extra flags
2840     assert(!ftip->klass_is_exact(), "interface could not be exact");
2841     return ktip->cast_to_ptr_type(ftip->ptr());
2842   }
2843 
2844   return ft;
2845 }
2846 
2847 //------------------------------eq---------------------------------------------
2848 // Structural equality check for Type representations
2849 bool TypeOopPtr::eq( const Type *t ) const {
2850   const TypeOopPtr *a = (const TypeOopPtr*)t;
2851   if (_klass_is_exact != a->_klass_is_exact ||
2852       _instance_id != a->_instance_id ||
2853       !eq_speculative(a) ||
2854       _inline_depth != a->_inline_depth)  return false;
2855   ciObject* one = const_oop();
2856   ciObject* two = a->const_oop();
2857   if (one == NULL || two == NULL) {
2858     return (one == two) && TypePtr::eq(t);
2859   } else {
2860     return one->equals(two) && TypePtr::eq(t);
2861   }
2862 }
2863 
2864 //------------------------------hash-------------------------------------------
2865 // Type-specific hashing function.
2866 int TypeOopPtr::hash(void) const {
2867   return
2868     (const_oop() ? const_oop()->hash() : 0) +
2869     _klass_is_exact +
2870     _instance_id +
2871     hash_speculative() +
2872     _inline_depth +
2873     TypePtr::hash();
2874 }
2875 
2876 //------------------------------dump2------------------------------------------
2877 #ifndef PRODUCT
2878 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2879   st->print("oopptr:%s", ptr_msg[_ptr]);
2880   if( _klass_is_exact ) st->print(":exact");
2881   if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
2882   switch( _offset ) {
2883   case OffsetTop: st->print("+top"); break;
2884   case OffsetBot: st->print("+any"); break;
2885   case         0: break;
2886   default:        st->print("+%d",_offset); break;
2887   }
2888   if (_instance_id == InstanceTop)
2889     st->print(",iid=top");
2890   else if (_instance_id != InstanceBot)
2891     st->print(",iid=%d",_instance_id);
2892 
2893   dump_inline_depth(st);
2894   dump_speculative(st);
2895 }
2896 
2897 /**
2898  *dump the speculative part of the type
2899  */
2900 void TypeOopPtr::dump_speculative(outputStream *st) const {
2901   if (_speculative != NULL) {
2902     st->print(" (speculative=");
2903     _speculative->dump_on(st);
2904     st->print(")");
2905   }
2906 }
2907 
2908 void TypeOopPtr::dump_inline_depth(outputStream *st) const {
2909   if (_inline_depth != InlineDepthBottom) {
2910     if (_inline_depth == InlineDepthTop) {
2911       st->print(" (inline_depth=InlineDepthTop)");
2912     } else {
2913       st->print(" (inline_depth=%d)", _inline_depth);
2914     }
2915   }
2916 }
2917 #endif
2918 
2919 //------------------------------singleton--------------------------------------
2920 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2921 // constants
2922 bool TypeOopPtr::singleton(void) const {
2923   // detune optimizer to not generate constant oop + constant offset as a constant!
2924   // TopPTR, Null, AnyNull, Constant are all singletons
2925   return (_offset == 0) && !below_centerline(_ptr);
2926 }
2927 
2928 //------------------------------add_offset-------------------------------------
2929 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
2930   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
2931 }
2932 
2933 /**
2934  * Return same type without a speculative part
2935  */
2936 const Type* TypeOopPtr::remove_speculative() const {
2937   if (_speculative == NULL) {
2938     return this;
2939   }
2940   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
2941 }
2942 
2943 /**
2944  * Return same type but with a different inline depth (used for speculation)
2945  *
2946  * @param depth  depth to meet with
2947  */
2948 const TypeOopPtr* TypeOopPtr::with_inline_depth(int depth) const {
2949   return make(_ptr, _offset, _instance_id, _speculative, depth);
2950 }
2951 
2952 //------------------------------meet_instance_id--------------------------------
2953 int TypeOopPtr::meet_instance_id( int instance_id ) const {
2954   // Either is 'TOP' instance?  Return the other instance!
2955   if( _instance_id == InstanceTop ) return  instance_id;
2956   if(  instance_id == InstanceTop ) return _instance_id;
2957   // If either is different, return 'BOTTOM' instance
2958   if( _instance_id != instance_id ) return InstanceBot;
2959   return _instance_id;
2960 }
2961 
2962 //------------------------------dual_instance_id--------------------------------
2963 int TypeOopPtr::dual_instance_id( ) const {
2964   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
2965   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
2966   return _instance_id;              // Map everything else into self
2967 }
2968 
2969 /**


3032   }
3033 
3034   if (_speculative->base() != other->speculative()->base()) {
3035     return false;
3036   }
3037 
3038   return _speculative->eq(other->speculative());
3039 }
3040 
3041 /**
3042  * Hash of the speculative part of the type
3043  */
3044 int TypeOopPtr::hash_speculative() const {
3045   if (_speculative == NULL) {
3046     return 0;
3047   }
3048 
3049   return _speculative->hash();
3050 }
3051 
3052 /**
3053  * dual of the inline depth for this type (used for speculation)
3054  */
3055 int TypeOopPtr::dual_inline_depth() const {
3056   return -inline_depth();
3057 }
3058 
3059 /**
3060  * meet of 2 inline depth (used for speculation)
3061  *
3062  * @param depth  depth to meet with
3063  */
3064 int TypeOopPtr::meet_inline_depth(int depth) const {
3065   return MIN2(inline_depth(), depth);
3066 }
3067 
3068 //=============================================================================
3069 // Convenience common pre-built types.
3070 const TypeInstPtr *TypeInstPtr::NOTNULL;
3071 const TypeInstPtr *TypeInstPtr::BOTTOM;
3072 const TypeInstPtr *TypeInstPtr::MIRROR;
3073 const TypeInstPtr *TypeInstPtr::MARK;
3074 const TypeInstPtr *TypeInstPtr::KLASS;
3075 
3076 //------------------------------TypeInstPtr-------------------------------------
3077 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id, const TypeOopPtr* speculative, int inline_depth)
3078   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative, inline_depth), _name(k->name()) {
3079    assert(k != NULL &&
3080           (k->is_loaded() || o == NULL),
3081           "cannot have constants with non-loaded klass");
3082 };
3083 
3084 //------------------------------make-------------------------------------------
3085 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3086                                      ciKlass* k,
3087                                      bool xk,
3088                                      ciObject* o,
3089                                      int offset,
3090                                      int instance_id,
3091                                      const TypeOopPtr* speculative,
3092                                      int inline_depth) {
3093   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3094   // Either const_oop() is NULL or else ptr is Constant
3095   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3096           "constant pointers must have a value supplied" );
3097   // Ptr is never Null
3098   assert( ptr != Null, "NULL pointers are not typed" );
3099 
3100   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3101   if (!UseExactTypes)  xk = false;
3102   if (ptr == Constant) {
3103     // Note:  This case includes meta-object constants, such as methods.
3104     xk = true;
3105   } else if (k->is_loaded()) {
3106     ciInstanceKlass* ik = k->as_instance_klass();
3107     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3108     if (xk && ik->is_interface())  xk = false;  // no exact interface
3109   }
3110 
3111   // Now hash this baby
3112   TypeInstPtr *result =
3113     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
3114 
3115   return result;
3116 }
3117 
3118 /**
3119  *  Create constant type for a constant boxed value
3120  */
3121 const Type* TypeInstPtr::get_const_boxed_value() const {
3122   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3123   assert((const_oop() != NULL), "should be called only for constant object");
3124   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3125   BasicType bt = constant.basic_type();
3126   switch (bt) {
3127     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
3128     case T_INT:      return TypeInt::make(constant.as_int());
3129     case T_CHAR:     return TypeInt::make(constant.as_char());
3130     case T_BYTE:     return TypeInt::make(constant.as_byte());
3131     case T_SHORT:    return TypeInt::make(constant.as_short());
3132     case T_FLOAT:    return TypeF::make(constant.as_float());
3133     case T_DOUBLE:   return TypeD::make(constant.as_double());
3134     case T_LONG:     return TypeLong::make(constant.as_long());
3135     default:         break;
3136   }
3137   fatal(err_msg_res("Invalid boxed value type '%s'", type2name(bt)));
3138   return NULL;
3139 }
3140 
3141 //------------------------------cast_to_ptr_type-------------------------------
3142 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3143   if( ptr == _ptr ) return this;
3144   // Reconstruct _sig info here since not a problem with later lazy
3145   // construction, _sig will show up on demand.
3146   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3147 }
3148 
3149 
3150 //-----------------------------cast_to_exactness-------------------------------
3151 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3152   if( klass_is_exact == _klass_is_exact ) return this;
3153   if (!UseExactTypes)  return this;
3154   if (!_klass->is_loaded())  return this;
3155   ciInstanceKlass* ik = _klass->as_instance_klass();
3156   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3157   if( ik->is_interface() )              return this;  // cannot set xk
3158   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3159 }
3160 
3161 //-----------------------------cast_to_instance_id----------------------------
3162 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3163   if( instance_id == _instance_id ) return this;
3164   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3165 }
3166 
3167 //------------------------------xmeet_unloaded---------------------------------
3168 // Compute the MEET of two InstPtrs when at least one is unloaded.
3169 // Assume classes are different since called after check for same name/class-loader
3170 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3171     int off = meet_offset(tinst->offset());
3172     PTR ptr = meet_ptr(tinst->ptr());
3173     int instance_id = meet_instance_id(tinst->instance_id());
3174     const TypeOopPtr* speculative = xmeet_speculative(tinst);
3175     int depth = meet_inline_depth(tinst->inline_depth());
3176 
3177     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3178     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3179     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3180       //
3181       // Meet unloaded class with java/lang/Object
3182       //
3183       // Meet
3184       //          |                     Unloaded Class
3185       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3186       //  ===================================================================
3187       //   TOP    | ..........................Unloaded......................|
3188       //  AnyNull |  U-AN    |................Unloaded......................|
3189       // Constant | ... O-NN .................................. |   O-BOT   |
3190       //  NotNull | ... O-NN .................................. |   O-BOT   |
3191       //  BOTTOM  | ........................Object-BOTTOM ..................|
3192       //
3193       assert(loaded->ptr() != TypePtr::Null, "insanity check");
3194       //
3195       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
3196       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative, depth); }
3197       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
3198       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
3199         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
3200         else                                      { return TypeInstPtr::NOTNULL; }
3201       }
3202       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
3203 
3204       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
3205     }
3206 
3207     // Both are unloaded, not the same class, not Object
3208     // Or meet unloaded with a different loaded class, not java/lang/Object
3209     if( ptr != TypePtr::BotPTR ) {
3210       return TypeInstPtr::NOTNULL;
3211     }
3212     return TypeInstPtr::BOTTOM;
3213 }
3214 
3215 
3216 //------------------------------meet-------------------------------------------


3233   case NarrowOop:
3234   case NarrowKlass:
3235   case Bottom:                  // Ye Olde Default
3236     return Type::BOTTOM;
3237   case Top:
3238     return this;
3239 
3240   default:                      // All else is a mistake
3241     typerr(t);
3242 
3243   case MetadataPtr:
3244   case KlassPtr:
3245   case RawPtr: return TypePtr::BOTTOM;
3246 
3247   case AryPtr: {                // All arrays inherit from Object class
3248     const TypeAryPtr *tp = t->is_aryptr();
3249     int offset = meet_offset(tp->offset());
3250     PTR ptr = meet_ptr(tp->ptr());
3251     int instance_id = meet_instance_id(tp->instance_id());
3252     const TypeOopPtr* speculative = xmeet_speculative(tp);
3253     int depth = meet_inline_depth(tp->inline_depth());
3254     switch (ptr) {
3255     case TopPTR:
3256     case AnyNull:                // Fall 'down' to dual of object klass
3257       // For instances when a subclass meets a superclass we fall
3258       // below the centerline when the superclass is exact. We need to
3259       // do the same here.
3260       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3261         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth);
3262       } else {
3263         // cannot subclass, so the meet has to fall badly below the centerline
3264         ptr = NotNull;
3265         instance_id = InstanceBot;
3266         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3267       }
3268     case Constant:
3269     case NotNull:
3270     case BotPTR:                // Fall down to object klass
3271       // LCA is object_klass, but if we subclass from the top we can do better
3272       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
3273         // If 'this' (InstPtr) is above the centerline and it is Object class
3274         // then we can subclass in the Java class hierarchy.
3275         // For instances when a subclass meets a superclass we fall
3276         // below the centerline when the superclass is exact. We need
3277         // to do the same here.
3278         if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3279           // that is, tp's array type is a subtype of my klass
3280           return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
3281                                   tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth);
3282         }
3283       }
3284       // The other case cannot happen, since I cannot be a subtype of an array.
3285       // The meet falls down to Object class below centerline.
3286       if( ptr == Constant )
3287          ptr = NotNull;
3288       instance_id = InstanceBot;
3289       return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3290     default: typerr(t);
3291     }
3292   }
3293 
3294   case OopPtr: {                // Meeting to OopPtrs
3295     // Found a OopPtr type vs self-InstPtr type
3296     const TypeOopPtr *tp = t->is_oopptr();
3297     int offset = meet_offset(tp->offset());
3298     PTR ptr = meet_ptr(tp->ptr());
3299     switch (tp->ptr()) {
3300     case TopPTR:
3301     case AnyNull: {
3302       int instance_id = meet_instance_id(InstanceTop);
3303       const TypeOopPtr* speculative = xmeet_speculative(tp);
3304       int depth = meet_inline_depth(tp->inline_depth());
3305       return make(ptr, klass(), klass_is_exact(),
3306                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3307     }
3308     case NotNull:
3309     case BotPTR: {
3310       int instance_id = meet_instance_id(tp->instance_id());
3311       const TypeOopPtr* speculative = xmeet_speculative(tp);
3312       int depth = meet_inline_depth(tp->inline_depth());
3313       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3314     }
3315     default: typerr(t);
3316     }
3317   }
3318 
3319   case AnyPtr: {                // Meeting to AnyPtrs
3320     // Found an AnyPtr type vs self-InstPtr type
3321     const TypePtr *tp = t->is_ptr();
3322     int offset = meet_offset(tp->offset());
3323     PTR ptr = meet_ptr(tp->ptr());
3324     switch (tp->ptr()) {
3325     case Null:
3326       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
3327       // else fall through to AnyNull
3328     case TopPTR:
3329     case AnyNull: {
3330       int instance_id = meet_instance_id(InstanceTop);
3331       const TypeOopPtr* speculative = _speculative;
3332       return make(ptr, klass(), klass_is_exact(),
3333                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, _inline_depth);
3334     }
3335     case NotNull:
3336     case BotPTR:
3337       return TypePtr::make(AnyPtr, ptr, offset);
3338     default: typerr(t);
3339     }
3340   }
3341 
3342   /*
3343                  A-top         }
3344                /   |   \       }  Tops
3345            B-top A-any C-top   }
3346               | /  |  \ |      }  Any-nulls
3347            B-any   |   C-any   }
3348               |    |    |
3349            B-con A-con C-con   } constants; not comparable across classes
3350               |    |    |
3351            B-not   |   C-not   }
3352               | \  |  / |      }  not-nulls
3353            B-bot A-not C-bot   }
3354                \   |   /       }  Bottoms
3355                  A-bot         }
3356   */
3357 
3358   case InstPtr: {                // Meeting 2 Oops?
3359     // Found an InstPtr sub-type vs self-InstPtr type
3360     const TypeInstPtr *tinst = t->is_instptr();
3361     int off = meet_offset( tinst->offset() );
3362     PTR ptr = meet_ptr( tinst->ptr() );
3363     int instance_id = meet_instance_id(tinst->instance_id());
3364     const TypeOopPtr* speculative = xmeet_speculative(tinst);
3365     int depth = meet_inline_depth(tinst->inline_depth());
3366 
3367     // Check for easy case; klasses are equal (and perhaps not loaded!)
3368     // If we have constants, then we created oops so classes are loaded
3369     // and we can handle the constants further down.  This case handles
3370     // both-not-loaded or both-loaded classes
3371     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
3372       return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth);
3373     }
3374 
3375     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
3376     ciKlass* tinst_klass = tinst->klass();
3377     ciKlass* this_klass  = this->klass();
3378     bool tinst_xk = tinst->klass_is_exact();
3379     bool this_xk  = this->klass_is_exact();
3380     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
3381       // One of these classes has not been loaded
3382       const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
3383 #ifndef PRODUCT
3384       if( PrintOpto && Verbose ) {
3385         tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
3386         tty->print("  this == "); this->dump(); tty->cr();
3387         tty->print(" tinst == "); tinst->dump(); tty->cr();
3388       }
3389 #endif
3390       return unloaded_meet;
3391     }
3392 


3416         // below the centerline.  If we are on the centerline
3417         // (e.g., Constant vs. AnyNull interface), use the constant.
3418         k  = below_centerline(ptr) ? tinst_klass : this_klass;
3419         // If we are keeping this_klass, keep its exactness too.
3420         xk = below_centerline(ptr) ? tinst_xk    : this_xk;
3421       } else {                  // Does not implement, fall to Object
3422         // Oop does not implement interface, so mixing falls to Object
3423         // just like the verifier does (if both are above the
3424         // centerline fall to interface)
3425         k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
3426         xk = above_centerline(ptr) ? tinst_xk : false;
3427         // Watch out for Constant vs. AnyNull interface.
3428         if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
3429         instance_id = InstanceBot;
3430       }
3431       ciObject* o = NULL;  // the Constant value, if any
3432       if (ptr == Constant) {
3433         // Find out which constant.
3434         o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
3435       }
3436       return make(ptr, k, xk, o, off, instance_id, speculative, depth);
3437     }
3438 
3439     // Either oop vs oop or interface vs interface or interface vs Object
3440 
3441     // !!! Here's how the symmetry requirement breaks down into invariants:
3442     // If we split one up & one down AND they subtype, take the down man.
3443     // If we split one up & one down AND they do NOT subtype, "fall hard".
3444     // If both are up and they subtype, take the subtype class.
3445     // If both are up and they do NOT subtype, "fall hard".
3446     // If both are down and they subtype, take the supertype class.
3447     // If both are down and they do NOT subtype, "fall hard".
3448     // Constants treated as down.
3449 
3450     // Now, reorder the above list; observe that both-down+subtype is also
3451     // "fall hard"; "fall hard" becomes the default case:
3452     // If we split one up & one down AND they subtype, take the down man.
3453     // If both are up and they subtype, take the subtype class.
3454 
3455     // If both are down and they subtype, "fall hard".
3456     // If both are down and they do NOT subtype, "fall hard".


3493 
3494     // Check for classes now being equal
3495     if (tinst_klass->equals(this_klass)) {
3496       // If the klasses are equal, the constants may still differ.  Fall to
3497       // NotNull if they do (neither constant is NULL; that is a special case
3498       // handled elsewhere).
3499       ciObject* o = NULL;             // Assume not constant when done
3500       ciObject* this_oop  = const_oop();
3501       ciObject* tinst_oop = tinst->const_oop();
3502       if( ptr == Constant ) {
3503         if (this_oop != NULL && tinst_oop != NULL &&
3504             this_oop->equals(tinst_oop) )
3505           o = this_oop;
3506         else if (above_centerline(this ->_ptr))
3507           o = tinst_oop;
3508         else if (above_centerline(tinst ->_ptr))
3509           o = this_oop;
3510         else
3511           ptr = NotNull;
3512       }
3513       return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth);
3514     } // Else classes are not equal
3515 
3516     // Since klasses are different, we require a LCA in the Java
3517     // class hierarchy - which means we have to fall to at least NotNull.
3518     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3519       ptr = NotNull;
3520     instance_id = InstanceBot;
3521 
3522     // Now we find the LCA of Java classes
3523     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
3524     return make(ptr, k, false, NULL, off, instance_id, speculative, depth);
3525   } // End of case InstPtr
3526 
3527   } // End of switch
3528   return this;                  // Return the double constant
3529 }
3530 
3531 
3532 //------------------------java_mirror_type--------------------------------------
3533 ciType* TypeInstPtr::java_mirror_type() const {
3534   // must be a singleton type
3535   if( const_oop() == NULL )  return NULL;
3536 
3537   // must be of type java.lang.Class
3538   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
3539 
3540   return const_oop()->as_instance()->java_mirror_type();
3541 }
3542 
3543 
3544 //------------------------------xdual------------------------------------------
3545 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
3546 // inheritance mechanism.
3547 const Type *TypeInstPtr::xdual() const {
3548   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3549 }
3550 
3551 //------------------------------eq---------------------------------------------
3552 // Structural equality check for Type representations
3553 bool TypeInstPtr::eq( const Type *t ) const {
3554   const TypeInstPtr *p = t->is_instptr();
3555   return
3556     klass()->equals(p->klass()) &&
3557     TypeOopPtr::eq(p);          // Check sub-type stuff
3558 }
3559 
3560 //------------------------------hash-------------------------------------------
3561 // Type-specific hashing function.
3562 int TypeInstPtr::hash(void) const {
3563   int hash = klass()->hash() + TypeOopPtr::hash();
3564   return hash;
3565 }
3566 
3567 //------------------------------dump2------------------------------------------
3568 // Dump oop Type


3585   case TopPTR:
3586   case AnyNull:
3587   case NotNull:
3588     st->print(":%s", ptr_msg[_ptr]);
3589     if( _klass_is_exact ) st->print(":exact");
3590     break;
3591   }
3592 
3593   if( _offset ) {               // Dump offset, if any
3594     if( _offset == OffsetBot )      st->print("+any");
3595     else if( _offset == OffsetTop ) st->print("+unknown");
3596     else st->print("+%d", _offset);
3597   }
3598 
3599   st->print(" *");
3600   if (_instance_id == InstanceTop)
3601     st->print(",iid=top");
3602   else if (_instance_id != InstanceBot)
3603     st->print(",iid=%d",_instance_id);
3604 
3605   dump_inline_depth(st);
3606   dump_speculative(st);
3607 }
3608 #endif
3609 
3610 //------------------------------add_offset-------------------------------------
3611 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
3612   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id, add_offset_speculative(offset));
3613 }
3614 
3615 const Type *TypeInstPtr::remove_speculative() const {
3616   if (_speculative == NULL) {
3617     return this;
3618   }
3619   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, NULL, _inline_depth);
3620 }
3621 
3622 const TypeOopPtr *TypeInstPtr::with_inline_depth(int depth) const {
3623   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
3624 }
3625 
3626 //=============================================================================
3627 // Convenience common pre-built types.
3628 const TypeAryPtr *TypeAryPtr::RANGE;
3629 const TypeAryPtr *TypeAryPtr::OOPS;
3630 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
3631 const TypeAryPtr *TypeAryPtr::BYTES;
3632 const TypeAryPtr *TypeAryPtr::SHORTS;
3633 const TypeAryPtr *TypeAryPtr::CHARS;
3634 const TypeAryPtr *TypeAryPtr::INTS;
3635 const TypeAryPtr *TypeAryPtr::LONGS;
3636 const TypeAryPtr *TypeAryPtr::FLOATS;
3637 const TypeAryPtr *TypeAryPtr::DOUBLES;
3638 
3639 //------------------------------make-------------------------------------------
3640 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth) {
3641   assert(!(k == NULL && ary->_elem->isa_int()),
3642          "integral arrays must be pre-equipped with a class");
3643   if (!xk)  xk = ary->ary_must_be_exact();
3644   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3645   if (!UseExactTypes)  xk = (ptr == Constant);
3646   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
3647 }
3648 
3649 //------------------------------make-------------------------------------------
3650 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth, bool is_autobox_cache) {
3651   assert(!(k == NULL && ary->_elem->isa_int()),
3652          "integral arrays must be pre-equipped with a class");
3653   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
3654   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
3655   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3656   if (!UseExactTypes)  xk = (ptr == Constant);
3657   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
3658 }
3659 
3660 //------------------------------cast_to_ptr_type-------------------------------
3661 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
3662   if( ptr == _ptr ) return this;
3663   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
3664 }
3665 
3666 
3667 //-----------------------------cast_to_exactness-------------------------------
3668 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
3669   if( klass_is_exact == _klass_is_exact ) return this;
3670   if (!UseExactTypes)  return this;
3671   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
3672   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
3673 }
3674 
3675 //-----------------------------cast_to_instance_id----------------------------
3676 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
3677   if( instance_id == _instance_id ) return this;
3678   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
3679 }
3680 
3681 //-----------------------------narrow_size_type-------------------------------
3682 // Local cache for arrayOopDesc::max_array_length(etype),
3683 // which is kind of slow (and cached elsewhere by other users).
3684 static jint max_array_length_cache[T_CONFLICT+1];
3685 static jint max_array_length(BasicType etype) {
3686   jint& cache = max_array_length_cache[etype];
3687   jint res = cache;
3688   if (res == 0) {
3689     switch (etype) {
3690     case T_NARROWOOP:
3691       etype = T_OBJECT;
3692       break;
3693     case T_NARROWKLASS:
3694     case T_CONFLICT:
3695     case T_ILLEGAL:
3696     case T_VOID:
3697       etype = T_BYTE;           // will produce conservatively high value
3698     }


3721     hi = max_hi;
3722     if (size->is_con()) {
3723       lo = hi;
3724     }
3725     chg = true;
3726   }
3727   // Negative length arrays will produce weird intermediate dead fast-path code
3728   if (lo > hi)
3729     return TypeInt::ZERO;
3730   if (!chg)
3731     return size;
3732   return TypeInt::make(lo, hi, Type::WidenMin);
3733 }
3734 
3735 //-------------------------------cast_to_size----------------------------------
3736 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
3737   assert(new_size != NULL, "");
3738   new_size = narrow_size_type(new_size);
3739   if (new_size == size())  return this;
3740   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
3741   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
3742 }
3743 
3744 
3745 //------------------------------cast_to_stable---------------------------------
3746 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
3747   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
3748     return this;
3749 
3750   const Type* elem = this->elem();
3751   const TypePtr* elem_ptr = elem->make_ptr();
3752 
3753   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
3754     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
3755     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
3756   }
3757 
3758   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
3759 
3760   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
3761 }


3800   case FloatCon:
3801   case FloatBot:
3802   case DoubleTop:
3803   case DoubleCon:
3804   case DoubleBot:
3805   case NarrowOop:
3806   case NarrowKlass:
3807   case Bottom:                  // Ye Olde Default
3808     return Type::BOTTOM;
3809   case Top:
3810     return this;
3811 
3812   default:                      // All else is a mistake
3813     typerr(t);
3814 
3815   case OopPtr: {                // Meeting to OopPtrs
3816     // Found a OopPtr type vs self-AryPtr type
3817     const TypeOopPtr *tp = t->is_oopptr();
3818     int offset = meet_offset(tp->offset());
3819     PTR ptr = meet_ptr(tp->ptr());
3820     int depth = meet_inline_depth(tp->inline_depth());
3821     switch (tp->ptr()) {
3822     case TopPTR:
3823     case AnyNull: {
3824       int instance_id = meet_instance_id(InstanceTop);
3825       const TypeOopPtr* speculative = xmeet_speculative(tp);
3826       return make(ptr, (ptr == Constant ? const_oop() : NULL),
3827                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
3828     }
3829     case BotPTR:
3830     case NotNull: {
3831       int instance_id = meet_instance_id(tp->instance_id());
3832       const TypeOopPtr* speculative = xmeet_speculative(tp);
3833       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3834     }
3835     default: ShouldNotReachHere();
3836     }
3837   }
3838 
3839   case AnyPtr: {                // Meeting two AnyPtrs
3840     // Found an AnyPtr type vs self-AryPtr type
3841     const TypePtr *tp = t->is_ptr();
3842     int offset = meet_offset(tp->offset());
3843     PTR ptr = meet_ptr(tp->ptr());
3844     switch (tp->ptr()) {
3845     case TopPTR:
3846       return this;
3847     case BotPTR:
3848     case NotNull:
3849       return TypePtr::make(AnyPtr, ptr, offset);
3850     case Null:
3851       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
3852       // else fall through to AnyNull
3853     case AnyNull: {
3854       int instance_id = meet_instance_id(InstanceTop);
3855       const TypeOopPtr* speculative = _speculative;
3856       return make(ptr, (ptr == Constant ? const_oop() : NULL),
3857                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, _inline_depth);
3858     }
3859     default: ShouldNotReachHere();
3860     }
3861   }
3862 
3863   case MetadataPtr:
3864   case KlassPtr:
3865   case RawPtr: return TypePtr::BOTTOM;
3866 
3867   case AryPtr: {                // Meeting 2 references?
3868     const TypeAryPtr *tap = t->is_aryptr();
3869     int off = meet_offset(tap->offset());
3870     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
3871     PTR ptr = meet_ptr(tap->ptr());
3872     int instance_id = meet_instance_id(tap->instance_id());
3873     const TypeOopPtr* speculative = xmeet_speculative(tap);
3874     int depth = meet_inline_depth(tap->inline_depth());
3875     ciKlass* lazy_klass = NULL;
3876     if (tary->_elem->isa_int()) {
3877       // Integral array element types have irrelevant lattice relations.
3878       // It is the klass that determines array layout, not the element type.
3879       if (_klass == NULL)
3880         lazy_klass = tap->_klass;
3881       else if (tap->_klass == NULL || tap->_klass == _klass) {
3882         lazy_klass = _klass;
3883       } else {
3884         // Something like byte[int+] meets char[int+].
3885         // This must fall to bottom, not (int[-128..65535])[int+].
3886         instance_id = InstanceBot;
3887         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
3888       }
3889     } else // Non integral arrays.
3890       // Must fall to bottom if exact klasses in upper lattice
3891       // are not equal or super klass is exact.
3892       if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
3893           // meet with top[] and bottom[] are processed further down:
3894           tap->_klass != NULL  && this->_klass != NULL   &&
3895           // both are exact and not equal:
3896           ((tap->_klass_is_exact && this->_klass_is_exact) ||
3897            // 'tap'  is exact and super or unrelated:
3898            (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
3899            // 'this' is exact and super or unrelated:
3900            (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
3901       tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
3902       return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot);
3903     }
3904 
3905     bool xk = false;
3906     switch (tap->ptr()) {
3907     case AnyNull:
3908     case TopPTR:
3909       // Compute new klass on demand, do not use tap->_klass
3910       if (below_centerline(this->_ptr)) {
3911         xk = this->_klass_is_exact;
3912       } else {
3913         xk = (tap->_klass_is_exact | this->_klass_is_exact);
3914       }
3915       return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative, depth);
3916     case Constant: {
3917       ciObject* o = const_oop();
3918       if( _ptr == Constant ) {
3919         if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
3920           xk = (klass() == tap->klass());
3921           ptr = NotNull;
3922           o = NULL;
3923           instance_id = InstanceBot;
3924         } else {
3925           xk = true;
3926         }
3927       } else if(above_centerline(_ptr)) {
3928         o = tap->const_oop();
3929         xk = true;
3930       } else {
3931         // Only precise for identical arrays
3932         xk = this->_klass_is_exact && (klass() == tap->klass());
3933       }
3934       return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, instance_id, speculative, depth);
3935     }
3936     case NotNull:
3937     case BotPTR:
3938       // Compute new klass on demand, do not use tap->_klass
3939       if (above_centerline(this->_ptr))
3940             xk = tap->_klass_is_exact;
3941       else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
3942               (klass() == tap->klass()); // Only precise for identical arrays
3943       return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, instance_id, speculative, depth);
3944     default: ShouldNotReachHere();
3945     }
3946   }
3947 
3948   // All arrays inherit from Object class
3949   case InstPtr: {
3950     const TypeInstPtr *tp = t->is_instptr();
3951     int offset = meet_offset(tp->offset());
3952     PTR ptr = meet_ptr(tp->ptr());
3953     int instance_id = meet_instance_id(tp->instance_id());
3954     const TypeOopPtr* speculative = xmeet_speculative(tp);
3955     int depth = meet_inline_depth(tp->inline_depth());
3956     switch (ptr) {
3957     case TopPTR:
3958     case AnyNull:                // Fall 'down' to dual of object klass
3959       // For instances when a subclass meets a superclass we fall
3960       // below the centerline when the superclass is exact. We need to
3961       // do the same here.
3962       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
3963         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
3964       } else {
3965         // cannot subclass, so the meet has to fall badly below the centerline
3966         ptr = NotNull;
3967         instance_id = InstanceBot;
3968         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
3969       }
3970     case Constant:
3971     case NotNull:
3972     case BotPTR:                // Fall down to object klass
3973       // LCA is object_klass, but if we subclass from the top we can do better
3974       if (above_centerline(tp->ptr())) {
3975         // If 'tp'  is above the centerline and it is Object class
3976         // then we can subclass in the Java class hierarchy.
3977         // For instances when a subclass meets a superclass we fall
3978         // below the centerline when the superclass is exact. We need
3979         // to do the same here.
3980         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
3981           // that is, my array type is a subtype of 'tp' klass
3982           return make(ptr, (ptr == Constant ? const_oop() : NULL),
3983                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
3984         }
3985       }
3986       // The other case cannot happen, since t cannot be a subtype of an array.
3987       // The meet falls down to Object class below centerline.
3988       if( ptr == Constant )
3989          ptr = NotNull;
3990       instance_id = InstanceBot;
3991       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
3992     default: typerr(t);
3993     }
3994   }
3995   }
3996   return this;                  // Lint noise
3997 }
3998 
3999 //------------------------------xdual------------------------------------------
4000 // Dual: compute field-by-field dual
4001 const Type *TypeAryPtr::xdual() const {
4002   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(), dual_inline_depth());
4003 }
4004 
4005 //----------------------interface_vs_oop---------------------------------------
4006 #ifdef ASSERT
4007 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
4008   const TypeAryPtr* t_aryptr = t->isa_aryptr();
4009   if (t_aryptr) {
4010     return _ary->interface_vs_oop(t_aryptr->_ary);
4011   }
4012   return false;
4013 }
4014 #endif
4015 
4016 //------------------------------dump2------------------------------------------
4017 #ifndef PRODUCT
4018 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4019   _ary->dump2(d,depth,st);
4020   switch( _ptr ) {
4021   case Constant:
4022     const_oop()->print(st);


4035   }
4036 
4037   if( _offset != 0 ) {
4038     int header_size = objArrayOopDesc::header_size() * wordSize;
4039     if( _offset == OffsetTop )       st->print("+undefined");
4040     else if( _offset == OffsetBot )  st->print("+any");
4041     else if( _offset < header_size ) st->print("+%d", _offset);
4042     else {
4043       BasicType basic_elem_type = elem()->basic_type();
4044       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4045       int elem_size = type2aelembytes(basic_elem_type);
4046       st->print("[%d]", (_offset - array_base)/elem_size);
4047     }
4048   }
4049   st->print(" *");
4050   if (_instance_id == InstanceTop)
4051     st->print(",iid=top");
4052   else if (_instance_id != InstanceBot)
4053     st->print(",iid=%d",_instance_id);
4054 
4055   dump_inline_depth(st);
4056   dump_speculative(st);
4057 }
4058 #endif
4059 
4060 bool TypeAryPtr::empty(void) const {
4061   if (_ary->empty())       return true;
4062   return TypeOopPtr::empty();
4063 }
4064 
4065 //------------------------------add_offset-------------------------------------
4066 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4067   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4068 }
4069 
4070 const Type *TypeAryPtr::remove_speculative() const {
4071   if (_speculative == NULL) {
4072     return this;
4073   } 
4074   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL, _inline_depth);
4075 }
4076 
4077 const TypeOopPtr *TypeAryPtr::with_inline_depth(int depth) const {
4078   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
4079 }
4080 
4081 //=============================================================================
4082 
4083 //------------------------------hash-------------------------------------------
4084 // Type-specific hashing function.
4085 int TypeNarrowPtr::hash(void) const {
4086   return _ptrtype->hash() + 7;
4087 }
4088 
4089 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
4090   return _ptrtype->singleton();
4091 }
4092 
4093 bool TypeNarrowPtr::empty(void) const {
4094   return _ptrtype->empty();
4095 }
4096 
4097 intptr_t TypeNarrowPtr::get_con() const {
4098   return _ptrtype->get_con();


src/share/vm/opto/type.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File