Mercurial > hg > truffle
comparison src/share/vm/opto/type.cpp @ 306:af945ba2e739
6741738: TypePtr::add_offset() set incorrect offset when the add overflows
Summary: Set offset to OffsetBot when the add overflows in TypePtr::add_offset()
Reviewed-by: jrose, never
author | kvn |
---|---|
date | Wed, 27 Aug 2008 14:47:32 -0700 |
parents | c3e045194476 |
children | 8261ee795323 |
comparison
equal
deleted
inserted
replaced
305:ab075d07f1ba | 306:af945ba2e739 |
---|---|
1954 }; | 1954 }; |
1955 const Type *TypePtr::xdual() const { | 1955 const Type *TypePtr::xdual() const { |
1956 return new TypePtr( AnyPtr, dual_ptr(), dual_offset() ); | 1956 return new TypePtr( AnyPtr, dual_ptr(), dual_offset() ); |
1957 } | 1957 } |
1958 | 1958 |
1959 //------------------------------xadd_offset------------------------------------ | |
1960 int TypePtr::xadd_offset( intptr_t offset ) const { | |
1961 // Adding to 'TOP' offset? Return 'TOP'! | |
1962 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop; | |
1963 // Adding to 'BOTTOM' offset? Return 'BOTTOM'! | |
1964 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot; | |
1965 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'! | |
1966 offset += (intptr_t)_offset; | |
1967 if (offset != (int)offset || offset == OffsetTop) return OffsetBot; | |
1968 | |
1969 // assert( _offset >= 0 && _offset+offset >= 0, "" ); | |
1970 // It is possible to construct a negative offset during PhaseCCP | |
1971 | |
1972 return (int)offset; // Sum valid offsets | |
1973 } | |
1974 | |
1959 //------------------------------add_offset------------------------------------- | 1975 //------------------------------add_offset------------------------------------- |
1960 const TypePtr *TypePtr::add_offset( int offset ) const { | 1976 const TypePtr *TypePtr::add_offset( intptr_t offset ) const { |
1961 if( offset == 0 ) return this; // No change | 1977 return make( AnyPtr, _ptr, xadd_offset(offset) ); |
1962 if( _offset == OffsetBot ) return this; | |
1963 if( offset == OffsetBot ) offset = OffsetBot; | |
1964 else if( _offset == OffsetTop || offset == OffsetTop ) offset = OffsetTop; | |
1965 else offset += _offset; | |
1966 return make( AnyPtr, _ptr, offset ); | |
1967 } | 1978 } |
1968 | 1979 |
1969 //------------------------------eq--------------------------------------------- | 1980 //------------------------------eq--------------------------------------------- |
1970 // Structural equality check for Type representations | 1981 // Structural equality check for Type representations |
1971 bool TypePtr::eq( const Type *t ) const { | 1982 bool TypePtr::eq( const Type *t ) const { |
2094 const Type *TypeRawPtr::xdual() const { | 2105 const Type *TypeRawPtr::xdual() const { |
2095 return new TypeRawPtr( dual_ptr(), _bits ); | 2106 return new TypeRawPtr( dual_ptr(), _bits ); |
2096 } | 2107 } |
2097 | 2108 |
2098 //------------------------------add_offset------------------------------------- | 2109 //------------------------------add_offset------------------------------------- |
2099 const TypePtr *TypeRawPtr::add_offset( int offset ) const { | 2110 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const { |
2100 if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer | 2111 if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer |
2101 if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer | 2112 if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer |
2102 if( offset == 0 ) return this; // No change | 2113 if( offset == 0 ) return this; // No change |
2103 switch (_ptr) { | 2114 switch (_ptr) { |
2104 case TypePtr::TopPTR: | 2115 case TypePtr::TopPTR: |
2543 // detune optimizer to not generate constant oop + constant offset as a constant! | 2554 // detune optimizer to not generate constant oop + constant offset as a constant! |
2544 // TopPTR, Null, AnyNull, Constant are all singletons | 2555 // TopPTR, Null, AnyNull, Constant are all singletons |
2545 return (_offset == 0) && !below_centerline(_ptr); | 2556 return (_offset == 0) && !below_centerline(_ptr); |
2546 } | 2557 } |
2547 | 2558 |
2548 //------------------------------xadd_offset------------------------------------ | |
2549 int TypeOopPtr::xadd_offset( int offset ) const { | |
2550 // Adding to 'TOP' offset? Return 'TOP'! | |
2551 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop; | |
2552 // Adding to 'BOTTOM' offset? Return 'BOTTOM'! | |
2553 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot; | |
2554 | |
2555 // assert( _offset >= 0 && _offset+offset >= 0, "" ); | |
2556 // It is possible to construct a negative offset during PhaseCCP | |
2557 | |
2558 return _offset+offset; // Sum valid offsets | |
2559 } | |
2560 | |
2561 //------------------------------add_offset------------------------------------- | 2559 //------------------------------add_offset------------------------------------- |
2562 const TypePtr *TypeOopPtr::add_offset( int offset ) const { | 2560 const TypePtr *TypeOopPtr::add_offset( intptr_t offset ) const { |
2563 return make( _ptr, xadd_offset(offset) ); | 2561 return make( _ptr, xadd_offset(offset) ); |
2564 } | 2562 } |
2565 | 2563 |
2566 //------------------------------meet_instance_id-------------------------------- | 2564 //------------------------------meet_instance_id-------------------------------- |
2567 int TypeOopPtr::meet_instance_id( int instance_id ) const { | 2565 int TypeOopPtr::meet_instance_id( int instance_id ) const { |
3074 st->print(",iid=%d",_instance_id); | 3072 st->print(",iid=%d",_instance_id); |
3075 } | 3073 } |
3076 #endif | 3074 #endif |
3077 | 3075 |
3078 //------------------------------add_offset------------------------------------- | 3076 //------------------------------add_offset------------------------------------- |
3079 const TypePtr *TypeInstPtr::add_offset( int offset ) const { | 3077 const TypePtr *TypeInstPtr::add_offset( intptr_t offset ) const { |
3080 return make( _ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id ); | 3078 return make( _ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id ); |
3081 } | 3079 } |
3082 | 3080 |
3083 //============================================================================= | 3081 //============================================================================= |
3084 // Convenience common pre-built types. | 3082 // Convenience common pre-built types. |
3425 if (_ary->empty()) return true; | 3423 if (_ary->empty()) return true; |
3426 return TypeOopPtr::empty(); | 3424 return TypeOopPtr::empty(); |
3427 } | 3425 } |
3428 | 3426 |
3429 //------------------------------add_offset------------------------------------- | 3427 //------------------------------add_offset------------------------------------- |
3430 const TypePtr *TypeAryPtr::add_offset( int offset ) const { | 3428 const TypePtr *TypeAryPtr::add_offset( intptr_t offset ) const { |
3431 return make( _ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id ); | 3429 return make( _ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id ); |
3432 } | 3430 } |
3433 | 3431 |
3434 | 3432 |
3435 //============================================================================= | 3433 //============================================================================= |
3652 } | 3650 } |
3653 | 3651 |
3654 | 3652 |
3655 //------------------------------add_offset------------------------------------- | 3653 //------------------------------add_offset------------------------------------- |
3656 // Access internals of klass object | 3654 // Access internals of klass object |
3657 const TypePtr *TypeKlassPtr::add_offset( int offset ) const { | 3655 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const { |
3658 return make( _ptr, klass(), xadd_offset(offset) ); | 3656 return make( _ptr, klass(), xadd_offset(offset) ); |
3659 } | 3657 } |
3660 | 3658 |
3661 //------------------------------cast_to_ptr_type------------------------------- | 3659 //------------------------------cast_to_ptr_type------------------------------- |
3662 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const { | 3660 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const { |