< prev index next >

src/hotspot/share/c1/c1_Instruction.cpp

Print this page

  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "c1/c1_IR.hpp"
  27 #include "c1/c1_Instruction.hpp"
  28 #include "c1/c1_InstructionPrinter.hpp"
  29 #include "c1/c1_ValueStack.hpp"


  30 #include "ci/ciObjArrayKlass.hpp"
  31 #include "ci/ciTypeArrayKlass.hpp"
  32 #include "utilities/bitMap.inline.hpp"
  33 
  34 
  35 // Implementation of Instruction
  36 
  37 
  38 int Instruction::dominator_depth() {
  39   int result = -1;
  40   if (block()) {
  41     result = block()->dominator_depth();
  42   }
  43   assert(result != -1 || this->as_Local(), "Only locals have dominator depth -1");
  44   return result;
  45 }
  46 
  47 Instruction::Condition Instruction::mirror(Condition cond) {
  48   switch (cond) {
  49     case eql: return eql;

  89   Instruction* p = nullptr;
  90   Instruction* q = block();
  91   while (q != this) {
  92     assert(q != nullptr, "this is not in the block's instruction list");
  93     p = q; q = q->next();
  94   }
  95   return p;
  96 }
  97 
  98 
  99 void Instruction::state_values_do(ValueVisitor* f) {
 100   if (state_before() != nullptr) {
 101     state_before()->values_do(f);
 102   }
 103   if (exception_state() != nullptr) {
 104     exception_state()->values_do(f);
 105   }
 106 }
 107 
 108 ciType* Instruction::exact_type() const {
 109   ciType* t =  declared_type();
 110   if (t != nullptr && t->is_klass()) {
 111     return t->as_klass()->exact_klass();
 112   }
 113   return nullptr;
 114 }
 115 




























































 116 
 117 #ifndef PRODUCT
 118 void Instruction::check_state(ValueStack* state) {
 119   if (state != nullptr) {
 120     state->verify();
 121   }
 122 }
 123 
 124 
 125 void Instruction::print() {
 126   InstructionPrinter ip;
 127   print(ip);
 128 }
 129 
 130 
 131 void Instruction::print_line() {
 132   InstructionPrinter ip;
 133   ip.print_line(this);
 134 }
 135 

 156     }
 157   }
 158 
 159   if (!this->check_flag(NeedsRangeCheckFlag)) {
 160     return false;
 161   }
 162 
 163   return true;
 164 }
 165 
 166 
 167 ciType* Constant::exact_type() const {
 168   if (type()->is_object() && type()->as_ObjectType()->is_loaded()) {
 169     return type()->as_ObjectType()->exact_type();
 170   }
 171   return nullptr;
 172 }
 173 
 174 ciType* LoadIndexed::exact_type() const {
 175   ciType* array_type = array()->exact_type();
 176   if (array_type != nullptr) {
 177     assert(array_type->is_array_klass(), "what else?");
 178     ciArrayKlass* ak = (ciArrayKlass*)array_type;
 179 
 180     if (ak->element_type()->is_instance_klass()) {
 181       ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type();
 182       if (ik->is_loaded() && ik->is_final()) {
 183         return ik;
 184       }
 185     }
 186   }
 187   return Instruction::exact_type();
 188 }
 189 
 190 
 191 ciType* LoadIndexed::declared_type() const {



 192   ciType* array_type = array()->declared_type();
 193   if (array_type == nullptr || !array_type->is_loaded()) {
 194     return nullptr;
 195   }
 196   assert(array_type->is_array_klass(), "what else?");
 197   ciArrayKlass* ak = (ciArrayKlass*)array_type;
 198   return ak->element_type();
 199 }
 200 














 201 
 202 ciType* LoadField::declared_type() const {
 203   return field()->type();
 204 }
 205 
 206 
 207 ciType* NewTypeArray::exact_type() const {
 208   return ciTypeArrayKlass::make(elt_type());
 209 }
 210 
 211 ciType* NewObjectArray::exact_type() const {
 212   return ciObjArrayKlass::make(klass());




 213 }
 214 
 215 ciType* NewArray::declared_type() const {
 216   return exact_type();
 217 }
 218 
 219 ciType* NewInstance::exact_type() const {
 220   return klass();
 221 }
 222 
 223 ciType* NewInstance::declared_type() const {
 224   return exact_type();
 225 }
 226 
 227 ciType* CheckCast::declared_type() const {
 228   return klass();
 229 }
 230 
 231 // Implementation of ArithmeticOp
 232 

 302 }
 303 
 304 
 305 void StateSplit::state_values_do(ValueVisitor* f) {
 306   Instruction::state_values_do(f);
 307   if (state() != nullptr) state()->values_do(f);
 308 }
 309 
 310 
 311 void BlockBegin::state_values_do(ValueVisitor* f) {
 312   StateSplit::state_values_do(f);
 313 
 314   if (is_set(BlockBegin::exception_entry_flag)) {
 315     for (int i = 0; i < number_of_exception_states(); i++) {
 316       exception_state_at(i)->values_do(f);
 317     }
 318   }
 319 }
 320 
 321 





























 322 // Implementation of Invoke
 323 
 324 
 325 Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
 326                ciMethod* target, ValueStack* state_before)
 327   : StateSplit(result_type, state_before)
 328   , _code(code)
 329   , _recv(recv)
 330   , _args(args)
 331   , _target(target)
 332 {
 333   set_flag(TargetIsLoadedFlag,   target->is_loaded());
 334   set_flag(TargetIsFinalFlag,    target_is_loaded() && target->is_final_method());
 335 
 336   assert(args != nullptr, "args must exist");
 337 #ifdef ASSERT
 338   AssertValues assert_value;
 339   values_do(&assert_value);
 340 #endif
 341 
 342   // provide an initial guess of signature size.
 343   _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
 344   if (has_receiver()) {
 345     _signature->append(as_BasicType(receiver()->type()));
 346   }
 347   for (int i = 0; i < number_of_arguments(); i++) {
 348     ValueType* t = argument_at(i)->type();

 349     BasicType bt = as_BasicType(t);
 350     _signature->append(bt);
 351   }
 352 }
 353 
 354 
 355 void Invoke::state_values_do(ValueVisitor* f) {
 356   StateSplit::state_values_do(f);
 357   if (state_before() != nullptr) state_before()->values_do(f);
 358   if (state()        != nullptr) state()->values_do(f);
 359 }
 360 
 361 ciType* Invoke::declared_type() const {
 362   ciSignature* declared_signature = state()->scope()->method()->get_declared_signature_at_bci(state()->bci());
 363   ciType *t = declared_signature->return_type();
 364   assert(t->basic_type() != T_VOID, "need return value of void method?");
 365   return t;
 366 }
 367 
 368 // Implementation of Constant

 973   ip1.print_instr(x);
 974 
 975   stringStream strStream2;
 976   InstructionPrinter ip2(1, &strStream2);
 977   ip2.print_instr(y);
 978 
 979   stringStream ss;
 980   ss.print("Assertion %s %s %s in method %s", strStream1.freeze(), ip2.cond_name(cond), strStream2.freeze(), strStream.freeze());
 981 
 982   _message = ss.as_string();
 983 }
 984 #endif
 985 
 986 void RangeCheckPredicate::check_state() {
 987   assert(state()->kind() != ValueStack::EmptyExceptionState && state()->kind() != ValueStack::ExceptionState, "will deopt with empty state");
 988 }
 989 
 990 void ProfileInvoke::state_values_do(ValueVisitor* f) {
 991   if (state() != nullptr) state()->values_do(f);
 992 }


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "c1/c1_IR.hpp"
  27 #include "c1/c1_Instruction.hpp"
  28 #include "c1/c1_InstructionPrinter.hpp"
  29 #include "c1/c1_ValueStack.hpp"
  30 #include "ci/ciFlatArrayKlass.hpp"
  31 #include "ci/ciInlineKlass.hpp"
  32 #include "ci/ciObjArrayKlass.hpp"
  33 #include "ci/ciTypeArrayKlass.hpp"
  34 #include "utilities/bitMap.inline.hpp"
  35 
  36 
  37 // Implementation of Instruction
  38 
  39 
  40 int Instruction::dominator_depth() {
  41   int result = -1;
  42   if (block()) {
  43     result = block()->dominator_depth();
  44   }
  45   assert(result != -1 || this->as_Local(), "Only locals have dominator depth -1");
  46   return result;
  47 }
  48 
  49 Instruction::Condition Instruction::mirror(Condition cond) {
  50   switch (cond) {
  51     case eql: return eql;

  91   Instruction* p = nullptr;
  92   Instruction* q = block();
  93   while (q != this) {
  94     assert(q != nullptr, "this is not in the block's instruction list");
  95     p = q; q = q->next();
  96   }
  97   return p;
  98 }
  99 
 100 
 101 void Instruction::state_values_do(ValueVisitor* f) {
 102   if (state_before() != nullptr) {
 103     state_before()->values_do(f);
 104   }
 105   if (exception_state() != nullptr) {
 106     exception_state()->values_do(f);
 107   }
 108 }
 109 
 110 ciType* Instruction::exact_type() const {
 111   ciType* t = declared_type();
 112   if (t != nullptr && t->is_klass()) {
 113     return t->as_klass()->exact_klass();
 114   }
 115   return nullptr;
 116 }
 117 
 118 ciKlass* Instruction::as_loaded_klass_or_null() const {
 119   ciType* type = declared_type();
 120   if (type != nullptr && type->is_klass()) {
 121     ciKlass* klass = type->as_klass();
 122     if (klass->is_loaded()) {
 123       return klass;
 124     }
 125   }
 126   return nullptr;
 127 }
 128 
 129 bool Instruction::is_loaded_flat_array() const {
 130   if (UseFlatArray) {
 131     ciType* type = declared_type();
 132     return type != nullptr && type->is_flat_array_klass();
 133   }
 134   return false;
 135 }
 136 
 137 bool Instruction::maybe_flat_array() {
 138   if (UseFlatArray) {
 139     ciType* type = declared_type();
 140     if (type != nullptr) {
 141       if (type->is_obj_array_klass()) {
 142         // Due to array covariance, the runtime type might be a flat array.
 143         ciKlass* element_klass = type->as_obj_array_klass()->element_klass();
 144         if (element_klass->can_be_inline_klass() && (!element_klass->is_inlinetype() || element_klass->as_inline_klass()->flat_in_array())) {
 145           return true;
 146         }
 147       } else if (type->is_flat_array_klass()) {
 148         return true;
 149       } else if (type->is_klass() && type->as_klass()->is_java_lang_Object()) {
 150         // This can happen as a parameter to System.arraycopy()
 151         return true;
 152       }
 153     } else {
 154       // Type info gets lost during Phi merging (Phi, IfOp, etc), but we might be storing into a
 155       // flat array, so we should do a runtime check.
 156       return true;
 157     }
 158   }
 159   return false;
 160 }
 161 
 162 bool Instruction::maybe_null_free_array() {
 163   ciType* type = declared_type();
 164   if (type != nullptr) {
 165     if (type->is_obj_array_klass()) {
 166       // Due to array covariance, the runtime type might be a null-free array.
 167       if (type->as_obj_array_klass()->can_be_inline_array_klass()) {
 168         return true;
 169       }
 170     }
 171   } else {
 172     // Type info gets lost during Phi merging (Phi, IfOp, etc), but we might be storing into a
 173     // null-free array, so we should do a runtime check.
 174     return true;
 175   }
 176   return false;
 177 }
 178 
 179 #ifndef PRODUCT
 180 void Instruction::check_state(ValueStack* state) {
 181   if (state != nullptr) {
 182     state->verify();
 183   }
 184 }
 185 
 186 
 187 void Instruction::print() {
 188   InstructionPrinter ip;
 189   print(ip);
 190 }
 191 
 192 
 193 void Instruction::print_line() {
 194   InstructionPrinter ip;
 195   ip.print_line(this);
 196 }
 197 

 218     }
 219   }
 220 
 221   if (!this->check_flag(NeedsRangeCheckFlag)) {
 222     return false;
 223   }
 224 
 225   return true;
 226 }
 227 
 228 
 229 ciType* Constant::exact_type() const {
 230   if (type()->is_object() && type()->as_ObjectType()->is_loaded()) {
 231     return type()->as_ObjectType()->exact_type();
 232   }
 233   return nullptr;
 234 }
 235 
 236 ciType* LoadIndexed::exact_type() const {
 237   ciType* array_type = array()->exact_type();
 238   if (delayed() == nullptr && array_type != nullptr) {
 239     assert(array_type->is_array_klass(), "what else?");
 240     ciArrayKlass* ak = (ciArrayKlass*)array_type;
 241 
 242     if (ak->element_type()->is_instance_klass()) {
 243       ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type();
 244       if (ik->is_loaded() && ik->is_final()) {
 245         return ik;
 246       }
 247     }
 248   }
 249   return Instruction::exact_type();
 250 }
 251 

 252 ciType* LoadIndexed::declared_type() const {
 253   if (delayed() != nullptr) {
 254     return delayed()->field()->type();
 255   }
 256   ciType* array_type = array()->declared_type();
 257   if (array_type == nullptr || !array_type->is_loaded()) {
 258     return nullptr;
 259   }
 260   assert(array_type->is_array_klass(), "what else?");
 261   ciArrayKlass* ak = (ciArrayKlass*)array_type;
 262   return ak->element_type();
 263 }
 264 
 265 bool StoreIndexed::is_exact_flat_array_store() const {
 266   if (array()->is_loaded_flat_array() && value()->as_Constant() == nullptr && value()->declared_type() != nullptr) {
 267     ciKlass* element_klass = array()->declared_type()->as_flat_array_klass()->element_klass();
 268     ciKlass* actual_klass = value()->declared_type()->as_klass();
 269 
 270     // The following check can fail with inlining:
 271     //     void test45_inline(Object[] oa, Object o, int index) { oa[index] = o; }
 272     //     void test45(MyValue1[] va, int index, MyValue2 v) { test45_inline(va, v, index); }
 273     if (element_klass == actual_klass) {
 274       return true;
 275     }
 276   }
 277   return false;
 278 }
 279 
 280 ciType* LoadField::declared_type() const {
 281   return field()->type();
 282 }
 283 
 284 
 285 ciType* NewTypeArray::exact_type() const {
 286   return ciTypeArrayKlass::make(elt_type());
 287 }
 288 
 289 ciType* NewObjectArray::exact_type() const {
 290   return ciArrayKlass::make(klass());
 291 }
 292 
 293 ciType* NewMultiArray::exact_type() const {
 294   return _klass;
 295 }
 296 
 297 ciType* NewArray::declared_type() const {
 298   return exact_type();
 299 }
 300 
 301 ciType* NewInstance::exact_type() const {
 302   return klass();
 303 }
 304 
 305 ciType* NewInstance::declared_type() const {
 306   return exact_type();
 307 }
 308 
 309 ciType* CheckCast::declared_type() const {
 310   return klass();
 311 }
 312 
 313 // Implementation of ArithmeticOp
 314 

 384 }
 385 
 386 
 387 void StateSplit::state_values_do(ValueVisitor* f) {
 388   Instruction::state_values_do(f);
 389   if (state() != nullptr) state()->values_do(f);
 390 }
 391 
 392 
 393 void BlockBegin::state_values_do(ValueVisitor* f) {
 394   StateSplit::state_values_do(f);
 395 
 396   if (is_set(BlockBegin::exception_entry_flag)) {
 397     for (int i = 0; i < number_of_exception_states(); i++) {
 398       exception_state_at(i)->values_do(f);
 399     }
 400   }
 401 }
 402 
 403 
 404 StoreField::StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
 405                        ValueStack* state_before, bool needs_patching)
 406   : AccessField(obj, offset, field, is_static, state_before, needs_patching)
 407   , _value(value)
 408   , _enclosing_field(nullptr)
 409 {
 410   set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object());
 411 #ifdef ASSERT
 412   AssertValues assert_value;
 413   values_do(&assert_value);
 414 #endif
 415   pin();
 416 }
 417 
 418 StoreIndexed::StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value,
 419                            ValueStack* state_before, bool check_boolean, bool mismatched)
 420   : AccessIndexed(array, index, length, elt_type, state_before, mismatched)
 421   , _value(value), _check_boolean(check_boolean)
 422 {
 423   set_flag(NeedsWriteBarrierFlag, (as_ValueType(elt_type)->is_object()));
 424   set_flag(NeedsStoreCheckFlag, (as_ValueType(elt_type)->is_object()));
 425 #ifdef ASSERT
 426   AssertValues assert_value;
 427   values_do(&assert_value);
 428 #endif
 429   pin();
 430 }
 431 
 432 
 433 // Implementation of Invoke
 434 
 435 
 436 Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
 437                ciMethod* target, ValueStack* state_before)
 438   : StateSplit(result_type, state_before)
 439   , _code(code)
 440   , _recv(recv)
 441   , _args(args)
 442   , _target(target)
 443 {
 444   set_flag(TargetIsLoadedFlag,   target->is_loaded());
 445   set_flag(TargetIsFinalFlag,    target_is_loaded() && target->is_final_method());
 446 
 447   assert(args != nullptr, "args must exist");
 448 #ifdef ASSERT
 449   AssertValues assert_value;
 450   values_do(&assert_value);
 451 #endif
 452 
 453   // provide an initial guess of signature size.
 454   _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
 455   if (has_receiver()) {
 456     _signature->append(as_BasicType(receiver()->type()));
 457   }
 458   for (int i = 0; i < number_of_arguments(); i++) {
 459     Value v = argument_at(i);
 460     ValueType* t = v->type();
 461     BasicType bt = as_BasicType(t);
 462     _signature->append(bt);
 463   }
 464 }
 465 
 466 
 467 void Invoke::state_values_do(ValueVisitor* f) {
 468   StateSplit::state_values_do(f);
 469   if (state_before() != nullptr) state_before()->values_do(f);
 470   if (state()        != nullptr) state()->values_do(f);
 471 }
 472 
 473 ciType* Invoke::declared_type() const {
 474   ciSignature* declared_signature = state()->scope()->method()->get_declared_signature_at_bci(state()->bci());
 475   ciType *t = declared_signature->return_type();
 476   assert(t->basic_type() != T_VOID, "need return value of void method?");
 477   return t;
 478 }
 479 
 480 // Implementation of Constant

1085   ip1.print_instr(x);
1086 
1087   stringStream strStream2;
1088   InstructionPrinter ip2(1, &strStream2);
1089   ip2.print_instr(y);
1090 
1091   stringStream ss;
1092   ss.print("Assertion %s %s %s in method %s", strStream1.freeze(), ip2.cond_name(cond), strStream2.freeze(), strStream.freeze());
1093 
1094   _message = ss.as_string();
1095 }
1096 #endif
1097 
1098 void RangeCheckPredicate::check_state() {
1099   assert(state()->kind() != ValueStack::EmptyExceptionState && state()->kind() != ValueStack::ExceptionState, "will deopt with empty state");
1100 }
1101 
1102 void ProfileInvoke::state_values_do(ValueVisitor* f) {
1103   if (state() != nullptr) state()->values_do(f);
1104 }
1105 
< prev index next >