3226 |
3222 |
3227 //------------------------------make_from_constant----------------------------- |
3223 //------------------------------make_from_constant----------------------------- |
3228 // Make a java pointer from an oop constant |
3224 // Make a java pointer from an oop constant |
3229 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) { |
3225 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) { |
3230 assert(!o->is_null_object(), "null object not yet handled here."); |
3226 assert(!o->is_null_object(), "null object not yet handled here."); |
|
3227 |
|
3228 const bool make_constant = require_constant || o->should_be_constant(); |
|
3229 |
3231 ciKlass* klass = o->klass(); |
3230 ciKlass* klass = o->klass(); |
3232 if (klass->is_instance_klass()) { |
3231 if (klass->is_instance_klass()) { |
3233 // Element is an instance |
3232 // Element is an instance |
3234 if (require_constant) { |
3233 if (make_constant) { |
3235 if (!o->can_be_constant()) return NULL; |
3234 return TypeInstPtr::make(o); |
3236 } else if (!o->should_be_constant()) { |
3235 } else { |
3237 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0); |
3236 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0); |
3238 } |
3237 } |
3239 return TypeInstPtr::make(o); |
|
3240 } else if (klass->is_obj_array_klass()) { |
3238 } else if (klass->is_obj_array_klass()) { |
3241 // Element is an object array. Recursively call ourself. |
3239 // Element is an object array. Recursively call ourself. |
3242 const TypeOopPtr *etype = |
3240 const TypeOopPtr *etype = |
3243 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass()); |
3241 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass()); |
3244 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); |
3242 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); |
3245 // We used to pass NotNull in here, asserting that the sub-arrays |
3243 // We used to pass NotNull in here, asserting that the sub-arrays |
3246 // are all not-null. This is not true in generally, as code can |
3244 // are all not-null. This is not true in generally, as code can |
3247 // slam NULLs down in the subarrays. |
3245 // slam NULLs down in the subarrays. |
3248 if (require_constant) { |
3246 if (make_constant) { |
3249 if (!o->can_be_constant()) return NULL; |
3247 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); |
3250 } else if (!o->should_be_constant()) { |
3248 } else { |
3251 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); |
3249 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); |
3252 } |
3250 } |
3253 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); |
|
3254 return arr; |
|
3255 } else if (klass->is_type_array_klass()) { |
3251 } else if (klass->is_type_array_klass()) { |
3256 // Element is an typeArray |
3252 // Element is an typeArray |
3257 const Type* etype = |
3253 const Type* etype = |
3258 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type()); |
3254 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type()); |
3259 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); |
3255 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); |
3260 // We used to pass NotNull in here, asserting that the array pointer |
3256 // We used to pass NotNull in here, asserting that the array pointer |
3261 // is not-null. That was not true in general. |
3257 // is not-null. That was not true in general. |
3262 if (require_constant) { |
3258 if (make_constant) { |
3263 if (!o->can_be_constant()) return NULL; |
3259 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); |
3264 } else if (!o->should_be_constant()) { |
3260 } else { |
3265 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); |
3261 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); |
3266 } |
3262 } |
3267 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); |
|
3268 return arr; |
|
3269 } |
3263 } |
3270 |
3264 |
3271 fatal("unhandled object type"); |
3265 fatal("unhandled object type"); |
3272 return NULL; |
3266 return NULL; |
3273 } |
3267 } |