1.1 --- a/src/share/vm/opto/type.cpp Mon May 06 19:49:23 2013 -0700 1.2 +++ b/src/share/vm/opto/type.cpp Wed May 08 15:08:01 2013 -0700 1.3 @@ -2372,7 +2372,12 @@ 1.4 _klass_is_exact(xk), 1.5 _is_ptr_to_narrowoop(false), 1.6 _is_ptr_to_narrowklass(false), 1.7 + _is_ptr_to_boxed_value(false), 1.8 _instance_id(instance_id) { 1.9 + if (Compile::current()->eliminate_boxing() && (t == InstPtr) && 1.10 + (offset > 0) && xk && (k != 0) && k->is_instance_klass()) { 1.11 + _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset); 1.12 + } 1.13 #ifdef _LP64 1.14 if (_offset != 0) { 1.15 if (_offset == oopDesc::klass_offset_in_bytes()) { 1.16 @@ -2613,44 +2618,50 @@ 1.17 1.18 //------------------------------make_from_constant----------------------------- 1.19 // Make a java pointer from an oop constant 1.20 -const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) { 1.21 - assert(!o->is_null_object(), "null object not yet handled here."); 1.22 - ciKlass* klass = o->klass(); 1.23 - if (klass->is_instance_klass()) { 1.24 - // Element is an instance 1.25 - if (require_constant) { 1.26 - if (!o->can_be_constant()) return NULL; 1.27 - } else if (!o->should_be_constant()) { 1.28 - return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0); 1.29 - } 1.30 - return TypeInstPtr::make(o); 1.31 - } else if (klass->is_obj_array_klass()) { 1.32 - // Element is an object array. Recursively call ourself. 1.33 - const Type *etype = 1.34 +const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, 1.35 + bool require_constant, 1.36 + bool is_autobox_cache) { 1.37 + assert(!o->is_null_object(), "null object not yet handled here."); 1.38 + ciKlass* klass = o->klass(); 1.39 + if (klass->is_instance_klass()) { 1.40 + // Element is an instance 1.41 + if (require_constant) { 1.42 + if (!o->can_be_constant()) return NULL; 1.43 + } else if (!o->should_be_constant()) { 1.44 + return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0); 1.45 + } 1.46 + return TypeInstPtr::make(o); 1.47 + } else if (klass->is_obj_array_klass()) { 1.48 + // Element is an object array. Recursively call ourself. 1.49 + const TypeOopPtr *etype = 1.50 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass()); 1.51 - const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 1.52 - // We used to pass NotNull in here, asserting that the sub-arrays 1.53 - // are all not-null. This is not true in generally, as code can 1.54 - // slam NULLs down in the subarrays. 1.55 - if (require_constant) { 1.56 - if (!o->can_be_constant()) return NULL; 1.57 - } else if (!o->should_be_constant()) { 1.58 - return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); 1.59 - } 1.60 - const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); 1.61 + if (is_autobox_cache) { 1.62 + // The pointers in the autobox arrays are always non-null. 1.63 + etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr(); 1.64 + } 1.65 + const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 1.66 + // We used to pass NotNull in here, asserting that the sub-arrays 1.67 + // are all not-null. This is not true in generally, as code can 1.68 + // slam NULLs down in the subarrays. 1.69 + if (require_constant) { 1.70 + if (!o->can_be_constant()) return NULL; 1.71 + } else if (!o->should_be_constant()) { 1.72 + return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); 1.73 + } 1.74 + const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0, InstanceBot, is_autobox_cache); 1.75 return arr; 1.76 - } else if (klass->is_type_array_klass()) { 1.77 - // Element is an typeArray 1.78 + } else if (klass->is_type_array_klass()) { 1.79 + // Element is an typeArray 1.80 const Type* etype = 1.81 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type()); 1.82 - const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 1.83 - // We used to pass NotNull in here, asserting that the array pointer 1.84 - // is not-null. That was not true in general. 1.85 - if (require_constant) { 1.86 - if (!o->can_be_constant()) return NULL; 1.87 - } else if (!o->should_be_constant()) { 1.88 - return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); 1.89 - } 1.90 + const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 1.91 + // We used to pass NotNull in here, asserting that the array pointer 1.92 + // is not-null. That was not true in general. 1.93 + if (require_constant) { 1.94 + if (!o->can_be_constant()) return NULL; 1.95 + } else if (!o->should_be_constant()) { 1.96 + return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); 1.97 + } 1.98 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); 1.99 return arr; 1.100 } 1.101 @@ -2856,6 +2867,28 @@ 1.102 return result; 1.103 } 1.104 1.105 +/** 1.106 + * Create constant type for a constant boxed value 1.107 + */ 1.108 +const Type* TypeInstPtr::get_const_boxed_value() const { 1.109 + assert(is_ptr_to_boxed_value(), "should be called only for boxed value"); 1.110 + assert((const_oop() != NULL), "should be called only for constant object"); 1.111 + ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset()); 1.112 + BasicType bt = constant.basic_type(); 1.113 + switch (bt) { 1.114 + case T_BOOLEAN: return TypeInt::make(constant.as_boolean()); 1.115 + case T_INT: return TypeInt::make(constant.as_int()); 1.116 + case T_CHAR: return TypeInt::make(constant.as_char()); 1.117 + case T_BYTE: return TypeInt::make(constant.as_byte()); 1.118 + case T_SHORT: return TypeInt::make(constant.as_short()); 1.119 + case T_FLOAT: return TypeF::make(constant.as_float()); 1.120 + case T_DOUBLE: return TypeD::make(constant.as_double()); 1.121 + case T_LONG: return TypeLong::make(constant.as_long()); 1.122 + default: break; 1.123 + } 1.124 + fatal(err_msg_res("Invalid boxed value type '%s'", type2name(bt))); 1.125 + return NULL; 1.126 +} 1.127 1.128 //------------------------------cast_to_ptr_type------------------------------- 1.129 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const { 1.130 @@ -3330,18 +3363,18 @@ 1.131 if (!xk) xk = ary->ary_must_be_exact(); 1.132 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 1.133 if (!UseExactTypes) xk = (ptr == Constant); 1.134 - return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id))->hashcons(); 1.135 + return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false))->hashcons(); 1.136 } 1.137 1.138 //------------------------------make------------------------------------------- 1.139 -const TypeAryPtr *TypeAryPtr::make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) { 1.140 +const TypeAryPtr *TypeAryPtr::make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, bool is_autobox_cache) { 1.141 assert(!(k == NULL && ary->_elem->isa_int()), 1.142 "integral arrays must be pre-equipped with a class"); 1.143 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" ); 1.144 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact(); 1.145 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 1.146 if (!UseExactTypes) xk = (ptr == Constant); 1.147 - return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id))->hashcons(); 1.148 + return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache))->hashcons(); 1.149 } 1.150 1.151 //------------------------------cast_to_ptr_type------------------------------- 1.152 @@ -3397,8 +3430,20 @@ 1.153 jint max_hi = max_array_length(elem()->basic_type()); 1.154 //if (index_not_size) --max_hi; // type of a valid array index, FTR 1.155 bool chg = false; 1.156 - if (lo < min_lo) { lo = min_lo; chg = true; } 1.157 - if (hi > max_hi) { hi = max_hi; chg = true; } 1.158 + if (lo < min_lo) { 1.159 + lo = min_lo; 1.160 + if (size->is_con()) { 1.161 + hi = lo; 1.162 + } 1.163 + chg = true; 1.164 + } 1.165 + if (hi > max_hi) { 1.166 + hi = max_hi; 1.167 + if (size->is_con()) { 1.168 + lo = hi; 1.169 + } 1.170 + chg = true; 1.171 + } 1.172 // Negative length arrays will produce weird intermediate dead fast-path code 1.173 if (lo > hi) 1.174 return TypeInt::ZERO; 1.175 @@ -3630,7 +3675,7 @@ 1.176 //------------------------------xdual------------------------------------------ 1.177 // Dual: compute field-by-field dual 1.178 const Type *TypeAryPtr::xdual() const { 1.179 - return new TypeAryPtr( dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id() ); 1.180 + return new TypeAryPtr( dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id(), is_autobox_cache() ); 1.181 } 1.182 1.183 //----------------------interface_vs_oop---------------------------------------