132 } 133 return; 134 } 135 136 // Push the bool result back on stack 137 Node* res = gen_instanceof(peek(), makecon(TypeKlassPtr::make(klass)), true); 138 139 // Pop from stack AFTER gen_instanceof because it can uncommon trap. 140 pop(); 141 push(res); 142 } 143 144 //------------------------------array_store_check------------------------------ 145 // pull array from stack and check that the store is valid 146 Node* Parse::array_store_check() { 147 // Shorthand access to array store elements without popping them. 148 Node *obj = peek(0); 149 Node *idx = peek(1); 150 Node *ary = peek(2); 151 152 const Type* elemtype = _gvn.type(ary)->is_aryptr()->elem(); 153 const TypeOopPtr* elemptr = elemtype->make_oopptr(); 154 bool is_value_array = elemtype->isa_valuetype() != NULL || (elemptr != NULL && elemptr->is_valuetypeptr()); 155 bool can_be_value_array = is_value_array || (elemptr != NULL && (elemptr->can_be_value_type())); 156 157 if (_gvn.type(obj) == TypePtr::NULL_PTR) { 158 // There's never a type check on null values. 159 // This cutout lets us avoid the uncommon_trap(Reason_array_check) 160 // below, which turns into a performance liability if the 161 // gen_checkcast folds up completely. 162 if (is_value_array) { 163 // Can not store null into a value type array 164 uncommon_trap(Deoptimization::Reason_null_check, Deoptimization::Action_none); 165 return obj; 166 } else if (can_be_value_array) { 167 // Throw exception if array is a value type array 168 gen_value_type_array_guard(ary, zerocon(T_OBJECT)); 169 return obj; 170 } 171 return obj; 172 } 173 174 // Extract the array klass type 175 Node* array_klass = load_object_klass(ary); 176 // Get the array klass 177 const TypeKlassPtr *tak = _gvn.type(array_klass)->is_klassptr(); 178 179 // The type of array_klass is usually INexact array-of-oop. Heroically 180 // cast array_klass to EXACT array and uncommon-trap if the cast fails. 181 // Make constant out of the inexact array klass, but use it only if the cast 182 // succeeds. 183 bool always_see_exact_class = false; 184 if (MonomorphicArrayCheck 185 && !too_many_traps(Deoptimization::Reason_array_check) 186 && !tak->klass_is_exact() 187 && tak != TypeKlassPtr::OBJECT) { 188 // Regarding the fourth condition in the if-statement from above: 189 // 190 // If the compiler has determined that the type of array 'ary' (represented 235 } 236 237 // Come here for polymorphic array klasses 238 239 // Extract the array element class 240 int element_klass_offset = in_bytes(ArrayKlass::element_klass_offset()); 241 242 Node *p2 = basic_plus_adr(array_klass, array_klass, element_klass_offset); 243 // We are allowed to use the constant type only if cast succeeded. If always_see_exact_class is true, 244 // we must set a control edge from the IfTrue node created by the uncommon_trap above to the 245 // LoadKlassNode. 246 Node* a_e_klass = _gvn.transform(LoadKlassNode::make(_gvn, always_see_exact_class ? control() : NULL, 247 immutable_memory(), p2, tak)); 248 249 // Handle value type arrays 250 if (is_value_array) { 251 // We statically know that this is a value type array, use precise klass ptr 252 ciValueKlass* vk = elemtype->isa_valuetype() ? elemtype->is_valuetype()->value_klass() : 253 elemptr->value_klass(); 254 a_e_klass = makecon(TypeKlassPtr::make(vk)); 255 } else if (can_be_value_array && !obj->is_ValueType() && _gvn.type(obj)->is_oopptr()->can_be_value_type()) { 256 // We cannot statically determine if the array is a value type array 257 // and we also don't know if 'obj' is a value type. Emit runtime checks. 258 gen_value_type_array_guard(ary, obj, a_e_klass); 259 } 260 261 // Check (the hard way) and throw if not a subklass. 262 return gen_checkcast(obj, a_e_klass); 263 } 264 265 266 void Parse::emit_guard_for_new(ciInstanceKlass* klass) { 267 if ((!klass->is_initialized() && !klass->is_being_initialized()) || 268 klass->is_abstract() || klass->is_interface() || 269 klass->name() == ciSymbol::java_lang_Class() || 270 iter().is_unresolved_klass()) { 271 uncommon_trap(Deoptimization::Reason_uninitialized, 272 Deoptimization::Action_reinterpret, 273 klass); 274 } if (klass->is_being_initialized()) { 275 // Emit guarded new 276 // if (klass->_init_thread != current_thread || 277 // klass->_init_state != being_initialized) 278 // uncommon_trap | 132 } 133 return; 134 } 135 136 // Push the bool result back on stack 137 Node* res = gen_instanceof(peek(), makecon(TypeKlassPtr::make(klass)), true); 138 139 // Pop from stack AFTER gen_instanceof because it can uncommon trap. 140 pop(); 141 push(res); 142 } 143 144 //------------------------------array_store_check------------------------------ 145 // pull array from stack and check that the store is valid 146 Node* Parse::array_store_check() { 147 // Shorthand access to array store elements without popping them. 148 Node *obj = peek(0); 149 Node *idx = peek(1); 150 Node *ary = peek(2); 151 152 const TypeAryPtr* ary_t = _gvn.type(ary)->is_aryptr(); 153 const Type* elemtype = ary_t->elem(); 154 const TypeOopPtr* elemptr = elemtype->make_oopptr(); 155 bool is_value_array = elemtype->isa_valuetype() != NULL || (elemptr != NULL && elemptr->is_valuetypeptr()); 156 157 if (_gvn.type(obj) == TypePtr::NULL_PTR) { 158 // There's never a type check on null values. 159 // This cutout lets us avoid the uncommon_trap(Reason_array_check) 160 // below, which turns into a performance liability if the 161 // gen_checkcast folds up completely. 162 return obj; 163 } 164 165 // Extract the array klass type 166 Node* array_klass = load_object_klass(ary); 167 // Get the array klass 168 const TypeKlassPtr *tak = _gvn.type(array_klass)->is_klassptr(); 169 170 // The type of array_klass is usually INexact array-of-oop. Heroically 171 // cast array_klass to EXACT array and uncommon-trap if the cast fails. 172 // Make constant out of the inexact array klass, but use it only if the cast 173 // succeeds. 174 bool always_see_exact_class = false; 175 if (MonomorphicArrayCheck 176 && !too_many_traps(Deoptimization::Reason_array_check) 177 && !tak->klass_is_exact() 178 && tak != TypeKlassPtr::OBJECT) { 179 // Regarding the fourth condition in the if-statement from above: 180 // 181 // If the compiler has determined that the type of array 'ary' (represented 226 } 227 228 // Come here for polymorphic array klasses 229 230 // Extract the array element class 231 int element_klass_offset = in_bytes(ArrayKlass::element_klass_offset()); 232 233 Node *p2 = basic_plus_adr(array_klass, array_klass, element_klass_offset); 234 // We are allowed to use the constant type only if cast succeeded. If always_see_exact_class is true, 235 // we must set a control edge from the IfTrue node created by the uncommon_trap above to the 236 // LoadKlassNode. 237 Node* a_e_klass = _gvn.transform(LoadKlassNode::make(_gvn, always_see_exact_class ? control() : NULL, 238 immutable_memory(), p2, tak)); 239 240 // Handle value type arrays 241 if (is_value_array) { 242 // We statically know that this is a value type array, use precise klass ptr 243 ciValueKlass* vk = elemtype->isa_valuetype() ? elemtype->is_valuetype()->value_klass() : 244 elemptr->value_klass(); 245 a_e_klass = makecon(TypeKlassPtr::make(vk)); 246 } 247 248 // Check (the hard way) and throw if not a subklass. 249 return gen_checkcast(obj, a_e_klass); 250 } 251 252 253 void Parse::emit_guard_for_new(ciInstanceKlass* klass) { 254 if ((!klass->is_initialized() && !klass->is_being_initialized()) || 255 klass->is_abstract() || klass->is_interface() || 256 klass->name() == ciSymbol::java_lang_Class() || 257 iter().is_unresolved_klass()) { 258 uncommon_trap(Deoptimization::Reason_uninitialized, 259 Deoptimization::Action_reinterpret, 260 klass); 261 } if (klass->is_being_initialized()) { 262 // Emit guarded new 263 // if (klass->_init_thread != current_thread || 264 // klass->_init_state != being_initialized) 265 // uncommon_trap |