< prev index next >
src/share/vm/opto/type.cpp
Print this page
rev 9644 : 8145096: Undefined behaviour in HotSpot
Summary: Fix some integer overflows
Reviewed-by: duke
@@ -1368,12 +1368,12 @@
if (_lo < olo || _hi > ohi)
return this; // doesn't narrow; pretty wierd
// The new type narrows the old type, so look for a "death march".
// See comments on PhaseTransform::saturate.
- juint nrange = _hi - _lo;
- juint orange = ohi - olo;
+ juint nrange = (juint)_hi - _lo;
+ juint orange = (juint)ohi - olo;
if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
// Use the new type only if the range shrinks a lot.
// We do not want the optimizer computing 2^31 point by point.
return old;
}
@@ -1402,11 +1402,11 @@
}
//------------------------------hash-------------------------------------------
// Type-specific hashing function.
int TypeInt::hash(void) const {
- return _lo+_hi+_widen+(int)Type::Int;
+ return java_add(java_add(_lo, _hi), java_add(_widen, (int)Type::Int));
}
//------------------------------is_finite--------------------------------------
// Has a finite value
bool TypeInt::is_finite() const {
@@ -1583,11 +1583,11 @@
}
if (min < _lo && _hi < max) {
// If neither endpoint is extremal yet, push out the endpoint
// which is closer to its respective limit.
if (_lo >= 0 || // easy common case
- (julong)(_lo - min) >= (julong)(max - _hi)) {
+ ((julong)_lo - min) >= ((julong)max - _hi)) {
// Try to widen to an unsigned range type of 32/63 bits:
if (max >= max_juint && _hi < max_juint)
return make(_lo, max_juint, WidenMax);
else
return make(_lo, max, WidenMax);
@@ -2402,11 +2402,11 @@
}
//------------------------------hash-------------------------------------------
// Type-specific hashing function.
int TypePtr::hash(void) const {
- return _ptr + _offset + hash_speculative() + _inline_depth;
+ return java_add(java_add(_ptr, _offset), java_add( hash_speculative(), _inline_depth));
;
}
/**
* Return same type without a speculative part
@@ -3212,14 +3212,12 @@
//------------------------------hash-------------------------------------------
// Type-specific hashing function.
int TypeOopPtr::hash(void) const {
return
- (const_oop() ? const_oop()->hash() : 0) +
- _klass_is_exact +
- _instance_id +
- TypePtr::hash();
+ java_add(java_add(const_oop() ? const_oop()->hash() : 0, _klass_is_exact),
+ java_add(_instance_id, TypePtr::hash()));
}
//------------------------------dump2------------------------------------------
#ifndef PRODUCT
void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
@@ -3822,11 +3820,11 @@
}
//------------------------------hash-------------------------------------------
// Type-specific hashing function.
int TypeInstPtr::hash(void) const {
- int hash = klass()->hash() + TypeOopPtr::hash();
+ int hash = java_add(klass()->hash(), TypeOopPtr::hash());
return hash;
}
//------------------------------dump2------------------------------------------
// Dump oop Type
@@ -4740,11 +4738,11 @@
}
//------------------------------hash-------------------------------------------
// Type-specific hashing function.
int TypeKlassPtr::hash(void) const {
- return klass()->hash() + TypePtr::hash();
+ return java_add(klass()->hash(), TypePtr::hash());
}
//------------------------------singleton--------------------------------------
// TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
// constants
< prev index next >