src/share/vm/opto/type.cpp

changeset 670
9c2ecc2ffb12
parent 631
d1605aabd0a1
parent 658
1dd146f17531
child 682
02a35ad4adf8
equal deleted inserted replaced
632:de141433919f 670:9c2ecc2ffb12
489 //------------------------------meet------------------------------------------- 489 //------------------------------meet-------------------------------------------
490 // Compute the MEET of two types. NOT virtual. It enforces that meet is 490 // Compute the MEET of two types. NOT virtual. It enforces that meet is
491 // commutative and the lattice is symmetric. 491 // commutative and the lattice is symmetric.
492 const Type *Type::meet( const Type *t ) const { 492 const Type *Type::meet( const Type *t ) const {
493 if (isa_narrowoop() && t->isa_narrowoop()) { 493 if (isa_narrowoop() && t->isa_narrowoop()) {
494 const Type* result = is_narrowoop()->make_oopptr()->meet(t->is_narrowoop()->make_oopptr()); 494 const Type* result = make_ptr()->meet(t->make_ptr());
495 if (result->isa_oopptr()) { 495 return result->make_narrowoop();
496 return result->isa_oopptr()->make_narrowoop();
497 } else if (result == TypePtr::NULL_PTR) {
498 return TypeNarrowOop::NULL_PTR;
499 } else {
500 return result;
501 }
502 } 496 }
503 497
504 const Type *mt = xmeet(t); 498 const Type *mt = xmeet(t);
505 if (isa_narrowoop() || t->isa_narrowoop()) return mt; 499 if (isa_narrowoop() || t->isa_narrowoop()) return mt;
506 #ifdef ASSERT 500 #ifdef ASSERT
518 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() ) {
519 bool this_interface = this_inst->klass()->is_interface(); 513 bool this_interface = this_inst->klass()->is_interface();
520 bool t_interface = t_inst->klass()->is_interface(); 514 bool t_interface = t_inst->klass()->is_interface();
521 interface_vs_oop = this_interface ^ t_interface; 515 interface_vs_oop = this_interface ^ t_interface;
522 } 516 }
523 const Type *tdual = t->_dual; 517
524 const Type *thisdual = _dual; 518 if( !interface_vs_oop && (t2t != t->_dual || t2this != _dual) ) {
525 // strip out instances
526 if (t2t->isa_oopptr() != NULL) {
527 t2t = t2t->isa_oopptr()->cast_to_instance(TypeOopPtr::UNKNOWN_INSTANCE);
528 }
529 if (t2this->isa_oopptr() != NULL) {
530 t2this = t2this->isa_oopptr()->cast_to_instance(TypeOopPtr::UNKNOWN_INSTANCE);
531 }
532 if (tdual->isa_oopptr() != NULL) {
533 tdual = tdual->isa_oopptr()->cast_to_instance(TypeOopPtr::UNKNOWN_INSTANCE);
534 }
535 if (thisdual->isa_oopptr() != NULL) {
536 thisdual = thisdual->isa_oopptr()->cast_to_instance(TypeOopPtr::UNKNOWN_INSTANCE);
537 }
538
539 if( !interface_vs_oop && (t2t != tdual || t2this != thisdual) ) {
540 tty->print_cr("=== Meet Not Symmetric ==="); 519 tty->print_cr("=== Meet Not Symmetric ===");
541 tty->print("t = "); t->dump(); tty->cr(); 520 tty->print("t = "); t->dump(); tty->cr();
542 tty->print("this= "); dump(); tty->cr(); 521 tty->print("this= "); dump(); tty->cr();
543 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr(); 522 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
544 523
1762 } 1741 }
1763 1742
1764 //------------------------------make------------------------------------------- 1743 //------------------------------make-------------------------------------------
1765 const TypeAry *TypeAry::make( const Type *elem, const TypeInt *size) { 1744 const TypeAry *TypeAry::make( const Type *elem, const TypeInt *size) {
1766 if (UseCompressedOops && elem->isa_oopptr()) { 1745 if (UseCompressedOops && elem->isa_oopptr()) {
1767 elem = elem->is_oopptr()->make_narrowoop(); 1746 elem = elem->make_narrowoop();
1768 } 1747 }
1769 size = normalize_array_size(size); 1748 size = normalize_array_size(size);
1770 return (TypeAry*)(new TypeAry(elem,size))->hashcons(); 1749 return (TypeAry*)(new TypeAry(elem,size))->hashcons();
1771 } 1750 }
1772 1751
1847 // if the element type is either a primitive or a final instance class. 1826 // if the element type is either a primitive or a final instance class.
1848 // In such cases, an array built on this ary must have no subclasses. 1827 // In such cases, an array built on this ary must have no subclasses.
1849 if (_elem == BOTTOM) return false; // general array not exact 1828 if (_elem == BOTTOM) return false; // general array not exact
1850 if (_elem == TOP ) return false; // inverted general array not exact 1829 if (_elem == TOP ) return false; // inverted general array not exact
1851 const TypeOopPtr* toop = NULL; 1830 const TypeOopPtr* toop = NULL;
1852 if (UseCompressedOops) { 1831 if (UseCompressedOops && _elem->isa_narrowoop()) {
1853 const TypeNarrowOop* noop = _elem->isa_narrowoop(); 1832 toop = _elem->make_ptr()->isa_oopptr();
1854 if (noop) toop = noop->make_oopptr()->isa_oopptr();
1855 } else { 1833 } else {
1856 toop = _elem->isa_oopptr(); 1834 toop = _elem->isa_oopptr();
1857 } 1835 }
1858 if (!toop) return true; // a primitive type, like int 1836 if (!toop) return true; // a primitive type, like int
1859 ciKlass* tklass = toop->klass(); 1837 ciKlass* tklass = toop->klass();
1860 if (tklass == NULL) return false; // unloaded class 1838 if (tklass == NULL) return false; // unloaded class
1861 if (!tklass->is_loaded()) return false; // unloaded class 1839 if (!tklass->is_loaded()) return false; // unloaded class
1862 const TypeInstPtr* tinst; 1840 const TypeInstPtr* tinst;
1863 if (_elem->isa_narrowoop()) 1841 if (_elem->isa_narrowoop())
1864 tinst = _elem->is_narrowoop()->make_oopptr()->isa_instptr(); 1842 tinst = _elem->make_ptr()->isa_instptr();
1865 else 1843 else
1866 tinst = _elem->isa_instptr(); 1844 tinst = _elem->isa_instptr();
1867 if (tinst) return tklass->as_instance_klass()->is_final(); 1845 if (tinst)
1846 return tklass->as_instance_klass()->is_final();
1868 const TypeAryPtr* tap; 1847 const TypeAryPtr* tap;
1869 if (_elem->isa_narrowoop()) 1848 if (_elem->isa_narrowoop())
1870 tap = _elem->is_narrowoop()->make_oopptr()->isa_aryptr(); 1849 tap = _elem->make_ptr()->isa_aryptr();
1871 else 1850 else
1872 tap = _elem->isa_aryptr(); 1851 tap = _elem->isa_aryptr();
1873 if (tap) return tap->ary()->ary_must_be_exact(); 1852 if (tap)
1853 return tap->ary()->ary_must_be_exact();
1874 return false; 1854 return false;
1875 } 1855 }
1876 1856
1877 //============================================================================= 1857 //=============================================================================
1878 // Convenience common pre-built types. 1858 // Convenience common pre-built types.
2225 int offset) { 2205 int offset) {
2226 assert(ptr != Constant, "no constant generic pointers"); 2206 assert(ptr != Constant, "no constant generic pointers");
2227 ciKlass* k = ciKlassKlass::make(); 2207 ciKlass* k = ciKlassKlass::make();
2228 bool xk = false; 2208 bool xk = false;
2229 ciObject* o = NULL; 2209 ciObject* o = NULL;
2230 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();
2231 } 2211 }
2232 2212
2233 2213
2234 //------------------------------cast_to_ptr_type------------------------------- 2214 //------------------------------cast_to_ptr_type-------------------------------
2235 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const { 2215 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
2237 if( ptr == _ptr ) return this; 2217 if( ptr == _ptr ) return this;
2238 return make(ptr, _offset); 2218 return make(ptr, _offset);
2239 } 2219 }
2240 2220
2241 //-----------------------------cast_to_instance------------------------------- 2221 //-----------------------------cast_to_instance-------------------------------
2242 const TypeOopPtr *TypeOopPtr::cast_to_instance(int instance_id) const { 2222 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
2243 // There are no instances of a general oop. 2223 // There are no instances of a general oop.
2244 // Return self unchanged. 2224 // Return self unchanged.
2245 return this; 2225 return this;
2246 } 2226 }
2247 2227
2331 //------------------------------xdual------------------------------------------ 2311 //------------------------------xdual------------------------------------------
2332 // 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.
2333 const Type *TypeOopPtr::xdual() const { 2313 const Type *TypeOopPtr::xdual() const {
2334 assert(klass() == ciKlassKlass::make(), "no klasses here"); 2314 assert(klass() == ciKlassKlass::make(), "no klasses here");
2335 assert(const_oop() == NULL, "no constants here"); 2315 assert(const_oop() == NULL, "no constants here");
2336 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() );
2337 } 2317 }
2338 2318
2339 //--------------------------make_from_klass_common----------------------------- 2319 //--------------------------make_from_klass_common-----------------------------
2340 // Computes the element-type given a klass. 2320 // Computes the element-type given a klass.
2341 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) {
2545 case OffsetTop: st->print("+top"); break; 2525 case OffsetTop: st->print("+top"); break;
2546 case OffsetBot: st->print("+any"); break; 2526 case OffsetBot: st->print("+any"); break;
2547 case 0: break; 2527 case 0: break;
2548 default: st->print("+%d",_offset); break; 2528 default: st->print("+%d",_offset); break;
2549 } 2529 }
2550 if (_instance_id != UNKNOWN_INSTANCE) 2530 if (_instance_id == InstanceTop)
2531 st->print(",iid=top");
2532 else if (_instance_id != InstanceBot)
2551 st->print(",iid=%d",_instance_id); 2533 st->print(",iid=%d",_instance_id);
2552 } 2534 }
2553 #endif 2535 #endif
2554 2536
2555 //------------------------------singleton-------------------------------------- 2537 //------------------------------singleton--------------------------------------
2577 //------------------------------add_offset------------------------------------- 2559 //------------------------------add_offset-------------------------------------
2578 const TypePtr *TypeOopPtr::add_offset( int offset ) const { 2560 const TypePtr *TypeOopPtr::add_offset( int offset ) const {
2579 return make( _ptr, xadd_offset(offset) ); 2561 return make( _ptr, xadd_offset(offset) );
2580 } 2562 }
2581 2563
2582 const TypeNarrowOop* TypeOopPtr::make_narrowoop() const { 2564 //------------------------------meet_instance_id--------------------------------
2583 return TypeNarrowOop::make(this); 2565 int TypeOopPtr::meet_instance_id( int instance_id ) const {
2584 } 2566 // Either is 'TOP' instance? Return the other instance!
2585 2567 if( _instance_id == InstanceTop ) return instance_id;
2586 int TypeOopPtr::meet_instance(int iid) const { 2568 if( instance_id == InstanceTop ) return _instance_id;
2587 if (iid == 0) { 2569 // If either is different, return 'BOTTOM' instance
2588 return (_instance_id < 0) ? _instance_id : UNKNOWN_INSTANCE; 2570 if( _instance_id != instance_id ) return InstanceBot;
2589 } else if (_instance_id == UNKNOWN_INSTANCE) { 2571 return _instance_id;
2590 return (iid < 0) ? iid : UNKNOWN_INSTANCE; 2572 }
2591 } else { 2573
2592 return (_instance_id == iid) ? iid : UNKNOWN_INSTANCE; 2574 //------------------------------dual_instance_id--------------------------------
2593 } 2575 int TypeOopPtr::dual_instance_id( ) const {
2594 } 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
2595 2581
2596 //============================================================================= 2582 //=============================================================================
2597 // Convenience common pre-built types. 2583 // Convenience common pre-built types.
2598 const TypeInstPtr *TypeInstPtr::NOTNULL; 2584 const TypeInstPtr *TypeInstPtr::NOTNULL;
2599 const TypeInstPtr *TypeInstPtr::BOTTOM; 2585 const TypeInstPtr *TypeInstPtr::BOTTOM;
2622 assert( (!o && ptr != Constant) || (o && ptr == Constant), 2608 assert( (!o && ptr != Constant) || (o && ptr == Constant),
2623 "constant pointers must have a value supplied" ); 2609 "constant pointers must have a value supplied" );
2624 // Ptr is never Null 2610 // Ptr is never Null
2625 assert( ptr != Null, "NULL pointers are not typed" ); 2611 assert( ptr != Null, "NULL pointers are not typed" );
2626 2612
2627 if (instance_id != UNKNOWN_INSTANCE) 2613 if ( instance_id > 0 )
2628 xk = true; // instances are always exactly typed 2614 xk = true; // instances are always exactly typed
2629 if (!UseExactTypes) xk = false; 2615 if (!UseExactTypes) xk = false;
2630 if (ptr == Constant) { 2616 if (ptr == Constant) {
2631 // Note: This case includes meta-object constants, such as methods. 2617 // Note: This case includes meta-object constants, such as methods.
2632 xk = true; 2618 xk = true;
2647 //------------------------------cast_to_ptr_type------------------------------- 2633 //------------------------------cast_to_ptr_type-------------------------------
2648 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const { 2634 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
2649 if( ptr == _ptr ) return this; 2635 if( ptr == _ptr ) return this;
2650 // Reconstruct _sig info here since not a problem with later lazy 2636 // Reconstruct _sig info here since not a problem with later lazy
2651 // construction, _sig will show up on demand. 2637 // construction, _sig will show up on demand.
2652 return make(ptr, klass(), klass_is_exact(), const_oop(), _offset); 2638 return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id);
2653 } 2639 }
2654 2640
2655 2641
2656 //-----------------------------cast_to_exactness------------------------------- 2642 //-----------------------------cast_to_exactness-------------------------------
2657 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const { 2643 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
2663 if( ik->is_interface() ) return this; // cannot set xk 2649 if( ik->is_interface() ) return this; // cannot set xk
2664 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);
2665 } 2651 }
2666 2652
2667 //-----------------------------cast_to_instance------------------------------- 2653 //-----------------------------cast_to_instance-------------------------------
2668 const TypeOopPtr *TypeInstPtr::cast_to_instance(int instance_id) const { 2654 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
2669 if( instance_id == _instance_id) return this; 2655 if( instance_id == _instance_id ) return this;
2670 bool exact = true; 2656 bool exact = _klass_is_exact;
2671 PTR ptr_t = NotNull; 2657 PTR ptr_t = _ptr;
2672 if (instance_id == UNKNOWN_INSTANCE) { 2658 if ( instance_id > 0 ) { // instances are always exactly typed
2673 exact = _klass_is_exact; 2659 if (UseExactTypes) exact = true;
2674 ptr_t = _ptr; 2660 ptr_t = NotNull;
2675 } 2661 }
2676 return make(ptr_t, klass(), exact, const_oop(), _offset, instance_id); 2662 return make(ptr_t, klass(), exact, const_oop(), _offset, instance_id);
2677 } 2663 }
2678 2664
2679 //------------------------------xmeet_unloaded--------------------------------- 2665 //------------------------------xmeet_unloaded---------------------------------
2752 2738
2753 case AryPtr: { // All arrays inherit from Object class 2739 case AryPtr: { // All arrays inherit from Object class
2754 const TypeAryPtr *tp = t->is_aryptr(); 2740 const TypeAryPtr *tp = t->is_aryptr();
2755 int offset = meet_offset(tp->offset()); 2741 int offset = meet_offset(tp->offset());
2756 PTR ptr = meet_ptr(tp->ptr()); 2742 PTR ptr = meet_ptr(tp->ptr());
2757 int iid = meet_instance(tp->instance_id()); 2743 int instance_id = meet_instance_id(tp->instance_id());
2758 switch (ptr) { 2744 switch (ptr) {
2759 case TopPTR: 2745 case TopPTR:
2760 case AnyNull: // Fall 'down' to dual of object klass 2746 case AnyNull: // Fall 'down' to dual of object klass
2761 if (klass()->equals(ciEnv::current()->Object_klass())) { 2747 if (klass()->equals(ciEnv::current()->Object_klass())) {
2762 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);
2763 } else { 2749 } else {
2764 // 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
2765 ptr = NotNull; 2751 ptr = NotNull;
2766 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);
2767 } 2754 }
2768 case Constant: 2755 case Constant:
2769 case NotNull: 2756 case NotNull:
2770 case BotPTR: // Fall down to object klass 2757 case BotPTR: // Fall down to object klass
2771 // 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
2772 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull ) 2759 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
2773 // 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
2774 // then we can subclass in the Java class heirarchy. 2761 // then we can subclass in the Java class heirarchy.
2775 if (klass()->equals(ciEnv::current()->Object_klass())) { 2762 if (klass()->equals(ciEnv::current()->Object_klass())) {
2776 // 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
2777 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);
2778 } 2765 }
2779 } 2766 }
2780 // 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.
2781 // The meet falls down to Object class below centerline. 2768 // The meet falls down to Object class below centerline.
2782 if( ptr == Constant ) 2769 if( ptr == Constant )
2783 ptr = NotNull; 2770 ptr = NotNull;
2784 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 );
2785 default: typerr(t); 2773 default: typerr(t);
2786 } 2774 }
2787 } 2775 }
2788 2776
2789 case OopPtr: { // Meeting to OopPtrs 2777 case OopPtr: { // Meeting to OopPtrs
2791 const TypePtr *tp = t->is_oopptr(); 2779 const TypePtr *tp = t->is_oopptr();
2792 int offset = meet_offset(tp->offset()); 2780 int offset = meet_offset(tp->offset());
2793 PTR ptr = meet_ptr(tp->ptr()); 2781 PTR ptr = meet_ptr(tp->ptr());
2794 switch (tp->ptr()) { 2782 switch (tp->ptr()) {
2795 case TopPTR: 2783 case TopPTR:
2796 case AnyNull: 2784 case AnyNull: {
2785 int instance_id = meet_instance_id(InstanceTop);
2797 return make(ptr, klass(), klass_is_exact(), 2786 return make(ptr, klass(), klass_is_exact(),
2798 (ptr == Constant ? const_oop() : NULL), offset); 2787 (ptr == Constant ? const_oop() : NULL), offset, instance_id);
2788 }
2799 case NotNull: 2789 case NotNull:
2800 case BotPTR: 2790 case BotPTR:
2801 return TypeOopPtr::make(ptr, offset); 2791 return TypeOopPtr::make(ptr, offset);
2802 default: typerr(t); 2792 default: typerr(t);
2803 } 2793 }
2809 int offset = meet_offset(tp->offset()); 2799 int offset = meet_offset(tp->offset());
2810 PTR ptr = meet_ptr(tp->ptr()); 2800 PTR ptr = meet_ptr(tp->ptr());
2811 switch (tp->ptr()) { 2801 switch (tp->ptr()) {
2812 case Null: 2802 case Null:
2813 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
2814 case TopPTR: 2805 case TopPTR:
2815 case AnyNull: 2806 case AnyNull: {
2807 int instance_id = meet_instance_id(InstanceTop);
2816 return make( ptr, klass(), klass_is_exact(), 2808 return make( ptr, klass(), klass_is_exact(),
2817 (ptr == Constant ? const_oop() : NULL), offset ); 2809 (ptr == Constant ? const_oop() : NULL), offset, instance_id);
2810 }
2818 case NotNull: 2811 case NotNull:
2819 case BotPTR: 2812 case BotPTR:
2820 return TypePtr::make( AnyPtr, ptr, offset ); 2813 return TypePtr::make( AnyPtr, ptr, offset );
2821 default: typerr(t); 2814 default: typerr(t);
2822 } 2815 }
2841 case InstPtr: { // Meeting 2 Oops? 2834 case InstPtr: { // Meeting 2 Oops?
2842 // Found an InstPtr sub-type vs self-InstPtr type 2835 // Found an InstPtr sub-type vs self-InstPtr type
2843 const TypeInstPtr *tinst = t->is_instptr(); 2836 const TypeInstPtr *tinst = t->is_instptr();
2844 int off = meet_offset( tinst->offset() ); 2837 int off = meet_offset( tinst->offset() );
2845 PTR ptr = meet_ptr( tinst->ptr() ); 2838 PTR ptr = meet_ptr( tinst->ptr() );
2846 int instance_id = meet_instance(tinst->instance_id()); 2839 int instance_id = meet_instance_id(tinst->instance_id());
2847 2840
2848 // Check for easy case; klasses are equal (and perhaps not loaded!) 2841 // Check for easy case; klasses are equal (and perhaps not loaded!)
2849 // 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
2850 // and we can handle the constants further down. This case handles 2843 // and we can handle the constants further down. This case handles
2851 // both-not-loaded or both-loaded classes 2844 // both-not-loaded or both-loaded classes
2910 ciObject* o = NULL; // the Constant value, if any 2903 ciObject* o = NULL; // the Constant value, if any
2911 if (ptr == Constant) { 2904 if (ptr == Constant) {
2912 // Find out which constant. 2905 // Find out which constant.
2913 o = (this_klass == klass()) ? const_oop() : tinst->const_oop(); 2906 o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
2914 } 2907 }
2915 return make( ptr, k, xk, o, off ); 2908 return make( ptr, k, xk, o, off, instance_id );
2916 } 2909 }
2917 2910
2918 // 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
2919 2912
2920 // !!! Here's how the symmetry requirement breaks down into invariants: 2913 // !!! Here's how the symmetry requirement breaks down into invariants:
2997 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant ) 2990 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
2998 ptr = NotNull; 2991 ptr = NotNull;
2999 2992
3000 // Now we find the LCA of Java classes 2993 // Now we find the LCA of Java classes
3001 ciKlass* k = this_klass->least_common_ancestor(tinst_klass); 2994 ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
3002 return make( ptr, k, false, NULL, off ); 2995 return make( ptr, k, false, NULL, off, instance_id );
3003 } // End of case InstPtr 2996 } // End of case InstPtr
3004 2997
3005 case KlassPtr: 2998 case KlassPtr:
3006 return TypeInstPtr::BOTTOM; 2999 return TypeInstPtr::BOTTOM;
3007 3000
3024 3017
3025 //------------------------------xdual------------------------------------------ 3018 //------------------------------xdual------------------------------------------
3026 // 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
3027 // inheritence mechanism. 3020 // inheritence mechanism.
3028 const Type *TypeInstPtr::xdual() const { 3021 const Type *TypeInstPtr::xdual() const {
3029 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() );
3030 } 3023 }
3031 3024
3032 //------------------------------eq--------------------------------------------- 3025 //------------------------------eq---------------------------------------------
3033 // Structural equality check for Type representations 3026 // Structural equality check for Type representations
3034 bool TypeInstPtr::eq( const Type *t ) const { 3027 bool TypeInstPtr::eq( const Type *t ) const {
3076 else if( _offset == OffsetTop ) st->print("+unknown"); 3069 else if( _offset == OffsetTop ) st->print("+unknown");
3077 else st->print("+%d", _offset); 3070 else st->print("+%d", _offset);
3078 } 3071 }
3079 3072
3080 st->print(" *"); 3073 st->print(" *");
3081 if (_instance_id != UNKNOWN_INSTANCE) 3074 if (_instance_id == InstanceTop)
3075 st->print(",iid=top");
3076 else if (_instance_id != InstanceBot)
3082 st->print(",iid=%d",_instance_id); 3077 st->print(",iid=%d",_instance_id);
3083 } 3078 }
3084 #endif 3079 #endif
3085 3080
3086 //------------------------------add_offset------------------------------------- 3081 //------------------------------add_offset-------------------------------------
3104 //------------------------------make------------------------------------------- 3099 //------------------------------make-------------------------------------------
3105 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 ) {
3106 assert(!(k == NULL && ary->_elem->isa_int()), 3101 assert(!(k == NULL && ary->_elem->isa_int()),
3107 "integral arrays must be pre-equipped with a class"); 3102 "integral arrays must be pre-equipped with a class");
3108 if (!xk) xk = ary->ary_must_be_exact(); 3103 if (!xk) xk = ary->ary_must_be_exact();
3109 if (instance_id != UNKNOWN_INSTANCE) 3104 if ( instance_id > 0 )
3110 xk = true; // instances are always exactly typed 3105 xk = true; // instances are always exactly typed
3111 if (!UseExactTypes) xk = (ptr == Constant); 3106 if (!UseExactTypes) xk = (ptr == Constant);
3112 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();
3113 } 3108 }
3114 3109
3116 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 ) {
3117 assert(!(k == NULL && ary->_elem->isa_int()), 3112 assert(!(k == NULL && ary->_elem->isa_int()),
3118 "integral arrays must be pre-equipped with a class"); 3113 "integral arrays must be pre-equipped with a class");
3119 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" ); 3114 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
3120 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact(); 3115 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact();
3121 if (instance_id != UNKNOWN_INSTANCE) 3116 if ( instance_id > 0 )
3122 xk = true; // instances are always exactly typed 3117 xk = true; // instances are always exactly typed
3123 if (!UseExactTypes) xk = (ptr == Constant); 3118 if (!UseExactTypes) xk = (ptr == Constant);
3124 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();
3125 } 3120 }
3126 3121
3127 //------------------------------cast_to_ptr_type------------------------------- 3122 //------------------------------cast_to_ptr_type-------------------------------
3128 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const { 3123 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
3129 if( ptr == _ptr ) return this; 3124 if( ptr == _ptr ) return this;
3130 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);
3131 } 3126 }
3132 3127
3133 3128
3134 //-----------------------------cast_to_exactness------------------------------- 3129 //-----------------------------cast_to_exactness-------------------------------
3135 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const { 3130 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
3138 if (_ary->ary_must_be_exact()) return this; // cannot clear xk 3133 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
3139 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);
3140 } 3135 }
3141 3136
3142 //-----------------------------cast_to_instance------------------------------- 3137 //-----------------------------cast_to_instance-------------------------------
3143 const TypeOopPtr *TypeAryPtr::cast_to_instance(int instance_id) const { 3138 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
3144 if( instance_id == _instance_id) return this; 3139 if( instance_id == _instance_id ) return this;
3145 bool exact = true; 3140 bool exact = _klass_is_exact;
3146 PTR ptr_t = NotNull; 3141 PTR ptr_t = _ptr;
3147 if (instance_id == UNKNOWN_INSTANCE) { 3142 if ( instance_id > 0 ) { // instances are always exactly typed
3148 exact = _klass_is_exact; 3143 if (UseExactTypes) exact = true;
3149 ptr_t = _ptr; 3144 ptr_t = NotNull;
3150 } 3145 }
3151 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);
3152 } 3147 }
3153 3148
3154 //-----------------------------narrow_size_type------------------------------- 3149 //-----------------------------narrow_size_type-------------------------------
3197 new_size = narrow_size_type(new_size, elem()->basic_type()); 3192 new_size = narrow_size_type(new_size, elem()->basic_type());
3198 if (new_size == NULL) // Negative length arrays will produce weird 3193 if (new_size == NULL) // Negative length arrays will produce weird
3199 new_size = TypeInt::ZERO; // intermediate dead fast-path goo 3194 new_size = TypeInt::ZERO; // intermediate dead fast-path goo
3200 if (new_size == size()) return this; 3195 if (new_size == size()) return this;
3201 const TypeAry* new_ary = TypeAry::make(elem(), new_size); 3196 const TypeAry* new_ary = TypeAry::make(elem(), new_size);
3202 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);
3203 } 3198 }
3204 3199
3205 3200
3206 //------------------------------eq--------------------------------------------- 3201 //------------------------------eq---------------------------------------------
3207 // Structural equality check for Type representations 3202 // Structural equality check for Type representations
3249 const TypePtr *tp = t->is_oopptr(); 3244 const TypePtr *tp = t->is_oopptr();
3250 int offset = meet_offset(tp->offset()); 3245 int offset = meet_offset(tp->offset());
3251 PTR ptr = meet_ptr(tp->ptr()); 3246 PTR ptr = meet_ptr(tp->ptr());
3252 switch (tp->ptr()) { 3247 switch (tp->ptr()) {
3253 case TopPTR: 3248 case TopPTR:
3254 case AnyNull: 3249 case AnyNull: {
3255 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 }
3256 case BotPTR: 3254 case BotPTR:
3257 case NotNull: 3255 case NotNull:
3258 return TypeOopPtr::make(ptr, offset); 3256 return TypeOopPtr::make(ptr, offset);
3259 default: ShouldNotReachHere(); 3257 default: ShouldNotReachHere();
3260 } 3258 }
3271 case BotPTR: 3269 case BotPTR:
3272 case NotNull: 3270 case NotNull:
3273 return TypePtr::make(AnyPtr, ptr, offset); 3271 return TypePtr::make(AnyPtr, ptr, offset);
3274 case Null: 3272 case Null:
3275 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset); 3273 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
3276 case AnyNull: 3274 // else fall through to AnyNull
3277 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 }
3278 default: ShouldNotReachHere(); 3280 default: ShouldNotReachHere();
3279 } 3281 }
3280 } 3282 }
3281 3283
3282 case RawPtr: return TypePtr::BOTTOM; 3284 case RawPtr: return TypePtr::BOTTOM;
3284 case AryPtr: { // Meeting 2 references? 3286 case AryPtr: { // Meeting 2 references?
3285 const TypeAryPtr *tap = t->is_aryptr(); 3287 const TypeAryPtr *tap = t->is_aryptr();
3286 int off = meet_offset(tap->offset()); 3288 int off = meet_offset(tap->offset());
3287 const TypeAry *tary = _ary->meet(tap->_ary)->is_ary(); 3289 const TypeAry *tary = _ary->meet(tap->_ary)->is_ary();
3288 PTR ptr = meet_ptr(tap->ptr()); 3290 PTR ptr = meet_ptr(tap->ptr());
3289 int iid = meet_instance(tap->instance_id()); 3291 int instance_id = meet_instance_id(tap->instance_id());
3290 ciKlass* lazy_klass = NULL; 3292 ciKlass* lazy_klass = NULL;
3291 if (tary->_elem->isa_int()) { 3293 if (tary->_elem->isa_int()) {
3292 // Integral array element types have irrelevant lattice relations. 3294 // Integral array element types have irrelevant lattice relations.
3293 // 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.
3294 if (_klass == NULL) 3296 if (_klass == NULL)
3305 switch (tap->ptr()) { 3307 switch (tap->ptr()) {
3306 case AnyNull: 3308 case AnyNull:
3307 case TopPTR: 3309 case TopPTR:
3308 // Compute new klass on demand, do not use tap->_klass 3310 // Compute new klass on demand, do not use tap->_klass
3309 xk = (tap->_klass_is_exact | this->_klass_is_exact); 3311 xk = (tap->_klass_is_exact | this->_klass_is_exact);
3310 return make( ptr, const_oop(), tary, lazy_klass, xk, off, iid ); 3312 return make( ptr, const_oop(), tary, lazy_klass, xk, off, instance_id );
3311 case Constant: { 3313 case Constant: {
3312 ciObject* o = const_oop(); 3314 ciObject* o = const_oop();
3313 if( _ptr == Constant ) { 3315 if( _ptr == Constant ) {
3314 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) { 3316 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
3315 ptr = NotNull; 3317 ptr = NotNull;
3317 } 3319 }
3318 } else if( above_centerline(_ptr) ) { 3320 } else if( above_centerline(_ptr) ) {
3319 o = tap->const_oop(); 3321 o = tap->const_oop();
3320 } 3322 }
3321 xk = true; 3323 xk = true;
3322 return TypeAryPtr::make( ptr, o, tary, tap->_klass, xk, off, iid ); 3324 return TypeAryPtr::make( ptr, o, tary, tap->_klass, xk, off, instance_id );
3323 } 3325 }
3324 case NotNull: 3326 case NotNull:
3325 case BotPTR: 3327 case BotPTR:
3326 // Compute new klass on demand, do not use tap->_klass 3328 // Compute new klass on demand, do not use tap->_klass
3327 if (above_centerline(this->_ptr)) 3329 if (above_centerline(this->_ptr))
3328 xk = tap->_klass_is_exact; 3330 xk = tap->_klass_is_exact;
3329 else if (above_centerline(tap->_ptr)) 3331 else if (above_centerline(tap->_ptr))
3330 xk = this->_klass_is_exact; 3332 xk = this->_klass_is_exact;
3331 else xk = (tap->_klass_is_exact & this->_klass_is_exact) && 3333 else xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
3332 (klass() == tap->klass()); // Only precise for identical arrays 3334 (klass() == tap->klass()); // Only precise for identical arrays
3333 return TypeAryPtr::make( ptr, NULL, tary, lazy_klass, xk, off, iid ); 3335 return TypeAryPtr::make( ptr, NULL, tary, lazy_klass, xk, off, instance_id );
3334 default: ShouldNotReachHere(); 3336 default: ShouldNotReachHere();
3335 } 3337 }
3336 } 3338 }
3337 3339
3338 // All arrays inherit from Object class 3340 // All arrays inherit from Object class
3339 case InstPtr: { 3341 case InstPtr: {
3340 const TypeInstPtr *tp = t->is_instptr(); 3342 const TypeInstPtr *tp = t->is_instptr();
3341 int offset = meet_offset(tp->offset()); 3343 int offset = meet_offset(tp->offset());
3342 PTR ptr = meet_ptr(tp->ptr()); 3344 PTR ptr = meet_ptr(tp->ptr());
3343 int iid = meet_instance(tp->instance_id()); 3345 int instance_id = meet_instance_id(tp->instance_id());
3344 switch (ptr) { 3346 switch (ptr) {
3345 case TopPTR: 3347 case TopPTR:
3346 case AnyNull: // Fall 'down' to dual of object klass 3348 case AnyNull: // Fall 'down' to dual of object klass
3347 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) { 3349 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
3348 return TypeAryPtr::make( ptr, _ary, _klass, _klass_is_exact, offset, iid ); 3350 return TypeAryPtr::make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id );
3349 } else { 3351 } else {
3350 // 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
3351 ptr = NotNull; 3353 ptr = NotNull;
3352 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);
3353 } 3356 }
3354 case Constant: 3357 case Constant:
3355 case NotNull: 3358 case NotNull:
3356 case BotPTR: // Fall down to object klass 3359 case BotPTR: // Fall down to object klass
3357 // 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
3358 if (above_centerline(tp->ptr())) { 3361 if (above_centerline(tp->ptr())) {
3359 // If 'tp' is above the centerline and it is Object class 3362 // If 'tp' is above the centerline and it is Object class
3360 // then we can subclass in the Java class heirarchy. 3363 // then we can subclass in the Java class heirarchy.
3361 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) { 3364 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
3362 // that is, my array type is a subtype of 'tp' klass 3365 // that is, my array type is a subtype of 'tp' klass
3363 return make( ptr, _ary, _klass, _klass_is_exact, offset, iid ); 3366 return make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id );
3364 } 3367 }
3365 } 3368 }
3366 // 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.
3367 // The meet falls down to Object class below centerline. 3370 // The meet falls down to Object class below centerline.
3368 if( ptr == Constant ) 3371 if( ptr == Constant )
3369 ptr = NotNull; 3372 ptr = NotNull;
3370 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);
3371 default: typerr(t); 3375 default: typerr(t);
3372 } 3376 }
3373 } 3377 }
3374 3378
3375 case KlassPtr: 3379 case KlassPtr:
3380 } 3384 }
3381 3385
3382 //------------------------------xdual------------------------------------------ 3386 //------------------------------xdual------------------------------------------
3383 // Dual: compute field-by-field dual 3387 // Dual: compute field-by-field dual
3384 const Type *TypeAryPtr::xdual() const { 3388 const Type *TypeAryPtr::xdual() const {
3385 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() );
3386 } 3390 }
3387 3391
3388 //------------------------------dump2------------------------------------------ 3392 //------------------------------dump2------------------------------------------
3389 #ifndef PRODUCT 3393 #ifndef PRODUCT
3390 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 3394 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3417 int elem_size = type2aelembytes(basic_elem_type); 3421 int elem_size = type2aelembytes(basic_elem_type);
3418 st->print("[%d]", (_offset - array_base)/elem_size); 3422 st->print("[%d]", (_offset - array_base)/elem_size);
3419 } 3423 }
3420 } 3424 }
3421 st->print(" *"); 3425 st->print(" *");
3422 if (_instance_id != UNKNOWN_INSTANCE) 3426 if (_instance_id == InstanceTop)
3427 st->print(",iid=top");
3428 else if (_instance_id != InstanceBot)
3423 st->print(",iid=%d",_instance_id); 3429 st->print(",iid=%d",_instance_id);
3424 } 3430 }
3425 #endif 3431 #endif
3426 3432
3427 bool TypeAryPtr::empty(void) const { 3433 bool TypeAryPtr::empty(void) const {
3492 return Type::BOTTOM; 3498 return Type::BOTTOM;
3493 case Top: 3499 case Top:
3494 return this; 3500 return this;
3495 3501
3496 case NarrowOop: { 3502 case NarrowOop: {
3497 const Type* result = _ooptype->xmeet(t->is_narrowoop()->make_oopptr()); 3503 const Type* result = _ooptype->xmeet(t->make_ptr());
3498 if (result->isa_ptr()) { 3504 if (result->isa_ptr()) {
3499 return TypeNarrowOop::make(result->is_ptr()); 3505 return TypeNarrowOop::make(result->is_ptr());
3500 } 3506 }
3501 return result; 3507 return result;
3502 } 3508 }
3602 ciKlass* k_ary = NULL; 3608 ciKlass* k_ary = NULL;
3603 const TypeInstPtr *tinst; 3609 const TypeInstPtr *tinst;
3604 const TypeAryPtr *tary; 3610 const TypeAryPtr *tary;
3605 const Type* el = elem(); 3611 const Type* el = elem();
3606 if (el->isa_narrowoop()) { 3612 if (el->isa_narrowoop()) {
3607 el = el->is_narrowoop()->make_oopptr(); 3613 el = el->make_ptr();
3608 } 3614 }
3609 3615
3610 // Get element klass 3616 // Get element klass
3611 if ((tinst = el->isa_instptr()) != NULL) { 3617 if ((tinst = el->isa_instptr()) != NULL) {
3612 // Compute array klass from element klass 3618 // Compute array klass from element klass

mercurial