comparison src/share/vm/opto/type.cpp @ 223:1dd146f17531

6716441: error in meet with +DoEscapeAnalysis Summary: Set instance_id to InstanceBot for InstPtr->meet(AryPtr) when types are not related. Reviewed-by: jrose, never
author kvn
date Thu, 26 Jun 2008 13:34:00 -0700
parents 1e026f8da827
children 9c2ecc2ffb12
comparison
equal deleted inserted replaced
222:2a1a77d3458f 223:1dd146f17531
166 // Create a simple Type, with default empty symbol sets. Then hashcons it 166 // Create a simple Type, with default empty symbol sets. Then hashcons it
167 // and look for an existing copy in the type dictionary. 167 // and look for an existing copy in the type dictionary.
168 const Type *Type::make( enum TYPES t ) { 168 const Type *Type::make( enum TYPES t ) {
169 return (new Type(t))->hashcons(); 169 return (new Type(t))->hashcons();
170 } 170 }
171 /* 171
172 //------------------------------make_ptr---------------------------------------
173 // Returns this ptr type or the equivalent ptr type for this compressed pointer.
174 const TypePtr* Type::make_ptr() const {
175 return (_base == NarrowOop) ? is_narrowoop()->make_oopptr() : is_ptr();
176 }
177
178 //------------------------------make_narrowoop---------------------------------
179 // Returns this compressed pointer or the equivalent compressed version
180 // of this pointer type.
181 const TypeNarrowOop* Type::make_narrowoop() const {
182 return (_base == NarrowOop) ? is_narrowoop() : TypeNarrowOop::make(is_ptr());
183 }
184 */
185 //------------------------------cmp-------------------------------------------- 172 //------------------------------cmp--------------------------------------------
186 int Type::cmp( const Type *const t1, const Type *const t2 ) { 173 int Type::cmp( const Type *const t1, const Type *const t2 ) {
187 if( t1->_base != t2->_base ) 174 if( t1->_base != t2->_base )
188 return 1; // Missed badly 175 return 1; // Missed badly
189 assert(t1 != t2 || t1->eq(t2), "eq must be reflexive"); 176 assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
525 if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) { 512 if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
526 bool this_interface = this_inst->klass()->is_interface(); 513 bool this_interface = this_inst->klass()->is_interface();
527 bool t_interface = t_inst->klass()->is_interface(); 514 bool t_interface = t_inst->klass()->is_interface();
528 interface_vs_oop = this_interface ^ t_interface; 515 interface_vs_oop = this_interface ^ t_interface;
529 } 516 }
530 const Type *tdual = t->_dual; 517
531 const Type *thisdual = _dual; 518 if( !interface_vs_oop && (t2t != t->_dual || t2this != _dual) ) {
532 // strip out instances
533 if (t2t->isa_oopptr() != NULL) {
534 t2t = t2t->isa_oopptr()->cast_to_instance(TypeOopPtr::UNKNOWN_INSTANCE);
535 }
536 if (t2this->isa_oopptr() != NULL) {
537 t2this = t2this->isa_oopptr()->cast_to_instance(TypeOopPtr::UNKNOWN_INSTANCE);
538 }
539 if (tdual->isa_oopptr() != NULL) {
540 tdual = tdual->isa_oopptr()->cast_to_instance(TypeOopPtr::UNKNOWN_INSTANCE);
541 }
542 if (thisdual->isa_oopptr() != NULL) {
543 thisdual = thisdual->isa_oopptr()->cast_to_instance(TypeOopPtr::UNKNOWN_INSTANCE);
544 }
545
546 if( !interface_vs_oop && (t2t != tdual || t2this != thisdual) ) {
547 tty->print_cr("=== Meet Not Symmetric ==="); 519 tty->print_cr("=== Meet Not Symmetric ===");
548 tty->print("t = "); t->dump(); tty->cr(); 520 tty->print("t = "); t->dump(); tty->cr();
549 tty->print("this= "); dump(); tty->cr(); 521 tty->print("this= "); dump(); tty->cr();
550 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr(); 522 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
551 523
2233 int offset) { 2205 int offset) {
2234 assert(ptr != Constant, "no constant generic pointers"); 2206 assert(ptr != Constant, "no constant generic pointers");
2235 ciKlass* k = ciKlassKlass::make(); 2207 ciKlass* k = ciKlassKlass::make();
2236 bool xk = false; 2208 bool xk = false;
2237 ciObject* o = NULL; 2209 ciObject* o = NULL;
2238 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, UNKNOWN_INSTANCE))->hashcons(); 2210 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, InstanceBot))->hashcons();
2239 } 2211 }
2240 2212
2241 2213
2242 //------------------------------cast_to_ptr_type------------------------------- 2214 //------------------------------cast_to_ptr_type-------------------------------
2243 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const { 2215 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
2245 if( ptr == _ptr ) return this; 2217 if( ptr == _ptr ) return this;
2246 return make(ptr, _offset); 2218 return make(ptr, _offset);
2247 } 2219 }
2248 2220
2249 //-----------------------------cast_to_instance------------------------------- 2221 //-----------------------------cast_to_instance-------------------------------
2250 const TypeOopPtr *TypeOopPtr::cast_to_instance(int instance_id) const { 2222 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
2251 // There are no instances of a general oop. 2223 // There are no instances of a general oop.
2252 // Return self unchanged. 2224 // Return self unchanged.
2253 return this; 2225 return this;
2254 } 2226 }
2255 2227
2339 //------------------------------xdual------------------------------------------ 2311 //------------------------------xdual------------------------------------------
2340 // Dual of a pure heap pointer. No relevant klass or oop information. 2312 // Dual of a pure heap pointer. No relevant klass or oop information.
2341 const Type *TypeOopPtr::xdual() const { 2313 const Type *TypeOopPtr::xdual() const {
2342 assert(klass() == ciKlassKlass::make(), "no klasses here"); 2314 assert(klass() == ciKlassKlass::make(), "no klasses here");
2343 assert(const_oop() == NULL, "no constants here"); 2315 assert(const_oop() == NULL, "no constants here");
2344 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance() ); 2316 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id() );
2345 } 2317 }
2346 2318
2347 //--------------------------make_from_klass_common----------------------------- 2319 //--------------------------make_from_klass_common-----------------------------
2348 // Computes the element-type given a klass. 2320 // Computes the element-type given a klass.
2349 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) { 2321 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
2553 case OffsetTop: st->print("+top"); break; 2525 case OffsetTop: st->print("+top"); break;
2554 case OffsetBot: st->print("+any"); break; 2526 case OffsetBot: st->print("+any"); break;
2555 case 0: break; 2527 case 0: break;
2556 default: st->print("+%d",_offset); break; 2528 default: st->print("+%d",_offset); break;
2557 } 2529 }
2558 if (_instance_id != UNKNOWN_INSTANCE) 2530 if (_instance_id == InstanceTop)
2531 st->print(",iid=top");
2532 else if (_instance_id != InstanceBot)
2559 st->print(",iid=%d",_instance_id); 2533 st->print(",iid=%d",_instance_id);
2560 } 2534 }
2561 #endif 2535 #endif
2562 2536
2563 //------------------------------singleton-------------------------------------- 2537 //------------------------------singleton--------------------------------------
2585 //------------------------------add_offset------------------------------------- 2559 //------------------------------add_offset-------------------------------------
2586 const TypePtr *TypeOopPtr::add_offset( int offset ) const { 2560 const TypePtr *TypeOopPtr::add_offset( int offset ) const {
2587 return make( _ptr, xadd_offset(offset) ); 2561 return make( _ptr, xadd_offset(offset) );
2588 } 2562 }
2589 2563
2590 int TypeOopPtr::meet_instance(int iid) const { 2564 //------------------------------meet_instance_id--------------------------------
2591 if (iid == 0) { 2565 int TypeOopPtr::meet_instance_id( int instance_id ) const {
2592 return (_instance_id < 0) ? _instance_id : UNKNOWN_INSTANCE; 2566 // Either is 'TOP' instance? Return the other instance!
2593 } else if (_instance_id == UNKNOWN_INSTANCE) { 2567 if( _instance_id == InstanceTop ) return instance_id;
2594 return (iid < 0) ? iid : UNKNOWN_INSTANCE; 2568 if( instance_id == InstanceTop ) return _instance_id;
2595 } else { 2569 // If either is different, return 'BOTTOM' instance
2596 return (_instance_id == iid) ? iid : UNKNOWN_INSTANCE; 2570 if( _instance_id != instance_id ) return InstanceBot;
2597 } 2571 return _instance_id;
2598 } 2572 }
2573
2574 //------------------------------dual_instance_id--------------------------------
2575 int TypeOopPtr::dual_instance_id( ) const {
2576 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
2577 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
2578 return _instance_id; // Map everything else into self
2579 }
2580
2599 2581
2600 //============================================================================= 2582 //=============================================================================
2601 // Convenience common pre-built types. 2583 // Convenience common pre-built types.
2602 const TypeInstPtr *TypeInstPtr::NOTNULL; 2584 const TypeInstPtr *TypeInstPtr::NOTNULL;
2603 const TypeInstPtr *TypeInstPtr::BOTTOM; 2585 const TypeInstPtr *TypeInstPtr::BOTTOM;
2626 assert( (!o && ptr != Constant) || (o && ptr == Constant), 2608 assert( (!o && ptr != Constant) || (o && ptr == Constant),
2627 "constant pointers must have a value supplied" ); 2609 "constant pointers must have a value supplied" );
2628 // Ptr is never Null 2610 // Ptr is never Null
2629 assert( ptr != Null, "NULL pointers are not typed" ); 2611 assert( ptr != Null, "NULL pointers are not typed" );
2630 2612
2631 if (instance_id != UNKNOWN_INSTANCE) 2613 if ( instance_id > 0 )
2632 xk = true; // instances are always exactly typed 2614 xk = true; // instances are always exactly typed
2633 if (!UseExactTypes) xk = false; 2615 if (!UseExactTypes) xk = false;
2634 if (ptr == Constant) { 2616 if (ptr == Constant) {
2635 // Note: This case includes meta-object constants, such as methods. 2617 // Note: This case includes meta-object constants, such as methods.
2636 xk = true; 2618 xk = true;
2651 //------------------------------cast_to_ptr_type------------------------------- 2633 //------------------------------cast_to_ptr_type-------------------------------
2652 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const { 2634 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
2653 if( ptr == _ptr ) return this; 2635 if( ptr == _ptr ) return this;
2654 // Reconstruct _sig info here since not a problem with later lazy 2636 // Reconstruct _sig info here since not a problem with later lazy
2655 // construction, _sig will show up on demand. 2637 // construction, _sig will show up on demand.
2656 return make(ptr, klass(), klass_is_exact(), const_oop(), _offset); 2638 return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id);
2657 } 2639 }
2658 2640
2659 2641
2660 //-----------------------------cast_to_exactness------------------------------- 2642 //-----------------------------cast_to_exactness-------------------------------
2661 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const { 2643 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
2667 if( ik->is_interface() ) return this; // cannot set xk 2649 if( ik->is_interface() ) return this; // cannot set xk
2668 return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id); 2650 return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id);
2669 } 2651 }
2670 2652
2671 //-----------------------------cast_to_instance------------------------------- 2653 //-----------------------------cast_to_instance-------------------------------
2672 const TypeOopPtr *TypeInstPtr::cast_to_instance(int instance_id) const { 2654 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
2673 if( instance_id == _instance_id) return this; 2655 if( instance_id == _instance_id ) return this;
2674 bool exact = true; 2656 bool exact = _klass_is_exact;
2675 PTR ptr_t = NotNull; 2657 PTR ptr_t = _ptr;
2676 if (instance_id == UNKNOWN_INSTANCE) { 2658 if ( instance_id > 0 ) { // instances are always exactly typed
2677 exact = _klass_is_exact; 2659 if (UseExactTypes) exact = true;
2678 ptr_t = _ptr; 2660 ptr_t = NotNull;
2679 } 2661 }
2680 return make(ptr_t, klass(), exact, const_oop(), _offset, instance_id); 2662 return make(ptr_t, klass(), exact, const_oop(), _offset, instance_id);
2681 } 2663 }
2682 2664
2683 //------------------------------xmeet_unloaded--------------------------------- 2665 //------------------------------xmeet_unloaded---------------------------------
2756 2738
2757 case AryPtr: { // All arrays inherit from Object class 2739 case AryPtr: { // All arrays inherit from Object class
2758 const TypeAryPtr *tp = t->is_aryptr(); 2740 const TypeAryPtr *tp = t->is_aryptr();
2759 int offset = meet_offset(tp->offset()); 2741 int offset = meet_offset(tp->offset());
2760 PTR ptr = meet_ptr(tp->ptr()); 2742 PTR ptr = meet_ptr(tp->ptr());
2761 int iid = meet_instance(tp->instance_id()); 2743 int instance_id = meet_instance_id(tp->instance_id());
2762 switch (ptr) { 2744 switch (ptr) {
2763 case TopPTR: 2745 case TopPTR:
2764 case AnyNull: // Fall 'down' to dual of object klass 2746 case AnyNull: // Fall 'down' to dual of object klass
2765 if (klass()->equals(ciEnv::current()->Object_klass())) { 2747 if (klass()->equals(ciEnv::current()->Object_klass())) {
2766 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, iid); 2748 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);
2767 } else { 2749 } else {
2768 // cannot subclass, so the meet has to fall badly below the centerline 2750 // cannot subclass, so the meet has to fall badly below the centerline
2769 ptr = NotNull; 2751 ptr = NotNull;
2770 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, iid); 2752 instance_id = InstanceBot;
2753 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id);
2771 } 2754 }
2772 case Constant: 2755 case Constant:
2773 case NotNull: 2756 case NotNull:
2774 case BotPTR: // Fall down to object klass 2757 case BotPTR: // Fall down to object klass
2775 // LCA is object_klass, but if we subclass from the top we can do better 2758 // LCA is object_klass, but if we subclass from the top we can do better
2776 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull ) 2759 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
2777 // If 'this' (InstPtr) is above the centerline and it is Object class 2760 // If 'this' (InstPtr) is above the centerline and it is Object class
2778 // then we can subclass in the Java class heirarchy. 2761 // then we can subclass in the Java class heirarchy.
2779 if (klass()->equals(ciEnv::current()->Object_klass())) { 2762 if (klass()->equals(ciEnv::current()->Object_klass())) {
2780 // that is, tp's array type is a subtype of my klass 2763 // that is, tp's array type is a subtype of my klass
2781 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, iid); 2764 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);
2782 } 2765 }
2783 } 2766 }
2784 // The other case cannot happen, since I cannot be a subtype of an array. 2767 // The other case cannot happen, since I cannot be a subtype of an array.
2785 // The meet falls down to Object class below centerline. 2768 // The meet falls down to Object class below centerline.
2786 if( ptr == Constant ) 2769 if( ptr == Constant )
2787 ptr = NotNull; 2770 ptr = NotNull;
2788 return make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, iid ); 2771 instance_id = InstanceBot;
2772 return make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id );
2789 default: typerr(t); 2773 default: typerr(t);
2790 } 2774 }
2791 } 2775 }
2792 2776
2793 case OopPtr: { // Meeting to OopPtrs 2777 case OopPtr: { // Meeting to OopPtrs
2795 const TypePtr *tp = t->is_oopptr(); 2779 const TypePtr *tp = t->is_oopptr();
2796 int offset = meet_offset(tp->offset()); 2780 int offset = meet_offset(tp->offset());
2797 PTR ptr = meet_ptr(tp->ptr()); 2781 PTR ptr = meet_ptr(tp->ptr());
2798 switch (tp->ptr()) { 2782 switch (tp->ptr()) {
2799 case TopPTR: 2783 case TopPTR:
2800 case AnyNull: 2784 case AnyNull: {
2785 int instance_id = meet_instance_id(InstanceTop);
2801 return make(ptr, klass(), klass_is_exact(), 2786 return make(ptr, klass(), klass_is_exact(),
2802 (ptr == Constant ? const_oop() : NULL), offset); 2787 (ptr == Constant ? const_oop() : NULL), offset, instance_id);
2788 }
2803 case NotNull: 2789 case NotNull:
2804 case BotPTR: 2790 case BotPTR:
2805 return TypeOopPtr::make(ptr, offset); 2791 return TypeOopPtr::make(ptr, offset);
2806 default: typerr(t); 2792 default: typerr(t);
2807 } 2793 }
2813 int offset = meet_offset(tp->offset()); 2799 int offset = meet_offset(tp->offset());
2814 PTR ptr = meet_ptr(tp->ptr()); 2800 PTR ptr = meet_ptr(tp->ptr());
2815 switch (tp->ptr()) { 2801 switch (tp->ptr()) {
2816 case Null: 2802 case Null:
2817 if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset ); 2803 if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
2804 // else fall through to AnyNull
2818 case TopPTR: 2805 case TopPTR:
2819 case AnyNull: 2806 case AnyNull: {
2807 int instance_id = meet_instance_id(InstanceTop);
2820 return make( ptr, klass(), klass_is_exact(), 2808 return make( ptr, klass(), klass_is_exact(),
2821 (ptr == Constant ? const_oop() : NULL), offset ); 2809 (ptr == Constant ? const_oop() : NULL), offset, instance_id);
2810 }
2822 case NotNull: 2811 case NotNull:
2823 case BotPTR: 2812 case BotPTR:
2824 return TypePtr::make( AnyPtr, ptr, offset ); 2813 return TypePtr::make( AnyPtr, ptr, offset );
2825 default: typerr(t); 2814 default: typerr(t);
2826 } 2815 }
2845 case InstPtr: { // Meeting 2 Oops? 2834 case InstPtr: { // Meeting 2 Oops?
2846 // Found an InstPtr sub-type vs self-InstPtr type 2835 // Found an InstPtr sub-type vs self-InstPtr type
2847 const TypeInstPtr *tinst = t->is_instptr(); 2836 const TypeInstPtr *tinst = t->is_instptr();
2848 int off = meet_offset( tinst->offset() ); 2837 int off = meet_offset( tinst->offset() );
2849 PTR ptr = meet_ptr( tinst->ptr() ); 2838 PTR ptr = meet_ptr( tinst->ptr() );
2850 int instance_id = meet_instance(tinst->instance_id()); 2839 int instance_id = meet_instance_id(tinst->instance_id());
2851 2840
2852 // Check for easy case; klasses are equal (and perhaps not loaded!) 2841 // Check for easy case; klasses are equal (and perhaps not loaded!)
2853 // If we have constants, then we created oops so classes are loaded 2842 // If we have constants, then we created oops so classes are loaded
2854 // and we can handle the constants further down. This case handles 2843 // and we can handle the constants further down. This case handles
2855 // both-not-loaded or both-loaded classes 2844 // both-not-loaded or both-loaded classes
2914 ciObject* o = NULL; // the Constant value, if any 2903 ciObject* o = NULL; // the Constant value, if any
2915 if (ptr == Constant) { 2904 if (ptr == Constant) {
2916 // Find out which constant. 2905 // Find out which constant.
2917 o = (this_klass == klass()) ? const_oop() : tinst->const_oop(); 2906 o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
2918 } 2907 }
2919 return make( ptr, k, xk, o, off ); 2908 return make( ptr, k, xk, o, off, instance_id );
2920 } 2909 }
2921 2910
2922 // Either oop vs oop or interface vs interface or interface vs Object 2911 // Either oop vs oop or interface vs interface or interface vs Object
2923 2912
2924 // !!! Here's how the symmetry requirement breaks down into invariants: 2913 // !!! Here's how the symmetry requirement breaks down into invariants:
3001 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant ) 2990 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3002 ptr = NotNull; 2991 ptr = NotNull;
3003 2992
3004 // Now we find the LCA of Java classes 2993 // Now we find the LCA of Java classes
3005 ciKlass* k = this_klass->least_common_ancestor(tinst_klass); 2994 ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
3006 return make( ptr, k, false, NULL, off ); 2995 return make( ptr, k, false, NULL, off, instance_id );
3007 } // End of case InstPtr 2996 } // End of case InstPtr
3008 2997
3009 case KlassPtr: 2998 case KlassPtr:
3010 return TypeInstPtr::BOTTOM; 2999 return TypeInstPtr::BOTTOM;
3011 3000
3028 3017
3029 //------------------------------xdual------------------------------------------ 3018 //------------------------------xdual------------------------------------------
3030 // Dual: do NOT dual on klasses. This means I do NOT understand the Java 3019 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
3031 // inheritence mechanism. 3020 // inheritence mechanism.
3032 const Type *TypeInstPtr::xdual() const { 3021 const Type *TypeInstPtr::xdual() const {
3033 return new TypeInstPtr( dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance() ); 3022 return new TypeInstPtr( dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id() );
3034 } 3023 }
3035 3024
3036 //------------------------------eq--------------------------------------------- 3025 //------------------------------eq---------------------------------------------
3037 // Structural equality check for Type representations 3026 // Structural equality check for Type representations
3038 bool TypeInstPtr::eq( const Type *t ) const { 3027 bool TypeInstPtr::eq( const Type *t ) const {
3080 else if( _offset == OffsetTop ) st->print("+unknown"); 3069 else if( _offset == OffsetTop ) st->print("+unknown");
3081 else st->print("+%d", _offset); 3070 else st->print("+%d", _offset);
3082 } 3071 }
3083 3072
3084 st->print(" *"); 3073 st->print(" *");
3085 if (_instance_id != UNKNOWN_INSTANCE) 3074 if (_instance_id == InstanceTop)
3075 st->print(",iid=top");
3076 else if (_instance_id != InstanceBot)
3086 st->print(",iid=%d",_instance_id); 3077 st->print(",iid=%d",_instance_id);
3087 } 3078 }
3088 #endif 3079 #endif
3089 3080
3090 //------------------------------add_offset------------------------------------- 3081 //------------------------------add_offset-------------------------------------
3108 //------------------------------make------------------------------------------- 3099 //------------------------------make-------------------------------------------
3109 const TypeAryPtr *TypeAryPtr::make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) { 3100 const TypeAryPtr *TypeAryPtr::make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) {
3110 assert(!(k == NULL && ary->_elem->isa_int()), 3101 assert(!(k == NULL && ary->_elem->isa_int()),
3111 "integral arrays must be pre-equipped with a class"); 3102 "integral arrays must be pre-equipped with a class");
3112 if (!xk) xk = ary->ary_must_be_exact(); 3103 if (!xk) xk = ary->ary_must_be_exact();
3113 if (instance_id != UNKNOWN_INSTANCE) 3104 if ( instance_id > 0 )
3114 xk = true; // instances are always exactly typed 3105 xk = true; // instances are always exactly typed
3115 if (!UseExactTypes) xk = (ptr == Constant); 3106 if (!UseExactTypes) xk = (ptr == Constant);
3116 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id))->hashcons(); 3107 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id))->hashcons();
3117 } 3108 }
3118 3109
3120 const TypeAryPtr *TypeAryPtr::make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) { 3111 const TypeAryPtr *TypeAryPtr::make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) {
3121 assert(!(k == NULL && ary->_elem->isa_int()), 3112 assert(!(k == NULL && ary->_elem->isa_int()),
3122 "integral arrays must be pre-equipped with a class"); 3113 "integral arrays must be pre-equipped with a class");
3123 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" ); 3114 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
3124 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact(); 3115 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact();
3125 if (instance_id != UNKNOWN_INSTANCE) 3116 if ( instance_id > 0 )
3126 xk = true; // instances are always exactly typed 3117 xk = true; // instances are always exactly typed
3127 if (!UseExactTypes) xk = (ptr == Constant); 3118 if (!UseExactTypes) xk = (ptr == Constant);
3128 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id))->hashcons(); 3119 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id))->hashcons();
3129 } 3120 }
3130 3121
3131 //------------------------------cast_to_ptr_type------------------------------- 3122 //------------------------------cast_to_ptr_type-------------------------------
3132 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const { 3123 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
3133 if( ptr == _ptr ) return this; 3124 if( ptr == _ptr ) return this;
3134 return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset); 3125 return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id);
3135 } 3126 }
3136 3127
3137 3128
3138 //-----------------------------cast_to_exactness------------------------------- 3129 //-----------------------------cast_to_exactness-------------------------------
3139 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const { 3130 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
3142 if (_ary->ary_must_be_exact()) return this; // cannot clear xk 3133 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
3143 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id); 3134 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id);
3144 } 3135 }
3145 3136
3146 //-----------------------------cast_to_instance------------------------------- 3137 //-----------------------------cast_to_instance-------------------------------
3147 const TypeOopPtr *TypeAryPtr::cast_to_instance(int instance_id) const { 3138 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
3148 if( instance_id == _instance_id) return this; 3139 if( instance_id == _instance_id ) return this;
3149 bool exact = true; 3140 bool exact = _klass_is_exact;
3150 PTR ptr_t = NotNull; 3141 PTR ptr_t = _ptr;
3151 if (instance_id == UNKNOWN_INSTANCE) { 3142 if ( instance_id > 0 ) { // instances are always exactly typed
3152 exact = _klass_is_exact; 3143 if (UseExactTypes) exact = true;
3153 ptr_t = _ptr; 3144 ptr_t = NotNull;
3154 } 3145 }
3155 return make(ptr_t, const_oop(), _ary, klass(), exact, _offset, instance_id); 3146 return make(ptr_t, const_oop(), _ary, klass(), exact, _offset, instance_id);
3156 } 3147 }
3157 3148
3158 //-----------------------------narrow_size_type------------------------------- 3149 //-----------------------------narrow_size_type-------------------------------
3201 new_size = narrow_size_type(new_size, elem()->basic_type()); 3192 new_size = narrow_size_type(new_size, elem()->basic_type());
3202 if (new_size == NULL) // Negative length arrays will produce weird 3193 if (new_size == NULL) // Negative length arrays will produce weird
3203 new_size = TypeInt::ZERO; // intermediate dead fast-path goo 3194 new_size = TypeInt::ZERO; // intermediate dead fast-path goo
3204 if (new_size == size()) return this; 3195 if (new_size == size()) return this;
3205 const TypeAry* new_ary = TypeAry::make(elem(), new_size); 3196 const TypeAry* new_ary = TypeAry::make(elem(), new_size);
3206 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset); 3197 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
3207 } 3198 }
3208 3199
3209 3200
3210 //------------------------------eq--------------------------------------------- 3201 //------------------------------eq---------------------------------------------
3211 // Structural equality check for Type representations 3202 // Structural equality check for Type representations
3253 const TypePtr *tp = t->is_oopptr(); 3244 const TypePtr *tp = t->is_oopptr();
3254 int offset = meet_offset(tp->offset()); 3245 int offset = meet_offset(tp->offset());
3255 PTR ptr = meet_ptr(tp->ptr()); 3246 PTR ptr = meet_ptr(tp->ptr());
3256 switch (tp->ptr()) { 3247 switch (tp->ptr()) {
3257 case TopPTR: 3248 case TopPTR:
3258 case AnyNull: 3249 case AnyNull: {
3259 return make(ptr, (ptr == Constant ? const_oop() : NULL), _ary, _klass, _klass_is_exact, offset); 3250 int instance_id = meet_instance_id(InstanceTop);
3251 return make(ptr, (ptr == Constant ? const_oop() : NULL),
3252 _ary, _klass, _klass_is_exact, offset, instance_id);
3253 }
3260 case BotPTR: 3254 case BotPTR:
3261 case NotNull: 3255 case NotNull:
3262 return TypeOopPtr::make(ptr, offset); 3256 return TypeOopPtr::make(ptr, offset);
3263 default: ShouldNotReachHere(); 3257 default: ShouldNotReachHere();
3264 } 3258 }
3275 case BotPTR: 3269 case BotPTR:
3276 case NotNull: 3270 case NotNull:
3277 return TypePtr::make(AnyPtr, ptr, offset); 3271 return TypePtr::make(AnyPtr, ptr, offset);
3278 case Null: 3272 case Null:
3279 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset); 3273 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
3280 case AnyNull: 3274 // else fall through to AnyNull
3281 return make( ptr, (ptr == Constant ? const_oop() : NULL), _ary, _klass, _klass_is_exact, offset ); 3275 case AnyNull: {
3276 int instance_id = meet_instance_id(InstanceTop);
3277 return make( ptr, (ptr == Constant ? const_oop() : NULL),
3278 _ary, _klass, _klass_is_exact, offset, instance_id);
3279 }
3282 default: ShouldNotReachHere(); 3280 default: ShouldNotReachHere();
3283 } 3281 }
3284 } 3282 }
3285 3283
3286 case RawPtr: return TypePtr::BOTTOM; 3284 case RawPtr: return TypePtr::BOTTOM;
3288 case AryPtr: { // Meeting 2 references? 3286 case AryPtr: { // Meeting 2 references?
3289 const TypeAryPtr *tap = t->is_aryptr(); 3287 const TypeAryPtr *tap = t->is_aryptr();
3290 int off = meet_offset(tap->offset()); 3288 int off = meet_offset(tap->offset());
3291 const TypeAry *tary = _ary->meet(tap->_ary)->is_ary(); 3289 const TypeAry *tary = _ary->meet(tap->_ary)->is_ary();
3292 PTR ptr = meet_ptr(tap->ptr()); 3290 PTR ptr = meet_ptr(tap->ptr());
3293 int iid = meet_instance(tap->instance_id()); 3291 int instance_id = meet_instance_id(tap->instance_id());
3294 ciKlass* lazy_klass = NULL; 3292 ciKlass* lazy_klass = NULL;
3295 if (tary->_elem->isa_int()) { 3293 if (tary->_elem->isa_int()) {
3296 // Integral array element types have irrelevant lattice relations. 3294 // Integral array element types have irrelevant lattice relations.
3297 // It is the klass that determines array layout, not the element type. 3295 // It is the klass that determines array layout, not the element type.
3298 if (_klass == NULL) 3296 if (_klass == NULL)
3309 switch (tap->ptr()) { 3307 switch (tap->ptr()) {
3310 case AnyNull: 3308 case AnyNull:
3311 case TopPTR: 3309 case TopPTR:
3312 // Compute new klass on demand, do not use tap->_klass 3310 // Compute new klass on demand, do not use tap->_klass
3313 xk = (tap->_klass_is_exact | this->_klass_is_exact); 3311 xk = (tap->_klass_is_exact | this->_klass_is_exact);
3314 return make( ptr, const_oop(), tary, lazy_klass, xk, off, iid ); 3312 return make( ptr, const_oop(), tary, lazy_klass, xk, off, instance_id );
3315 case Constant: { 3313 case Constant: {
3316 ciObject* o = const_oop(); 3314 ciObject* o = const_oop();
3317 if( _ptr == Constant ) { 3315 if( _ptr == Constant ) {
3318 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) { 3316 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
3319 ptr = NotNull; 3317 ptr = NotNull;
3321 } 3319 }
3322 } else if( above_centerline(_ptr) ) { 3320 } else if( above_centerline(_ptr) ) {
3323 o = tap->const_oop(); 3321 o = tap->const_oop();
3324 } 3322 }
3325 xk = true; 3323 xk = true;
3326 return TypeAryPtr::make( ptr, o, tary, tap->_klass, xk, off, iid ); 3324 return TypeAryPtr::make( ptr, o, tary, tap->_klass, xk, off, instance_id );
3327 } 3325 }
3328 case NotNull: 3326 case NotNull:
3329 case BotPTR: 3327 case BotPTR:
3330 // Compute new klass on demand, do not use tap->_klass 3328 // Compute new klass on demand, do not use tap->_klass
3331 if (above_centerline(this->_ptr)) 3329 if (above_centerline(this->_ptr))
3332 xk = tap->_klass_is_exact; 3330 xk = tap->_klass_is_exact;
3333 else if (above_centerline(tap->_ptr)) 3331 else if (above_centerline(tap->_ptr))
3334 xk = this->_klass_is_exact; 3332 xk = this->_klass_is_exact;
3335 else xk = (tap->_klass_is_exact & this->_klass_is_exact) && 3333 else xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
3336 (klass() == tap->klass()); // Only precise for identical arrays 3334 (klass() == tap->klass()); // Only precise for identical arrays
3337 return TypeAryPtr::make( ptr, NULL, tary, lazy_klass, xk, off, iid ); 3335 return TypeAryPtr::make( ptr, NULL, tary, lazy_klass, xk, off, instance_id );
3338 default: ShouldNotReachHere(); 3336 default: ShouldNotReachHere();
3339 } 3337 }
3340 } 3338 }
3341 3339
3342 // All arrays inherit from Object class 3340 // All arrays inherit from Object class
3343 case InstPtr: { 3341 case InstPtr: {
3344 const TypeInstPtr *tp = t->is_instptr(); 3342 const TypeInstPtr *tp = t->is_instptr();
3345 int offset = meet_offset(tp->offset()); 3343 int offset = meet_offset(tp->offset());
3346 PTR ptr = meet_ptr(tp->ptr()); 3344 PTR ptr = meet_ptr(tp->ptr());
3347 int iid = meet_instance(tp->instance_id()); 3345 int instance_id = meet_instance_id(tp->instance_id());
3348 switch (ptr) { 3346 switch (ptr) {
3349 case TopPTR: 3347 case TopPTR:
3350 case AnyNull: // Fall 'down' to dual of object klass 3348 case AnyNull: // Fall 'down' to dual of object klass
3351 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) { 3349 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
3352 return TypeAryPtr::make( ptr, _ary, _klass, _klass_is_exact, offset, iid ); 3350 return TypeAryPtr::make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id );
3353 } else { 3351 } else {
3354 // cannot subclass, so the meet has to fall badly below the centerline 3352 // cannot subclass, so the meet has to fall badly below the centerline
3355 ptr = NotNull; 3353 ptr = NotNull;
3356 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, iid); 3354 instance_id = InstanceBot;
3355 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id);
3357 } 3356 }
3358 case Constant: 3357 case Constant:
3359 case NotNull: 3358 case NotNull:
3360 case BotPTR: // Fall down to object klass 3359 case BotPTR: // Fall down to object klass
3361 // LCA is object_klass, but if we subclass from the top we can do better 3360 // LCA is object_klass, but if we subclass from the top we can do better
3362 if (above_centerline(tp->ptr())) { 3361 if (above_centerline(tp->ptr())) {
3363 // If 'tp' is above the centerline and it is Object class 3362 // If 'tp' is above the centerline and it is Object class
3364 // then we can subclass in the Java class heirarchy. 3363 // then we can subclass in the Java class heirarchy.
3365 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) { 3364 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
3366 // that is, my array type is a subtype of 'tp' klass 3365 // that is, my array type is a subtype of 'tp' klass
3367 return make( ptr, _ary, _klass, _klass_is_exact, offset, iid ); 3366 return make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id );
3368 } 3367 }
3369 } 3368 }
3370 // The other case cannot happen, since t cannot be a subtype of an array. 3369 // The other case cannot happen, since t cannot be a subtype of an array.
3371 // The meet falls down to Object class below centerline. 3370 // The meet falls down to Object class below centerline.
3372 if( ptr == Constant ) 3371 if( ptr == Constant )
3373 ptr = NotNull; 3372 ptr = NotNull;
3374 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, iid); 3373 instance_id = InstanceBot;
3374 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id);
3375 default: typerr(t); 3375 default: typerr(t);
3376 } 3376 }
3377 } 3377 }
3378 3378
3379 case KlassPtr: 3379 case KlassPtr:
3384 } 3384 }
3385 3385
3386 //------------------------------xdual------------------------------------------ 3386 //------------------------------xdual------------------------------------------
3387 // Dual: compute field-by-field dual 3387 // Dual: compute field-by-field dual
3388 const Type *TypeAryPtr::xdual() const { 3388 const Type *TypeAryPtr::xdual() const {
3389 return new TypeAryPtr( dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance() ); 3389 return new TypeAryPtr( dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id() );
3390 } 3390 }
3391 3391
3392 //------------------------------dump2------------------------------------------ 3392 //------------------------------dump2------------------------------------------
3393 #ifndef PRODUCT 3393 #ifndef PRODUCT
3394 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 3394 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3421 int elem_size = type2aelembytes(basic_elem_type); 3421 int elem_size = type2aelembytes(basic_elem_type);
3422 st->print("[%d]", (_offset - array_base)/elem_size); 3422 st->print("[%d]", (_offset - array_base)/elem_size);
3423 } 3423 }
3424 } 3424 }
3425 st->print(" *"); 3425 st->print(" *");
3426 if (_instance_id != UNKNOWN_INSTANCE) 3426 if (_instance_id == InstanceTop)
3427 st->print(",iid=top");
3428 else if (_instance_id != InstanceBot)
3427 st->print(",iid=%d",_instance_id); 3429 st->print(",iid=%d",_instance_id);
3428 } 3430 }
3429 #endif 3431 #endif
3430 3432
3431 bool TypeAryPtr::empty(void) const { 3433 bool TypeAryPtr::empty(void) const {