comparison src/share/vm/opto/type.cpp @ 10278:6f3fd5150b67

6934604: enable parts of EliminateAutoBox by default Summary: Resurrected autobox elimination code and enabled part of it by default. Reviewed-by: roland, twisti
author kvn
date Wed, 08 May 2013 15:08:01 -0700
parents 96ef09c26978
children edb5ab0f3fe5 7944aba7ba41
comparison
equal deleted inserted replaced
10277:aabf54ccedb1 10278:6f3fd5150b67
2370 : TypePtr(t, ptr, offset), 2370 : TypePtr(t, ptr, offset),
2371 _const_oop(o), _klass(k), 2371 _const_oop(o), _klass(k),
2372 _klass_is_exact(xk), 2372 _klass_is_exact(xk),
2373 _is_ptr_to_narrowoop(false), 2373 _is_ptr_to_narrowoop(false),
2374 _is_ptr_to_narrowklass(false), 2374 _is_ptr_to_narrowklass(false),
2375 _is_ptr_to_boxed_value(false),
2375 _instance_id(instance_id) { 2376 _instance_id(instance_id) {
2377 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
2378 (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
2379 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
2380 }
2376 #ifdef _LP64 2381 #ifdef _LP64
2377 if (_offset != 0) { 2382 if (_offset != 0) {
2378 if (_offset == oopDesc::klass_offset_in_bytes()) { 2383 if (_offset == oopDesc::klass_offset_in_bytes()) {
2379 _is_ptr_to_narrowklass = UseCompressedKlassPointers; 2384 _is_ptr_to_narrowklass = UseCompressedKlassPointers;
2380 } else if (klass() == NULL) { 2385 } else if (klass() == NULL) {
2611 } 2616 }
2612 } 2617 }
2613 2618
2614 //------------------------------make_from_constant----------------------------- 2619 //------------------------------make_from_constant-----------------------------
2615 // Make a java pointer from an oop constant 2620 // Make a java pointer from an oop constant
2616 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) { 2621 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o,
2617 assert(!o->is_null_object(), "null object not yet handled here."); 2622 bool require_constant,
2618 ciKlass* klass = o->klass(); 2623 bool is_autobox_cache) {
2619 if (klass->is_instance_klass()) { 2624 assert(!o->is_null_object(), "null object not yet handled here.");
2620 // Element is an instance 2625 ciKlass* klass = o->klass();
2621 if (require_constant) { 2626 if (klass->is_instance_klass()) {
2622 if (!o->can_be_constant()) return NULL; 2627 // Element is an instance
2623 } else if (!o->should_be_constant()) { 2628 if (require_constant) {
2624 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0); 2629 if (!o->can_be_constant()) return NULL;
2625 } 2630 } else if (!o->should_be_constant()) {
2626 return TypeInstPtr::make(o); 2631 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
2627 } else if (klass->is_obj_array_klass()) { 2632 }
2628 // Element is an object array. Recursively call ourself. 2633 return TypeInstPtr::make(o);
2629 const Type *etype = 2634 } else if (klass->is_obj_array_klass()) {
2635 // Element is an object array. Recursively call ourself.
2636 const TypeOopPtr *etype =
2630 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass()); 2637 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
2631 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 2638 if (is_autobox_cache) {
2632 // We used to pass NotNull in here, asserting that the sub-arrays 2639 // The pointers in the autobox arrays are always non-null.
2633 // are all not-null. This is not true in generally, as code can 2640 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
2634 // slam NULLs down in the subarrays. 2641 }
2635 if (require_constant) { 2642 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
2636 if (!o->can_be_constant()) return NULL; 2643 // We used to pass NotNull in here, asserting that the sub-arrays
2637 } else if (!o->should_be_constant()) { 2644 // are all not-null. This is not true in generally, as code can
2638 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); 2645 // slam NULLs down in the subarrays.
2639 } 2646 if (require_constant) {
2640 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); 2647 if (!o->can_be_constant()) return NULL;
2648 } else if (!o->should_be_constant()) {
2649 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
2650 }
2651 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0, InstanceBot, is_autobox_cache);
2641 return arr; 2652 return arr;
2642 } else if (klass->is_type_array_klass()) { 2653 } else if (klass->is_type_array_klass()) {
2643 // Element is an typeArray 2654 // Element is an typeArray
2644 const Type* etype = 2655 const Type* etype =
2645 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type()); 2656 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
2646 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 2657 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
2647 // We used to pass NotNull in here, asserting that the array pointer 2658 // We used to pass NotNull in here, asserting that the array pointer
2648 // is not-null. That was not true in general. 2659 // is not-null. That was not true in general.
2649 if (require_constant) { 2660 if (require_constant) {
2650 if (!o->can_be_constant()) return NULL; 2661 if (!o->can_be_constant()) return NULL;
2651 } else if (!o->should_be_constant()) { 2662 } else if (!o->should_be_constant()) {
2652 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); 2663 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
2653 } 2664 }
2654 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); 2665 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
2655 return arr; 2666 return arr;
2656 } 2667 }
2657 2668
2658 fatal("unhandled object type"); 2669 fatal("unhandled object type");
2854 (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id))->hashcons(); 2865 (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id))->hashcons();
2855 2866
2856 return result; 2867 return result;
2857 } 2868 }
2858 2869
2870 /**
2871 * Create constant type for a constant boxed value
2872 */
2873 const Type* TypeInstPtr::get_const_boxed_value() const {
2874 assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
2875 assert((const_oop() != NULL), "should be called only for constant object");
2876 ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
2877 BasicType bt = constant.basic_type();
2878 switch (bt) {
2879 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
2880 case T_INT: return TypeInt::make(constant.as_int());
2881 case T_CHAR: return TypeInt::make(constant.as_char());
2882 case T_BYTE: return TypeInt::make(constant.as_byte());
2883 case T_SHORT: return TypeInt::make(constant.as_short());
2884 case T_FLOAT: return TypeF::make(constant.as_float());
2885 case T_DOUBLE: return TypeD::make(constant.as_double());
2886 case T_LONG: return TypeLong::make(constant.as_long());
2887 default: break;
2888 }
2889 fatal(err_msg_res("Invalid boxed value type '%s'", type2name(bt)));
2890 return NULL;
2891 }
2859 2892
2860 //------------------------------cast_to_ptr_type------------------------------- 2893 //------------------------------cast_to_ptr_type-------------------------------
2861 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const { 2894 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
2862 if( ptr == _ptr ) return this; 2895 if( ptr == _ptr ) return this;
2863 // Reconstruct _sig info here since not a problem with later lazy 2896 // Reconstruct _sig info here since not a problem with later lazy
3328 assert(!(k == NULL && ary->_elem->isa_int()), 3361 assert(!(k == NULL && ary->_elem->isa_int()),
3329 "integral arrays must be pre-equipped with a class"); 3362 "integral arrays must be pre-equipped with a class");
3330 if (!xk) xk = ary->ary_must_be_exact(); 3363 if (!xk) xk = ary->ary_must_be_exact();
3331 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 3364 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3332 if (!UseExactTypes) xk = (ptr == Constant); 3365 if (!UseExactTypes) xk = (ptr == Constant);
3333 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id))->hashcons(); 3366 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false))->hashcons();
3334 } 3367 }
3335 3368
3336 //------------------------------make------------------------------------------- 3369 //------------------------------make-------------------------------------------
3337 const TypeAryPtr *TypeAryPtr::make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) { 3370 const TypeAryPtr *TypeAryPtr::make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, bool is_autobox_cache) {
3338 assert(!(k == NULL && ary->_elem->isa_int()), 3371 assert(!(k == NULL && ary->_elem->isa_int()),
3339 "integral arrays must be pre-equipped with a class"); 3372 "integral arrays must be pre-equipped with a class");
3340 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" ); 3373 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
3341 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact(); 3374 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact();
3342 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 3375 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3343 if (!UseExactTypes) xk = (ptr == Constant); 3376 if (!UseExactTypes) xk = (ptr == Constant);
3344 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id))->hashcons(); 3377 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache))->hashcons();
3345 } 3378 }
3346 3379
3347 //------------------------------cast_to_ptr_type------------------------------- 3380 //------------------------------cast_to_ptr_type-------------------------------
3348 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const { 3381 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
3349 if( ptr == _ptr ) return this; 3382 if( ptr == _ptr ) return this;
3395 jint lo = size->_lo; 3428 jint lo = size->_lo;
3396 jint min_lo = 0; 3429 jint min_lo = 0;
3397 jint max_hi = max_array_length(elem()->basic_type()); 3430 jint max_hi = max_array_length(elem()->basic_type());
3398 //if (index_not_size) --max_hi; // type of a valid array index, FTR 3431 //if (index_not_size) --max_hi; // type of a valid array index, FTR
3399 bool chg = false; 3432 bool chg = false;
3400 if (lo < min_lo) { lo = min_lo; chg = true; } 3433 if (lo < min_lo) {
3401 if (hi > max_hi) { hi = max_hi; chg = true; } 3434 lo = min_lo;
3435 if (size->is_con()) {
3436 hi = lo;
3437 }
3438 chg = true;
3439 }
3440 if (hi > max_hi) {
3441 hi = max_hi;
3442 if (size->is_con()) {
3443 lo = hi;
3444 }
3445 chg = true;
3446 }
3402 // Negative length arrays will produce weird intermediate dead fast-path code 3447 // Negative length arrays will produce weird intermediate dead fast-path code
3403 if (lo > hi) 3448 if (lo > hi)
3404 return TypeInt::ZERO; 3449 return TypeInt::ZERO;
3405 if (!chg) 3450 if (!chg)
3406 return size; 3451 return size;
3628 } 3673 }
3629 3674
3630 //------------------------------xdual------------------------------------------ 3675 //------------------------------xdual------------------------------------------
3631 // Dual: compute field-by-field dual 3676 // Dual: compute field-by-field dual
3632 const Type *TypeAryPtr::xdual() const { 3677 const Type *TypeAryPtr::xdual() const {
3633 return new TypeAryPtr( dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id() ); 3678 return new TypeAryPtr( dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id(), is_autobox_cache() );
3634 } 3679 }
3635 3680
3636 //----------------------interface_vs_oop--------------------------------------- 3681 //----------------------interface_vs_oop---------------------------------------
3637 #ifdef ASSERT 3682 #ifdef ASSERT
3638 bool TypeAryPtr::interface_vs_oop(const Type *t) const { 3683 bool TypeAryPtr::interface_vs_oop(const Type *t) const {