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