1312 // Only happens for pessimistic optimizations.
1313 const Type *TypeInt::narrow( const Type *old ) const {
1314 if (_lo >= _hi) return this; // already narrow enough
1315 if (old == NULL) return this;
1316 const TypeInt* ot = old->isa_int();
1317 if (ot == NULL) return this;
1318 jint olo = ot->_lo;
1319 jint ohi = ot->_hi;
1320
1321 // If new guy is equal to old guy, no narrowing
1322 if (_lo == olo && _hi == ohi) return old;
1323
1324 // If old guy was maximum range, allow the narrowing
1325 if (olo == min_jint && ohi == max_jint) return this;
1326
1327 if (_lo < olo || _hi > ohi)
1328 return this; // doesn't narrow; pretty wierd
1329
1330 // The new type narrows the old type, so look for a "death march".
1331 // See comments on PhaseTransform::saturate.
1332 juint nrange = _hi - _lo;
1333 juint orange = ohi - olo;
1334 if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1335 // Use the new type only if the range shrinks a lot.
1336 // We do not want the optimizer computing 2^31 point by point.
1337 return old;
1338 }
1339
1340 return this;
1341 }
1342
1343 //-----------------------------filter------------------------------------------
1344 const Type *TypeInt::filter_helper(const Type *kills, bool include_speculative) const {
1345 const TypeInt* ft = join_helper(kills, include_speculative)->isa_int();
1346 if (ft == NULL || ft->empty())
1347 return Type::TOP; // Canonical empty value
1348 if (ft->_widen < this->_widen) {
1349 // Do not allow the value of kill->_widen to affect the outcome.
1350 // The widen bits must be allowed to run freely through the graph.
1351 ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
1352 }
1353 return ft;
1354 }
1355
1356 //------------------------------eq---------------------------------------------
1357 // Structural equality check for Type representations
1358 bool TypeInt::eq( const Type *t ) const {
1359 const TypeInt *r = t->is_int(); // Handy access
1360 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1361 }
1362
1363 //------------------------------hash-------------------------------------------
1364 // Type-specific hashing function.
1365 int TypeInt::hash(void) const {
1366 return _lo+_hi+_widen+(int)Type::Int;
1367 }
1368
1369 //------------------------------is_finite--------------------------------------
1370 // Has a finite value
1371 bool TypeInt::is_finite() const {
1372 return true;
1373 }
1374
1375 //------------------------------dump2------------------------------------------
1376 // Dump TypeInt
1377 #ifndef PRODUCT
1378 static const char* intname(char* buf, jint n) {
1379 if (n == min_jint)
1380 return "min";
1381 else if (n < min_jint + 10000)
1382 sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
1383 else if (n == max_jint)
1384 return "max";
1385 else if (n > max_jint - 10000)
1386 sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
1527 // If new guy contains old, then we widened
1528 if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1529 // New contains old
1530 // If new guy is already wider than old, no widening
1531 if( _widen > ot->_widen ) return this;
1532 // If old guy was a constant, do not bother
1533 if (ot->_lo == ot->_hi) return this;
1534 // Now widen new guy.
1535 // Check for widening too far
1536 if (_widen == WidenMax) {
1537 jlong max = max_jlong;
1538 jlong min = min_jlong;
1539 if (limit->isa_long()) {
1540 max = limit->is_long()->_hi;
1541 min = limit->is_long()->_lo;
1542 }
1543 if (min < _lo && _hi < max) {
1544 // If neither endpoint is extremal yet, push out the endpoint
1545 // which is closer to its respective limit.
1546 if (_lo >= 0 || // easy common case
1547 (julong)(_lo - min) >= (julong)(max - _hi)) {
1548 // Try to widen to an unsigned range type of 32/63 bits:
1549 if (max >= max_juint && _hi < max_juint)
1550 return make(_lo, max_juint, WidenMax);
1551 else
1552 return make(_lo, max, WidenMax);
1553 } else {
1554 return make(min, _hi, WidenMax);
1555 }
1556 }
1557 return TypeLong::LONG;
1558 }
1559 // Returned widened new guy
1560 return make(_lo,_hi,_widen+1);
1561 }
1562
1563 // If old guy contains new, then we probably widened too far & dropped to
1564 // bottom. Return the wider fellow.
1565 if ( ot->_lo <= _lo && ot->_hi >= _hi )
1566 return old;
1567
2297 // It is possible to construct a negative offset during PhaseCCP
2298
2299 return (int)offset; // Sum valid offsets
2300 }
2301
2302 //------------------------------add_offset-------------------------------------
2303 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2304 return make( AnyPtr, _ptr, xadd_offset(offset) );
2305 }
2306
2307 //------------------------------eq---------------------------------------------
2308 // Structural equality check for Type representations
2309 bool TypePtr::eq( const Type *t ) const {
2310 const TypePtr *a = (const TypePtr*)t;
2311 return _ptr == a->ptr() && _offset == a->offset();
2312 }
2313
2314 //------------------------------hash-------------------------------------------
2315 // Type-specific hashing function.
2316 int TypePtr::hash(void) const {
2317 return _ptr + _offset;
2318 }
2319
2320 //------------------------------dump2------------------------------------------
2321 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2322 "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2323 };
2324
2325 #ifndef PRODUCT
2326 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2327 if( _ptr == Null ) st->print("NULL");
2328 else st->print("%s *", ptr_msg[_ptr]);
2329 if( _offset == OffsetTop ) st->print("+top");
2330 else if( _offset == OffsetBot ) st->print("+bot");
2331 else if( _offset ) st->print("+%d", _offset);
2332 }
2333 #endif
2334
2335 //------------------------------singleton--------------------------------------
2336 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2337 // constants
2887 // Structural equality check for Type representations
2888 bool TypeOopPtr::eq( const Type *t ) const {
2889 const TypeOopPtr *a = (const TypeOopPtr*)t;
2890 if (_klass_is_exact != a->_klass_is_exact ||
2891 _instance_id != a->_instance_id ||
2892 !eq_speculative(a) ||
2893 _inline_depth != a->_inline_depth) return false;
2894 ciObject* one = const_oop();
2895 ciObject* two = a->const_oop();
2896 if (one == NULL || two == NULL) {
2897 return (one == two) && TypePtr::eq(t);
2898 } else {
2899 return one->equals(two) && TypePtr::eq(t);
2900 }
2901 }
2902
2903 //------------------------------hash-------------------------------------------
2904 // Type-specific hashing function.
2905 int TypeOopPtr::hash(void) const {
2906 return
2907 (const_oop() ? const_oop()->hash() : 0) +
2908 _klass_is_exact +
2909 _instance_id +
2910 hash_speculative() +
2911 _inline_depth +
2912 TypePtr::hash();
2913 }
2914
2915 //------------------------------dump2------------------------------------------
2916 #ifndef PRODUCT
2917 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2918 st->print("oopptr:%s", ptr_msg[_ptr]);
2919 if( _klass_is_exact ) st->print(":exact");
2920 if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
2921 switch( _offset ) {
2922 case OffsetTop: st->print("+top"); break;
2923 case OffsetBot: st->print("+any"); break;
2924 case 0: break;
2925 default: st->print("+%d",_offset); break;
2926 }
2927 if (_instance_id == InstanceTop)
2928 st->print(",iid=top");
2929 else if (_instance_id != InstanceBot)
2930 st->print(",iid=%d",_instance_id);
2931
2932 dump_inline_depth(st);
3618
3619 //------------------------------xdual------------------------------------------
3620 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
3621 // inheritance mechanism.
3622 const Type *TypeInstPtr::xdual() const {
3623 return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3624 }
3625
3626 //------------------------------eq---------------------------------------------
3627 // Structural equality check for Type representations
3628 bool TypeInstPtr::eq( const Type *t ) const {
3629 const TypeInstPtr *p = t->is_instptr();
3630 return
3631 klass()->equals(p->klass()) &&
3632 TypeOopPtr::eq(p); // Check sub-type stuff
3633 }
3634
3635 //------------------------------hash-------------------------------------------
3636 // Type-specific hashing function.
3637 int TypeInstPtr::hash(void) const {
3638 int hash = klass()->hash() + TypeOopPtr::hash();
3639 return hash;
3640 }
3641
3642 //------------------------------dump2------------------------------------------
3643 // Dump oop Type
3644 #ifndef PRODUCT
3645 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3646 // Print the name of the klass.
3647 klass()->print_name_on(st);
3648
3649 switch( _ptr ) {
3650 case Constant:
3651 // TO DO: Make CI print the hex address of the underlying oop.
3652 if (WizardMode || Verbose) {
3653 const_oop()->print_oop(st);
3654 }
3655 case BotPTR:
3656 if (!WizardMode && !Verbose) {
3657 if( _klass_is_exact ) st->print(":exact");
3658 break;
4513 assert( k != NULL, "Expect a non-NULL klass");
4514 assert(k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
4515 TypeKlassPtr *r =
4516 (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
4517
4518 return r;
4519 }
4520
4521 //------------------------------eq---------------------------------------------
4522 // Structural equality check for Type representations
4523 bool TypeKlassPtr::eq( const Type *t ) const {
4524 const TypeKlassPtr *p = t->is_klassptr();
4525 return
4526 klass()->equals(p->klass()) &&
4527 TypePtr::eq(p);
4528 }
4529
4530 //------------------------------hash-------------------------------------------
4531 // Type-specific hashing function.
4532 int TypeKlassPtr::hash(void) const {
4533 return klass()->hash() + TypePtr::hash();
4534 }
4535
4536 //------------------------------singleton--------------------------------------
4537 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4538 // constants
4539 bool TypeKlassPtr::singleton(void) const {
4540 // detune optimizer to not generate constant klass + constant offset as a constant!
4541 // TopPTR, Null, AnyNull, Constant are all singletons
4542 return (_offset == 0) && !below_centerline(_ptr);
4543 }
4544
4545 // Do not allow interface-vs.-noninterface joins to collapse to top.
4546 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
4547 // logic here mirrors the one from TypeOopPtr::filter. See comments
4548 // there.
4549 const Type* ft = join_helper(kills, include_speculative);
4550 const TypeKlassPtr* ftkp = ft->isa_klassptr();
4551 const TypeKlassPtr* ktkp = kills->isa_klassptr();
4552
4553 if (ft->empty()) {
|
1312 // Only happens for pessimistic optimizations.
1313 const Type *TypeInt::narrow( const Type *old ) const {
1314 if (_lo >= _hi) return this; // already narrow enough
1315 if (old == NULL) return this;
1316 const TypeInt* ot = old->isa_int();
1317 if (ot == NULL) return this;
1318 jint olo = ot->_lo;
1319 jint ohi = ot->_hi;
1320
1321 // If new guy is equal to old guy, no narrowing
1322 if (_lo == olo && _hi == ohi) return old;
1323
1324 // If old guy was maximum range, allow the narrowing
1325 if (olo == min_jint && ohi == max_jint) return this;
1326
1327 if (_lo < olo || _hi > ohi)
1328 return this; // doesn't narrow; pretty wierd
1329
1330 // The new type narrows the old type, so look for a "death march".
1331 // See comments on PhaseTransform::saturate.
1332 juint nrange = (juint)_hi - _lo;
1333 juint orange = (juint)ohi - olo;
1334 if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1335 // Use the new type only if the range shrinks a lot.
1336 // We do not want the optimizer computing 2^31 point by point.
1337 return old;
1338 }
1339
1340 return this;
1341 }
1342
1343 //-----------------------------filter------------------------------------------
1344 const Type *TypeInt::filter_helper(const Type *kills, bool include_speculative) const {
1345 const TypeInt* ft = join_helper(kills, include_speculative)->isa_int();
1346 if (ft == NULL || ft->empty())
1347 return Type::TOP; // Canonical empty value
1348 if (ft->_widen < this->_widen) {
1349 // Do not allow the value of kill->_widen to affect the outcome.
1350 // The widen bits must be allowed to run freely through the graph.
1351 ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
1352 }
1353 return ft;
1354 }
1355
1356 //------------------------------eq---------------------------------------------
1357 // Structural equality check for Type representations
1358 bool TypeInt::eq( const Type *t ) const {
1359 const TypeInt *r = t->is_int(); // Handy access
1360 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1361 }
1362
1363 //------------------------------hash-------------------------------------------
1364 // Type-specific hashing function.
1365 int TypeInt::hash(void) const {
1366 return java_add(java_add(_lo, _hi), java_add(_widen, (int)Type::Int));
1367 }
1368
1369 //------------------------------is_finite--------------------------------------
1370 // Has a finite value
1371 bool TypeInt::is_finite() const {
1372 return true;
1373 }
1374
1375 //------------------------------dump2------------------------------------------
1376 // Dump TypeInt
1377 #ifndef PRODUCT
1378 static const char* intname(char* buf, jint n) {
1379 if (n == min_jint)
1380 return "min";
1381 else if (n < min_jint + 10000)
1382 sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
1383 else if (n == max_jint)
1384 return "max";
1385 else if (n > max_jint - 10000)
1386 sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
1527 // If new guy contains old, then we widened
1528 if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1529 // New contains old
1530 // If new guy is already wider than old, no widening
1531 if( _widen > ot->_widen ) return this;
1532 // If old guy was a constant, do not bother
1533 if (ot->_lo == ot->_hi) return this;
1534 // Now widen new guy.
1535 // Check for widening too far
1536 if (_widen == WidenMax) {
1537 jlong max = max_jlong;
1538 jlong min = min_jlong;
1539 if (limit->isa_long()) {
1540 max = limit->is_long()->_hi;
1541 min = limit->is_long()->_lo;
1542 }
1543 if (min < _lo && _hi < max) {
1544 // If neither endpoint is extremal yet, push out the endpoint
1545 // which is closer to its respective limit.
1546 if (_lo >= 0 || // easy common case
1547 ((julong)_lo - min) >= ((julong)max - _hi)) {
1548 // Try to widen to an unsigned range type of 32/63 bits:
1549 if (max >= max_juint && _hi < max_juint)
1550 return make(_lo, max_juint, WidenMax);
1551 else
1552 return make(_lo, max, WidenMax);
1553 } else {
1554 return make(min, _hi, WidenMax);
1555 }
1556 }
1557 return TypeLong::LONG;
1558 }
1559 // Returned widened new guy
1560 return make(_lo,_hi,_widen+1);
1561 }
1562
1563 // If old guy contains new, then we probably widened too far & dropped to
1564 // bottom. Return the wider fellow.
1565 if ( ot->_lo <= _lo && ot->_hi >= _hi )
1566 return old;
1567
2297 // It is possible to construct a negative offset during PhaseCCP
2298
2299 return (int)offset; // Sum valid offsets
2300 }
2301
2302 //------------------------------add_offset-------------------------------------
2303 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2304 return make( AnyPtr, _ptr, xadd_offset(offset) );
2305 }
2306
2307 //------------------------------eq---------------------------------------------
2308 // Structural equality check for Type representations
2309 bool TypePtr::eq( const Type *t ) const {
2310 const TypePtr *a = (const TypePtr*)t;
2311 return _ptr == a->ptr() && _offset == a->offset();
2312 }
2313
2314 //------------------------------hash-------------------------------------------
2315 // Type-specific hashing function.
2316 int TypePtr::hash(void) const {
2317 return java_add(_ptr, _offset);
2318 }
2319
2320 //------------------------------dump2------------------------------------------
2321 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2322 "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2323 };
2324
2325 #ifndef PRODUCT
2326 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2327 if( _ptr == Null ) st->print("NULL");
2328 else st->print("%s *", ptr_msg[_ptr]);
2329 if( _offset == OffsetTop ) st->print("+top");
2330 else if( _offset == OffsetBot ) st->print("+bot");
2331 else if( _offset ) st->print("+%d", _offset);
2332 }
2333 #endif
2334
2335 //------------------------------singleton--------------------------------------
2336 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2337 // constants
2887 // Structural equality check for Type representations
2888 bool TypeOopPtr::eq( const Type *t ) const {
2889 const TypeOopPtr *a = (const TypeOopPtr*)t;
2890 if (_klass_is_exact != a->_klass_is_exact ||
2891 _instance_id != a->_instance_id ||
2892 !eq_speculative(a) ||
2893 _inline_depth != a->_inline_depth) return false;
2894 ciObject* one = const_oop();
2895 ciObject* two = a->const_oop();
2896 if (one == NULL || two == NULL) {
2897 return (one == two) && TypePtr::eq(t);
2898 } else {
2899 return one->equals(two) && TypePtr::eq(t);
2900 }
2901 }
2902
2903 //------------------------------hash-------------------------------------------
2904 // Type-specific hashing function.
2905 int TypeOopPtr::hash(void) const {
2906 return
2907 java_add(java_add(java_add(const_oop() ? const_oop()->hash() : 0, _klass_is_exact),
2908 java_add(_instance_id , hash_speculative())), java_add(_inline_depth , TypePtr::hash()));
2909 }
2910
2911 //------------------------------dump2------------------------------------------
2912 #ifndef PRODUCT
2913 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2914 st->print("oopptr:%s", ptr_msg[_ptr]);
2915 if( _klass_is_exact ) st->print(":exact");
2916 if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
2917 switch( _offset ) {
2918 case OffsetTop: st->print("+top"); break;
2919 case OffsetBot: st->print("+any"); break;
2920 case 0: break;
2921 default: st->print("+%d",_offset); break;
2922 }
2923 if (_instance_id == InstanceTop)
2924 st->print(",iid=top");
2925 else if (_instance_id != InstanceBot)
2926 st->print(",iid=%d",_instance_id);
2927
2928 dump_inline_depth(st);
3614
3615 //------------------------------xdual------------------------------------------
3616 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
3617 // inheritance mechanism.
3618 const Type *TypeInstPtr::xdual() const {
3619 return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3620 }
3621
3622 //------------------------------eq---------------------------------------------
3623 // Structural equality check for Type representations
3624 bool TypeInstPtr::eq( const Type *t ) const {
3625 const TypeInstPtr *p = t->is_instptr();
3626 return
3627 klass()->equals(p->klass()) &&
3628 TypeOopPtr::eq(p); // Check sub-type stuff
3629 }
3630
3631 //------------------------------hash-------------------------------------------
3632 // Type-specific hashing function.
3633 int TypeInstPtr::hash(void) const {
3634 int hash = java_add(klass()->hash(), TypeOopPtr::hash());
3635 return hash;
3636 }
3637
3638 //------------------------------dump2------------------------------------------
3639 // Dump oop Type
3640 #ifndef PRODUCT
3641 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3642 // Print the name of the klass.
3643 klass()->print_name_on(st);
3644
3645 switch( _ptr ) {
3646 case Constant:
3647 // TO DO: Make CI print the hex address of the underlying oop.
3648 if (WizardMode || Verbose) {
3649 const_oop()->print_oop(st);
3650 }
3651 case BotPTR:
3652 if (!WizardMode && !Verbose) {
3653 if( _klass_is_exact ) st->print(":exact");
3654 break;
4509 assert( k != NULL, "Expect a non-NULL klass");
4510 assert(k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
4511 TypeKlassPtr *r =
4512 (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
4513
4514 return r;
4515 }
4516
4517 //------------------------------eq---------------------------------------------
4518 // Structural equality check for Type representations
4519 bool TypeKlassPtr::eq( const Type *t ) const {
4520 const TypeKlassPtr *p = t->is_klassptr();
4521 return
4522 klass()->equals(p->klass()) &&
4523 TypePtr::eq(p);
4524 }
4525
4526 //------------------------------hash-------------------------------------------
4527 // Type-specific hashing function.
4528 int TypeKlassPtr::hash(void) const {
4529 return java_add(klass()->hash(), TypePtr::hash());
4530 }
4531
4532 //------------------------------singleton--------------------------------------
4533 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4534 // constants
4535 bool TypeKlassPtr::singleton(void) const {
4536 // detune optimizer to not generate constant klass + constant offset as a constant!
4537 // TopPTR, Null, AnyNull, Constant are all singletons
4538 return (_offset == 0) && !below_centerline(_ptr);
4539 }
4540
4541 // Do not allow interface-vs.-noninterface joins to collapse to top.
4542 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
4543 // logic here mirrors the one from TypeOopPtr::filter. See comments
4544 // there.
4545 const Type* ft = join_helper(kills, include_speculative);
4546 const TypeKlassPtr* ftkp = ft->isa_klassptr();
4547 const TypeKlassPtr* ktkp = kills->isa_klassptr();
4548
4549 if (ft->empty()) {
|