< prev index next >

src/hotspot/share/c1/c1_Instruction.cpp

Print this page

   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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 "c1/c1_IR.hpp"
  26 #include "c1/c1_Instruction.hpp"
  27 #include "c1/c1_InstructionPrinter.hpp"
  28 #include "c1/c1_ValueStack.hpp"


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

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




























































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

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



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














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




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

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


























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

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

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


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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 "c1/c1_IR.hpp"
  26 #include "c1/c1_Instruction.hpp"
  27 #include "c1/c1_InstructionPrinter.hpp"
  28 #include "c1/c1_ValueStack.hpp"
  29 #include "ci/ciFlatArrayKlass.hpp"
  30 #include "ci/ciInlineKlass.hpp"
  31 #include "ci/ciObjArrayKlass.hpp"
  32 #include "ci/ciTypeArrayKlass.hpp"
  33 #include "utilities/bitMap.inline.hpp"
  34 
  35 
  36 // Implementation of Instruction
  37 
  38 
  39 int Instruction::dominator_depth() {
  40   int result = -1;
  41   if (block()) {
  42     result = block()->dominator_depth();
  43   }
  44   assert(result != -1 || this->as_Local(), "Only locals have dominator depth -1");
  45   return result;
  46 }
  47 
  48 Instruction::Condition Instruction::mirror(Condition cond) {
  49   switch (cond) {
  50     case eql: return eql;

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

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

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

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

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