1 /* 2 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 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 #ifndef SHARE_C1_C1_INSTRUCTION_HPP 26 #define SHARE_C1_C1_INSTRUCTION_HPP 27 28 #include "c1/c1_Compilation.hpp" 29 #include "c1/c1_LIR.hpp" 30 #include "c1/c1_ValueType.hpp" 31 #include "ci/ciField.hpp" 32 33 // Predefined classes 34 class ciField; 35 class ValueStack; 36 class InstructionPrinter; 37 class IRScope; 38 class LIR_OprDesc; 39 typedef LIR_OprDesc* LIR_Opr; 40 41 42 // Instruction class hierarchy 43 // 44 // All leaf classes in the class hierarchy are concrete classes 45 // (i.e., are instantiated). All other classes are abstract and 46 // serve factoring. 47 48 class Instruction; 49 class Phi; 50 class Local; 51 class Constant; 52 class AccessField; 53 class LoadField; 54 class StoreField; 55 class AccessArray; 56 class ArrayLength; 57 class AccessIndexed; 58 class LoadIndexed; 59 class StoreIndexed; 60 class NegateOp; 61 class Op2; 62 class ArithmeticOp; 63 class ShiftOp; 64 class LogicOp; 65 class CompareOp; 66 class IfOp; 67 class Convert; 68 class NullCheck; 69 class TypeCast; 70 class OsrEntry; 71 class ExceptionObject; 72 class StateSplit; 73 class Invoke; 74 class NewInstance; 75 class NewValueTypeInstance; 76 class NewArray; 77 class NewTypeArray; 78 class NewObjectArray; 79 class NewMultiArray; 80 class TypeCheck; 81 class CheckCast; 82 class InstanceOf; 83 class AccessMonitor; 84 class MonitorEnter; 85 class MonitorExit; 86 class Intrinsic; 87 class BlockBegin; 88 class BlockEnd; 89 class Goto; 90 class If; 91 class IfInstanceOf; 92 class Switch; 93 class TableSwitch; 94 class LookupSwitch; 95 class Return; 96 class Throw; 97 class Base; 98 class RoundFP; 99 class UnsafeOp; 100 class UnsafeRawOp; 101 class UnsafeGetRaw; 102 class UnsafePutRaw; 103 class UnsafeObjectOp; 104 class UnsafeGetObject; 105 class UnsafePutObject; 106 class UnsafeGetAndSetObject; 107 class ProfileCall; 108 class ProfileReturnType; 109 class ProfileInvoke; 110 class RuntimeCall; 111 class MemBar; 112 class RangeCheckPredicate; 113 #ifdef ASSERT 114 class Assert; 115 #endif 116 117 // A Value is a reference to the instruction creating the value 118 typedef Instruction* Value; 119 typedef GrowableArray<Value> Values; 120 typedef GrowableArray<ValueStack*> ValueStackStack; 121 122 // BlockClosure is the base class for block traversal/iteration. 123 124 class BlockClosure: public CompilationResourceObj { 125 public: 126 virtual void block_do(BlockBegin* block) = 0; 127 }; 128 129 130 // A simple closure class for visiting the values of an Instruction 131 class ValueVisitor: public StackObj { 132 public: 133 virtual void visit(Value* v) = 0; 134 }; 135 136 137 // Some array and list classes 138 typedef GrowableArray<BlockBegin*> BlockBeginArray; 139 140 class BlockList: public GrowableArray<BlockBegin*> { 141 public: 142 BlockList(): GrowableArray<BlockBegin*>() {} 143 BlockList(const int size): GrowableArray<BlockBegin*>(size) {} 144 BlockList(const int size, BlockBegin* init): GrowableArray<BlockBegin*>(size, size, init) {} 145 146 void iterate_forward(BlockClosure* closure); 147 void iterate_backward(BlockClosure* closure); 148 void blocks_do(void f(BlockBegin*)); 149 void values_do(ValueVisitor* f); 150 void print(bool cfg_only = false, bool live_only = false) PRODUCT_RETURN; 151 }; 152 153 154 // InstructionVisitors provide type-based dispatch for instructions. 155 // For each concrete Instruction class X, a virtual function do_X is 156 // provided. Functionality that needs to be implemented for all classes 157 // (e.g., printing, code generation) is factored out into a specialised 158 // visitor instead of added to the Instruction classes itself. 159 160 class InstructionVisitor: public StackObj { 161 public: 162 virtual void do_Phi (Phi* x) = 0; 163 virtual void do_Local (Local* x) = 0; 164 virtual void do_Constant (Constant* x) = 0; 165 virtual void do_LoadField (LoadField* x) = 0; 166 virtual void do_StoreField (StoreField* x) = 0; 167 virtual void do_ArrayLength (ArrayLength* x) = 0; 168 virtual void do_LoadIndexed (LoadIndexed* x) = 0; 169 virtual void do_StoreIndexed (StoreIndexed* x) = 0; 170 virtual void do_NegateOp (NegateOp* x) = 0; 171 virtual void do_ArithmeticOp (ArithmeticOp* x) = 0; 172 virtual void do_ShiftOp (ShiftOp* x) = 0; 173 virtual void do_LogicOp (LogicOp* x) = 0; 174 virtual void do_CompareOp (CompareOp* x) = 0; 175 virtual void do_IfOp (IfOp* x) = 0; 176 virtual void do_Convert (Convert* x) = 0; 177 virtual void do_NullCheck (NullCheck* x) = 0; 178 virtual void do_TypeCast (TypeCast* x) = 0; 179 virtual void do_Invoke (Invoke* x) = 0; 180 virtual void do_NewInstance (NewInstance* x) = 0; 181 virtual void do_NewValueTypeInstance(NewValueTypeInstance* x) = 0; 182 virtual void do_NewTypeArray (NewTypeArray* x) = 0; 183 virtual void do_NewObjectArray (NewObjectArray* x) = 0; 184 virtual void do_NewMultiArray (NewMultiArray* x) = 0; 185 virtual void do_CheckCast (CheckCast* x) = 0; 186 virtual void do_InstanceOf (InstanceOf* x) = 0; 187 virtual void do_MonitorEnter (MonitorEnter* x) = 0; 188 virtual void do_MonitorExit (MonitorExit* x) = 0; 189 virtual void do_Intrinsic (Intrinsic* x) = 0; 190 virtual void do_BlockBegin (BlockBegin* x) = 0; 191 virtual void do_Goto (Goto* x) = 0; 192 virtual void do_If (If* x) = 0; 193 virtual void do_IfInstanceOf (IfInstanceOf* x) = 0; 194 virtual void do_TableSwitch (TableSwitch* x) = 0; 195 virtual void do_LookupSwitch (LookupSwitch* x) = 0; 196 virtual void do_Return (Return* x) = 0; 197 virtual void do_Throw (Throw* x) = 0; 198 virtual void do_Base (Base* x) = 0; 199 virtual void do_OsrEntry (OsrEntry* x) = 0; 200 virtual void do_ExceptionObject(ExceptionObject* x) = 0; 201 virtual void do_RoundFP (RoundFP* x) = 0; 202 virtual void do_UnsafeGetRaw (UnsafeGetRaw* x) = 0; 203 virtual void do_UnsafePutRaw (UnsafePutRaw* x) = 0; 204 virtual void do_UnsafeGetObject(UnsafeGetObject* x) = 0; 205 virtual void do_UnsafePutObject(UnsafePutObject* x) = 0; 206 virtual void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) = 0; 207 virtual void do_ProfileCall (ProfileCall* x) = 0; 208 virtual void do_ProfileReturnType (ProfileReturnType* x) = 0; 209 virtual void do_ProfileInvoke (ProfileInvoke* x) = 0; 210 virtual void do_RuntimeCall (RuntimeCall* x) = 0; 211 virtual void do_MemBar (MemBar* x) = 0; 212 virtual void do_RangeCheckPredicate(RangeCheckPredicate* x) = 0; 213 #ifdef ASSERT 214 virtual void do_Assert (Assert* x) = 0; 215 #endif 216 }; 217 218 219 // Hashing support 220 // 221 // Note: This hash functions affect the performance 222 // of ValueMap - make changes carefully! 223 224 #define HASH1(x1 ) ((intx)(x1)) 225 #define HASH2(x1, x2 ) ((HASH1(x1 ) << 7) ^ HASH1(x2)) 226 #define HASH3(x1, x2, x3 ) ((HASH2(x1, x2 ) << 7) ^ HASH1(x3)) 227 #define HASH4(x1, x2, x3, x4) ((HASH3(x1, x2, x3) << 7) ^ HASH1(x4)) 228 229 230 // The following macros are used to implement instruction-specific hashing. 231 // By default, each instruction implements hash() and is_equal(Value), used 232 // for value numbering/common subexpression elimination. The default imple- 233 // mentation disables value numbering. Each instruction which can be value- 234 // numbered, should define corresponding hash() and is_equal(Value) functions 235 // via the macros below. The f arguments specify all the values/op codes, etc. 236 // that need to be identical for two instructions to be identical. 237 // 238 // Note: The default implementation of hash() returns 0 in order to indicate 239 // that the instruction should not be considered for value numbering. 240 // The currently used hash functions do not guarantee that never a 0 241 // is produced. While this is still correct, it may be a performance 242 // bug (no value numbering for that node). However, this situation is 243 // so unlikely, that we are not going to handle it specially. 244 245 #define HASHING1(class_name, enabled, f1) \ 246 virtual intx hash() const { \ 247 return (enabled) ? HASH2(name(), f1) : 0; \ 248 } \ 249 virtual bool is_equal(Value v) const { \ 250 if (!(enabled) ) return false; \ 251 class_name* _v = v->as_##class_name(); \ 252 if (_v == NULL ) return false; \ 253 if (f1 != _v->f1) return false; \ 254 return true; \ 255 } \ 256 257 258 #define HASHING2(class_name, enabled, f1, f2) \ 259 virtual intx hash() const { \ 260 return (enabled) ? HASH3(name(), f1, f2) : 0; \ 261 } \ 262 virtual bool is_equal(Value v) const { \ 263 if (!(enabled) ) return false; \ 264 class_name* _v = v->as_##class_name(); \ 265 if (_v == NULL ) return false; \ 266 if (f1 != _v->f1) return false; \ 267 if (f2 != _v->f2) return false; \ 268 return true; \ 269 } \ 270 271 272 #define HASHING3(class_name, enabled, f1, f2, f3) \ 273 virtual intx hash() const { \ 274 return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \ 275 } \ 276 virtual bool is_equal(Value v) const { \ 277 if (!(enabled) ) return false; \ 278 class_name* _v = v->as_##class_name(); \ 279 if (_v == NULL ) return false; \ 280 if (f1 != _v->f1) return false; \ 281 if (f2 != _v->f2) return false; \ 282 if (f3 != _v->f3) return false; \ 283 return true; \ 284 } \ 285 286 287 // The mother of all instructions... 288 289 class Instruction: public CompilationResourceObj { 290 private: 291 int _id; // the unique instruction id 292 #ifndef PRODUCT 293 int _printable_bci; // the bci of the instruction for printing 294 #endif 295 int _use_count; // the number of instructions refering to this value (w/o prev/next); only roots can have use count = 0 or > 1 296 int _pin_state; // set of PinReason describing the reason for pinning 297 ValueType* _type; // the instruction value type 298 Instruction* _next; // the next instruction if any (NULL for BlockEnd instructions) 299 Instruction* _subst; // the substitution instruction if any 300 LIR_Opr _operand; // LIR specific information 301 unsigned int _flags; // Flag bits 302 303 ValueStack* _state_before; // Copy of state with input operands still on stack (or NULL) 304 ValueStack* _exception_state; // Copy of state for exception handling 305 XHandlers* _exception_handlers; // Flat list of exception handlers covering this instruction 306 307 friend class UseCountComputer; 308 friend class BlockBegin; 309 310 void update_exception_state(ValueStack* state); 311 312 protected: 313 BlockBegin* _block; // Block that contains this instruction 314 315 void set_type(ValueType* type) { 316 assert(type != NULL, "type must exist"); 317 _type = type; 318 } 319 320 // Helper class to keep track of which arguments need a null check 321 class ArgsNonNullState { 322 private: 323 int _nonnull_state; // mask identifying which args are nonnull 324 public: 325 ArgsNonNullState() 326 : _nonnull_state(AllBits) {} 327 328 // Does argument number i needs a null check? 329 bool arg_needs_null_check(int i) const { 330 // No data is kept for arguments starting at position 33 so 331 // conservatively assume that they need a null check. 332 if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) { 333 return is_set_nth_bit(_nonnull_state, i); 334 } 335 return true; 336 } 337 338 // Set whether argument number i needs a null check or not 339 void set_arg_needs_null_check(int i, bool check) { 340 if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) { 341 if (check) { 342 _nonnull_state |= nth_bit(i); 343 } else { 344 _nonnull_state &= ~(nth_bit(i)); 345 } 346 } 347 } 348 }; 349 350 public: 351 void* operator new(size_t size) throw() { 352 Compilation* c = Compilation::current(); 353 void* res = c->arena()->Amalloc(size); 354 ((Instruction*)res)->_id = c->get_next_id(); 355 return res; 356 } 357 358 static const int no_bci = -99; 359 360 enum InstructionFlag { 361 NeedsNullCheckFlag = 0, 362 NeverNullFlag, // For "Q" signatures 363 CanTrapFlag, 364 DirectCompareFlag, 365 IsEliminatedFlag, 366 IsSafepointFlag, 367 IsStaticFlag, 368 IsStrictfpFlag, 369 NeedsStoreCheckFlag, 370 NeedsWriteBarrierFlag, 371 PreservesStateFlag, 372 TargetIsFinalFlag, 373 TargetIsLoadedFlag, 374 TargetIsStrictfpFlag, 375 UnorderedIsTrueFlag, 376 NeedsPatchingFlag, 377 ThrowIncompatibleClassChangeErrorFlag, 378 InvokeSpecialReceiverCheckFlag, 379 ProfileMDOFlag, 380 IsLinkedInBlockFlag, 381 NeedsRangeCheckFlag, 382 InWorkListFlag, 383 DeoptimizeOnException, 384 InstructionLastFlag 385 }; 386 387 public: 388 bool check_flag(InstructionFlag id) const { return (_flags & (1 << id)) != 0; } 389 void set_flag(InstructionFlag id, bool f) { _flags = f ? (_flags | (1 << id)) : (_flags & ~(1 << id)); }; 390 391 // 'globally' used condition values 392 enum Condition { 393 eql, neq, lss, leq, gtr, geq, aeq, beq 394 }; 395 396 // Instructions may be pinned for many reasons and under certain conditions 397 // with enough knowledge it's possible to safely unpin them. 398 enum PinReason { 399 PinUnknown = 1 << 0 400 , PinExplicitNullCheck = 1 << 3 401 , PinStackForStateSplit= 1 << 12 402 , PinStateSplitConstructor= 1 << 13 403 , PinGlobalValueNumbering= 1 << 14 404 }; 405 406 static Condition mirror(Condition cond); 407 static Condition negate(Condition cond); 408 409 // initialization 410 static int number_of_instructions() { 411 return Compilation::current()->number_of_instructions(); 412 } 413 414 // creation 415 Instruction(ValueType* type, ValueStack* state_before = NULL, bool type_is_constant = false) 416 : 417 #ifndef PRODUCT 418 _printable_bci(-99), 419 #endif 420 _use_count(0) 421 , _pin_state(0) 422 , _type(type) 423 , _next(NULL) 424 , _subst(NULL) 425 , _operand(LIR_OprFact::illegalOpr) 426 , _flags(0) 427 , _state_before(state_before) 428 , _exception_handlers(NULL) 429 , _block(NULL) 430 { 431 check_state(state_before); 432 assert(type != NULL && (!type->is_constant() || type_is_constant), "type must exist"); 433 update_exception_state(_state_before); 434 } 435 436 // accessors 437 int id() const { return _id; } 438 #ifndef PRODUCT 439 bool has_printable_bci() const { return _printable_bci != -99; } 440 int printable_bci() const { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; } 441 void set_printable_bci(int bci) { _printable_bci = bci; } 442 #endif 443 int dominator_depth(); 444 int use_count() const { return _use_count; } 445 int pin_state() const { return _pin_state; } 446 bool is_pinned() const { return _pin_state != 0 || PinAllInstructions; } 447 ValueType* type() const { return _type; } 448 BlockBegin *block() const { return _block; } 449 Instruction* prev(); // use carefully, expensive operation 450 Instruction* next() const { return _next; } 451 bool has_subst() const { return _subst != NULL; } 452 Instruction* subst() { return _subst == NULL ? this : _subst->subst(); } 453 LIR_Opr operand() const { return _operand; } 454 455 void set_needs_null_check(bool f) { set_flag(NeedsNullCheckFlag, f); } 456 bool needs_null_check() const { return check_flag(NeedsNullCheckFlag); } 457 void set_never_null(bool f) { set_flag(NeverNullFlag, f); } 458 bool is_never_null() const { return check_flag(NeverNullFlag); } 459 bool is_linked() const { return check_flag(IsLinkedInBlockFlag); } 460 bool can_be_linked() { return as_Local() == NULL && as_Phi() == NULL; } 461 462 bool has_uses() const { return use_count() > 0; } 463 ValueStack* state_before() const { return _state_before; } 464 ValueStack* exception_state() const { return _exception_state; } 465 virtual bool needs_exception_state() const { return true; } 466 XHandlers* exception_handlers() const { return _exception_handlers; } 467 468 // manipulation 469 void pin(PinReason reason) { _pin_state |= reason; } 470 void pin() { _pin_state |= PinUnknown; } 471 // DANGEROUS: only used by EliminateStores 472 void unpin(PinReason reason) { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; } 473 474 Instruction* set_next(Instruction* next) { 475 assert(next->has_printable_bci(), "_printable_bci should have been set"); 476 assert(next != NULL, "must not be NULL"); 477 assert(as_BlockEnd() == NULL, "BlockEnd instructions must have no next"); 478 assert(next->can_be_linked(), "shouldn't link these instructions into list"); 479 480 BlockBegin *block = this->block(); 481 next->_block = block; 482 483 next->set_flag(Instruction::IsLinkedInBlockFlag, true); 484 _next = next; 485 return next; 486 } 487 488 Instruction* set_next(Instruction* next, int bci) { 489 #ifndef PRODUCT 490 next->set_printable_bci(bci); 491 #endif 492 return set_next(next); 493 } 494 495 // when blocks are merged 496 void fixup_block_pointers() { 497 Instruction *cur = next()->next(); // next()'s block is set in set_next 498 while (cur && cur->_block != block()) { 499 cur->_block = block(); 500 cur = cur->next(); 501 } 502 } 503 504 Instruction *insert_after(Instruction *i) { 505 Instruction* n = _next; 506 set_next(i); 507 i->set_next(n); 508 return _next; 509 } 510 511 bool is_flattened_array() const; // FIXME -- remove it 512 513 bool is_loaded_flattened_array() const; 514 bool maybe_flattened_array(); 515 516 Instruction *insert_after_same_bci(Instruction *i) { 517 #ifndef PRODUCT 518 i->set_printable_bci(printable_bci()); 519 #endif 520 return insert_after(i); 521 } 522 523 void set_subst(Instruction* subst) { 524 assert(subst == NULL || 525 type()->base() == subst->type()->base() || 526 subst->type()->base() == illegalType, "type can't change"); 527 _subst = subst; 528 } 529 void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; } 530 void set_exception_state(ValueStack* s) { check_state(s); _exception_state = s; } 531 void set_state_before(ValueStack* s) { check_state(s); _state_before = s; } 532 533 // machine-specifics 534 void set_operand(LIR_Opr operand) { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; } 535 void clear_operand() { _operand = LIR_OprFact::illegalOpr; } 536 537 // generic 538 virtual Instruction* as_Instruction() { return this; } // to satisfy HASHING1 macro 539 virtual Phi* as_Phi() { return NULL; } 540 virtual Local* as_Local() { return NULL; } 541 virtual Constant* as_Constant() { return NULL; } 542 virtual AccessField* as_AccessField() { return NULL; } 543 virtual LoadField* as_LoadField() { return NULL; } 544 virtual StoreField* as_StoreField() { return NULL; } 545 virtual AccessArray* as_AccessArray() { return NULL; } 546 virtual ArrayLength* as_ArrayLength() { return NULL; } 547 virtual AccessIndexed* as_AccessIndexed() { return NULL; } 548 virtual LoadIndexed* as_LoadIndexed() { return NULL; } 549 virtual StoreIndexed* as_StoreIndexed() { return NULL; } 550 virtual NegateOp* as_NegateOp() { return NULL; } 551 virtual Op2* as_Op2() { return NULL; } 552 virtual ArithmeticOp* as_ArithmeticOp() { return NULL; } 553 virtual ShiftOp* as_ShiftOp() { return NULL; } 554 virtual LogicOp* as_LogicOp() { return NULL; } 555 virtual CompareOp* as_CompareOp() { return NULL; } 556 virtual IfOp* as_IfOp() { return NULL; } 557 virtual Convert* as_Convert() { return NULL; } 558 virtual NullCheck* as_NullCheck() { return NULL; } 559 virtual OsrEntry* as_OsrEntry() { return NULL; } 560 virtual StateSplit* as_StateSplit() { return NULL; } 561 virtual Invoke* as_Invoke() { return NULL; } 562 virtual NewInstance* as_NewInstance() { return NULL; } 563 virtual NewValueTypeInstance* as_NewValueTypeInstance() { return NULL; } 564 virtual NewArray* as_NewArray() { return NULL; } 565 virtual NewTypeArray* as_NewTypeArray() { return NULL; } 566 virtual NewObjectArray* as_NewObjectArray() { return NULL; } 567 virtual NewMultiArray* as_NewMultiArray() { return NULL; } 568 virtual TypeCheck* as_TypeCheck() { return NULL; } 569 virtual CheckCast* as_CheckCast() { return NULL; } 570 virtual InstanceOf* as_InstanceOf() { return NULL; } 571 virtual TypeCast* as_TypeCast() { return NULL; } 572 virtual AccessMonitor* as_AccessMonitor() { return NULL; } 573 virtual MonitorEnter* as_MonitorEnter() { return NULL; } 574 virtual MonitorExit* as_MonitorExit() { return NULL; } 575 virtual Intrinsic* as_Intrinsic() { return NULL; } 576 virtual BlockBegin* as_BlockBegin() { return NULL; } 577 virtual BlockEnd* as_BlockEnd() { return NULL; } 578 virtual Goto* as_Goto() { return NULL; } 579 virtual If* as_If() { return NULL; } 580 virtual IfInstanceOf* as_IfInstanceOf() { return NULL; } 581 virtual TableSwitch* as_TableSwitch() { return NULL; } 582 virtual LookupSwitch* as_LookupSwitch() { return NULL; } 583 virtual Return* as_Return() { return NULL; } 584 virtual Throw* as_Throw() { return NULL; } 585 virtual Base* as_Base() { return NULL; } 586 virtual RoundFP* as_RoundFP() { return NULL; } 587 virtual ExceptionObject* as_ExceptionObject() { return NULL; } 588 virtual UnsafeOp* as_UnsafeOp() { return NULL; } 589 virtual ProfileInvoke* as_ProfileInvoke() { return NULL; } 590 virtual RangeCheckPredicate* as_RangeCheckPredicate() { return NULL; } 591 592 #ifdef ASSERT 593 virtual Assert* as_Assert() { return NULL; } 594 #endif 595 596 virtual void visit(InstructionVisitor* v) = 0; 597 598 virtual bool can_trap() const { return false; } 599 600 virtual void input_values_do(ValueVisitor* f) = 0; 601 virtual void state_values_do(ValueVisitor* f); 602 virtual void other_values_do(ValueVisitor* f) { /* usually no other - override on demand */ } 603 void values_do(ValueVisitor* f) { input_values_do(f); state_values_do(f); other_values_do(f); } 604 605 virtual ciType* exact_type() const; 606 virtual ciType* declared_type() const { return NULL; } 607 608 // hashing 609 virtual const char* name() const = 0; 610 HASHING1(Instruction, false, id()) // hashing disabled by default 611 612 // debugging 613 static void check_state(ValueStack* state) PRODUCT_RETURN; 614 void print() PRODUCT_RETURN; 615 void print_line() PRODUCT_RETURN; 616 void print(InstructionPrinter& ip) PRODUCT_RETURN; 617 }; 618 619 620 // The following macros are used to define base (i.e., non-leaf) 621 // and leaf instruction classes. They define class-name related 622 // generic functionality in one place. 623 624 #define BASE(class_name, super_class_name) \ 625 class class_name: public super_class_name { \ 626 public: \ 627 virtual class_name* as_##class_name() { return this; } \ 628 629 630 #define LEAF(class_name, super_class_name) \ 631 BASE(class_name, super_class_name) \ 632 public: \ 633 virtual const char* name() const { return #class_name; } \ 634 virtual void visit(InstructionVisitor* v) { v->do_##class_name(this); } \ 635 636 637 // Debugging support 638 639 640 #ifdef ASSERT 641 class AssertValues: public ValueVisitor { 642 void visit(Value* x) { assert((*x) != NULL, "value must exist"); } 643 }; 644 #define ASSERT_VALUES { AssertValues assert_value; values_do(&assert_value); } 645 #else 646 #define ASSERT_VALUES 647 #endif // ASSERT 648 649 650 // A Phi is a phi function in the sense of SSA form. It stands for 651 // the value of a local variable at the beginning of a join block. 652 // A Phi consists of n operands, one for every incoming branch. 653 654 LEAF(Phi, Instruction) 655 private: 656 int _pf_flags; // the flags of the phi function 657 int _index; // to value on operand stack (index < 0) or to local 658 ciType* _exact_type; // currently is set only for flattened arrays, NULL otherwise. 659 public: 660 // creation 661 Phi(ValueType* type, BlockBegin* b, int index, ciType* exact_type) 662 : Instruction(type->base()) 663 , _pf_flags(0) 664 , _index(index) 665 , _exact_type(exact_type) 666 { 667 _block = b; 668 NOT_PRODUCT(set_printable_bci(Value(b)->printable_bci())); 669 if (type->is_illegal()) { 670 make_illegal(); 671 } 672 } 673 674 virtual ciType* exact_type() const { 675 return _exact_type; 676 } 677 678 virtual ciType* declared_type() const { 679 return _exact_type; 680 } 681 682 // flags 683 enum Flag { 684 no_flag = 0, 685 visited = 1 << 0, 686 cannot_simplify = 1 << 1 687 }; 688 689 // accessors 690 bool is_local() const { return _index >= 0; } 691 bool is_on_stack() const { return !is_local(); } 692 int local_index() const { assert(is_local(), ""); return _index; } 693 int stack_index() const { assert(is_on_stack(), ""); return -(_index+1); } 694 695 Value operand_at(int i) const; 696 int operand_count() const; 697 698 void set(Flag f) { _pf_flags |= f; } 699 void clear(Flag f) { _pf_flags &= ~f; } 700 bool is_set(Flag f) const { return (_pf_flags & f) != 0; } 701 702 // Invalidates phis corresponding to merges of locals of two different types 703 // (these should never be referenced, otherwise the bytecodes are illegal) 704 void make_illegal() { 705 set(cannot_simplify); 706 set_type(illegalType); 707 } 708 709 bool is_illegal() const { 710 return type()->is_illegal(); 711 } 712 713 // generic 714 virtual void input_values_do(ValueVisitor* f) { 715 } 716 }; 717 718 719 // A local is a placeholder for an incoming argument to a function call. 720 LEAF(Local, Instruction) 721 private: 722 int _java_index; // the local index within the method to which the local belongs 723 bool _is_receiver; // if local variable holds the receiver: "this" for non-static methods 724 ciType* _declared_type; 725 public: 726 // creation 727 Local(ciType* declared, ValueType* type, int index, bool receiver, bool never_null) 728 : Instruction(type) 729 , _java_index(index) 730 , _is_receiver(receiver) 731 , _declared_type(declared) 732 { 733 set_never_null(never_null); 734 NOT_PRODUCT(set_printable_bci(-1)); 735 } 736 737 // accessors 738 int java_index() const { return _java_index; } 739 bool is_receiver() const { return _is_receiver; } 740 741 virtual ciType* declared_type() const { return _declared_type; } 742 743 // generic 744 virtual void input_values_do(ValueVisitor* f) { /* no values */ } 745 }; 746 747 748 LEAF(Constant, Instruction) 749 public: 750 // creation 751 Constant(ValueType* type): 752 Instruction(type, NULL, /*type_is_constant*/ true) 753 { 754 assert(type->is_constant(), "must be a constant"); 755 } 756 757 Constant(ValueType* type, ValueStack* state_before): 758 Instruction(type, state_before, /*type_is_constant*/ true) 759 { 760 assert(state_before != NULL, "only used for constants which need patching"); 761 assert(type->is_constant(), "must be a constant"); 762 // since it's patching it needs to be pinned 763 pin(); 764 } 765 766 // generic 767 virtual bool can_trap() const { return state_before() != NULL; } 768 virtual void input_values_do(ValueVisitor* f) { /* no values */ } 769 770 virtual intx hash() const; 771 virtual bool is_equal(Value v) const; 772 773 virtual ciType* exact_type() const; 774 775 enum CompareResult { not_comparable = -1, cond_false, cond_true }; 776 777 virtual CompareResult compare(Instruction::Condition condition, Value right) const; 778 BlockBegin* compare(Instruction::Condition cond, Value right, 779 BlockBegin* true_sux, BlockBegin* false_sux) const { 780 switch (compare(cond, right)) { 781 case not_comparable: 782 return NULL; 783 case cond_false: 784 return false_sux; 785 case cond_true: 786 return true_sux; 787 default: 788 ShouldNotReachHere(); 789 return NULL; 790 } 791 } 792 }; 793 794 795 BASE(AccessField, Instruction) 796 private: 797 Value _obj; 798 int _offset; 799 ciField* _field; 800 NullCheck* _explicit_null_check; // For explicit null check elimination 801 802 public: 803 // creation 804 AccessField(Value obj, int offset, ciField* field, bool is_static, 805 ValueStack* state_before, bool needs_patching) 806 : Instruction(as_ValueType(field->type()->basic_type()), state_before) 807 , _obj(obj) 808 , _offset(offset) 809 , _field(field) 810 , _explicit_null_check(NULL) 811 { 812 set_needs_null_check(!is_static); 813 set_flag(IsStaticFlag, is_static); 814 set_flag(NeedsPatchingFlag, needs_patching); 815 ASSERT_VALUES 816 // pin of all instructions with memory access 817 pin(); 818 } 819 820 // accessors 821 Value obj() const { return _obj; } 822 int offset() const { return _offset; } 823 ciField* field() const { return _field; } 824 BasicType field_type() const { return _field->type()->basic_type(); } 825 bool is_static() const { return check_flag(IsStaticFlag); } 826 NullCheck* explicit_null_check() const { return _explicit_null_check; } 827 bool needs_patching() const { return check_flag(NeedsPatchingFlag); } 828 829 // Unresolved getstatic and putstatic can cause initialization. 830 // Technically it occurs at the Constant that materializes the base 831 // of the static fields but it's simpler to model it here. 832 bool is_init_point() const { return is_static() && (needs_patching() || !_field->holder()->is_initialized()); } 833 834 // manipulation 835 836 // Under certain circumstances, if a previous NullCheck instruction 837 // proved the target object non-null, we can eliminate the explicit 838 // null check and do an implicit one, simply specifying the debug 839 // information from the NullCheck. This field should only be consulted 840 // if needs_null_check() is true. 841 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; } 842 843 // generic 844 virtual bool can_trap() const { return needs_null_check() || needs_patching(); } 845 virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); } 846 }; 847 848 849 LEAF(LoadField, AccessField) 850 ciValueKlass* _value_klass; 851 Value _default_value; 852 public: 853 // creation 854 LoadField(Value obj, int offset, ciField* field, bool is_static, 855 ValueStack* state_before, bool needs_patching, 856 ciValueKlass* value_klass = NULL, Value default_value = NULL ) 857 : AccessField(obj, offset, field, is_static, state_before, needs_patching) 858 , _value_klass(value_klass), _default_value(default_value) 859 {} 860 861 ciType* declared_type() const; 862 863 // generic 864 HASHING2(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset()) // cannot be eliminated if needs patching or if volatile 865 866 ciValueKlass* value_klass() const { return _value_klass;} 867 Value default_value() const { return _default_value; } 868 }; 869 870 871 LEAF(StoreField, AccessField) 872 private: 873 Value _value; 874 875 public: 876 // creation 877 StoreField(Value obj, int offset, ciField* field, Value value, bool is_static, 878 ValueStack* state_before, bool needs_patching) 879 : AccessField(obj, offset, field, is_static, state_before, needs_patching) 880 , _value(value) 881 { 882 set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object()); 883 ASSERT_VALUES 884 pin(); 885 } 886 887 // accessors 888 Value value() const { return _value; } 889 bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); } 890 891 // generic 892 virtual void input_values_do(ValueVisitor* f) { AccessField::input_values_do(f); f->visit(&_value); } 893 }; 894 895 896 BASE(AccessArray, Instruction) 897 private: 898 Value _array; 899 900 public: 901 // creation 902 AccessArray(ValueType* type, Value array, ValueStack* state_before) 903 : Instruction(type, state_before) 904 , _array(array) 905 { 906 set_needs_null_check(true); 907 ASSERT_VALUES 908 pin(); // instruction with side effect (null exception or range check throwing) 909 } 910 911 Value array() const { return _array; } 912 913 // generic 914 virtual bool can_trap() const { return needs_null_check(); } 915 virtual void input_values_do(ValueVisitor* f) { f->visit(&_array); } 916 }; 917 918 919 LEAF(ArrayLength, AccessArray) 920 private: 921 NullCheck* _explicit_null_check; // For explicit null check elimination 922 923 public: 924 // creation 925 ArrayLength(Value array, ValueStack* state_before) 926 : AccessArray(intType, array, state_before) 927 , _explicit_null_check(NULL) {} 928 929 // accessors 930 NullCheck* explicit_null_check() const { return _explicit_null_check; } 931 932 // setters 933 // See LoadField::set_explicit_null_check for documentation 934 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; } 935 936 // generic 937 HASHING1(ArrayLength, true, array()->subst()) 938 }; 939 940 941 BASE(AccessIndexed, AccessArray) 942 private: 943 Value _index; 944 Value _length; 945 BasicType _elt_type; 946 bool _mismatched; 947 948 public: 949 // creation 950 AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched) 951 : AccessArray(as_ValueType(elt_type), array, state_before) 952 , _index(index) 953 , _length(length) 954 , _elt_type(elt_type) 955 , _mismatched(mismatched) 956 { 957 set_flag(Instruction::NeedsRangeCheckFlag, true); 958 ASSERT_VALUES 959 } 960 961 // accessors 962 Value index() const { return _index; } 963 Value length() const { return _length; } 964 BasicType elt_type() const { return _elt_type; } 965 bool mismatched() const { return _mismatched; } 966 967 void clear_length() { _length = NULL; } 968 // perform elimination of range checks involving constants 969 bool compute_needs_range_check(); 970 971 // generic 972 virtual void input_values_do(ValueVisitor* f) { AccessArray::input_values_do(f); f->visit(&_index); if (_length != NULL) f->visit(&_length); } 973 }; 974 975 976 LEAF(LoadIndexed, AccessIndexed) 977 private: 978 NullCheck* _explicit_null_check; // For explicit null check elimination 979 NewValueTypeInstance* _vt; 980 981 public: 982 // creation 983 LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched = false) 984 : AccessIndexed(array, index, length, elt_type, state_before, mismatched) 985 , _explicit_null_check(NULL) {} 986 987 // accessors 988 NullCheck* explicit_null_check() const { return _explicit_null_check; } 989 990 // setters 991 // See LoadField::set_explicit_null_check for documentation 992 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; } 993 994 ciType* exact_type() const; 995 ciType* declared_type() const; 996 997 NewValueTypeInstance* vt() { return _vt; } 998 void set_vt(NewValueTypeInstance* vt) { _vt = vt; } 999 1000 // generic 1001 HASHING2(LoadIndexed, true, array()->subst(), index()->subst()) 1002 }; 1003 1004 1005 LEAF(StoreIndexed, AccessIndexed) 1006 private: 1007 Value _value; 1008 1009 ciMethod* _profiled_method; 1010 int _profiled_bci; 1011 bool _check_boolean; 1012 1013 public: 1014 // creation 1015 StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before, 1016 bool check_boolean, bool mismatched = false) 1017 : AccessIndexed(array, index, length, elt_type, state_before, mismatched) 1018 , _value(value), _profiled_method(NULL), _profiled_bci(0), _check_boolean(check_boolean) 1019 { 1020 set_flag(NeedsWriteBarrierFlag, (as_ValueType(elt_type)->is_object())); 1021 set_flag(NeedsStoreCheckFlag, (as_ValueType(elt_type)->is_object())); 1022 ASSERT_VALUES 1023 pin(); 1024 } 1025 1026 // accessors 1027 Value value() const { return _value; } 1028 bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); } 1029 bool needs_store_check() const { return check_flag(NeedsStoreCheckFlag); } 1030 bool check_boolean() const { return _check_boolean; } 1031 // Helpers for MethodData* profiling 1032 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); } 1033 void set_profiled_method(ciMethod* method) { _profiled_method = method; } 1034 void set_profiled_bci(int bci) { _profiled_bci = bci; } 1035 bool should_profile() const { return check_flag(ProfileMDOFlag); } 1036 ciMethod* profiled_method() const { return _profiled_method; } 1037 int profiled_bci() const { return _profiled_bci; } 1038 // Flattened array support 1039 bool is_exact_flattened_array_store() const; 1040 // generic 1041 virtual void input_values_do(ValueVisitor* f) { AccessIndexed::input_values_do(f); f->visit(&_value); } 1042 }; 1043 1044 1045 LEAF(NegateOp, Instruction) 1046 private: 1047 Value _x; 1048 1049 public: 1050 // creation 1051 NegateOp(Value x) : Instruction(x->type()->base()), _x(x) { 1052 ASSERT_VALUES 1053 } 1054 1055 // accessors 1056 Value x() const { return _x; } 1057 1058 // generic 1059 virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); } 1060 }; 1061 1062 1063 BASE(Op2, Instruction) 1064 private: 1065 Bytecodes::Code _op; 1066 Value _x; 1067 Value _y; 1068 1069 public: 1070 // creation 1071 Op2(ValueType* type, Bytecodes::Code op, Value x, Value y, ValueStack* state_before = NULL) 1072 : Instruction(type, state_before) 1073 , _op(op) 1074 , _x(x) 1075 , _y(y) 1076 { 1077 ASSERT_VALUES 1078 } 1079 1080 // accessors 1081 Bytecodes::Code op() const { return _op; } 1082 Value x() const { return _x; } 1083 Value y() const { return _y; } 1084 1085 // manipulators 1086 void swap_operands() { 1087 assert(is_commutative(), "operation must be commutative"); 1088 Value t = _x; _x = _y; _y = t; 1089 } 1090 1091 // generic 1092 virtual bool is_commutative() const { return false; } 1093 virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); f->visit(&_y); } 1094 }; 1095 1096 1097 LEAF(ArithmeticOp, Op2) 1098 public: 1099 // creation 1100 ArithmeticOp(Bytecodes::Code op, Value x, Value y, bool is_strictfp, ValueStack* state_before) 1101 : Op2(x->type()->meet(y->type()), op, x, y, state_before) 1102 { 1103 set_flag(IsStrictfpFlag, is_strictfp); 1104 if (can_trap()) pin(); 1105 } 1106 1107 // accessors 1108 bool is_strictfp() const { return check_flag(IsStrictfpFlag); } 1109 1110 // generic 1111 virtual bool is_commutative() const; 1112 virtual bool can_trap() const; 1113 HASHING3(Op2, true, op(), x()->subst(), y()->subst()) 1114 }; 1115 1116 1117 LEAF(ShiftOp, Op2) 1118 public: 1119 // creation 1120 ShiftOp(Bytecodes::Code op, Value x, Value s) : Op2(x->type()->base(), op, x, s) {} 1121 1122 // generic 1123 HASHING3(Op2, true, op(), x()->subst(), y()->subst()) 1124 }; 1125 1126 1127 LEAF(LogicOp, Op2) 1128 public: 1129 // creation 1130 LogicOp(Bytecodes::Code op, Value x, Value y) : Op2(x->type()->meet(y->type()), op, x, y) {} 1131 1132 // generic 1133 virtual bool is_commutative() const; 1134 HASHING3(Op2, true, op(), x()->subst(), y()->subst()) 1135 }; 1136 1137 1138 LEAF(CompareOp, Op2) 1139 public: 1140 // creation 1141 CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before) 1142 : Op2(intType, op, x, y, state_before) 1143 {} 1144 1145 // generic 1146 HASHING3(Op2, true, op(), x()->subst(), y()->subst()) 1147 }; 1148 1149 1150 LEAF(IfOp, Op2) 1151 private: 1152 Value _tval; 1153 Value _fval; 1154 1155 public: 1156 // creation 1157 IfOp(Value x, Condition cond, Value y, Value tval, Value fval) 1158 : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y) 1159 , _tval(tval) 1160 , _fval(fval) 1161 { 1162 ASSERT_VALUES 1163 assert(tval->type()->tag() == fval->type()->tag(), "types must match"); 1164 } 1165 1166 // accessors 1167 virtual bool is_commutative() const; 1168 Bytecodes::Code op() const { ShouldNotCallThis(); return Bytecodes::_illegal; } 1169 Condition cond() const { return (Condition)Op2::op(); } 1170 Value tval() const { return _tval; } 1171 Value fval() const { return _fval; } 1172 1173 // generic 1174 virtual void input_values_do(ValueVisitor* f) { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); } 1175 }; 1176 1177 1178 LEAF(Convert, Instruction) 1179 private: 1180 Bytecodes::Code _op; 1181 Value _value; 1182 1183 public: 1184 // creation 1185 Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) { 1186 ASSERT_VALUES 1187 } 1188 1189 // accessors 1190 Bytecodes::Code op() const { return _op; } 1191 Value value() const { return _value; } 1192 1193 // generic 1194 virtual void input_values_do(ValueVisitor* f) { f->visit(&_value); } 1195 HASHING2(Convert, true, op(), value()->subst()) 1196 }; 1197 1198 1199 LEAF(NullCheck, Instruction) 1200 private: 1201 Value _obj; 1202 1203 public: 1204 // creation 1205 NullCheck(Value obj, ValueStack* state_before) 1206 : Instruction(obj->type()->base(), state_before) 1207 , _obj(obj) 1208 { 1209 ASSERT_VALUES 1210 set_can_trap(true); 1211 assert(_obj->type()->is_object(), "null check must be applied to objects only"); 1212 pin(Instruction::PinExplicitNullCheck); 1213 } 1214 1215 // accessors 1216 Value obj() const { return _obj; } 1217 1218 // setters 1219 void set_can_trap(bool can_trap) { set_flag(CanTrapFlag, can_trap); } 1220 1221 // generic 1222 virtual bool can_trap() const { return check_flag(CanTrapFlag); /* null-check elimination sets to false */ } 1223 virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); } 1224 HASHING1(NullCheck, true, obj()->subst()) 1225 }; 1226 1227 1228 // This node is supposed to cast the type of another node to a more precise 1229 // declared type. 1230 LEAF(TypeCast, Instruction) 1231 private: 1232 ciType* _declared_type; 1233 Value _obj; 1234 1235 public: 1236 // The type of this node is the same type as the object type (and it might be constant). 1237 TypeCast(ciType* type, Value obj, ValueStack* state_before) 1238 : Instruction(obj->type(), state_before, obj->type()->is_constant()), 1239 _declared_type(type), 1240 _obj(obj) {} 1241 1242 // accessors 1243 ciType* declared_type() const { return _declared_type; } 1244 Value obj() const { return _obj; } 1245 1246 // generic 1247 virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); } 1248 }; 1249 1250 1251 BASE(StateSplit, Instruction) 1252 private: 1253 ValueStack* _state; 1254 1255 protected: 1256 static void substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block); 1257 1258 public: 1259 // creation 1260 StateSplit(ValueType* type, ValueStack* state_before = NULL) 1261 : Instruction(type, state_before) 1262 , _state(NULL) 1263 { 1264 pin(PinStateSplitConstructor); 1265 } 1266 1267 // accessors 1268 ValueStack* state() const { return _state; } 1269 IRScope* scope() const; // the state's scope 1270 1271 // manipulation 1272 void set_state(ValueStack* state) { assert(_state == NULL, "overwriting existing state"); check_state(state); _state = state; } 1273 1274 // generic 1275 virtual void input_values_do(ValueVisitor* f) { /* no values */ } 1276 virtual void state_values_do(ValueVisitor* f); 1277 }; 1278 1279 1280 LEAF(Invoke, StateSplit) 1281 private: 1282 Bytecodes::Code _code; 1283 Value _recv; 1284 Values* _args; 1285 BasicTypeList* _signature; 1286 int _vtable_index; 1287 ciMethod* _target; 1288 1289 public: 1290 // creation 1291 Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args, 1292 int vtable_index, ciMethod* target, ValueStack* state_before, bool never_null); 1293 1294 // accessors 1295 Bytecodes::Code code() const { return _code; } 1296 Value receiver() const { return _recv; } 1297 bool has_receiver() const { return receiver() != NULL; } 1298 int number_of_arguments() const { return _args->length(); } 1299 Value argument_at(int i) const { return _args->at(i); } 1300 int vtable_index() const { return _vtable_index; } 1301 BasicTypeList* signature() const { return _signature; } 1302 ciMethod* target() const { return _target; } 1303 1304 ciType* declared_type() const; 1305 1306 // Returns false if target is not loaded 1307 bool target_is_final() const { return check_flag(TargetIsFinalFlag); } 1308 bool target_is_loaded() const { return check_flag(TargetIsLoadedFlag); } 1309 // Returns false if target is not loaded 1310 bool target_is_strictfp() const { return check_flag(TargetIsStrictfpFlag); } 1311 1312 // JSR 292 support 1313 bool is_invokedynamic() const { return code() == Bytecodes::_invokedynamic; } 1314 bool is_method_handle_intrinsic() const { return target()->is_method_handle_intrinsic(); } 1315 1316 virtual bool needs_exception_state() const { return false; } 1317 1318 // generic 1319 virtual bool can_trap() const { return true; } 1320 virtual void input_values_do(ValueVisitor* f) { 1321 StateSplit::input_values_do(f); 1322 if (has_receiver()) f->visit(&_recv); 1323 for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i)); 1324 } 1325 virtual void state_values_do(ValueVisitor *f); 1326 }; 1327 1328 1329 LEAF(NewInstance, StateSplit) 1330 private: 1331 ciInstanceKlass* _klass; 1332 bool _is_unresolved; 1333 1334 public: 1335 // creation 1336 NewInstance(ciInstanceKlass* klass, ValueStack* state_before, bool is_unresolved) 1337 : StateSplit(instanceType, state_before) 1338 , _klass(klass), _is_unresolved(is_unresolved) 1339 {} 1340 1341 // accessors 1342 ciInstanceKlass* klass() const { return _klass; } 1343 bool is_unresolved() const { return _is_unresolved; } 1344 1345 virtual bool needs_exception_state() const { return false; } 1346 1347 // generic 1348 virtual bool can_trap() const { return true; } 1349 ciType* exact_type() const; 1350 ciType* declared_type() const; 1351 }; 1352 1353 LEAF(NewValueTypeInstance, StateSplit) 1354 bool _is_unresolved; 1355 ciValueKlass* _klass; 1356 Value _depends_on; // Link to instance on with withfield was called on 1357 1358 public: 1359 1360 // Default creation, always allocated for now 1361 NewValueTypeInstance(ciValueKlass* klass, ValueStack* state_before, bool is_unresolved, Value depends_on = NULL) 1362 : StateSplit(instanceType, state_before) 1363 , _is_unresolved(is_unresolved) 1364 , _klass(klass) 1365 { 1366 if (depends_on == NULL) { 1367 _depends_on = this; 1368 } else { 1369 _depends_on = depends_on; 1370 } 1371 set_never_null(true); 1372 } 1373 1374 // accessors 1375 bool is_unresolved() const { return _is_unresolved; } 1376 Value depends_on(); 1377 1378 ciValueKlass* klass() const { return _klass; } 1379 1380 virtual bool needs_exception_state() const { return false; } 1381 1382 // generic 1383 virtual bool can_trap() const { return true; } 1384 ciType* exact_type() const; 1385 ciType* declared_type() const; 1386 1387 // Only done in LIR Generator -> map everything to object 1388 void set_to_object_type() { set_type(instanceType); } 1389 }; 1390 1391 BASE(NewArray, StateSplit) 1392 private: 1393 Value _length; 1394 1395 public: 1396 // creation 1397 NewArray(Value length, ValueStack* state_before) 1398 : StateSplit(objectType, state_before) 1399 , _length(length) 1400 { 1401 // Do not ASSERT_VALUES since length is NULL for NewMultiArray 1402 } 1403 1404 // accessors 1405 Value length() const { return _length; } 1406 1407 virtual bool needs_exception_state() const { return false; } 1408 1409 ciType* exact_type() const { return NULL; } 1410 ciType* declared_type() const; 1411 1412 // generic 1413 virtual bool can_trap() const { return true; } 1414 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_length); } 1415 }; 1416 1417 1418 LEAF(NewTypeArray, NewArray) 1419 private: 1420 BasicType _elt_type; 1421 1422 public: 1423 // creation 1424 NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before) 1425 : NewArray(length, state_before) 1426 , _elt_type(elt_type) 1427 {} 1428 1429 // accessors 1430 BasicType elt_type() const { return _elt_type; } 1431 ciType* exact_type() const; 1432 }; 1433 1434 1435 LEAF(NewObjectArray, NewArray) 1436 private: 1437 ciKlass* _klass; 1438 1439 public: 1440 // creation 1441 NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before) : NewArray(length, state_before), _klass(klass) {} 1442 1443 // accessors 1444 ciKlass* klass() const { return _klass; } 1445 ciType* exact_type() const; 1446 }; 1447 1448 1449 LEAF(NewMultiArray, NewArray) 1450 private: 1451 ciKlass* _klass; 1452 Values* _dims; 1453 1454 public: 1455 // creation 1456 NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(NULL, state_before), _klass(klass), _dims(dims) { 1457 ASSERT_VALUES 1458 } 1459 1460 // accessors 1461 ciKlass* klass() const { return _klass; } 1462 Values* dims() const { return _dims; } 1463 int rank() const { return dims()->length(); } 1464 1465 // generic 1466 virtual void input_values_do(ValueVisitor* f) { 1467 // NOTE: we do not call NewArray::input_values_do since "length" 1468 // is meaningless for a multi-dimensional array; passing the 1469 // zeroth element down to NewArray as its length is a bad idea 1470 // since there will be a copy in the "dims" array which doesn't 1471 // get updated, and the value must not be traversed twice. Was bug 1472 // - kbr 4/10/2001 1473 StateSplit::input_values_do(f); 1474 for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i)); 1475 } 1476 1477 ciType* exact_type() const; 1478 }; 1479 1480 1481 BASE(TypeCheck, StateSplit) 1482 private: 1483 ciKlass* _klass; 1484 Value _obj; 1485 1486 ciMethod* _profiled_method; 1487 int _profiled_bci; 1488 1489 public: 1490 // creation 1491 TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before) 1492 : StateSplit(type, state_before), _klass(klass), _obj(obj), 1493 _profiled_method(NULL), _profiled_bci(0) { 1494 ASSERT_VALUES 1495 set_direct_compare(false); 1496 } 1497 1498 // accessors 1499 ciKlass* klass() const { return _klass; } 1500 Value obj() const { return _obj; } 1501 bool is_loaded() const { return klass() != NULL; } 1502 bool direct_compare() const { return check_flag(DirectCompareFlag); } 1503 1504 // manipulation 1505 void set_direct_compare(bool flag) { set_flag(DirectCompareFlag, flag); } 1506 1507 // generic 1508 virtual bool can_trap() const { return true; } 1509 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); } 1510 1511 // Helpers for MethodData* profiling 1512 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); } 1513 void set_profiled_method(ciMethod* method) { _profiled_method = method; } 1514 void set_profiled_bci(int bci) { _profiled_bci = bci; } 1515 bool should_profile() const { return check_flag(ProfileMDOFlag); } 1516 ciMethod* profiled_method() const { return _profiled_method; } 1517 int profiled_bci() const { return _profiled_bci; } 1518 }; 1519 1520 1521 LEAF(CheckCast, TypeCheck) 1522 public: 1523 // creation 1524 CheckCast(ciKlass* klass, Value obj, ValueStack* state_before, bool never_null = false) 1525 : TypeCheck(klass, obj, objectType, state_before) { 1526 set_never_null(never_null); 1527 } 1528 1529 void set_incompatible_class_change_check() { 1530 set_flag(ThrowIncompatibleClassChangeErrorFlag, true); 1531 } 1532 bool is_incompatible_class_change_check() const { 1533 return check_flag(ThrowIncompatibleClassChangeErrorFlag); 1534 } 1535 void set_invokespecial_receiver_check() { 1536 set_flag(InvokeSpecialReceiverCheckFlag, true); 1537 } 1538 bool is_invokespecial_receiver_check() const { 1539 return check_flag(InvokeSpecialReceiverCheckFlag); 1540 } 1541 1542 virtual bool needs_exception_state() const { 1543 return !is_invokespecial_receiver_check(); 1544 } 1545 1546 ciType* declared_type() const; 1547 }; 1548 1549 1550 LEAF(InstanceOf, TypeCheck) 1551 public: 1552 // creation 1553 InstanceOf(ciKlass* klass, Value obj, ValueStack* state_before) : TypeCheck(klass, obj, intType, state_before) {} 1554 1555 virtual bool needs_exception_state() const { return false; } 1556 }; 1557 1558 1559 BASE(AccessMonitor, StateSplit) 1560 private: 1561 Value _obj; 1562 int _monitor_no; 1563 1564 public: 1565 // creation 1566 AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = NULL) 1567 : StateSplit(illegalType, state_before) 1568 , _obj(obj) 1569 , _monitor_no(monitor_no) 1570 { 1571 set_needs_null_check(true); 1572 ASSERT_VALUES 1573 } 1574 1575 // accessors 1576 Value obj() const { return _obj; } 1577 int monitor_no() const { return _monitor_no; } 1578 1579 // generic 1580 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); } 1581 }; 1582 1583 1584 LEAF(MonitorEnter, AccessMonitor) 1585 bool _maybe_valuetype; 1586 public: 1587 // creation 1588 MonitorEnter(Value obj, int monitor_no, ValueStack* state_before, bool maybe_valuetype) 1589 : AccessMonitor(obj, monitor_no, state_before) 1590 , _maybe_valuetype(maybe_valuetype) 1591 { 1592 ASSERT_VALUES 1593 } 1594 1595 // accessors 1596 bool maybe_valuetype() const { return _maybe_valuetype; } 1597 1598 // generic 1599 virtual bool can_trap() const { return true; } 1600 }; 1601 1602 1603 LEAF(MonitorExit, AccessMonitor) 1604 public: 1605 // creation 1606 MonitorExit(Value obj, int monitor_no) 1607 : AccessMonitor(obj, monitor_no, NULL) 1608 { 1609 ASSERT_VALUES 1610 } 1611 }; 1612 1613 1614 LEAF(Intrinsic, StateSplit) 1615 private: 1616 vmIntrinsics::ID _id; 1617 Values* _args; 1618 Value _recv; 1619 ArgsNonNullState _nonnull_state; 1620 1621 public: 1622 // preserves_state can be set to true for Intrinsics 1623 // which are guaranteed to preserve register state across any slow 1624 // cases; setting it to true does not mean that the Intrinsic can 1625 // not trap, only that if we continue execution in the same basic 1626 // block after the Intrinsic, all of the registers are intact. This 1627 // allows load elimination and common expression elimination to be 1628 // performed across the Intrinsic. The default value is false. 1629 Intrinsic(ValueType* type, 1630 vmIntrinsics::ID id, 1631 Values* args, 1632 bool has_receiver, 1633 ValueStack* state_before, 1634 bool preserves_state, 1635 bool cantrap = true) 1636 : StateSplit(type, state_before) 1637 , _id(id) 1638 , _args(args) 1639 , _recv(NULL) 1640 { 1641 assert(args != NULL, "args must exist"); 1642 ASSERT_VALUES 1643 set_flag(PreservesStateFlag, preserves_state); 1644 set_flag(CanTrapFlag, cantrap); 1645 if (has_receiver) { 1646 _recv = argument_at(0); 1647 } 1648 set_needs_null_check(has_receiver); 1649 1650 // some intrinsics can't trap, so don't force them to be pinned 1651 if (!can_trap() && !vmIntrinsics::should_be_pinned(_id)) { 1652 unpin(PinStateSplitConstructor); 1653 } 1654 } 1655 1656 // accessors 1657 vmIntrinsics::ID id() const { return _id; } 1658 int number_of_arguments() const { return _args->length(); } 1659 Value argument_at(int i) const { return _args->at(i); } 1660 1661 bool has_receiver() const { return (_recv != NULL); } 1662 Value receiver() const { assert(has_receiver(), "must have receiver"); return _recv; } 1663 bool preserves_state() const { return check_flag(PreservesStateFlag); } 1664 1665 bool arg_needs_null_check(int i) const { 1666 return _nonnull_state.arg_needs_null_check(i); 1667 } 1668 1669 void set_arg_needs_null_check(int i, bool check) { 1670 _nonnull_state.set_arg_needs_null_check(i, check); 1671 } 1672 1673 // generic 1674 virtual bool can_trap() const { return check_flag(CanTrapFlag); } 1675 virtual void input_values_do(ValueVisitor* f) { 1676 StateSplit::input_values_do(f); 1677 for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i)); 1678 } 1679 }; 1680 1681 1682 class LIR_List; 1683 1684 LEAF(BlockBegin, StateSplit) 1685 private: 1686 int _block_id; // the unique block id 1687 int _bci; // start-bci of block 1688 int _depth_first_number; // number of this block in a depth-first ordering 1689 int _linear_scan_number; // number of this block in linear-scan ordering 1690 int _dominator_depth; 1691 int _loop_depth; // the loop nesting level of this block 1692 int _loop_index; // number of the innermost loop of this block 1693 int _flags; // the flags associated with this block 1694 1695 // fields used by BlockListBuilder 1696 int _total_preds; // number of predecessors found by BlockListBuilder 1697 ResourceBitMap _stores_to_locals; // bit is set when a local variable is stored in the block 1698 1699 // SSA specific fields: (factor out later) 1700 BlockList _successors; // the successors of this block 1701 BlockList _predecessors; // the predecessors of this block 1702 BlockList _dominates; // list of blocks that are dominated by this block 1703 BlockBegin* _dominator; // the dominator of this block 1704 // SSA specific ends 1705 BlockEnd* _end; // the last instruction of this block 1706 BlockList _exception_handlers; // the exception handlers potentially invoked by this block 1707 ValueStackStack* _exception_states; // only for xhandler entries: states of all instructions that have an edge to this xhandler 1708 int _exception_handler_pco; // if this block is the start of an exception handler, 1709 // this records the PC offset in the assembly code of the 1710 // first instruction in this block 1711 Label _label; // the label associated with this block 1712 LIR_List* _lir; // the low level intermediate representation for this block 1713 1714 ResourceBitMap _live_in; // set of live LIR_Opr registers at entry to this block 1715 ResourceBitMap _live_out; // set of live LIR_Opr registers at exit from this block 1716 ResourceBitMap _live_gen; // set of registers used before any redefinition in this block 1717 ResourceBitMap _live_kill; // set of registers defined in this block 1718 1719 ResourceBitMap _fpu_register_usage; 1720 intArray* _fpu_stack_state; // For x86 FPU code generation with UseLinearScan 1721 int _first_lir_instruction_id; // ID of first LIR instruction in this block 1722 int _last_lir_instruction_id; // ID of last LIR instruction in this block 1723 1724 void iterate_preorder (boolArray& mark, BlockClosure* closure); 1725 void iterate_postorder(boolArray& mark, BlockClosure* closure); 1726 1727 friend class SuxAndWeightAdjuster; 1728 1729 public: 1730 void* operator new(size_t size) throw() { 1731 Compilation* c = Compilation::current(); 1732 void* res = c->arena()->Amalloc(size); 1733 ((BlockBegin*)res)->_id = c->get_next_id(); 1734 ((BlockBegin*)res)->_block_id = c->get_next_block_id(); 1735 return res; 1736 } 1737 1738 // initialization/counting 1739 static int number_of_blocks() { 1740 return Compilation::current()->number_of_blocks(); 1741 } 1742 1743 // creation 1744 BlockBegin(int bci) 1745 : StateSplit(illegalType) 1746 , _bci(bci) 1747 , _depth_first_number(-1) 1748 , _linear_scan_number(-1) 1749 , _dominator_depth(-1) 1750 , _loop_depth(0) 1751 , _loop_index(-1) 1752 , _flags(0) 1753 , _total_preds(0) 1754 , _stores_to_locals() 1755 , _successors(2) 1756 , _predecessors(2) 1757 , _dominates(2) 1758 , _dominator(NULL) 1759 , _end(NULL) 1760 , _exception_handlers(1) 1761 , _exception_states(NULL) 1762 , _exception_handler_pco(-1) 1763 , _lir(NULL) 1764 , _live_in() 1765 , _live_out() 1766 , _live_gen() 1767 , _live_kill() 1768 , _fpu_register_usage() 1769 , _fpu_stack_state(NULL) 1770 , _first_lir_instruction_id(-1) 1771 , _last_lir_instruction_id(-1) 1772 { 1773 _block = this; 1774 #ifndef PRODUCT 1775 set_printable_bci(bci); 1776 #endif 1777 } 1778 1779 // accessors 1780 int block_id() const { return _block_id; } 1781 int bci() const { return _bci; } 1782 BlockList* successors() { return &_successors; } 1783 BlockList* dominates() { return &_dominates; } 1784 BlockBegin* dominator() const { return _dominator; } 1785 int loop_depth() const { return _loop_depth; } 1786 int dominator_depth() const { return _dominator_depth; } 1787 int depth_first_number() const { return _depth_first_number; } 1788 int linear_scan_number() const { return _linear_scan_number; } 1789 BlockEnd* end() const { return _end; } 1790 Label* label() { return &_label; } 1791 LIR_List* lir() const { return _lir; } 1792 int exception_handler_pco() const { return _exception_handler_pco; } 1793 ResourceBitMap& live_in() { return _live_in; } 1794 ResourceBitMap& live_out() { return _live_out; } 1795 ResourceBitMap& live_gen() { return _live_gen; } 1796 ResourceBitMap& live_kill() { return _live_kill; } 1797 ResourceBitMap& fpu_register_usage() { return _fpu_register_usage; } 1798 intArray* fpu_stack_state() const { return _fpu_stack_state; } 1799 int first_lir_instruction_id() const { return _first_lir_instruction_id; } 1800 int last_lir_instruction_id() const { return _last_lir_instruction_id; } 1801 int total_preds() const { return _total_preds; } 1802 BitMap& stores_to_locals() { return _stores_to_locals; } 1803 1804 // manipulation 1805 void set_dominator(BlockBegin* dom) { _dominator = dom; } 1806 void set_loop_depth(int d) { _loop_depth = d; } 1807 void set_dominator_depth(int d) { _dominator_depth = d; } 1808 void set_depth_first_number(int dfn) { _depth_first_number = dfn; } 1809 void set_linear_scan_number(int lsn) { _linear_scan_number = lsn; } 1810 void set_end(BlockEnd* end); 1811 void clear_end(); 1812 void disconnect_from_graph(); 1813 static void disconnect_edge(BlockBegin* from, BlockBegin* to); 1814 BlockBegin* insert_block_between(BlockBegin* sux); 1815 void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux); 1816 void set_lir(LIR_List* lir) { _lir = lir; } 1817 void set_exception_handler_pco(int pco) { _exception_handler_pco = pco; } 1818 void set_live_in (const ResourceBitMap& map) { _live_in = map; } 1819 void set_live_out (const ResourceBitMap& map) { _live_out = map; } 1820 void set_live_gen (const ResourceBitMap& map) { _live_gen = map; } 1821 void set_live_kill(const ResourceBitMap& map) { _live_kill = map; } 1822 void set_fpu_register_usage(const ResourceBitMap& map) { _fpu_register_usage = map; } 1823 void set_fpu_stack_state(intArray* state) { _fpu_stack_state = state; } 1824 void set_first_lir_instruction_id(int id) { _first_lir_instruction_id = id; } 1825 void set_last_lir_instruction_id(int id) { _last_lir_instruction_id = id; } 1826 void increment_total_preds(int n = 1) { _total_preds += n; } 1827 void init_stores_to_locals(int locals_count) { _stores_to_locals.initialize(locals_count); } 1828 1829 // generic 1830 virtual void state_values_do(ValueVisitor* f); 1831 1832 // successors and predecessors 1833 int number_of_sux() const; 1834 BlockBegin* sux_at(int i) const; 1835 void add_successor(BlockBegin* sux); 1836 void remove_successor(BlockBegin* pred); 1837 bool is_successor(BlockBegin* sux) const { return _successors.contains(sux); } 1838 1839 void add_predecessor(BlockBegin* pred); 1840 void remove_predecessor(BlockBegin* pred); 1841 bool is_predecessor(BlockBegin* pred) const { return _predecessors.contains(pred); } 1842 int number_of_preds() const { return _predecessors.length(); } 1843 BlockBegin* pred_at(int i) const { return _predecessors.at(i); } 1844 1845 // exception handlers potentially invoked by this block 1846 void add_exception_handler(BlockBegin* b); 1847 bool is_exception_handler(BlockBegin* b) const { return _exception_handlers.contains(b); } 1848 int number_of_exception_handlers() const { return _exception_handlers.length(); } 1849 BlockBegin* exception_handler_at(int i) const { return _exception_handlers.at(i); } 1850 1851 // states of the instructions that have an edge to this exception handler 1852 int number_of_exception_states() { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states == NULL ? 0 : _exception_states->length(); } 1853 ValueStack* exception_state_at(int idx) const { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states->at(idx); } 1854 int add_exception_state(ValueStack* state); 1855 1856 // flags 1857 enum Flag { 1858 no_flag = 0, 1859 std_entry_flag = 1 << 0, 1860 osr_entry_flag = 1 << 1, 1861 exception_entry_flag = 1 << 2, 1862 subroutine_entry_flag = 1 << 3, 1863 backward_branch_target_flag = 1 << 4, 1864 is_on_work_list_flag = 1 << 5, 1865 was_visited_flag = 1 << 6, 1866 parser_loop_header_flag = 1 << 7, // set by parser to identify blocks where phi functions can not be created on demand 1867 critical_edge_split_flag = 1 << 8, // set for all blocks that are introduced when critical edges are split 1868 linear_scan_loop_header_flag = 1 << 9, // set during loop-detection for LinearScan 1869 linear_scan_loop_end_flag = 1 << 10, // set during loop-detection for LinearScan 1870 donot_eliminate_range_checks = 1 << 11 // Should be try to eliminate range checks in this block 1871 }; 1872 1873 void set(Flag f) { _flags |= f; } 1874 void clear(Flag f) { _flags &= ~f; } 1875 bool is_set(Flag f) const { return (_flags & f) != 0; } 1876 bool is_entry_block() const { 1877 const int entry_mask = std_entry_flag | osr_entry_flag | exception_entry_flag; 1878 return (_flags & entry_mask) != 0; 1879 } 1880 1881 // iteration 1882 void iterate_preorder (BlockClosure* closure); 1883 void iterate_postorder (BlockClosure* closure); 1884 1885 void block_values_do(ValueVisitor* f); 1886 1887 // loops 1888 void set_loop_index(int ix) { _loop_index = ix; } 1889 int loop_index() const { return _loop_index; } 1890 1891 // merging 1892 bool try_merge(ValueStack* state); // try to merge states at block begin 1893 void merge(ValueStack* state) { bool b = try_merge(state); assert(b, "merge failed"); } 1894 1895 // debugging 1896 void print_block() PRODUCT_RETURN; 1897 void print_block(InstructionPrinter& ip, bool live_only = false) PRODUCT_RETURN; 1898 }; 1899 1900 1901 BASE(BlockEnd, StateSplit) 1902 private: 1903 BlockList* _sux; 1904 1905 protected: 1906 BlockList* sux() const { return _sux; } 1907 1908 void set_sux(BlockList* sux) { 1909 #ifdef ASSERT 1910 assert(sux != NULL, "sux must exist"); 1911 for (int i = sux->length() - 1; i >= 0; i--) assert(sux->at(i) != NULL, "sux must exist"); 1912 #endif 1913 _sux = sux; 1914 } 1915 1916 public: 1917 // creation 1918 BlockEnd(ValueType* type, ValueStack* state_before, bool is_safepoint) 1919 : StateSplit(type, state_before) 1920 , _sux(NULL) 1921 { 1922 set_flag(IsSafepointFlag, is_safepoint); 1923 } 1924 1925 // accessors 1926 bool is_safepoint() const { return check_flag(IsSafepointFlag); } 1927 // For compatibility with old code, for new code use block() 1928 BlockBegin* begin() const { return _block; } 1929 1930 // manipulation 1931 void set_begin(BlockBegin* begin); 1932 1933 // successors 1934 int number_of_sux() const { return _sux != NULL ? _sux->length() : 0; } 1935 BlockBegin* sux_at(int i) const { return _sux->at(i); } 1936 BlockBegin* default_sux() const { return sux_at(number_of_sux() - 1); } 1937 BlockBegin** addr_sux_at(int i) const { return _sux->adr_at(i); } 1938 int sux_index(BlockBegin* sux) const { return _sux->find(sux); } 1939 void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux); 1940 }; 1941 1942 1943 LEAF(Goto, BlockEnd) 1944 public: 1945 enum Direction { 1946 none, // Just a regular goto 1947 taken, not_taken // Goto produced from If 1948 }; 1949 private: 1950 ciMethod* _profiled_method; 1951 int _profiled_bci; 1952 Direction _direction; 1953 public: 1954 // creation 1955 Goto(BlockBegin* sux, ValueStack* state_before, bool is_safepoint = false) 1956 : BlockEnd(illegalType, state_before, is_safepoint) 1957 , _profiled_method(NULL) 1958 , _profiled_bci(0) 1959 , _direction(none) { 1960 BlockList* s = new BlockList(1); 1961 s->append(sux); 1962 set_sux(s); 1963 } 1964 1965 Goto(BlockBegin* sux, bool is_safepoint) : BlockEnd(illegalType, NULL, is_safepoint) 1966 , _profiled_method(NULL) 1967 , _profiled_bci(0) 1968 , _direction(none) { 1969 BlockList* s = new BlockList(1); 1970 s->append(sux); 1971 set_sux(s); 1972 } 1973 1974 bool should_profile() const { return check_flag(ProfileMDOFlag); } 1975 ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches 1976 int profiled_bci() const { return _profiled_bci; } 1977 Direction direction() const { return _direction; } 1978 1979 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); } 1980 void set_profiled_method(ciMethod* method) { _profiled_method = method; } 1981 void set_profiled_bci(int bci) { _profiled_bci = bci; } 1982 void set_direction(Direction d) { _direction = d; } 1983 }; 1984 1985 #ifdef ASSERT 1986 LEAF(Assert, Instruction) 1987 private: 1988 Value _x; 1989 Condition _cond; 1990 Value _y; 1991 char *_message; 1992 1993 public: 1994 // creation 1995 // unordered_is_true is valid for float/double compares only 1996 Assert(Value x, Condition cond, bool unordered_is_true, Value y); 1997 1998 // accessors 1999 Value x() const { return _x; } 2000 Condition cond() const { return _cond; } 2001 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); } 2002 Value y() const { return _y; } 2003 const char *message() const { return _message; } 2004 2005 // generic 2006 virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); f->visit(&_y); } 2007 }; 2008 #endif 2009 2010 LEAF(RangeCheckPredicate, StateSplit) 2011 private: 2012 Value _x; 2013 Condition _cond; 2014 Value _y; 2015 2016 void check_state(); 2017 2018 public: 2019 // creation 2020 // unordered_is_true is valid for float/double compares only 2021 RangeCheckPredicate(Value x, Condition cond, bool unordered_is_true, Value y, ValueStack* state) : StateSplit(illegalType) 2022 , _x(x) 2023 , _cond(cond) 2024 , _y(y) 2025 { 2026 ASSERT_VALUES 2027 set_flag(UnorderedIsTrueFlag, unordered_is_true); 2028 assert(x->type()->tag() == y->type()->tag(), "types must match"); 2029 this->set_state(state); 2030 check_state(); 2031 } 2032 2033 // Always deoptimize 2034 RangeCheckPredicate(ValueStack* state) : StateSplit(illegalType) 2035 { 2036 this->set_state(state); 2037 _x = _y = NULL; 2038 check_state(); 2039 } 2040 2041 // accessors 2042 Value x() const { return _x; } 2043 Condition cond() const { return _cond; } 2044 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); } 2045 Value y() const { return _y; } 2046 2047 void always_fail() { _x = _y = NULL; } 2048 2049 // generic 2050 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_x); f->visit(&_y); } 2051 HASHING3(RangeCheckPredicate, true, x()->subst(), y()->subst(), cond()) 2052 }; 2053 2054 LEAF(If, BlockEnd) 2055 private: 2056 Value _x; 2057 Condition _cond; 2058 Value _y; 2059 ciMethod* _profiled_method; 2060 int _profiled_bci; // Canonicalizer may alter bci of If node 2061 bool _swapped; // Is the order reversed with respect to the original If in the 2062 // bytecode stream? 2063 public: 2064 // creation 2065 // unordered_is_true is valid for float/double compares only 2066 If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint) 2067 : BlockEnd(illegalType, state_before, is_safepoint) 2068 , _x(x) 2069 , _cond(cond) 2070 , _y(y) 2071 , _profiled_method(NULL) 2072 , _profiled_bci(0) 2073 , _swapped(false) 2074 { 2075 ASSERT_VALUES 2076 set_flag(UnorderedIsTrueFlag, unordered_is_true); 2077 assert(x->type()->tag() == y->type()->tag(), "types must match"); 2078 BlockList* s = new BlockList(2); 2079 s->append(tsux); 2080 s->append(fsux); 2081 set_sux(s); 2082 } 2083 2084 // accessors 2085 Value x() const { return _x; } 2086 Condition cond() const { return _cond; } 2087 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); } 2088 Value y() const { return _y; } 2089 BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); } 2090 BlockBegin* tsux() const { return sux_for(true); } 2091 BlockBegin* fsux() const { return sux_for(false); } 2092 BlockBegin* usux() const { return sux_for(unordered_is_true()); } 2093 bool should_profile() const { return check_flag(ProfileMDOFlag); } 2094 ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches 2095 int profiled_bci() const { return _profiled_bci; } // set for profiled branches and tiered 2096 bool is_swapped() const { return _swapped; } 2097 2098 // manipulation 2099 void swap_operands() { 2100 Value t = _x; _x = _y; _y = t; 2101 _cond = mirror(_cond); 2102 } 2103 2104 void swap_sux() { 2105 assert(number_of_sux() == 2, "wrong number of successors"); 2106 BlockList* s = sux(); 2107 BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t); 2108 _cond = negate(_cond); 2109 set_flag(UnorderedIsTrueFlag, !check_flag(UnorderedIsTrueFlag)); 2110 } 2111 2112 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); } 2113 void set_profiled_method(ciMethod* method) { _profiled_method = method; } 2114 void set_profiled_bci(int bci) { _profiled_bci = bci; } 2115 void set_swapped(bool value) { _swapped = value; } 2116 // generic 2117 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); } 2118 }; 2119 2120 2121 LEAF(IfInstanceOf, BlockEnd) 2122 private: 2123 ciKlass* _klass; 2124 Value _obj; 2125 bool _test_is_instance; // jump if instance 2126 int _instanceof_bci; 2127 2128 public: 2129 IfInstanceOf(ciKlass* klass, Value obj, bool test_is_instance, int instanceof_bci, BlockBegin* tsux, BlockBegin* fsux) 2130 : BlockEnd(illegalType, NULL, false) // temporary set to false 2131 , _klass(klass) 2132 , _obj(obj) 2133 , _test_is_instance(test_is_instance) 2134 , _instanceof_bci(instanceof_bci) 2135 { 2136 ASSERT_VALUES 2137 assert(instanceof_bci >= 0, "illegal bci"); 2138 BlockList* s = new BlockList(2); 2139 s->append(tsux); 2140 s->append(fsux); 2141 set_sux(s); 2142 } 2143 2144 // accessors 2145 // 2146 // Note 1: If test_is_instance() is true, IfInstanceOf tests if obj *is* an 2147 // instance of klass; otherwise it tests if it is *not* and instance 2148 // of klass. 2149 // 2150 // Note 2: IfInstanceOf instructions are created by combining an InstanceOf 2151 // and an If instruction. The IfInstanceOf bci() corresponds to the 2152 // bci that the If would have had; the (this->) instanceof_bci() is 2153 // the bci of the original InstanceOf instruction. 2154 ciKlass* klass() const { return _klass; } 2155 Value obj() const { return _obj; } 2156 int instanceof_bci() const { return _instanceof_bci; } 2157 bool test_is_instance() const { return _test_is_instance; } 2158 BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); } 2159 BlockBegin* tsux() const { return sux_for(true); } 2160 BlockBegin* fsux() const { return sux_for(false); } 2161 2162 // manipulation 2163 void swap_sux() { 2164 assert(number_of_sux() == 2, "wrong number of successors"); 2165 BlockList* s = sux(); 2166 BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t); 2167 _test_is_instance = !_test_is_instance; 2168 } 2169 2170 // generic 2171 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_obj); } 2172 }; 2173 2174 2175 BASE(Switch, BlockEnd) 2176 private: 2177 Value _tag; 2178 2179 public: 2180 // creation 2181 Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint) 2182 : BlockEnd(illegalType, state_before, is_safepoint) 2183 , _tag(tag) { 2184 ASSERT_VALUES 2185 set_sux(sux); 2186 } 2187 2188 // accessors 2189 Value tag() const { return _tag; } 2190 int length() const { return number_of_sux() - 1; } 2191 2192 virtual bool needs_exception_state() const { return false; } 2193 2194 // generic 2195 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_tag); } 2196 }; 2197 2198 2199 LEAF(TableSwitch, Switch) 2200 private: 2201 int _lo_key; 2202 2203 public: 2204 // creation 2205 TableSwitch(Value tag, BlockList* sux, int lo_key, ValueStack* state_before, bool is_safepoint) 2206 : Switch(tag, sux, state_before, is_safepoint) 2207 , _lo_key(lo_key) { assert(_lo_key <= hi_key(), "integer overflow"); } 2208 2209 // accessors 2210 int lo_key() const { return _lo_key; } 2211 int hi_key() const { return _lo_key + (length() - 1); } 2212 }; 2213 2214 2215 LEAF(LookupSwitch, Switch) 2216 private: 2217 intArray* _keys; 2218 2219 public: 2220 // creation 2221 LookupSwitch(Value tag, BlockList* sux, intArray* keys, ValueStack* state_before, bool is_safepoint) 2222 : Switch(tag, sux, state_before, is_safepoint) 2223 , _keys(keys) { 2224 assert(keys != NULL, "keys must exist"); 2225 assert(keys->length() == length(), "sux & keys have incompatible lengths"); 2226 } 2227 2228 // accessors 2229 int key_at(int i) const { return _keys->at(i); } 2230 }; 2231 2232 2233 LEAF(Return, BlockEnd) 2234 private: 2235 Value _result; 2236 2237 public: 2238 // creation 2239 Return(Value result) : 2240 BlockEnd(result == NULL ? voidType : result->type()->base(), NULL, true), 2241 _result(result) {} 2242 2243 // accessors 2244 Value result() const { return _result; } 2245 bool has_result() const { return result() != NULL; } 2246 2247 // generic 2248 virtual void input_values_do(ValueVisitor* f) { 2249 BlockEnd::input_values_do(f); 2250 if (has_result()) f->visit(&_result); 2251 } 2252 }; 2253 2254 2255 LEAF(Throw, BlockEnd) 2256 private: 2257 Value _exception; 2258 2259 public: 2260 // creation 2261 Throw(Value exception, ValueStack* state_before) : BlockEnd(illegalType, state_before, true), _exception(exception) { 2262 ASSERT_VALUES 2263 } 2264 2265 // accessors 2266 Value exception() const { return _exception; } 2267 2268 // generic 2269 virtual bool can_trap() const { return true; } 2270 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_exception); } 2271 }; 2272 2273 2274 LEAF(Base, BlockEnd) 2275 public: 2276 // creation 2277 Base(BlockBegin* std_entry, BlockBegin* osr_entry) : BlockEnd(illegalType, NULL, false) { 2278 assert(std_entry->is_set(BlockBegin::std_entry_flag), "std entry must be flagged"); 2279 assert(osr_entry == NULL || osr_entry->is_set(BlockBegin::osr_entry_flag), "osr entry must be flagged"); 2280 BlockList* s = new BlockList(2); 2281 if (osr_entry != NULL) s->append(osr_entry); 2282 s->append(std_entry); // must be default sux! 2283 set_sux(s); 2284 } 2285 2286 // accessors 2287 BlockBegin* std_entry() const { return default_sux(); } 2288 BlockBegin* osr_entry() const { return number_of_sux() < 2 ? NULL : sux_at(0); } 2289 }; 2290 2291 2292 LEAF(OsrEntry, Instruction) 2293 public: 2294 // creation 2295 #ifdef _LP64 2296 OsrEntry() : Instruction(longType) { pin(); } 2297 #else 2298 OsrEntry() : Instruction(intType) { pin(); } 2299 #endif 2300 2301 // generic 2302 virtual void input_values_do(ValueVisitor* f) { } 2303 }; 2304 2305 2306 // Models the incoming exception at a catch site 2307 LEAF(ExceptionObject, Instruction) 2308 public: 2309 // creation 2310 ExceptionObject() : Instruction(objectType) { 2311 pin(); 2312 } 2313 2314 // generic 2315 virtual void input_values_do(ValueVisitor* f) { } 2316 }; 2317 2318 2319 // Models needed rounding for floating-point values on Intel. 2320 // Currently only used to represent rounding of double-precision 2321 // values stored into local variables, but could be used to model 2322 // intermediate rounding of single-precision values as well. 2323 LEAF(RoundFP, Instruction) 2324 private: 2325 Value _input; // floating-point value to be rounded 2326 2327 public: 2328 RoundFP(Value input) 2329 : Instruction(input->type()) // Note: should not be used for constants 2330 , _input(input) 2331 { 2332 ASSERT_VALUES 2333 } 2334 2335 // accessors 2336 Value input() const { return _input; } 2337 2338 // generic 2339 virtual void input_values_do(ValueVisitor* f) { f->visit(&_input); } 2340 }; 2341 2342 2343 BASE(UnsafeOp, Instruction) 2344 private: 2345 BasicType _basic_type; // ValueType can not express byte-sized integers 2346 2347 protected: 2348 // creation 2349 UnsafeOp(BasicType basic_type, bool is_put) 2350 : Instruction(is_put ? voidType : as_ValueType(basic_type)) 2351 , _basic_type(basic_type) 2352 { 2353 //Note: Unsafe ops are not not guaranteed to throw NPE. 2354 // Convservatively, Unsafe operations must be pinned though we could be 2355 // looser about this if we wanted to.. 2356 pin(); 2357 } 2358 2359 public: 2360 // accessors 2361 BasicType basic_type() { return _basic_type; } 2362 2363 // generic 2364 virtual void input_values_do(ValueVisitor* f) { } 2365 }; 2366 2367 2368 BASE(UnsafeRawOp, UnsafeOp) 2369 private: 2370 Value _base; // Base address (a Java long) 2371 Value _index; // Index if computed by optimizer; initialized to NULL 2372 int _log2_scale; // Scale factor: 0, 1, 2, or 3. 2373 // Indicates log2 of number of bytes (1, 2, 4, or 8) 2374 // to scale index by. 2375 2376 protected: 2377 UnsafeRawOp(BasicType basic_type, Value addr, bool is_put) 2378 : UnsafeOp(basic_type, is_put) 2379 , _base(addr) 2380 , _index(NULL) 2381 , _log2_scale(0) 2382 { 2383 // Can not use ASSERT_VALUES because index may be NULL 2384 assert(addr != NULL && addr->type()->is_long(), "just checking"); 2385 } 2386 2387 UnsafeRawOp(BasicType basic_type, Value base, Value index, int log2_scale, bool is_put) 2388 : UnsafeOp(basic_type, is_put) 2389 , _base(base) 2390 , _index(index) 2391 , _log2_scale(log2_scale) 2392 { 2393 } 2394 2395 public: 2396 // accessors 2397 Value base() { return _base; } 2398 Value index() { return _index; } 2399 bool has_index() { return (_index != NULL); } 2400 int log2_scale() { return _log2_scale; } 2401 2402 // setters 2403 void set_base (Value base) { _base = base; } 2404 void set_index(Value index) { _index = index; } 2405 void set_log2_scale(int log2_scale) { _log2_scale = log2_scale; } 2406 2407 // generic 2408 virtual void input_values_do(ValueVisitor* f) { UnsafeOp::input_values_do(f); 2409 f->visit(&_base); 2410 if (has_index()) f->visit(&_index); } 2411 }; 2412 2413 2414 LEAF(UnsafeGetRaw, UnsafeRawOp) 2415 private: 2416 bool _may_be_unaligned, _is_wide; // For OSREntry 2417 2418 public: 2419 UnsafeGetRaw(BasicType basic_type, Value addr, bool may_be_unaligned, bool is_wide = false) 2420 : UnsafeRawOp(basic_type, addr, false) { 2421 _may_be_unaligned = may_be_unaligned; 2422 _is_wide = is_wide; 2423 } 2424 2425 UnsafeGetRaw(BasicType basic_type, Value base, Value index, int log2_scale, bool may_be_unaligned, bool is_wide = false) 2426 : UnsafeRawOp(basic_type, base, index, log2_scale, false) { 2427 _may_be_unaligned = may_be_unaligned; 2428 _is_wide = is_wide; 2429 } 2430 2431 bool may_be_unaligned() { return _may_be_unaligned; } 2432 bool is_wide() { return _is_wide; } 2433 }; 2434 2435 2436 LEAF(UnsafePutRaw, UnsafeRawOp) 2437 private: 2438 Value _value; // Value to be stored 2439 2440 public: 2441 UnsafePutRaw(BasicType basic_type, Value addr, Value value) 2442 : UnsafeRawOp(basic_type, addr, true) 2443 , _value(value) 2444 { 2445 assert(value != NULL, "just checking"); 2446 ASSERT_VALUES 2447 } 2448 2449 UnsafePutRaw(BasicType basic_type, Value base, Value index, int log2_scale, Value value) 2450 : UnsafeRawOp(basic_type, base, index, log2_scale, true) 2451 , _value(value) 2452 { 2453 assert(value != NULL, "just checking"); 2454 ASSERT_VALUES 2455 } 2456 2457 // accessors 2458 Value value() { return _value; } 2459 2460 // generic 2461 virtual void input_values_do(ValueVisitor* f) { UnsafeRawOp::input_values_do(f); 2462 f->visit(&_value); } 2463 }; 2464 2465 2466 BASE(UnsafeObjectOp, UnsafeOp) 2467 private: 2468 Value _object; // Object to be fetched from or mutated 2469 Value _offset; // Offset within object 2470 bool _is_volatile; // true if volatile - dl/JSR166 2471 public: 2472 UnsafeObjectOp(BasicType basic_type, Value object, Value offset, bool is_put, bool is_volatile) 2473 : UnsafeOp(basic_type, is_put), _object(object), _offset(offset), _is_volatile(is_volatile) 2474 { 2475 } 2476 2477 // accessors 2478 Value object() { return _object; } 2479 Value offset() { return _offset; } 2480 bool is_volatile() { return _is_volatile; } 2481 // generic 2482 virtual void input_values_do(ValueVisitor* f) { UnsafeOp::input_values_do(f); 2483 f->visit(&_object); 2484 f->visit(&_offset); } 2485 }; 2486 2487 2488 LEAF(UnsafeGetObject, UnsafeObjectOp) 2489 public: 2490 UnsafeGetObject(BasicType basic_type, Value object, Value offset, bool is_volatile) 2491 : UnsafeObjectOp(basic_type, object, offset, false, is_volatile) 2492 { 2493 ASSERT_VALUES 2494 } 2495 }; 2496 2497 2498 LEAF(UnsafePutObject, UnsafeObjectOp) 2499 private: 2500 Value _value; // Value to be stored 2501 public: 2502 UnsafePutObject(BasicType basic_type, Value object, Value offset, Value value, bool is_volatile) 2503 : UnsafeObjectOp(basic_type, object, offset, true, is_volatile) 2504 , _value(value) 2505 { 2506 ASSERT_VALUES 2507 } 2508 2509 // accessors 2510 Value value() { return _value; } 2511 2512 // generic 2513 virtual void input_values_do(ValueVisitor* f) { UnsafeObjectOp::input_values_do(f); 2514 f->visit(&_value); } 2515 }; 2516 2517 LEAF(UnsafeGetAndSetObject, UnsafeObjectOp) 2518 private: 2519 Value _value; // Value to be stored 2520 bool _is_add; 2521 public: 2522 UnsafeGetAndSetObject(BasicType basic_type, Value object, Value offset, Value value, bool is_add) 2523 : UnsafeObjectOp(basic_type, object, offset, false, false) 2524 , _value(value) 2525 , _is_add(is_add) 2526 { 2527 ASSERT_VALUES 2528 } 2529 2530 // accessors 2531 bool is_add() const { return _is_add; } 2532 Value value() { return _value; } 2533 2534 // generic 2535 virtual void input_values_do(ValueVisitor* f) { UnsafeObjectOp::input_values_do(f); 2536 f->visit(&_value); } 2537 }; 2538 2539 LEAF(ProfileCall, Instruction) 2540 private: 2541 ciMethod* _method; 2542 int _bci_of_invoke; 2543 ciMethod* _callee; // the method that is called at the given bci 2544 Value _recv; 2545 ciKlass* _known_holder; 2546 Values* _obj_args; // arguments for type profiling 2547 ArgsNonNullState _nonnull_state; // Do we know whether some arguments are never null? 2548 bool _inlined; // Are we profiling a call that is inlined 2549 2550 public: 2551 ProfileCall(ciMethod* method, int bci, ciMethod* callee, Value recv, ciKlass* known_holder, Values* obj_args, bool inlined) 2552 : Instruction(voidType) 2553 , _method(method) 2554 , _bci_of_invoke(bci) 2555 , _callee(callee) 2556 , _recv(recv) 2557 , _known_holder(known_holder) 2558 , _obj_args(obj_args) 2559 , _inlined(inlined) 2560 { 2561 // The ProfileCall has side-effects and must occur precisely where located 2562 pin(); 2563 } 2564 2565 ciMethod* method() const { return _method; } 2566 int bci_of_invoke() const { return _bci_of_invoke; } 2567 ciMethod* callee() const { return _callee; } 2568 Value recv() const { return _recv; } 2569 ciKlass* known_holder() const { return _known_holder; } 2570 int nb_profiled_args() const { return _obj_args == NULL ? 0 : _obj_args->length(); } 2571 Value profiled_arg_at(int i) const { return _obj_args->at(i); } 2572 bool arg_needs_null_check(int i) const { 2573 return _nonnull_state.arg_needs_null_check(i); 2574 } 2575 bool inlined() const { return _inlined; } 2576 2577 void set_arg_needs_null_check(int i, bool check) { 2578 _nonnull_state.set_arg_needs_null_check(i, check); 2579 } 2580 2581 virtual void input_values_do(ValueVisitor* f) { 2582 if (_recv != NULL) { 2583 f->visit(&_recv); 2584 } 2585 for (int i = 0; i < nb_profiled_args(); i++) { 2586 f->visit(_obj_args->adr_at(i)); 2587 } 2588 } 2589 }; 2590 2591 LEAF(ProfileReturnType, Instruction) 2592 private: 2593 ciMethod* _method; 2594 ciMethod* _callee; 2595 int _bci_of_invoke; 2596 Value _ret; 2597 2598 public: 2599 ProfileReturnType(ciMethod* method, int bci, ciMethod* callee, Value ret) 2600 : Instruction(voidType) 2601 , _method(method) 2602 , _callee(callee) 2603 , _bci_of_invoke(bci) 2604 , _ret(ret) 2605 { 2606 set_needs_null_check(true); 2607 // The ProfileType has side-effects and must occur precisely where located 2608 pin(); 2609 } 2610 2611 ciMethod* method() const { return _method; } 2612 ciMethod* callee() const { return _callee; } 2613 int bci_of_invoke() const { return _bci_of_invoke; } 2614 Value ret() const { return _ret; } 2615 2616 virtual void input_values_do(ValueVisitor* f) { 2617 if (_ret != NULL) { 2618 f->visit(&_ret); 2619 } 2620 } 2621 }; 2622 2623 // Call some C runtime function that doesn't safepoint, 2624 // optionally passing the current thread as the first argument. 2625 LEAF(RuntimeCall, Instruction) 2626 private: 2627 const char* _entry_name; 2628 address _entry; 2629 Values* _args; 2630 bool _pass_thread; // Pass the JavaThread* as an implicit first argument 2631 2632 public: 2633 RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true) 2634 : Instruction(type) 2635 , _entry_name(entry_name) 2636 , _entry(entry) 2637 , _args(args) 2638 , _pass_thread(pass_thread) { 2639 ASSERT_VALUES 2640 pin(); 2641 } 2642 2643 const char* entry_name() const { return _entry_name; } 2644 address entry() const { return _entry; } 2645 int number_of_arguments() const { return _args->length(); } 2646 Value argument_at(int i) const { return _args->at(i); } 2647 bool pass_thread() const { return _pass_thread; } 2648 2649 virtual void input_values_do(ValueVisitor* f) { 2650 for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i)); 2651 } 2652 }; 2653 2654 // Use to trip invocation counter of an inlined method 2655 2656 LEAF(ProfileInvoke, Instruction) 2657 private: 2658 ciMethod* _inlinee; 2659 ValueStack* _state; 2660 2661 public: 2662 ProfileInvoke(ciMethod* inlinee, ValueStack* state) 2663 : Instruction(voidType) 2664 , _inlinee(inlinee) 2665 , _state(state) 2666 { 2667 // The ProfileInvoke has side-effects and must occur precisely where located QQQ??? 2668 pin(); 2669 } 2670 2671 ciMethod* inlinee() { return _inlinee; } 2672 ValueStack* state() { return _state; } 2673 virtual void input_values_do(ValueVisitor*) {} 2674 virtual void state_values_do(ValueVisitor*); 2675 }; 2676 2677 LEAF(MemBar, Instruction) 2678 private: 2679 LIR_Code _code; 2680 2681 public: 2682 MemBar(LIR_Code code) 2683 : Instruction(voidType) 2684 , _code(code) 2685 { 2686 pin(); 2687 } 2688 2689 LIR_Code code() { return _code; } 2690 2691 virtual void input_values_do(ValueVisitor*) {} 2692 }; 2693 2694 class BlockPair: public CompilationResourceObj { 2695 private: 2696 BlockBegin* _from; 2697 BlockBegin* _to; 2698 public: 2699 BlockPair(BlockBegin* from, BlockBegin* to): _from(from), _to(to) {} 2700 BlockBegin* from() const { return _from; } 2701 BlockBegin* to() const { return _to; } 2702 bool is_same(BlockBegin* from, BlockBegin* to) const { return _from == from && _to == to; } 2703 bool is_same(BlockPair* p) const { return _from == p->from() && _to == p->to(); } 2704 void set_to(BlockBegin* b) { _to = b; } 2705 void set_from(BlockBegin* b) { _from = b; } 2706 }; 2707 2708 typedef GrowableArray<BlockPair*> BlockPairList; 2709 2710 inline int BlockBegin::number_of_sux() const { assert(_end == NULL || _end->number_of_sux() == _successors.length(), "mismatch"); return _successors.length(); } 2711 inline BlockBegin* BlockBegin::sux_at(int i) const { assert(_end == NULL || _end->sux_at(i) == _successors.at(i), "mismatch"); return _successors.at(i); } 2712 inline void BlockBegin::add_successor(BlockBegin* sux) { assert(_end == NULL, "Would create mismatch with successors of BlockEnd"); _successors.append(sux); } 2713 2714 #undef ASSERT_VALUES 2715 2716 #endif // SHARE_C1_C1_INSTRUCTION_HPP