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 5464 : 8024070: C2 needs some form of type speculation
Summary: record unused type profile information with type system, propagate and use it.
Reviewed-by:
rev 5465 : imported patch speculative-cleanup


 341   TypePtr::BOTTOM  = TypePtr::make( AnyPtr, TypePtr::BotPTR, OffsetBot );
 342 
 343   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
 344   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
 345 
 346   const Type **fmembar = TypeTuple::fields(0);
 347   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
 348 
 349   const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
 350   fsc[0] = TypeInt::CC;
 351   fsc[1] = Type::MEMORY;
 352   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
 353 
 354   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
 355   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
 356   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
 357   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 358                                            false, 0, oopDesc::mark_offset_in_bytes());
 359   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 360                                            false, 0, oopDesc::klass_offset_in_bytes());
 361   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
 362 
 363   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, OffsetBot);
 364 
 365   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
 366   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
 367 
 368   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
 369 
 370   mreg2type[Op_Node] = Type::BOTTOM;
 371   mreg2type[Op_Set ] = 0;
 372   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
 373   mreg2type[Op_RegI] = TypeInt::INT;
 374   mreg2type[Op_RegP] = TypePtr::BOTTOM;
 375   mreg2type[Op_RegF] = Type::FLOAT;
 376   mreg2type[Op_RegD] = Type::DOUBLE;
 377   mreg2type[Op_RegL] = TypeLong::LONG;
 378   mreg2type[Op_RegFlags] = TypeInt::CC;
 379 
 380   TypeAryPtr::RANGE   = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
 381 


 560 //------------------------------hash-------------------------------------------
 561 // Type-specific hashing function.
 562 int Type::hash(void) const {
 563   return _base;
 564 }
 565 
 566 //------------------------------is_finite--------------------------------------
 567 // Has a finite value
 568 bool Type::is_finite() const {
 569   return false;
 570 }
 571 
 572 //------------------------------is_nan-----------------------------------------
 573 // Is not a number (NaN)
 574 bool Type::is_nan()    const {
 575   return false;
 576 }
 577 
 578 //----------------------interface_vs_oop---------------------------------------
 579 #ifdef ASSERT
 580 bool Type::interface_vs_oop(const Type *t) const {
 581   bool result = false;
 582 
 583   const TypePtr* this_ptr = this->make_ptr(); // In case it is narrow_oop
 584   const TypePtr*    t_ptr =    t->make_ptr();
 585   if( this_ptr == NULL || t_ptr == NULL )
 586     return result;
 587 
 588   const TypeInstPtr* this_inst = this_ptr->isa_instptr();
 589   const TypeInstPtr*    t_inst =    t_ptr->isa_instptr();
 590   if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
 591     bool this_interface = this_inst->klass()->is_interface();
 592     bool    t_interface =    t_inst->klass()->is_interface();
 593     result = this_interface ^ t_interface;
 594   }
 595 
 596   return result;
 597 }























 598 #endif
 599 
 600 //------------------------------meet-------------------------------------------
 601 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
 602 // commutative and the lattice is symmetric.
 603 const Type *Type::meet( const Type *t ) const {
 604   if (isa_narrowoop() && t->isa_narrowoop()) {
 605     const Type* result = make_ptr()->meet(t->make_ptr());
 606     return result->make_narrowoop();
 607   }
 608   if (isa_narrowklass() && t->isa_narrowklass()) {
 609     const Type* result = make_ptr()->meet(t->make_ptr());
 610     return result->make_narrowklass();
 611   }
 612 
 613   const Type *mt = xmeet(t);
 614   if (isa_narrowoop() || t->isa_narrowoop()) return mt;
 615   if (isa_narrowklass() || t->isa_narrowklass()) return mt;
 616 #ifdef ASSERT
 617   assert( mt == t->xmeet(this), "meet not commutative" );


2390 // Type-specific hashing function.
2391 int TypeRawPtr::hash(void) const {
2392   return (intptr_t)_bits + TypePtr::hash();
2393 }
2394 
2395 //------------------------------dump2------------------------------------------
2396 #ifndef PRODUCT
2397 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2398   if( _ptr == Constant )
2399     st->print(INTPTR_FORMAT, _bits);
2400   else
2401     st->print("rawptr:%s", ptr_msg[_ptr]);
2402 }
2403 #endif
2404 
2405 //=============================================================================
2406 // Convenience common pre-built type.
2407 const TypeOopPtr *TypeOopPtr::BOTTOM;
2408 
2409 //------------------------------TypeOopPtr-------------------------------------
2410 TypeOopPtr::TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id )
2411   : TypePtr(t, ptr, offset),
2412     _const_oop(o), _klass(k),
2413     _klass_is_exact(xk),
2414     _is_ptr_to_narrowoop(false),
2415     _is_ptr_to_narrowklass(false),
2416     _is_ptr_to_boxed_value(false),
2417     _instance_id(instance_id) {

2418   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
2419       (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
2420     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
2421   }
2422 #ifdef _LP64
2423   if (_offset != 0) {
2424     if (_offset == oopDesc::klass_offset_in_bytes()) {
2425       _is_ptr_to_narrowklass = UseCompressedClassPointers;
2426     } else if (klass() == NULL) {
2427       // Array with unknown body type
2428       assert(this->isa_aryptr(), "only arrays without klass");
2429       _is_ptr_to_narrowoop = UseCompressedOops;
2430     } else if (this->isa_aryptr()) {
2431       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
2432                              _offset != arrayOopDesc::length_offset_in_bytes());
2433     } else if (klass()->is_instance_klass()) {
2434       ciInstanceKlass* ik = klass()->as_instance_klass();
2435       ciField* field = NULL;
2436       if (this->isa_klassptr()) {
2437         // Perm objects don't use compressed references


2464             BasicType basic_elem_type = field->layout_type();
2465             _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
2466                                                          basic_elem_type == T_ARRAY);
2467           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
2468             // Compile::find_alias_type() cast exactness on all types to verify
2469             // that it does not affect alias type.
2470             _is_ptr_to_narrowoop = UseCompressedOops;
2471           } else {
2472             // Type for the copy start in LibraryCallKit::inline_native_clone().
2473             _is_ptr_to_narrowoop = UseCompressedOops;
2474           }
2475         }
2476       }
2477     }
2478   }
2479 #endif
2480 }
2481 
2482 //------------------------------make-------------------------------------------
2483 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
2484                                    int offset, int instance_id) {
2485   assert(ptr != Constant, "no constant generic pointers");
2486   ciKlass*  k = Compile::current()->env()->Object_klass();
2487   bool      xk = false;
2488   ciObject* o = NULL;
2489   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id))->hashcons();
2490 }
2491 
2492 
2493 //------------------------------cast_to_ptr_type-------------------------------
2494 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
2495   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
2496   if( ptr == _ptr ) return this;
2497   return make(ptr, _offset, _instance_id);
2498 }
2499 
2500 //-----------------------------cast_to_instance_id----------------------------
2501 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
2502   // There are no instances of a general oop.
2503   // Return self unchanged.
2504   return this;
2505 }
2506 
2507 //-----------------------------cast_to_exactness-------------------------------
2508 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
2509   // There is no such thing as an exact general oop.
2510   // Return self unchanged.
2511   return this;
2512 }
2513 
2514 
2515 //------------------------------as_klass_type----------------------------------
2516 // Return the klass type corresponding to this instance or array type.
2517 // It is the type that is loaded from an object of this type.
2518 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
2519   ciKlass* k = klass();
2520   bool    xk = klass_is_exact();
2521   if (k == NULL)
2522     return TypeKlassPtr::OBJECT;
2523   else
2524     return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
2525 }
2526 





















2527 
2528 //------------------------------meet-------------------------------------------
2529 // Compute the MEET of two types.  It returns a new Type object.
2530 const Type *TypeOopPtr::xmeet( const Type *t ) const {
2531   // Perform a fast test for common case; meeting the same types together.
2532   if( this == t ) return this;  // Meeting same type-rep?
2533 
2534   // Current "this->_base" is OopPtr
2535   switch (t->base()) {          // switch on original type
2536 
2537   case Int:                     // Mixing ints & oops happens when javac
2538   case Long:                    // reuses local variables
2539   case FloatTop:
2540   case FloatCon:
2541   case FloatBot:
2542   case DoubleTop:
2543   case DoubleCon:
2544   case DoubleBot:
2545   case NarrowOop:
2546   case NarrowKlass:
2547   case Bottom:                  // Ye Olde Default
2548     return Type::BOTTOM;
2549   case Top:
2550     return this;


2552   default:                      // All else is a mistake
2553     typerr(t);
2554 
2555   case RawPtr:
2556   case MetadataPtr:
2557   case KlassPtr:
2558     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
2559 
2560   case AnyPtr: {
2561     // Found an AnyPtr type vs self-OopPtr type
2562     const TypePtr *tp = t->is_ptr();
2563     int offset = meet_offset(tp->offset());
2564     PTR ptr = meet_ptr(tp->ptr());
2565     switch (tp->ptr()) {
2566     case Null:
2567       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset);
2568       // else fall through:
2569     case TopPTR:
2570     case AnyNull: {
2571       int instance_id = meet_instance_id(InstanceTop);
2572       return make(ptr, offset, instance_id);

2573     }
2574     case BotPTR:
2575     case NotNull:
2576       return TypePtr::make(AnyPtr, ptr, offset);
2577     default: typerr(t);
2578     }
2579   }
2580 
2581   case OopPtr: {                 // Meeting to other OopPtrs
2582     const TypeOopPtr *tp = t->is_oopptr();
2583     int instance_id = meet_instance_id(tp->instance_id());
2584     return make( meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id );

2585   }
2586 
2587   case InstPtr:                  // For these, flip the call around to cut down
2588   case AryPtr:
2589     return t->xmeet(this);      // Call in reverse direction
2590 
2591   } // End of switch
2592   return this;                  // Return the double constant
2593 }
2594 
2595 
2596 //------------------------------xdual------------------------------------------
2597 // Dual of a pure heap pointer.  No relevant klass or oop information.
2598 const Type *TypeOopPtr::xdual() const {
2599   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
2600   assert(const_oop() == NULL,             "no constants here");
2601   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id()  );
2602 }
2603 
2604 //--------------------------make_from_klass_common-----------------------------
2605 // Computes the element-type given a klass.
2606 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
2607   if (klass->is_instance_klass()) {
2608     Compile* C = Compile::current();
2609     Dependencies* deps = C->dependencies();
2610     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
2611     // Element is an instance
2612     bool klass_is_exact = false;
2613     if (klass->is_loaded()) {
2614       // Try to set klass_is_exact.
2615       ciInstanceKlass* ik = klass->as_instance_klass();
2616       klass_is_exact = ik->is_final();
2617       if (!klass_is_exact && klass_change
2618           && deps != NULL && UseUniqueSubclasses) {
2619         ciInstanceKlass* sub = ik->unique_concrete_subklass();
2620         if (sub != NULL) {
2621           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);


2672       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
2673     }
2674     return TypeInstPtr::make(o);
2675   } else if (klass->is_obj_array_klass()) {
2676     // Element is an object array. Recursively call ourself.
2677     const TypeOopPtr *etype =
2678       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
2679     if (is_autobox_cache) {
2680       // The pointers in the autobox arrays are always non-null.
2681       etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
2682     }
2683     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
2684     // We used to pass NotNull in here, asserting that the sub-arrays
2685     // are all not-null.  This is not true in generally, as code can
2686     // slam NULLs down in the subarrays.
2687     if (require_constant) {
2688       if (!o->can_be_constant())  return NULL;
2689     } else if (!o->should_be_constant()) {
2690       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
2691     }
2692     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0, InstanceBot, is_autobox_cache);
2693     return arr;
2694   } else if (klass->is_type_array_klass()) {
2695     // Element is an typeArray
2696     const Type* etype =
2697       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
2698     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
2699     // We used to pass NotNull in here, asserting that the array pointer
2700     // is not-null. That was not true in general.
2701     if (require_constant) {
2702       if (!o->can_be_constant())  return NULL;
2703     } else if (!o->should_be_constant()) {
2704       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
2705     }
2706     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
2707     return arr;
2708   }
2709 
2710   fatal("unhandled object type");
2711   return NULL;
2712 }


2772     assert(!ftip->klass_is_exact(), "interface could not be exact");
2773     return ktip->cast_to_ptr_type(ftip->ptr());
2774   }
2775   // Interface klass type could be exact in opposite to interface type,
2776   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
2777   if (ftkp != NULL && ktkp != NULL &&
2778       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
2779       !ftkp->klass_is_exact() && // Keep exact interface klass
2780       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
2781     return ktkp->cast_to_ptr_type(ftkp->ptr());
2782   }
2783 
2784   return ft;
2785 }
2786 
2787 //------------------------------eq---------------------------------------------
2788 // Structural equality check for Type representations
2789 bool TypeOopPtr::eq( const Type *t ) const {
2790   const TypeOopPtr *a = (const TypeOopPtr*)t;
2791   if (_klass_is_exact != a->_klass_is_exact ||
2792       _instance_id != a->_instance_id)  return false;

2793   ciObject* one = const_oop();
2794   ciObject* two = a->const_oop();
2795   if (one == NULL || two == NULL) {
2796     return (one == two) && TypePtr::eq(t);
2797   } else {
2798     return one->equals(two) && TypePtr::eq(t);
2799   }
2800 }
2801 
2802 //------------------------------hash-------------------------------------------
2803 // Type-specific hashing function.
2804 int TypeOopPtr::hash(void) const {
2805   return
2806     (const_oop() ? const_oop()->hash() : 0) +
2807     _klass_is_exact +
2808     _instance_id +

2809     TypePtr::hash();
2810 }
2811 
2812 //------------------------------dump2------------------------------------------
2813 #ifndef PRODUCT
2814 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2815   st->print("oopptr:%s", ptr_msg[_ptr]);
2816   if( _klass_is_exact ) st->print(":exact");
2817   if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
2818   switch( _offset ) {
2819   case OffsetTop: st->print("+top"); break;
2820   case OffsetBot: st->print("+any"); break;
2821   case         0: break;
2822   default:        st->print("+%d",_offset); break;
2823   }
2824   if (_instance_id == InstanceTop)
2825     st->print(",iid=top");
2826   else if (_instance_id != InstanceBot)
2827     st->print(",iid=%d",_instance_id);











2828 }
2829 #endif
2830 
2831 //------------------------------singleton--------------------------------------
2832 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2833 // constants
2834 bool TypeOopPtr::singleton(void) const {
2835   // detune optimizer to not generate constant oop + constant offset as a constant!
2836   // TopPTR, Null, AnyNull, Constant are all singletons
2837   return (_offset == 0) && !below_centerline(_ptr);
2838 }
2839 
2840 //------------------------------add_offset-------------------------------------
2841 const TypePtr *TypeOopPtr::add_offset( intptr_t offset ) const {
2842   return make( _ptr, xadd_offset(offset), _instance_id);





2843 }
2844 
2845 //------------------------------meet_instance_id--------------------------------
2846 int TypeOopPtr::meet_instance_id( int instance_id ) const {
2847   // Either is 'TOP' instance?  Return the other instance!
2848   if( _instance_id == InstanceTop ) return  instance_id;
2849   if(  instance_id == InstanceTop ) return _instance_id;
2850   // If either is different, return 'BOTTOM' instance
2851   if( _instance_id != instance_id ) return InstanceBot;
2852   return _instance_id;
2853 }
2854 
2855 //------------------------------dual_instance_id--------------------------------
2856 int TypeOopPtr::dual_instance_id( ) const {
2857   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
2858   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
2859   return _instance_id;              // Map everything else into self
2860 }
2861 



































































2862 
2863 //=============================================================================
2864 // Convenience common pre-built types.
2865 const TypeInstPtr *TypeInstPtr::NOTNULL;
2866 const TypeInstPtr *TypeInstPtr::BOTTOM;
2867 const TypeInstPtr *TypeInstPtr::MIRROR;
2868 const TypeInstPtr *TypeInstPtr::MARK;
2869 const TypeInstPtr *TypeInstPtr::KLASS;
2870 
2871 //------------------------------TypeInstPtr-------------------------------------
2872 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id)
2873  : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id), _name(k->name()) {
2874    assert(k != NULL &&
2875           (k->is_loaded() || o == NULL),
2876           "cannot have constants with non-loaded klass");
2877 };
2878 
2879 //------------------------------make-------------------------------------------
2880 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
2881                                      ciKlass* k,
2882                                      bool xk,
2883                                      ciObject* o,
2884                                      int offset,
2885                                      int instance_id) {

2886   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
2887   // Either const_oop() is NULL or else ptr is Constant
2888   assert( (!o && ptr != Constant) || (o && ptr == Constant),
2889           "constant pointers must have a value supplied" );
2890   // Ptr is never Null
2891   assert( ptr != Null, "NULL pointers are not typed" );
2892 
2893   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
2894   if (!UseExactTypes)  xk = false;
2895   if (ptr == Constant) {
2896     // Note:  This case includes meta-object constants, such as methods.
2897     xk = true;
2898   } else if (k->is_loaded()) {
2899     ciInstanceKlass* ik = k->as_instance_klass();
2900     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
2901     if (xk && ik->is_interface())  xk = false;  // no exact interface
2902   }
2903 
2904   // Now hash this baby
2905   TypeInstPtr *result =
2906     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id))->hashcons();
2907 
2908   return result;
2909 }
2910 
2911 /**
2912  *  Create constant type for a constant boxed value
2913  */
2914 const Type* TypeInstPtr::get_const_boxed_value() const {
2915   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
2916   assert((const_oop() != NULL), "should be called only for constant object");
2917   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
2918   BasicType bt = constant.basic_type();
2919   switch (bt) {
2920     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
2921     case T_INT:      return TypeInt::make(constant.as_int());
2922     case T_CHAR:     return TypeInt::make(constant.as_char());
2923     case T_BYTE:     return TypeInt::make(constant.as_byte());
2924     case T_SHORT:    return TypeInt::make(constant.as_short());
2925     case T_FLOAT:    return TypeF::make(constant.as_float());
2926     case T_DOUBLE:   return TypeD::make(constant.as_double());
2927     case T_LONG:     return TypeLong::make(constant.as_long());
2928     default:         break;
2929   }
2930   fatal(err_msg_res("Invalid boxed value type '%s'", type2name(bt)));
2931   return NULL;
2932 }
2933 
2934 //------------------------------cast_to_ptr_type-------------------------------
2935 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
2936   if( ptr == _ptr ) return this;
2937   // Reconstruct _sig info here since not a problem with later lazy
2938   // construction, _sig will show up on demand.
2939   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id);
2940 }
2941 
2942 
2943 //-----------------------------cast_to_exactness-------------------------------
2944 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
2945   if( klass_is_exact == _klass_is_exact ) return this;
2946   if (!UseExactTypes)  return this;
2947   if (!_klass->is_loaded())  return this;
2948   ciInstanceKlass* ik = _klass->as_instance_klass();
2949   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
2950   if( ik->is_interface() )              return this;  // cannot set xk
2951   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id);
2952 }
2953 
2954 //-----------------------------cast_to_instance_id----------------------------
2955 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
2956   if( instance_id == _instance_id ) return this;
2957   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id);
2958 }
2959 
2960 //------------------------------xmeet_unloaded---------------------------------
2961 // Compute the MEET of two InstPtrs when at least one is unloaded.
2962 // Assume classes are different since called after check for same name/class-loader
2963 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
2964     int off = meet_offset(tinst->offset());
2965     PTR ptr = meet_ptr(tinst->ptr());
2966     int instance_id = meet_instance_id(tinst->instance_id());

2967 
2968     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
2969     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
2970     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
2971       //
2972       // Meet unloaded class with java/lang/Object
2973       //
2974       // Meet
2975       //          |                     Unloaded Class
2976       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
2977       //  ===================================================================
2978       //   TOP    | ..........................Unloaded......................|
2979       //  AnyNull |  U-AN    |................Unloaded......................|
2980       // Constant | ... O-NN .................................. |   O-BOT   |
2981       //  NotNull | ... O-NN .................................. |   O-BOT   |
2982       //  BOTTOM  | ........................Object-BOTTOM ..................|
2983       //
2984       assert(loaded->ptr() != TypePtr::Null, "insanity check");
2985       //
2986       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
2987       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make( ptr, unloaded->klass(), false, NULL, off, instance_id ); }
2988       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
2989       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
2990         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
2991         else                                      { return TypeInstPtr::NOTNULL; }
2992       }
2993       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
2994 
2995       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
2996     }
2997 
2998     // Both are unloaded, not the same class, not Object
2999     // Or meet unloaded with a different loaded class, not java/lang/Object
3000     if( ptr != TypePtr::BotPTR ) {
3001       return TypeInstPtr::NOTNULL;
3002     }
3003     return TypeInstPtr::BOTTOM;
3004 }
3005 
3006 
3007 //------------------------------meet-------------------------------------------
3008 // Compute the MEET of two types.  It returns a new Type object.
3009 const Type *TypeInstPtr::xmeet( const Type *t ) const {
3010   // Perform a fast test for common case; meeting the same types together.
3011   if( this == t ) return this;  // Meeting same type-rep?
3012 
3013   // Current "this->_base" is Pointer
3014   switch (t->base()) {          // switch on original type
3015 
3016   case Int:                     // Mixing ints & oops happens when javac
3017   case Long:                    // reuses local variables
3018   case FloatTop:
3019   case FloatCon:
3020   case FloatBot:
3021   case DoubleTop:
3022   case DoubleCon:
3023   case DoubleBot:
3024   case NarrowOop:
3025   case NarrowKlass:
3026   case Bottom:                  // Ye Olde Default
3027     return Type::BOTTOM;
3028   case Top:
3029     return this;
3030 
3031   default:                      // All else is a mistake
3032     typerr(t);
3033 
3034   case MetadataPtr:
3035   case KlassPtr:
3036   case RawPtr: return TypePtr::BOTTOM;
3037 
3038   case AryPtr: {                // All arrays inherit from Object class
3039     const TypeAryPtr *tp = t->is_aryptr();
3040     int offset = meet_offset(tp->offset());
3041     PTR ptr = meet_ptr(tp->ptr());
3042     int instance_id = meet_instance_id(tp->instance_id());

3043     switch (ptr) {
3044     case TopPTR:
3045     case AnyNull:                // Fall 'down' to dual of object klass
3046       if (klass()->equals(ciEnv::current()->Object_klass())) {
3047         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);



3048       } else {
3049         // cannot subclass, so the meet has to fall badly below the centerline
3050         ptr = NotNull;
3051         instance_id = InstanceBot;
3052         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id);
3053       }
3054     case Constant:
3055     case NotNull:
3056     case BotPTR:                // Fall down to object klass
3057       // LCA is object_klass, but if we subclass from the top we can do better
3058       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
3059         // If 'this' (InstPtr) is above the centerline and it is Object class
3060         // then we can subclass in the Java class hierarchy.
3061         if (klass()->equals(ciEnv::current()->Object_klass())) {



3062           // that is, tp's array type is a subtype of my klass
3063           return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
3064                                   tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);
3065         }
3066       }
3067       // The other case cannot happen, since I cannot be a subtype of an array.
3068       // The meet falls down to Object class below centerline.
3069       if( ptr == Constant )
3070          ptr = NotNull;
3071       instance_id = InstanceBot;
3072       return make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id );
3073     default: typerr(t);
3074     }
3075   }
3076 
3077   case OopPtr: {                // Meeting to OopPtrs
3078     // Found a OopPtr type vs self-InstPtr type
3079     const TypeOopPtr *tp = t->is_oopptr();
3080     int offset = meet_offset(tp->offset());
3081     PTR ptr = meet_ptr(tp->ptr());
3082     switch (tp->ptr()) {
3083     case TopPTR:
3084     case AnyNull: {
3085       int instance_id = meet_instance_id(InstanceTop);

3086       return make(ptr, klass(), klass_is_exact(),
3087                   (ptr == Constant ? const_oop() : NULL), offset, instance_id);
3088     }
3089     case NotNull:
3090     case BotPTR: {
3091       int instance_id = meet_instance_id(tp->instance_id());
3092       return TypeOopPtr::make(ptr, offset, instance_id);

3093     }
3094     default: typerr(t);
3095     }
3096   }
3097 
3098   case AnyPtr: {                // Meeting to AnyPtrs
3099     // Found an AnyPtr type vs self-InstPtr type
3100     const TypePtr *tp = t->is_ptr();
3101     int offset = meet_offset(tp->offset());
3102     PTR ptr = meet_ptr(tp->ptr());
3103     switch (tp->ptr()) {
3104     case Null:
3105       if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
3106       // else fall through to AnyNull
3107     case TopPTR:
3108     case AnyNull: {
3109       int instance_id = meet_instance_id(InstanceTop);
3110       return make( ptr, klass(), klass_is_exact(),
3111                    (ptr == Constant ? const_oop() : NULL), offset, instance_id);

3112     }
3113     case NotNull:
3114     case BotPTR:
3115       return TypePtr::make( AnyPtr, ptr, offset );
3116     default: typerr(t);
3117     }
3118   }
3119 
3120   /*
3121                  A-top         }
3122                /   |   \       }  Tops
3123            B-top A-any C-top   }
3124               | /  |  \ |      }  Any-nulls
3125            B-any   |   C-any   }
3126               |    |    |
3127            B-con A-con C-con   } constants; not comparable across classes
3128               |    |    |
3129            B-not   |   C-not   }
3130               | \  |  / |      }  not-nulls
3131            B-bot A-not C-bot   }
3132                \   |   /       }  Bottoms
3133                  A-bot         }
3134   */
3135 
3136   case InstPtr: {                // Meeting 2 Oops?
3137     // Found an InstPtr sub-type vs self-InstPtr type
3138     const TypeInstPtr *tinst = t->is_instptr();
3139     int off = meet_offset( tinst->offset() );
3140     PTR ptr = meet_ptr( tinst->ptr() );
3141     int instance_id = meet_instance_id(tinst->instance_id());

3142 
3143     // Check for easy case; klasses are equal (and perhaps not loaded!)
3144     // If we have constants, then we created oops so classes are loaded
3145     // and we can handle the constants further down.  This case handles
3146     // both-not-loaded or both-loaded classes
3147     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
3148       return make( ptr, klass(), klass_is_exact(), NULL, off, instance_id );
3149     }
3150 
3151     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
3152     ciKlass* tinst_klass = tinst->klass();
3153     ciKlass* this_klass  = this->klass();
3154     bool tinst_xk = tinst->klass_is_exact();
3155     bool this_xk  = this->klass_is_exact();
3156     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
3157       // One of these classes has not been loaded
3158       const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
3159 #ifndef PRODUCT
3160       if( PrintOpto && Verbose ) {
3161         tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
3162         tty->print("  this == "); this->dump(); tty->cr();
3163         tty->print(" tinst == "); tinst->dump(); tty->cr();
3164       }
3165 #endif
3166       return unloaded_meet;
3167     }
3168 
3169     // Handle mixing oops and interfaces first.
3170     if( this_klass->is_interface() && !tinst_klass->is_interface() ) {

3171       ciKlass *tmp = tinst_klass; // Swap interface around
3172       tinst_klass = this_klass;
3173       this_klass = tmp;
3174       bool tmp2 = tinst_xk;
3175       tinst_xk = this_xk;
3176       this_xk = tmp2;
3177     }
3178     if (tinst_klass->is_interface() &&
3179         !(this_klass->is_interface() ||
3180           // Treat java/lang/Object as an honorary interface,
3181           // because we need a bottom for the interface hierarchy.
3182           this_klass == ciEnv::current()->Object_klass())) {
3183       // Oop meets interface!
3184 
3185       // See if the oop subtypes (implements) interface.
3186       ciKlass *k;
3187       bool xk;
3188       if( this_klass->is_subtype_of( tinst_klass ) ) {
3189         // Oop indeed subtypes.  Now keep oop or interface depending
3190         // on whether we are both above the centerline or either is
3191         // below the centerline.  If we are on the centerline
3192         // (e.g., Constant vs. AnyNull interface), use the constant.
3193         k  = below_centerline(ptr) ? tinst_klass : this_klass;
3194         // If we are keeping this_klass, keep its exactness too.
3195         xk = below_centerline(ptr) ? tinst_xk    : this_xk;
3196       } else {                  // Does not implement, fall to Object
3197         // Oop does not implement interface, so mixing falls to Object
3198         // just like the verifier does (if both are above the
3199         // centerline fall to interface)
3200         k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
3201         xk = above_centerline(ptr) ? tinst_xk : false;
3202         // Watch out for Constant vs. AnyNull interface.
3203         if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
3204         instance_id = InstanceBot;
3205       }
3206       ciObject* o = NULL;  // the Constant value, if any
3207       if (ptr == Constant) {
3208         // Find out which constant.
3209         o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
3210       }
3211       return make( ptr, k, xk, o, off, instance_id );
3212     }
3213 
3214     // Either oop vs oop or interface vs interface or interface vs Object
3215 
3216     // !!! Here's how the symmetry requirement breaks down into invariants:
3217     // If we split one up & one down AND they subtype, take the down man.
3218     // If we split one up & one down AND they do NOT subtype, "fall hard".
3219     // If both are up and they subtype, take the subtype class.
3220     // If both are up and they do NOT subtype, "fall hard".
3221     // If both are down and they subtype, take the supertype class.
3222     // If both are down and they do NOT subtype, "fall hard".
3223     // Constants treated as down.
3224 
3225     // Now, reorder the above list; observe that both-down+subtype is also
3226     // "fall hard"; "fall hard" becomes the default case:
3227     // If we split one up & one down AND they subtype, take the down man.
3228     // If both are up and they subtype, take the subtype class.
3229 
3230     // If both are down and they subtype, "fall hard".
3231     // If both are down and they do NOT subtype, "fall hard".


3268 
3269     // Check for classes now being equal
3270     if (tinst_klass->equals(this_klass)) {
3271       // If the klasses are equal, the constants may still differ.  Fall to
3272       // NotNull if they do (neither constant is NULL; that is a special case
3273       // handled elsewhere).
3274       ciObject* o = NULL;             // Assume not constant when done
3275       ciObject* this_oop  = const_oop();
3276       ciObject* tinst_oop = tinst->const_oop();
3277       if( ptr == Constant ) {
3278         if (this_oop != NULL && tinst_oop != NULL &&
3279             this_oop->equals(tinst_oop) )
3280           o = this_oop;
3281         else if (above_centerline(this ->_ptr))
3282           o = tinst_oop;
3283         else if (above_centerline(tinst ->_ptr))
3284           o = this_oop;
3285         else
3286           ptr = NotNull;
3287       }
3288       return make( ptr, this_klass, this_xk, o, off, instance_id );
3289     } // Else classes are not equal
3290 
3291     // Since klasses are different, we require a LCA in the Java
3292     // class hierarchy - which means we have to fall to at least NotNull.
3293     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3294       ptr = NotNull;
3295     instance_id = InstanceBot;
3296 
3297     // Now we find the LCA of Java classes
3298     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
3299     return make( ptr, k, false, NULL, off, instance_id );
3300   } // End of case InstPtr
3301 
3302   } // End of switch
3303   return this;                  // Return the double constant
3304 }
3305 
3306 
3307 //------------------------java_mirror_type--------------------------------------
3308 ciType* TypeInstPtr::java_mirror_type() const {
3309   // must be a singleton type
3310   if( const_oop() == NULL )  return NULL;
3311 
3312   // must be of type java.lang.Class
3313   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
3314 
3315   return const_oop()->as_instance()->java_mirror_type();
3316 }
3317 
3318 
3319 //------------------------------xdual------------------------------------------
3320 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
3321 // inheritance mechanism.
3322 const Type *TypeInstPtr::xdual() const {
3323   return new TypeInstPtr( dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id()  );
3324 }
3325 
3326 //------------------------------eq---------------------------------------------
3327 // Structural equality check for Type representations
3328 bool TypeInstPtr::eq( const Type *t ) const {
3329   const TypeInstPtr *p = t->is_instptr();
3330   return
3331     klass()->equals(p->klass()) &&
3332     TypeOopPtr::eq(p);          // Check sub-type stuff
3333 }
3334 
3335 //------------------------------hash-------------------------------------------
3336 // Type-specific hashing function.
3337 int TypeInstPtr::hash(void) const {
3338   int hash = klass()->hash() + TypeOopPtr::hash();
3339   return hash;
3340 }
3341 
3342 //------------------------------dump2------------------------------------------
3343 // Dump oop Type


3359     }
3360   case TopPTR:
3361   case AnyNull:
3362   case NotNull:
3363     st->print(":%s", ptr_msg[_ptr]);
3364     if( _klass_is_exact ) st->print(":exact");
3365     break;
3366   }
3367 
3368   if( _offset ) {               // Dump offset, if any
3369     if( _offset == OffsetBot )      st->print("+any");
3370     else if( _offset == OffsetTop ) st->print("+unknown");
3371     else st->print("+%d", _offset);
3372   }
3373 
3374   st->print(" *");
3375   if (_instance_id == InstanceTop)
3376     st->print(",iid=top");
3377   else if (_instance_id != InstanceBot)
3378     st->print(",iid=%d",_instance_id);


3379 }
3380 #endif
3381 
3382 //------------------------------add_offset-------------------------------------
3383 const TypePtr *TypeInstPtr::add_offset( intptr_t offset ) const {
3384   return make( _ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id );




3385 }
3386 
3387 //=============================================================================
3388 // Convenience common pre-built types.
3389 const TypeAryPtr *TypeAryPtr::RANGE;
3390 const TypeAryPtr *TypeAryPtr::OOPS;
3391 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
3392 const TypeAryPtr *TypeAryPtr::BYTES;
3393 const TypeAryPtr *TypeAryPtr::SHORTS;
3394 const TypeAryPtr *TypeAryPtr::CHARS;
3395 const TypeAryPtr *TypeAryPtr::INTS;
3396 const TypeAryPtr *TypeAryPtr::LONGS;
3397 const TypeAryPtr *TypeAryPtr::FLOATS;
3398 const TypeAryPtr *TypeAryPtr::DOUBLES;
3399 
3400 //------------------------------make-------------------------------------------
3401 const TypeAryPtr *TypeAryPtr::make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) {
3402   assert(!(k == NULL && ary->_elem->isa_int()),
3403          "integral arrays must be pre-equipped with a class");
3404   if (!xk)  xk = ary->ary_must_be_exact();
3405   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3406   if (!UseExactTypes)  xk = (ptr == Constant);
3407   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false))->hashcons();
3408 }
3409 
3410 //------------------------------make-------------------------------------------
3411 const TypeAryPtr *TypeAryPtr::make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, bool is_autobox_cache) {
3412   assert(!(k == NULL && ary->_elem->isa_int()),
3413          "integral arrays must be pre-equipped with a class");
3414   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
3415   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
3416   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3417   if (!UseExactTypes)  xk = (ptr == Constant);
3418   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache))->hashcons();
3419 }
3420 
3421 //------------------------------cast_to_ptr_type-------------------------------
3422 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
3423   if( ptr == _ptr ) return this;
3424   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id);
3425 }
3426 
3427 
3428 //-----------------------------cast_to_exactness-------------------------------
3429 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
3430   if( klass_is_exact == _klass_is_exact ) return this;
3431   if (!UseExactTypes)  return this;
3432   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
3433   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id);
3434 }
3435 
3436 //-----------------------------cast_to_instance_id----------------------------
3437 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
3438   if( instance_id == _instance_id ) return this;
3439   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id);
3440 }
3441 
3442 //-----------------------------narrow_size_type-------------------------------
3443 // Local cache for arrayOopDesc::max_array_length(etype),
3444 // which is kind of slow (and cached elsewhere by other users).
3445 static jint max_array_length_cache[T_CONFLICT+1];
3446 static jint max_array_length(BasicType etype) {
3447   jint& cache = max_array_length_cache[etype];
3448   jint res = cache;
3449   if (res == 0) {
3450     switch (etype) {
3451     case T_NARROWOOP:
3452       etype = T_OBJECT;
3453       break;
3454     case T_NARROWKLASS:
3455     case T_CONFLICT:
3456     case T_ILLEGAL:
3457     case T_VOID:
3458       etype = T_BYTE;           // will produce conservatively high value
3459     }


3482     hi = max_hi;
3483     if (size->is_con()) {
3484       lo = hi;
3485     }
3486     chg = true;
3487   }
3488   // Negative length arrays will produce weird intermediate dead fast-path code
3489   if (lo > hi)
3490     return TypeInt::ZERO;
3491   if (!chg)
3492     return size;
3493   return TypeInt::make(lo, hi, Type::WidenMin);
3494 }
3495 
3496 //-------------------------------cast_to_size----------------------------------
3497 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
3498   assert(new_size != NULL, "");
3499   new_size = narrow_size_type(new_size);
3500   if (new_size == size())  return this;
3501   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
3502   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
3503 }
3504 
3505 
3506 //------------------------------cast_to_stable---------------------------------
3507 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
3508   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
3509     return this;
3510 
3511   const Type* elem = this->elem();
3512   const TypePtr* elem_ptr = elem->make_ptr();
3513 
3514   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
3515     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
3516     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
3517   }
3518 
3519   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
3520 
3521   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
3522 }


3531   return dim;
3532 }
3533 
3534 //------------------------------eq---------------------------------------------
3535 // Structural equality check for Type representations
3536 bool TypeAryPtr::eq( const Type *t ) const {
3537   const TypeAryPtr *p = t->is_aryptr();
3538   return
3539     _ary == p->_ary &&  // Check array
3540     TypeOopPtr::eq(p);  // Check sub-parts
3541 }
3542 
3543 //------------------------------hash-------------------------------------------
3544 // Type-specific hashing function.
3545 int TypeAryPtr::hash(void) const {
3546   return (intptr_t)_ary + TypeOopPtr::hash();
3547 }
3548 
3549 //------------------------------meet-------------------------------------------
3550 // Compute the MEET of two types.  It returns a new Type object.
3551 const Type *TypeAryPtr::xmeet( const Type *t ) const {
3552   // Perform a fast test for common case; meeting the same types together.
3553   if( this == t ) return this;  // Meeting same type-rep?
3554   // Current "this->_base" is Pointer
3555   switch (t->base()) {          // switch on original type
3556 
3557   // Mixing ints & oops happens when javac reuses local variables
3558   case Int:
3559   case Long:
3560   case FloatTop:
3561   case FloatCon:
3562   case FloatBot:
3563   case DoubleTop:
3564   case DoubleCon:
3565   case DoubleBot:
3566   case NarrowOop:
3567   case NarrowKlass:
3568   case Bottom:                  // Ye Olde Default
3569     return Type::BOTTOM;
3570   case Top:
3571     return this;
3572 
3573   default:                      // All else is a mistake
3574     typerr(t);
3575 
3576   case OopPtr: {                // Meeting to OopPtrs
3577     // Found a OopPtr type vs self-AryPtr type
3578     const TypeOopPtr *tp = t->is_oopptr();
3579     int offset = meet_offset(tp->offset());
3580     PTR ptr = meet_ptr(tp->ptr());
3581     switch (tp->ptr()) {
3582     case TopPTR:
3583     case AnyNull: {
3584       int instance_id = meet_instance_id(InstanceTop);

3585       return make(ptr, (ptr == Constant ? const_oop() : NULL),
3586                   _ary, _klass, _klass_is_exact, offset, instance_id);
3587     }
3588     case BotPTR:
3589     case NotNull: {
3590       int instance_id = meet_instance_id(tp->instance_id());
3591       return TypeOopPtr::make(ptr, offset, instance_id);

3592     }
3593     default: ShouldNotReachHere();
3594     }
3595   }
3596 
3597   case AnyPtr: {                // Meeting two AnyPtrs
3598     // Found an AnyPtr type vs self-AryPtr type
3599     const TypePtr *tp = t->is_ptr();
3600     int offset = meet_offset(tp->offset());
3601     PTR ptr = meet_ptr(tp->ptr());
3602     switch (tp->ptr()) {
3603     case TopPTR:
3604       return this;
3605     case BotPTR:
3606     case NotNull:
3607       return TypePtr::make(AnyPtr, ptr, offset);
3608     case Null:
3609       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
3610       // else fall through to AnyNull
3611     case AnyNull: {
3612       int instance_id = meet_instance_id(InstanceTop);
3613       return make( ptr, (ptr == Constant ? const_oop() : NULL),
3614                   _ary, _klass, _klass_is_exact, offset, instance_id);

3615     }
3616     default: ShouldNotReachHere();
3617     }
3618   }
3619 
3620   case MetadataPtr:
3621   case KlassPtr:
3622   case RawPtr: return TypePtr::BOTTOM;
3623 
3624   case AryPtr: {                // Meeting 2 references?
3625     const TypeAryPtr *tap = t->is_aryptr();
3626     int off = meet_offset(tap->offset());
3627     const TypeAry *tary = _ary->meet(tap->_ary)->is_ary();
3628     PTR ptr = meet_ptr(tap->ptr());
3629     int instance_id = meet_instance_id(tap->instance_id());

3630     ciKlass* lazy_klass = NULL;
3631     if (tary->_elem->isa_int()) {
3632       // Integral array element types have irrelevant lattice relations.
3633       // It is the klass that determines array layout, not the element type.
3634       if (_klass == NULL)
3635         lazy_klass = tap->_klass;
3636       else if (tap->_klass == NULL || tap->_klass == _klass) {
3637         lazy_klass = _klass;
3638       } else {
3639         // Something like byte[int+] meets char[int+].
3640         // This must fall to bottom, not (int[-128..65535])[int+].
3641         instance_id = InstanceBot;
3642         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
3643       }
3644     } else // Non integral arrays.
3645     // Must fall to bottom if exact klasses in upper lattice
3646     // are not equal or super klass is exact.
3647     if ( above_centerline(ptr) && klass() != tap->klass() &&
3648          // meet with top[] and bottom[] are processed further down:
3649          tap ->_klass != NULL  && this->_klass != NULL   &&
3650          // both are exact and not equal:
3651         ((tap ->_klass_is_exact && this->_klass_is_exact) ||
3652          // 'tap'  is exact and super or unrelated:
3653          (tap ->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
3654          // 'this' is exact and super or unrelated:
3655          (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
3656       tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
3657       return make( NotNull, NULL, tary, lazy_klass, false, off, InstanceBot );
3658     }
3659 
3660     bool xk = false;
3661     switch (tap->ptr()) {
3662     case AnyNull:
3663     case TopPTR:
3664       // Compute new klass on demand, do not use tap->_klass



3665       xk = (tap->_klass_is_exact | this->_klass_is_exact);
3666       return make( ptr, const_oop(), tary, lazy_klass, xk, off, instance_id );

3667     case Constant: {
3668       ciObject* o = const_oop();
3669       if( _ptr == Constant ) {
3670         if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
3671           xk = (klass() == tap->klass());
3672           ptr = NotNull;
3673           o = NULL;
3674           instance_id = InstanceBot;
3675         } else {
3676           xk = true;
3677         }
3678       } else if( above_centerline(_ptr) ) {
3679         o = tap->const_oop();
3680         xk = true;
3681       } else {
3682         // Only precise for identical arrays
3683         xk = this->_klass_is_exact && (klass() == tap->klass());
3684       }
3685       return TypeAryPtr::make( ptr, o, tary, lazy_klass, xk, off, instance_id );
3686     }
3687     case NotNull:
3688     case BotPTR:
3689       // Compute new klass on demand, do not use tap->_klass
3690       if (above_centerline(this->_ptr))
3691             xk = tap->_klass_is_exact;
3692       else if (above_centerline(tap->_ptr))
3693             xk = this->_klass_is_exact;
3694       else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
3695               (klass() == tap->klass()); // Only precise for identical arrays
3696       return TypeAryPtr::make( ptr, NULL, tary, lazy_klass, xk, off, instance_id );
3697     default: ShouldNotReachHere();
3698     }
3699   }
3700 
3701   // All arrays inherit from Object class
3702   case InstPtr: {
3703     const TypeInstPtr *tp = t->is_instptr();
3704     int offset = meet_offset(tp->offset());
3705     PTR ptr = meet_ptr(tp->ptr());
3706     int instance_id = meet_instance_id(tp->instance_id());

3707     switch (ptr) {
3708     case TopPTR:
3709     case AnyNull:                // Fall 'down' to dual of object klass
3710       if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
3711         return TypeAryPtr::make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id );



3712       } else {
3713         // cannot subclass, so the meet has to fall badly below the centerline
3714         ptr = NotNull;
3715         instance_id = InstanceBot;
3716         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id);
3717       }
3718     case Constant:
3719     case NotNull:
3720     case BotPTR:                // Fall down to object klass
3721       // LCA is object_klass, but if we subclass from the top we can do better
3722       if (above_centerline(tp->ptr())) {
3723         // If 'tp'  is above the centerline and it is Object class
3724         // then we can subclass in the Java class hierarchy.
3725         if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {



3726           // that is, my array type is a subtype of 'tp' klass
3727           return make( ptr, (ptr == Constant ? const_oop() : NULL),
3728                        _ary, _klass, _klass_is_exact, offset, instance_id );
3729         }
3730       }
3731       // The other case cannot happen, since t cannot be a subtype of an array.
3732       // The meet falls down to Object class below centerline.
3733       if( ptr == Constant )
3734          ptr = NotNull;
3735       instance_id = InstanceBot;
3736       return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id);
3737     default: typerr(t);
3738     }
3739   }
3740   }
3741   return this;                  // Lint noise
3742 }
3743 
3744 //------------------------------xdual------------------------------------------
3745 // Dual: compute field-by-field dual
3746 const Type *TypeAryPtr::xdual() const {
3747   return new TypeAryPtr( dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id(), is_autobox_cache() );
3748 }
3749 
3750 //----------------------interface_vs_oop---------------------------------------
3751 #ifdef ASSERT
3752 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
3753   const TypeAryPtr* t_aryptr = t->isa_aryptr();
3754   if (t_aryptr) {
3755     return _ary->interface_vs_oop(t_aryptr->_ary);
3756   }
3757   return false;
3758 }
3759 #endif
3760 
3761 //------------------------------dump2------------------------------------------
3762 #ifndef PRODUCT
3763 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3764   _ary->dump2(d,depth,st);
3765   switch( _ptr ) {
3766   case Constant:
3767     const_oop()->print(st);


3779     break;
3780   }
3781 
3782   if( _offset != 0 ) {
3783     int header_size = objArrayOopDesc::header_size() * wordSize;
3784     if( _offset == OffsetTop )       st->print("+undefined");
3785     else if( _offset == OffsetBot )  st->print("+any");
3786     else if( _offset < header_size ) st->print("+%d", _offset);
3787     else {
3788       BasicType basic_elem_type = elem()->basic_type();
3789       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
3790       int elem_size = type2aelembytes(basic_elem_type);
3791       st->print("[%d]", (_offset - array_base)/elem_size);
3792     }
3793   }
3794   st->print(" *");
3795   if (_instance_id == InstanceTop)
3796     st->print(",iid=top");
3797   else if (_instance_id != InstanceBot)
3798     st->print(",iid=%d",_instance_id);


3799 }
3800 #endif
3801 
3802 bool TypeAryPtr::empty(void) const {
3803   if (_ary->empty())       return true;
3804   return TypeOopPtr::empty();
3805 }
3806 
3807 //------------------------------add_offset-------------------------------------
3808 const TypePtr *TypeAryPtr::add_offset( intptr_t offset ) const {
3809   return make( _ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id );
3810 }
3811 



3812 
3813 //=============================================================================
3814 
3815 //------------------------------hash-------------------------------------------
3816 // Type-specific hashing function.
3817 int TypeNarrowPtr::hash(void) const {
3818   return _ptrtype->hash() + 7;
3819 }
3820 
3821 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
3822   return _ptrtype->singleton();
3823 }
3824 
3825 bool TypeNarrowPtr::empty(void) const {
3826   return _ptrtype->empty();
3827 }
3828 
3829 intptr_t TypeNarrowPtr::get_con() const {
3830   return _ptrtype->get_con();
3831 }




 341   TypePtr::BOTTOM  = TypePtr::make( AnyPtr, TypePtr::BotPTR, OffsetBot );
 342 
 343   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
 344   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
 345 
 346   const Type **fmembar = TypeTuple::fields(0);
 347   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
 348 
 349   const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
 350   fsc[0] = TypeInt::CC;
 351   fsc[1] = Type::MEMORY;
 352   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
 353 
 354   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
 355   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
 356   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
 357   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 358                                            false, 0, oopDesc::mark_offset_in_bytes());
 359   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 360                                            false, 0, oopDesc::klass_offset_in_bytes());
 361   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot, NULL);
 362 
 363   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, OffsetBot);
 364 
 365   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
 366   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
 367 
 368   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
 369 
 370   mreg2type[Op_Node] = Type::BOTTOM;
 371   mreg2type[Op_Set ] = 0;
 372   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
 373   mreg2type[Op_RegI] = TypeInt::INT;
 374   mreg2type[Op_RegP] = TypePtr::BOTTOM;
 375   mreg2type[Op_RegF] = Type::FLOAT;
 376   mreg2type[Op_RegD] = Type::DOUBLE;
 377   mreg2type[Op_RegL] = TypeLong::LONG;
 378   mreg2type[Op_RegFlags] = TypeInt::CC;
 379 
 380   TypeAryPtr::RANGE   = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
 381 


 560 //------------------------------hash-------------------------------------------
 561 // Type-specific hashing function.
 562 int Type::hash(void) const {
 563   return _base;
 564 }
 565 
 566 //------------------------------is_finite--------------------------------------
 567 // Has a finite value
 568 bool Type::is_finite() const {
 569   return false;
 570 }
 571 
 572 //------------------------------is_nan-----------------------------------------
 573 // Is not a number (NaN)
 574 bool Type::is_nan()    const {
 575   return false;
 576 }
 577 
 578 //----------------------interface_vs_oop---------------------------------------
 579 #ifdef ASSERT
 580 bool Type::interface_vs_oop_helper(const Type *t) const {
 581   bool result = false;
 582 
 583   const TypePtr* this_ptr = this->make_ptr(); // In case it is narrow_oop
 584   const TypePtr*    t_ptr =    t->make_ptr();
 585   if( this_ptr == NULL || t_ptr == NULL )
 586     return result;
 587 
 588   const TypeInstPtr* this_inst = this_ptr->isa_instptr();
 589   const TypeInstPtr*    t_inst =    t_ptr->isa_instptr();
 590   if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
 591     bool this_interface = this_inst->klass()->is_interface();
 592     bool    t_interface =    t_inst->klass()->is_interface();
 593     result = this_interface ^ t_interface;
 594   }
 595 
 596   return result;
 597 }
 598 
 599 bool Type::interface_vs_oop(const Type *t) const {
 600   if (interface_vs_oop_helper(t)) {
 601     return true;
 602   }
 603   // Now check the speculative parts as well
 604   const TypeOopPtr* this_spec = isa_oopptr() != NULL ? isa_oopptr()->speculative() : NULL;
 605   const TypeOopPtr* t_spec = t->isa_oopptr() != NULL ? t->isa_oopptr()->speculative() : NULL;
 606   if (this_spec != NULL && t_spec != NULL) {
 607     if (this_spec->interface_vs_oop_helper(t_spec)) {
 608       return true;
 609     }
 610     return false;
 611   }
 612   if (this_spec != NULL && this_spec->interface_vs_oop_helper(t)) {
 613     return true;
 614   }
 615   if (t_spec != NULL && interface_vs_oop_helper(t_spec)) {
 616     return true;
 617   }
 618   return false;
 619 }
 620 
 621 #endif
 622 
 623 //------------------------------meet-------------------------------------------
 624 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
 625 // commutative and the lattice is symmetric.
 626 const Type *Type::meet( const Type *t ) const {
 627   if (isa_narrowoop() && t->isa_narrowoop()) {
 628     const Type* result = make_ptr()->meet(t->make_ptr());
 629     return result->make_narrowoop();
 630   }
 631   if (isa_narrowklass() && t->isa_narrowklass()) {
 632     const Type* result = make_ptr()->meet(t->make_ptr());
 633     return result->make_narrowklass();
 634   }
 635 
 636   const Type *mt = xmeet(t);
 637   if (isa_narrowoop() || t->isa_narrowoop()) return mt;
 638   if (isa_narrowklass() || t->isa_narrowklass()) return mt;
 639 #ifdef ASSERT
 640   assert( mt == t->xmeet(this), "meet not commutative" );


2413 // Type-specific hashing function.
2414 int TypeRawPtr::hash(void) const {
2415   return (intptr_t)_bits + TypePtr::hash();
2416 }
2417 
2418 //------------------------------dump2------------------------------------------
2419 #ifndef PRODUCT
2420 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2421   if( _ptr == Constant )
2422     st->print(INTPTR_FORMAT, _bits);
2423   else
2424     st->print("rawptr:%s", ptr_msg[_ptr]);
2425 }
2426 #endif
2427 
2428 //=============================================================================
2429 // Convenience common pre-built type.
2430 const TypeOopPtr *TypeOopPtr::BOTTOM;
2431 
2432 //------------------------------TypeOopPtr-------------------------------------
2433 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative)
2434   : TypePtr(t, ptr, offset),
2435     _const_oop(o), _klass(k),
2436     _klass_is_exact(xk),
2437     _is_ptr_to_narrowoop(false),
2438     _is_ptr_to_narrowklass(false),
2439     _is_ptr_to_boxed_value(false),
2440     _instance_id(instance_id),
2441     _speculative(speculative) {
2442   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
2443       (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
2444     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
2445   }
2446 #ifdef _LP64
2447   if (_offset != 0) {
2448     if (_offset == oopDesc::klass_offset_in_bytes()) {
2449       _is_ptr_to_narrowklass = UseCompressedClassPointers;
2450     } else if (klass() == NULL) {
2451       // Array with unknown body type
2452       assert(this->isa_aryptr(), "only arrays without klass");
2453       _is_ptr_to_narrowoop = UseCompressedOops;
2454     } else if (this->isa_aryptr()) {
2455       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
2456                              _offset != arrayOopDesc::length_offset_in_bytes());
2457     } else if (klass()->is_instance_klass()) {
2458       ciInstanceKlass* ik = klass()->as_instance_klass();
2459       ciField* field = NULL;
2460       if (this->isa_klassptr()) {
2461         // Perm objects don't use compressed references


2488             BasicType basic_elem_type = field->layout_type();
2489             _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
2490                                                          basic_elem_type == T_ARRAY);
2491           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
2492             // Compile::find_alias_type() cast exactness on all types to verify
2493             // that it does not affect alias type.
2494             _is_ptr_to_narrowoop = UseCompressedOops;
2495           } else {
2496             // Type for the copy start in LibraryCallKit::inline_native_clone().
2497             _is_ptr_to_narrowoop = UseCompressedOops;
2498           }
2499         }
2500       }
2501     }
2502   }
2503 #endif
2504 }
2505 
2506 //------------------------------make-------------------------------------------
2507 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
2508                                    int offset, int instance_id, const TypeOopPtr* speculative) {
2509   assert(ptr != Constant, "no constant generic pointers");
2510   ciKlass*  k = Compile::current()->env()->Object_klass();
2511   bool      xk = false;
2512   ciObject* o = NULL;
2513   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative))->hashcons();
2514 }
2515 
2516 
2517 //------------------------------cast_to_ptr_type-------------------------------
2518 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
2519   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
2520   if( ptr == _ptr ) return this;
2521   return make(ptr, _offset, _instance_id, _speculative);
2522 }
2523 
2524 //-----------------------------cast_to_instance_id----------------------------
2525 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
2526   // There are no instances of a general oop.
2527   // Return self unchanged.
2528   return this;
2529 }
2530 
2531 //-----------------------------cast_to_exactness-------------------------------
2532 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
2533   // There is no such thing as an exact general oop.
2534   // Return self unchanged.
2535   return this;
2536 }
2537 
2538 
2539 //------------------------------as_klass_type----------------------------------
2540 // Return the klass type corresponding to this instance or array type.
2541 // It is the type that is loaded from an object of this type.
2542 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
2543   ciKlass* k = klass();
2544   bool    xk = klass_is_exact();
2545   if (k == NULL)
2546     return TypeKlassPtr::OBJECT;
2547   else
2548     return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
2549 }
2550 
2551 const Type *TypeOopPtr::xmeet(const Type *t) const {
2552   const Type* res = xmeet_helper(t);
2553   if (res->isa_oopptr() == NULL) {
2554     return res;
2555   }
2556   
2557   if (res->isa_oopptr() != NULL) {
2558     // type->speculative() == NULL means that speculation is no better
2559     // than type, i.e. type->speculative() == type. So there are 2
2560     // ways to represent the fact that we have no useful speculative
2561     // data and we should use a single one to be able to test for
2562     // equality between types. Check whether type->speculative() ==
2563     // type and set speculative to NULL if it is the case.
2564     const TypeOopPtr* res_oopptr = res->is_oopptr();
2565     if (res_oopptr->remove_speculative() == res_oopptr->speculative()) {
2566       return res_oopptr->remove_speculative();
2567     }
2568   }
2569 
2570   return res;
2571 }
2572 
2573 //------------------------------meet-------------------------------------------
2574 // Compute the MEET of two types.  It returns a new Type object.
2575 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
2576   // Perform a fast test for common case; meeting the same types together.
2577   if( this == t ) return this;  // Meeting same type-rep?
2578 
2579   // Current "this->_base" is OopPtr
2580   switch (t->base()) {          // switch on original type
2581 
2582   case Int:                     // Mixing ints & oops happens when javac
2583   case Long:                    // reuses local variables
2584   case FloatTop:
2585   case FloatCon:
2586   case FloatBot:
2587   case DoubleTop:
2588   case DoubleCon:
2589   case DoubleBot:
2590   case NarrowOop:
2591   case NarrowKlass:
2592   case Bottom:                  // Ye Olde Default
2593     return Type::BOTTOM;
2594   case Top:
2595     return this;


2597   default:                      // All else is a mistake
2598     typerr(t);
2599 
2600   case RawPtr:
2601   case MetadataPtr:
2602   case KlassPtr:
2603     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
2604 
2605   case AnyPtr: {
2606     // Found an AnyPtr type vs self-OopPtr type
2607     const TypePtr *tp = t->is_ptr();
2608     int offset = meet_offset(tp->offset());
2609     PTR ptr = meet_ptr(tp->ptr());
2610     switch (tp->ptr()) {
2611     case Null:
2612       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset);
2613       // else fall through:
2614     case TopPTR:
2615     case AnyNull: {
2616       int instance_id = meet_instance_id(InstanceTop);
2617       const TypeOopPtr* speculative = _speculative;
2618       return make(ptr, offset, instance_id, speculative);
2619     }
2620     case BotPTR:
2621     case NotNull:
2622       return TypePtr::make(AnyPtr, ptr, offset);
2623     default: typerr(t);
2624     }
2625   }
2626 
2627   case OopPtr: {                 // Meeting to other OopPtrs
2628     const TypeOopPtr *tp = t->is_oopptr();
2629     int instance_id = meet_instance_id(tp->instance_id());
2630     const TypeOopPtr* speculative = meet_speculative(tp);
2631     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative);
2632   }
2633 
2634   case InstPtr:                  // For these, flip the call around to cut down
2635   case AryPtr:
2636     return t->xmeet(this);      // Call in reverse direction
2637 
2638   } // End of switch
2639   return this;                  // Return the double constant
2640 }
2641 
2642 
2643 //------------------------------xdual------------------------------------------
2644 // Dual of a pure heap pointer.  No relevant klass or oop information.
2645 const Type *TypeOopPtr::xdual() const {
2646   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
2647   assert(const_oop() == NULL,             "no constants here");
2648   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative());
2649 }
2650 
2651 //--------------------------make_from_klass_common-----------------------------
2652 // Computes the element-type given a klass.
2653 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
2654   if (klass->is_instance_klass()) {
2655     Compile* C = Compile::current();
2656     Dependencies* deps = C->dependencies();
2657     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
2658     // Element is an instance
2659     bool klass_is_exact = false;
2660     if (klass->is_loaded()) {
2661       // Try to set klass_is_exact.
2662       ciInstanceKlass* ik = klass->as_instance_klass();
2663       klass_is_exact = ik->is_final();
2664       if (!klass_is_exact && klass_change
2665           && deps != NULL && UseUniqueSubclasses) {
2666         ciInstanceKlass* sub = ik->unique_concrete_subklass();
2667         if (sub != NULL) {
2668           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);


2719       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
2720     }
2721     return TypeInstPtr::make(o);
2722   } else if (klass->is_obj_array_klass()) {
2723     // Element is an object array. Recursively call ourself.
2724     const TypeOopPtr *etype =
2725       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
2726     if (is_autobox_cache) {
2727       // The pointers in the autobox arrays are always non-null.
2728       etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
2729     }
2730     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
2731     // We used to pass NotNull in here, asserting that the sub-arrays
2732     // are all not-null.  This is not true in generally, as code can
2733     // slam NULLs down in the subarrays.
2734     if (require_constant) {
2735       if (!o->can_be_constant())  return NULL;
2736     } else if (!o->should_be_constant()) {
2737       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
2738     }
2739     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0, InstanceBot, NULL, is_autobox_cache);
2740     return arr;
2741   } else if (klass->is_type_array_klass()) {
2742     // Element is an typeArray
2743     const Type* etype =
2744       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
2745     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
2746     // We used to pass NotNull in here, asserting that the array pointer
2747     // is not-null. That was not true in general.
2748     if (require_constant) {
2749       if (!o->can_be_constant())  return NULL;
2750     } else if (!o->should_be_constant()) {
2751       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
2752     }
2753     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
2754     return arr;
2755   }
2756 
2757   fatal("unhandled object type");
2758   return NULL;
2759 }


2819     assert(!ftip->klass_is_exact(), "interface could not be exact");
2820     return ktip->cast_to_ptr_type(ftip->ptr());
2821   }
2822   // Interface klass type could be exact in opposite to interface type,
2823   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
2824   if (ftkp != NULL && ktkp != NULL &&
2825       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
2826       !ftkp->klass_is_exact() && // Keep exact interface klass
2827       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
2828     return ktkp->cast_to_ptr_type(ftkp->ptr());
2829   }
2830 
2831   return ft;
2832 }
2833 
2834 //------------------------------eq---------------------------------------------
2835 // Structural equality check for Type representations
2836 bool TypeOopPtr::eq( const Type *t ) const {
2837   const TypeOopPtr *a = (const TypeOopPtr*)t;
2838   if (_klass_is_exact != a->_klass_is_exact ||
2839       _instance_id != a->_instance_id ||
2840       !eq_speculative(a))  return false;
2841   ciObject* one = const_oop();
2842   ciObject* two = a->const_oop();
2843   if (one == NULL || two == NULL) {
2844     return (one == two) && TypePtr::eq(t);
2845   } else {
2846     return one->equals(two) && TypePtr::eq(t);
2847   }
2848 }
2849 
2850 //------------------------------hash-------------------------------------------
2851 // Type-specific hashing function.
2852 int TypeOopPtr::hash(void) const {
2853   return
2854     (const_oop() ? const_oop()->hash() : 0) +
2855     _klass_is_exact +
2856     _instance_id +
2857     hash_speculative() +
2858     TypePtr::hash();
2859 }
2860 
2861 //------------------------------dump2------------------------------------------
2862 #ifndef PRODUCT
2863 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2864   st->print("oopptr:%s", ptr_msg[_ptr]);
2865   if( _klass_is_exact ) st->print(":exact");
2866   if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
2867   switch( _offset ) {
2868   case OffsetTop: st->print("+top"); break;
2869   case OffsetBot: st->print("+any"); break;
2870   case         0: break;
2871   default:        st->print("+%d",_offset); break;
2872   }
2873   if (_instance_id == InstanceTop)
2874     st->print(",iid=top");
2875   else if (_instance_id != InstanceBot)
2876     st->print(",iid=%d",_instance_id);
2877 
2878   dump_speculative(st);
2879 }
2880 
2881 // dump the speculative part of the type
2882 void TypeOopPtr::dump_speculative(outputStream *st) const {
2883   if (_speculative != NULL) {
2884     st->print(" (speculative=");
2885     _speculative->dump_on(st);
2886     st->print(")");
2887   }
2888 }
2889 #endif
2890 
2891 //------------------------------singleton--------------------------------------
2892 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2893 // constants
2894 bool TypeOopPtr::singleton(void) const {
2895   // detune optimizer to not generate constant oop + constant offset as a constant!
2896   // TopPTR, Null, AnyNull, Constant are all singletons
2897   return (_offset == 0) && !below_centerline(_ptr);
2898 }
2899 
2900 //------------------------------add_offset-------------------------------------
2901 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
2902   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset));
2903 }
2904 
2905 // Return same type without a speculative part
2906 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
2907   return make(_ptr, _offset, _instance_id, NULL);
2908 }
2909 
2910 //------------------------------meet_instance_id--------------------------------
2911 int TypeOopPtr::meet_instance_id( int instance_id ) const {
2912   // Either is 'TOP' instance?  Return the other instance!
2913   if( _instance_id == InstanceTop ) return  instance_id;
2914   if(  instance_id == InstanceTop ) return _instance_id;
2915   // If either is different, return 'BOTTOM' instance
2916   if( _instance_id != instance_id ) return InstanceBot;
2917   return _instance_id;
2918 }
2919 
2920 //------------------------------dual_instance_id--------------------------------
2921 int TypeOopPtr::dual_instance_id( ) const {
2922   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
2923   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
2924   return _instance_id;              // Map everything else into self
2925 }
2926 
2927 // meet of the speculative parts of 2 types
2928 const TypeOopPtr* TypeOopPtr::meet_speculative(const TypeOopPtr* other) const {
2929   bool this_has_spec = (_speculative != NULL);
2930   bool other_has_spec = (other->speculative() != NULL);
2931   
2932   if (!this_has_spec && !other_has_spec) {
2933     return NULL;
2934   }
2935 
2936   // If we are at a point where control flow meets and one branch has
2937   // a speculative type and the other has not, we meet the speculative
2938   // type of one branch with the actual type of the other. If the
2939   // actual type is exact and the speculative is as well, then the
2940   // result is a speculative type which is exact and we can continue
2941   // speculation further.
2942   const TypeOopPtr* this_spec = _speculative;
2943   const TypeOopPtr* other_spec = other->speculative();
2944 
2945   if (!this_has_spec) {
2946     this_spec = this;
2947   }
2948 
2949   if (!other_has_spec) {
2950     other_spec = other;
2951   }
2952 
2953   return this_spec->meet(other_spec)->is_oopptr();
2954 }
2955 
2956 // dual of the speculative part of the type
2957 const TypeOopPtr* TypeOopPtr::dual_speculative() const {
2958   if (_speculative == NULL) {
2959     return NULL;
2960   }
2961   return _speculative->dual()->is_oopptr();
2962 }
2963 
2964 // add offset to the speculative part of the type
2965 const TypeOopPtr* TypeOopPtr::add_offset_speculative(intptr_t offset) const {
2966   if (_speculative == NULL) {
2967     return NULL;
2968   }
2969   return _speculative->add_offset(offset)->is_oopptr();
2970 }
2971 
2972 // Are the speculative parts of 2 types equal?
2973 bool TypeOopPtr::eq_speculative(const TypeOopPtr* other) const {
2974   if (_speculative == NULL || other->speculative() == NULL) {
2975     return _speculative == other->speculative();
2976   }
2977 
2978   if (_speculative->base() != other->speculative()->base()) {
2979     return false;
2980   }
2981 
2982   return _speculative->eq(other->speculative());
2983 }
2984 
2985 // Hash of the speculative part of the type
2986 int TypeOopPtr::hash_speculative() const {
2987   if (_speculative == NULL) {
2988     return 0;
2989   }
2990 
2991   return _speculative->hash();
2992 }
2993 
2994 
2995 //=============================================================================
2996 // Convenience common pre-built types.
2997 const TypeInstPtr *TypeInstPtr::NOTNULL;
2998 const TypeInstPtr *TypeInstPtr::BOTTOM;
2999 const TypeInstPtr *TypeInstPtr::MIRROR;
3000 const TypeInstPtr *TypeInstPtr::MARK;
3001 const TypeInstPtr *TypeInstPtr::KLASS;
3002 
3003 //------------------------------TypeInstPtr-------------------------------------
3004 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id, const TypeOopPtr* speculative)
3005   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative), _name(k->name()) {
3006    assert(k != NULL &&
3007           (k->is_loaded() || o == NULL),
3008           "cannot have constants with non-loaded klass");
3009 };
3010 
3011 //------------------------------make-------------------------------------------
3012 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3013                                      ciKlass* k,
3014                                      bool xk,
3015                                      ciObject* o,
3016                                      int offset,
3017                                      int instance_id,
3018                                      const TypeOopPtr* speculative) {
3019   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3020   // Either const_oop() is NULL or else ptr is Constant
3021   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3022           "constant pointers must have a value supplied" );
3023   // Ptr is never Null
3024   assert( ptr != Null, "NULL pointers are not typed" );
3025 
3026   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3027   if (!UseExactTypes)  xk = false;
3028   if (ptr == Constant) {
3029     // Note:  This case includes meta-object constants, such as methods.
3030     xk = true;
3031   } else if (k->is_loaded()) {
3032     ciInstanceKlass* ik = k->as_instance_klass();
3033     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3034     if (xk && ik->is_interface())  xk = false;  // no exact interface
3035   }
3036 
3037   // Now hash this baby
3038   TypeInstPtr *result =
3039     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative))->hashcons();
3040 
3041   return result;
3042 }
3043 
3044 /**
3045  *  Create constant type for a constant boxed value
3046  */
3047 const Type* TypeInstPtr::get_const_boxed_value() const {
3048   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3049   assert((const_oop() != NULL), "should be called only for constant object");
3050   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3051   BasicType bt = constant.basic_type();
3052   switch (bt) {
3053     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
3054     case T_INT:      return TypeInt::make(constant.as_int());
3055     case T_CHAR:     return TypeInt::make(constant.as_char());
3056     case T_BYTE:     return TypeInt::make(constant.as_byte());
3057     case T_SHORT:    return TypeInt::make(constant.as_short());
3058     case T_FLOAT:    return TypeF::make(constant.as_float());
3059     case T_DOUBLE:   return TypeD::make(constant.as_double());
3060     case T_LONG:     return TypeLong::make(constant.as_long());
3061     default:         break;
3062   }
3063   fatal(err_msg_res("Invalid boxed value type '%s'", type2name(bt)));
3064   return NULL;
3065 }
3066 
3067 //------------------------------cast_to_ptr_type-------------------------------
3068 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3069   if( ptr == _ptr ) return this;
3070   // Reconstruct _sig info here since not a problem with later lazy
3071   // construction, _sig will show up on demand.
3072   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative);
3073 }
3074 
3075 
3076 //-----------------------------cast_to_exactness-------------------------------
3077 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3078   if( klass_is_exact == _klass_is_exact ) return this;
3079   if (!UseExactTypes)  return this;
3080   if (!_klass->is_loaded())  return this;
3081   ciInstanceKlass* ik = _klass->as_instance_klass();
3082   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3083   if( ik->is_interface() )              return this;  // cannot set xk
3084   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative);
3085 }
3086 
3087 //-----------------------------cast_to_instance_id----------------------------
3088 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3089   if( instance_id == _instance_id ) return this;
3090   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative);
3091 }
3092 
3093 //------------------------------xmeet_unloaded---------------------------------
3094 // Compute the MEET of two InstPtrs when at least one is unloaded.
3095 // Assume classes are different since called after check for same name/class-loader
3096 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3097     int off = meet_offset(tinst->offset());
3098     PTR ptr = meet_ptr(tinst->ptr());
3099     int instance_id = meet_instance_id(tinst->instance_id());
3100     const TypeOopPtr* speculative = meet_speculative(tinst);
3101 
3102     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3103     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3104     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3105       //
3106       // Meet unloaded class with java/lang/Object
3107       //
3108       // Meet
3109       //          |                     Unloaded Class
3110       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3111       //  ===================================================================
3112       //   TOP    | ..........................Unloaded......................|
3113       //  AnyNull |  U-AN    |................Unloaded......................|
3114       // Constant | ... O-NN .................................. |   O-BOT   |
3115       //  NotNull | ... O-NN .................................. |   O-BOT   |
3116       //  BOTTOM  | ........................Object-BOTTOM ..................|
3117       //
3118       assert(loaded->ptr() != TypePtr::Null, "insanity check");
3119       //
3120       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
3121       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative); }
3122       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
3123       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
3124         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
3125         else                                      { return TypeInstPtr::NOTNULL; }
3126       }
3127       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
3128 
3129       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
3130     }
3131 
3132     // Both are unloaded, not the same class, not Object
3133     // Or meet unloaded with a different loaded class, not java/lang/Object
3134     if( ptr != TypePtr::BotPTR ) {
3135       return TypeInstPtr::NOTNULL;
3136     }
3137     return TypeInstPtr::BOTTOM;
3138 }
3139 
3140 
3141 //------------------------------meet-------------------------------------------
3142 // Compute the MEET of two types.  It returns a new Type object.
3143 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
3144   // Perform a fast test for common case; meeting the same types together.
3145   if( this == t ) return this;  // Meeting same type-rep?
3146 
3147   // Current "this->_base" is Pointer
3148   switch (t->base()) {          // switch on original type
3149 
3150   case Int:                     // Mixing ints & oops happens when javac
3151   case Long:                    // reuses local variables
3152   case FloatTop:
3153   case FloatCon:
3154   case FloatBot:
3155   case DoubleTop:
3156   case DoubleCon:
3157   case DoubleBot:
3158   case NarrowOop:
3159   case NarrowKlass:
3160   case Bottom:                  // Ye Olde Default
3161     return Type::BOTTOM;
3162   case Top:
3163     return this;
3164 
3165   default:                      // All else is a mistake
3166     typerr(t);
3167 
3168   case MetadataPtr:
3169   case KlassPtr:
3170   case RawPtr: return TypePtr::BOTTOM;
3171 
3172   case AryPtr: {                // All arrays inherit from Object class
3173     const TypeAryPtr *tp = t->is_aryptr();
3174     int offset = meet_offset(tp->offset());
3175     PTR ptr = meet_ptr(tp->ptr());
3176     int instance_id = meet_instance_id(tp->instance_id());
3177     const TypeOopPtr* speculative = meet_speculative(tp);
3178     switch (ptr) {
3179     case TopPTR:
3180     case AnyNull:                // Fall 'down' to dual of object klass
3181       // For instances when a subclass meets a superclass we fall
3182       // below the centerline when the superclass is exact. We need to
3183       // do the same here.
3184       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3185         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative);
3186       } else {
3187         // cannot subclass, so the meet has to fall badly below the centerline
3188         ptr = NotNull;
3189         instance_id = InstanceBot;
3190         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative);
3191       }
3192     case Constant:
3193     case NotNull:
3194     case BotPTR:                // Fall down to object klass
3195       // LCA is object_klass, but if we subclass from the top we can do better
3196       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
3197         // If 'this' (InstPtr) is above the centerline and it is Object class
3198         // then we can subclass in the Java class hierarchy.
3199         // For instances when a subclass meets a superclass we fall
3200         // below the centerline when the superclass is exact. We need
3201         // to do the same here.
3202         if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3203           // that is, tp's array type is a subtype of my klass
3204           return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
3205                                   tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative);
3206         }
3207       }
3208       // The other case cannot happen, since I cannot be a subtype of an array.
3209       // The meet falls down to Object class below centerline.
3210       if( ptr == Constant )
3211          ptr = NotNull;
3212       instance_id = InstanceBot;
3213       return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative);
3214     default: typerr(t);
3215     }
3216   }
3217 
3218   case OopPtr: {                // Meeting to OopPtrs
3219     // Found a OopPtr type vs self-InstPtr type
3220     const TypeOopPtr *tp = t->is_oopptr();
3221     int offset = meet_offset(tp->offset());
3222     PTR ptr = meet_ptr(tp->ptr());
3223     switch (tp->ptr()) {
3224     case TopPTR:
3225     case AnyNull: {
3226       int instance_id = meet_instance_id(InstanceTop);
3227       const TypeOopPtr* speculative = meet_speculative(tp);
3228       return make(ptr, klass(), klass_is_exact(),
3229                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative);
3230     }
3231     case NotNull:
3232     case BotPTR: {
3233       int instance_id = meet_instance_id(tp->instance_id());
3234       const TypeOopPtr* speculative = meet_speculative(tp);
3235       return TypeOopPtr::make(ptr, offset, instance_id, speculative);
3236     }
3237     default: typerr(t);
3238     }
3239   }
3240 
3241   case AnyPtr: {                // Meeting to AnyPtrs
3242     // Found an AnyPtr type vs self-InstPtr type
3243     const TypePtr *tp = t->is_ptr();
3244     int offset = meet_offset(tp->offset());
3245     PTR ptr = meet_ptr(tp->ptr());
3246     switch (tp->ptr()) {
3247     case Null:
3248       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
3249       // else fall through to AnyNull
3250     case TopPTR:
3251     case AnyNull: {
3252       int instance_id = meet_instance_id(InstanceTop);
3253       const TypeOopPtr* speculative = _speculative;
3254       return make(ptr, klass(), klass_is_exact(),
3255                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative);
3256     }
3257     case NotNull:
3258     case BotPTR:
3259       return TypePtr::make(AnyPtr, ptr, offset);
3260     default: typerr(t);
3261     }
3262   }
3263 
3264   /*
3265                  A-top         }
3266                /   |   \       }  Tops
3267            B-top A-any C-top   }
3268               | /  |  \ |      }  Any-nulls
3269            B-any   |   C-any   }
3270               |    |    |
3271            B-con A-con C-con   } constants; not comparable across classes
3272               |    |    |
3273            B-not   |   C-not   }
3274               | \  |  / |      }  not-nulls
3275            B-bot A-not C-bot   }
3276                \   |   /       }  Bottoms
3277                  A-bot         }
3278   */
3279 
3280   case InstPtr: {                // Meeting 2 Oops?
3281     // Found an InstPtr sub-type vs self-InstPtr type
3282     const TypeInstPtr *tinst = t->is_instptr();
3283     int off = meet_offset( tinst->offset() );
3284     PTR ptr = meet_ptr( tinst->ptr() );
3285     int instance_id = meet_instance_id(tinst->instance_id());
3286     const TypeOopPtr* speculative = meet_speculative(tinst);
3287 
3288     // Check for easy case; klasses are equal (and perhaps not loaded!)
3289     // If we have constants, then we created oops so classes are loaded
3290     // and we can handle the constants further down.  This case handles
3291     // both-not-loaded or both-loaded classes
3292     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
3293       return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative);
3294     }
3295 
3296     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
3297     ciKlass* tinst_klass = tinst->klass();
3298     ciKlass* this_klass  = this->klass();
3299     bool tinst_xk = tinst->klass_is_exact();
3300     bool this_xk  = this->klass_is_exact();
3301     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
3302       // One of these classes has not been loaded
3303       const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
3304 #ifndef PRODUCT
3305       if( PrintOpto && Verbose ) {
3306         tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
3307         tty->print("  this == "); this->dump(); tty->cr();
3308         tty->print(" tinst == "); tinst->dump(); tty->cr();
3309       }
3310 #endif
3311       return unloaded_meet;
3312     }
3313 
3314     // Handle mixing oops and interfaces first.
3315     if( this_klass->is_interface() && !(tinst_klass->is_interface() ||
3316                                         tinst_klass == ciEnv::current()->Object_klass())) {
3317       ciKlass *tmp = tinst_klass; // Swap interface around
3318       tinst_klass = this_klass;
3319       this_klass = tmp;
3320       bool tmp2 = tinst_xk;
3321       tinst_xk = this_xk;
3322       this_xk = tmp2;
3323     }
3324     if (tinst_klass->is_interface() &&
3325         !(this_klass->is_interface() ||
3326           // Treat java/lang/Object as an honorary interface,
3327           // because we need a bottom for the interface hierarchy.
3328           this_klass == ciEnv::current()->Object_klass())) {
3329       // Oop meets interface!
3330 
3331       // See if the oop subtypes (implements) interface.
3332       ciKlass *k;
3333       bool xk;
3334       if( this_klass->is_subtype_of( tinst_klass ) ) {
3335         // Oop indeed subtypes.  Now keep oop or interface depending
3336         // on whether we are both above the centerline or either is
3337         // below the centerline.  If we are on the centerline
3338         // (e.g., Constant vs. AnyNull interface), use the constant.
3339         k  = below_centerline(ptr) ? tinst_klass : this_klass;
3340         // If we are keeping this_klass, keep its exactness too.
3341         xk = below_centerline(ptr) ? tinst_xk    : this_xk;
3342       } else {                  // Does not implement, fall to Object
3343         // Oop does not implement interface, so mixing falls to Object
3344         // just like the verifier does (if both are above the
3345         // centerline fall to interface)
3346         k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
3347         xk = above_centerline(ptr) ? tinst_xk : false;
3348         // Watch out for Constant vs. AnyNull interface.
3349         if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
3350         instance_id = InstanceBot;
3351       }
3352       ciObject* o = NULL;  // the Constant value, if any
3353       if (ptr == Constant) {
3354         // Find out which constant.
3355         o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
3356       }
3357       return make(ptr, k, xk, o, off, instance_id, speculative);
3358     }
3359 
3360     // Either oop vs oop or interface vs interface or interface vs Object
3361 
3362     // !!! Here's how the symmetry requirement breaks down into invariants:
3363     // If we split one up & one down AND they subtype, take the down man.
3364     // If we split one up & one down AND they do NOT subtype, "fall hard".
3365     // If both are up and they subtype, take the subtype class.
3366     // If both are up and they do NOT subtype, "fall hard".
3367     // If both are down and they subtype, take the supertype class.
3368     // If both are down and they do NOT subtype, "fall hard".
3369     // Constants treated as down.
3370 
3371     // Now, reorder the above list; observe that both-down+subtype is also
3372     // "fall hard"; "fall hard" becomes the default case:
3373     // If we split one up & one down AND they subtype, take the down man.
3374     // If both are up and they subtype, take the subtype class.
3375 
3376     // If both are down and they subtype, "fall hard".
3377     // If both are down and they do NOT subtype, "fall hard".


3414 
3415     // Check for classes now being equal
3416     if (tinst_klass->equals(this_klass)) {
3417       // If the klasses are equal, the constants may still differ.  Fall to
3418       // NotNull if they do (neither constant is NULL; that is a special case
3419       // handled elsewhere).
3420       ciObject* o = NULL;             // Assume not constant when done
3421       ciObject* this_oop  = const_oop();
3422       ciObject* tinst_oop = tinst->const_oop();
3423       if( ptr == Constant ) {
3424         if (this_oop != NULL && tinst_oop != NULL &&
3425             this_oop->equals(tinst_oop) )
3426           o = this_oop;
3427         else if (above_centerline(this ->_ptr))
3428           o = tinst_oop;
3429         else if (above_centerline(tinst ->_ptr))
3430           o = this_oop;
3431         else
3432           ptr = NotNull;
3433       }
3434       return make(ptr, this_klass, this_xk, o, off, instance_id, speculative);
3435     } // Else classes are not equal
3436 
3437     // Since klasses are different, we require a LCA in the Java
3438     // class hierarchy - which means we have to fall to at least NotNull.
3439     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3440       ptr = NotNull;
3441     instance_id = InstanceBot;
3442 
3443     // Now we find the LCA of Java classes
3444     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
3445     return make(ptr, k, false, NULL, off, instance_id, speculative);
3446   } // End of case InstPtr
3447 
3448   } // End of switch
3449   return this;                  // Return the double constant
3450 }
3451 
3452 
3453 //------------------------java_mirror_type--------------------------------------
3454 ciType* TypeInstPtr::java_mirror_type() const {
3455   // must be a singleton type
3456   if( const_oop() == NULL )  return NULL;
3457 
3458   // must be of type java.lang.Class
3459   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
3460 
3461   return const_oop()->as_instance()->java_mirror_type();
3462 }
3463 
3464 
3465 //------------------------------xdual------------------------------------------
3466 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
3467 // inheritance mechanism.
3468 const Type *TypeInstPtr::xdual() const {
3469   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative());
3470 }
3471 
3472 //------------------------------eq---------------------------------------------
3473 // Structural equality check for Type representations
3474 bool TypeInstPtr::eq( const Type *t ) const {
3475   const TypeInstPtr *p = t->is_instptr();
3476   return
3477     klass()->equals(p->klass()) &&
3478     TypeOopPtr::eq(p);          // Check sub-type stuff
3479 }
3480 
3481 //------------------------------hash-------------------------------------------
3482 // Type-specific hashing function.
3483 int TypeInstPtr::hash(void) const {
3484   int hash = klass()->hash() + TypeOopPtr::hash();
3485   return hash;
3486 }
3487 
3488 //------------------------------dump2------------------------------------------
3489 // Dump oop Type


3505     }
3506   case TopPTR:
3507   case AnyNull:
3508   case NotNull:
3509     st->print(":%s", ptr_msg[_ptr]);
3510     if( _klass_is_exact ) st->print(":exact");
3511     break;
3512   }
3513 
3514   if( _offset ) {               // Dump offset, if any
3515     if( _offset == OffsetBot )      st->print("+any");
3516     else if( _offset == OffsetTop ) st->print("+unknown");
3517     else st->print("+%d", _offset);
3518   }
3519 
3520   st->print(" *");
3521   if (_instance_id == InstanceTop)
3522     st->print(",iid=top");
3523   else if (_instance_id != InstanceBot)
3524     st->print(",iid=%d",_instance_id);
3525 
3526   dump_speculative(st);
3527 }
3528 #endif
3529 
3530 //------------------------------add_offset-------------------------------------
3531 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
3532   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id, add_offset_speculative(offset));
3533 }
3534 
3535 const TypeOopPtr *TypeInstPtr::remove_speculative() const {
3536   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, NULL);
3537 }
3538 
3539 //=============================================================================
3540 // Convenience common pre-built types.
3541 const TypeAryPtr *TypeAryPtr::RANGE;
3542 const TypeAryPtr *TypeAryPtr::OOPS;
3543 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
3544 const TypeAryPtr *TypeAryPtr::BYTES;
3545 const TypeAryPtr *TypeAryPtr::SHORTS;
3546 const TypeAryPtr *TypeAryPtr::CHARS;
3547 const TypeAryPtr *TypeAryPtr::INTS;
3548 const TypeAryPtr *TypeAryPtr::LONGS;
3549 const TypeAryPtr *TypeAryPtr::FLOATS;
3550 const TypeAryPtr *TypeAryPtr::DOUBLES;
3551 
3552 //------------------------------make-------------------------------------------
3553 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, const TypeOopPtr* speculative) {
3554   assert(!(k == NULL && ary->_elem->isa_int()),
3555          "integral arrays must be pre-equipped with a class");
3556   if (!xk)  xk = ary->ary_must_be_exact();
3557   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3558   if (!UseExactTypes)  xk = (ptr == Constant);
3559   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative))->hashcons();
3560 }
3561 
3562 //------------------------------make-------------------------------------------
3563 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) {
3564   assert(!(k == NULL && ary->_elem->isa_int()),
3565          "integral arrays must be pre-equipped with a class");
3566   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
3567   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
3568   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3569   if (!UseExactTypes)  xk = (ptr == Constant);
3570   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative))->hashcons();
3571 }
3572 
3573 //------------------------------cast_to_ptr_type-------------------------------
3574 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
3575   if( ptr == _ptr ) return this;
3576   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative);
3577 }
3578 
3579 
3580 //-----------------------------cast_to_exactness-------------------------------
3581 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
3582   if( klass_is_exact == _klass_is_exact ) return this;
3583   if (!UseExactTypes)  return this;
3584   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
3585   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative);
3586 }
3587 
3588 //-----------------------------cast_to_instance_id----------------------------
3589 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
3590   if( instance_id == _instance_id ) return this;
3591   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative);
3592 }
3593 
3594 //-----------------------------narrow_size_type-------------------------------
3595 // Local cache for arrayOopDesc::max_array_length(etype),
3596 // which is kind of slow (and cached elsewhere by other users).
3597 static jint max_array_length_cache[T_CONFLICT+1];
3598 static jint max_array_length(BasicType etype) {
3599   jint& cache = max_array_length_cache[etype];
3600   jint res = cache;
3601   if (res == 0) {
3602     switch (etype) {
3603     case T_NARROWOOP:
3604       etype = T_OBJECT;
3605       break;
3606     case T_NARROWKLASS:
3607     case T_CONFLICT:
3608     case T_ILLEGAL:
3609     case T_VOID:
3610       etype = T_BYTE;           // will produce conservatively high value
3611     }


3634     hi = max_hi;
3635     if (size->is_con()) {
3636       lo = hi;
3637     }
3638     chg = true;
3639   }
3640   // Negative length arrays will produce weird intermediate dead fast-path code
3641   if (lo > hi)
3642     return TypeInt::ZERO;
3643   if (!chg)
3644     return size;
3645   return TypeInt::make(lo, hi, Type::WidenMin);
3646 }
3647 
3648 //-------------------------------cast_to_size----------------------------------
3649 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
3650   assert(new_size != NULL, "");
3651   new_size = narrow_size_type(new_size);
3652   if (new_size == size())  return this;
3653   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
3654   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative);
3655 }
3656 
3657 
3658 //------------------------------cast_to_stable---------------------------------
3659 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
3660   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
3661     return this;
3662 
3663   const Type* elem = this->elem();
3664   const TypePtr* elem_ptr = elem->make_ptr();
3665 
3666   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
3667     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
3668     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
3669   }
3670 
3671   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
3672 
3673   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
3674 }


3683   return dim;
3684 }
3685 
3686 //------------------------------eq---------------------------------------------
3687 // Structural equality check for Type representations
3688 bool TypeAryPtr::eq( const Type *t ) const {
3689   const TypeAryPtr *p = t->is_aryptr();
3690   return
3691     _ary == p->_ary &&  // Check array
3692     TypeOopPtr::eq(p);  // Check sub-parts
3693 }
3694 
3695 //------------------------------hash-------------------------------------------
3696 // Type-specific hashing function.
3697 int TypeAryPtr::hash(void) const {
3698   return (intptr_t)_ary + TypeOopPtr::hash();
3699 }
3700 
3701 //------------------------------meet-------------------------------------------
3702 // Compute the MEET of two types.  It returns a new Type object.
3703 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
3704   // Perform a fast test for common case; meeting the same types together.
3705   if( this == t ) return this;  // Meeting same type-rep?
3706   // Current "this->_base" is Pointer
3707   switch (t->base()) {          // switch on original type
3708 
3709   // Mixing ints & oops happens when javac reuses local variables
3710   case Int:
3711   case Long:
3712   case FloatTop:
3713   case FloatCon:
3714   case FloatBot:
3715   case DoubleTop:
3716   case DoubleCon:
3717   case DoubleBot:
3718   case NarrowOop:
3719   case NarrowKlass:
3720   case Bottom:                  // Ye Olde Default
3721     return Type::BOTTOM;
3722   case Top:
3723     return this;
3724 
3725   default:                      // All else is a mistake
3726     typerr(t);
3727 
3728   case OopPtr: {                // Meeting to OopPtrs
3729     // Found a OopPtr type vs self-AryPtr type
3730     const TypeOopPtr *tp = t->is_oopptr();
3731     int offset = meet_offset(tp->offset());
3732     PTR ptr = meet_ptr(tp->ptr());
3733     switch (tp->ptr()) {
3734     case TopPTR:
3735     case AnyNull: {
3736       int instance_id = meet_instance_id(InstanceTop);
3737       const TypeOopPtr* speculative = meet_speculative(tp);
3738       return make(ptr, (ptr == Constant ? const_oop() : NULL),
3739                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
3740     }
3741     case BotPTR:
3742     case NotNull: {
3743       int instance_id = meet_instance_id(tp->instance_id());
3744       const TypeOopPtr* speculative = meet_speculative(tp);
3745       return TypeOopPtr::make(ptr, offset, instance_id, speculative);
3746     }
3747     default: ShouldNotReachHere();
3748     }
3749   }
3750 
3751   case AnyPtr: {                // Meeting two AnyPtrs
3752     // Found an AnyPtr type vs self-AryPtr type
3753     const TypePtr *tp = t->is_ptr();
3754     int offset = meet_offset(tp->offset());
3755     PTR ptr = meet_ptr(tp->ptr());
3756     switch (tp->ptr()) {
3757     case TopPTR:
3758       return this;
3759     case BotPTR:
3760     case NotNull:
3761       return TypePtr::make(AnyPtr, ptr, offset);
3762     case Null:
3763       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
3764       // else fall through to AnyNull
3765     case AnyNull: {
3766       int instance_id = meet_instance_id(InstanceTop);
3767       const TypeOopPtr* speculative = _speculative;
3768       return make(ptr, (ptr == Constant ? const_oop() : NULL),
3769                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
3770     }
3771     default: ShouldNotReachHere();
3772     }
3773   }
3774 
3775   case MetadataPtr:
3776   case KlassPtr:
3777   case RawPtr: return TypePtr::BOTTOM;
3778 
3779   case AryPtr: {                // Meeting 2 references?
3780     const TypeAryPtr *tap = t->is_aryptr();
3781     int off = meet_offset(tap->offset());
3782     const TypeAry *tary = _ary->meet(tap->_ary)->is_ary();
3783     PTR ptr = meet_ptr(tap->ptr());
3784     int instance_id = meet_instance_id(tap->instance_id());
3785     const TypeOopPtr* speculative = meet_speculative(tap);
3786     ciKlass* lazy_klass = NULL;
3787     if (tary->_elem->isa_int()) {
3788       // Integral array element types have irrelevant lattice relations.
3789       // It is the klass that determines array layout, not the element type.
3790       if (_klass == NULL)
3791         lazy_klass = tap->_klass;
3792       else if (tap->_klass == NULL || tap->_klass == _klass) {
3793         lazy_klass = _klass;
3794       } else {
3795         // Something like byte[int+] meets char[int+].
3796         // This must fall to bottom, not (int[-128..65535])[int+].
3797         instance_id = InstanceBot;
3798         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
3799       }
3800     } else // Non integral arrays.
3801     // Must fall to bottom if exact klasses in upper lattice
3802     // are not equal or super klass is exact.
3803     if ( above_centerline(ptr) && klass() != tap->klass() &&
3804          // meet with top[] and bottom[] are processed further down:
3805          tap ->_klass != NULL  && this->_klass != NULL   &&
3806          // both are exact and not equal:
3807         ((tap ->_klass_is_exact && this->_klass_is_exact) ||
3808          // 'tap'  is exact and super or unrelated:
3809          (tap ->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
3810          // 'this' is exact and super or unrelated:
3811          (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
3812       tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
3813       return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot);
3814     }
3815 
3816     bool xk = false;
3817     switch (tap->ptr()) {
3818     case AnyNull:
3819     case TopPTR:
3820       // Compute new klass on demand, do not use tap->_klass
3821       if (below_centerline(this->_ptr)) {
3822         xk = this->_klass_is_exact;
3823       } else {
3824         xk = (tap->_klass_is_exact | this->_klass_is_exact);
3825       }
3826       return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative);
3827     case Constant: {
3828       ciObject* o = const_oop();
3829       if( _ptr == Constant ) {
3830         if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
3831           xk = (klass() == tap->klass());
3832           ptr = NotNull;
3833           o = NULL;
3834           instance_id = InstanceBot;
3835         } else {
3836           xk = true;
3837         }
3838       } else if(above_centerline(_ptr)) {
3839         o = tap->const_oop();
3840         xk = true;
3841       } else {
3842         // Only precise for identical arrays
3843         xk = this->_klass_is_exact && (klass() == tap->klass());
3844       }
3845       return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, instance_id, speculative);
3846     }
3847     case NotNull:
3848     case BotPTR:
3849       // Compute new klass on demand, do not use tap->_klass
3850       if (above_centerline(this->_ptr))
3851             xk = tap->_klass_is_exact;


3852       else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
3853               (klass() == tap->klass()); // Only precise for identical arrays
3854       return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, instance_id, speculative);
3855     default: ShouldNotReachHere();
3856     }
3857   }
3858 
3859   // All arrays inherit from Object class
3860   case InstPtr: {
3861     const TypeInstPtr *tp = t->is_instptr();
3862     int offset = meet_offset(tp->offset());
3863     PTR ptr = meet_ptr(tp->ptr());
3864     int instance_id = meet_instance_id(tp->instance_id());
3865     const TypeOopPtr* speculative = meet_speculative(tp);
3866     switch (ptr) {
3867     case TopPTR:
3868     case AnyNull:                // Fall 'down' to dual of object klass
3869       // For instances when a subclass meets a superclass we fall
3870       // below the centerline when the superclass is exact. We need to
3871       // do the same here.
3872       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
3873         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
3874       } else {
3875         // cannot subclass, so the meet has to fall badly below the centerline
3876         ptr = NotNull;
3877         instance_id = InstanceBot;
3878         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative);
3879       }
3880     case Constant:
3881     case NotNull:
3882     case BotPTR:                // Fall down to object klass
3883       // LCA is object_klass, but if we subclass from the top we can do better
3884       if (above_centerline(tp->ptr())) {
3885         // If 'tp'  is above the centerline and it is Object class
3886         // then we can subclass in the Java class hierarchy.
3887         // For instances when a subclass meets a superclass we fall
3888         // below the centerline when the superclass is exact. We need
3889         // to do the same here.
3890         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
3891           // that is, my array type is a subtype of 'tp' klass
3892           return make(ptr, (ptr == Constant ? const_oop() : NULL),
3893                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
3894         }
3895       }
3896       // The other case cannot happen, since t cannot be a subtype of an array.
3897       // The meet falls down to Object class below centerline.
3898       if( ptr == Constant )
3899          ptr = NotNull;
3900       instance_id = InstanceBot;
3901       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative);
3902     default: typerr(t);
3903     }
3904   }
3905   }
3906   return this;                  // Lint noise
3907 }
3908 
3909 //------------------------------xdual------------------------------------------
3910 // Dual: compute field-by-field dual
3911 const Type *TypeAryPtr::xdual() const {
3912   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());
3913 }
3914 
3915 //----------------------interface_vs_oop---------------------------------------
3916 #ifdef ASSERT
3917 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
3918   const TypeAryPtr* t_aryptr = t->isa_aryptr();
3919   if (t_aryptr) {
3920     return _ary->interface_vs_oop(t_aryptr->_ary);
3921   }
3922   return false;
3923 }
3924 #endif
3925 
3926 //------------------------------dump2------------------------------------------
3927 #ifndef PRODUCT
3928 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3929   _ary->dump2(d,depth,st);
3930   switch( _ptr ) {
3931   case Constant:
3932     const_oop()->print(st);


3944     break;
3945   }
3946 
3947   if( _offset != 0 ) {
3948     int header_size = objArrayOopDesc::header_size() * wordSize;
3949     if( _offset == OffsetTop )       st->print("+undefined");
3950     else if( _offset == OffsetBot )  st->print("+any");
3951     else if( _offset < header_size ) st->print("+%d", _offset);
3952     else {
3953       BasicType basic_elem_type = elem()->basic_type();
3954       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
3955       int elem_size = type2aelembytes(basic_elem_type);
3956       st->print("[%d]", (_offset - array_base)/elem_size);
3957     }
3958   }
3959   st->print(" *");
3960   if (_instance_id == InstanceTop)
3961     st->print(",iid=top");
3962   else if (_instance_id != InstanceBot)
3963     st->print(",iid=%d",_instance_id);
3964 
3965   dump_speculative(st);
3966 }
3967 #endif
3968 
3969 bool TypeAryPtr::empty(void) const {
3970   if (_ary->empty())       return true;
3971   return TypeOopPtr::empty();
3972 }
3973 
3974 //------------------------------add_offset-------------------------------------
3975 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
3976   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset));
3977 }
3978 
3979 const TypeOopPtr *TypeAryPtr::remove_speculative() const {
3980   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, _offset, _instance_id, NULL);
3981 }
3982 
3983 //=============================================================================
3984 
3985 //------------------------------hash-------------------------------------------
3986 // Type-specific hashing function.
3987 int TypeNarrowPtr::hash(void) const {
3988   return _ptrtype->hash() + 7;
3989 }
3990 
3991 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
3992   return _ptrtype->singleton();
3993 }
3994 
3995 bool TypeNarrowPtr::empty(void) const {
3996   return _ptrtype->empty();
3997 }
3998 
3999 intptr_t TypeNarrowPtr::get_con() const {
4000   return _ptrtype->get_con();
4001 }


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