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