c1_Instruction.hpp 90.2 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25 26 27 28 29 30 31 32
#ifndef SHARE_VM_C1_C1_INSTRUCTION_HPP
#define SHARE_VM_C1_C1_INSTRUCTION_HPP

#include "c1/c1_Compilation.hpp"
#include "c1/c1_LIR.hpp"
#include "c1/c1_ValueType.hpp"
#include "ci/ciField.hpp"

D
duke 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
// Predefined classes
class ciField;
class ValueStack;
class InstructionPrinter;
class IRScope;
class LIR_OprDesc;
typedef LIR_OprDesc* LIR_Opr;


// Instruction class hierarchy
//
// All leaf classes in the class hierarchy are concrete classes
// (i.e., are instantiated). All other classes are abstract and
// serve factoring.

class Instruction;
class   Phi;
class   Local;
class   Constant;
class   AccessField;
class     LoadField;
class     StoreField;
class   AccessArray;
class     ArrayLength;
class     AccessIndexed;
class       LoadIndexed;
class       StoreIndexed;
class   NegateOp;
class   Op2;
class     ArithmeticOp;
class     ShiftOp;
class     LogicOp;
class     CompareOp;
class     IfOp;
class   Convert;
class   NullCheck;
69
class   TypeCast;
D
duke 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
class   OsrEntry;
class   ExceptionObject;
class   StateSplit;
class     Invoke;
class     NewInstance;
class     NewArray;
class       NewTypeArray;
class       NewObjectArray;
class       NewMultiArray;
class     TypeCheck;
class       CheckCast;
class       InstanceOf;
class     AccessMonitor;
class       MonitorEnter;
class       MonitorExit;
class     Intrinsic;
class     BlockBegin;
class     BlockEnd;
class       Goto;
class       If;
class       IfInstanceOf;
class       Switch;
class         TableSwitch;
class         LookupSwitch;
class       Return;
class       Throw;
class       Base;
class   RoundFP;
class   UnsafeOp;
class     UnsafeRawOp;
class       UnsafeGetRaw;
class       UnsafePutRaw;
class     UnsafeObjectOp;
class       UnsafeGetObject;
class       UnsafePutObject;
105
class         UnsafeGetAndSetObject;
D
duke 已提交
106 107 108 109
class       UnsafePrefetch;
class         UnsafePrefetchRead;
class         UnsafePrefetchWrite;
class   ProfileCall;
110
class   ProfileReturnType;
I
iveresov 已提交
111
class   ProfileInvoke;
112
class   RuntimeCall;
113
class   MemBar;
114
class   RangeCheckPredicate;
115
#ifdef ASSERT
116
class   Assert;
117
#endif
D
duke 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134

// A Value is a reference to the instruction creating the value
typedef Instruction* Value;
define_array(ValueArray, Value)
define_stack(Values, ValueArray)

define_array(ValueStackArray, ValueStack*)
define_stack(ValueStackStack, ValueStackArray)

// BlockClosure is the base class for block traversal/iteration.

class BlockClosure: public CompilationResourceObj {
 public:
  virtual void block_do(BlockBegin* block)       = 0;
};


135 136 137 138 139 140 141
// A simple closure class for visiting the values of an Instruction
class ValueVisitor: public StackObj {
 public:
  virtual void visit(Value* v) = 0;
};


D
duke 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154
// Some array and list classes
define_array(BlockBeginArray, BlockBegin*)
define_stack(_BlockList, BlockBeginArray)

class BlockList: public _BlockList {
 public:
  BlockList(): _BlockList() {}
  BlockList(const int size): _BlockList(size) {}
  BlockList(const int size, BlockBegin* init): _BlockList(size, init) {}

  void iterate_forward(BlockClosure* closure);
  void iterate_backward(BlockClosure* closure);
  void blocks_do(void f(BlockBegin*));
155
  void values_do(ValueVisitor* f);
D
duke 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
  void print(bool cfg_only = false, bool live_only = false) PRODUCT_RETURN;
};


// InstructionVisitors provide type-based dispatch for instructions.
// For each concrete Instruction class X, a virtual function do_X is
// provided. Functionality that needs to be implemented for all classes
// (e.g., printing, code generation) is factored out into a specialised
// visitor instead of added to the Instruction classes itself.

class InstructionVisitor: public StackObj {
 public:
  virtual void do_Phi            (Phi*             x) = 0;
  virtual void do_Local          (Local*           x) = 0;
  virtual void do_Constant       (Constant*        x) = 0;
  virtual void do_LoadField      (LoadField*       x) = 0;
  virtual void do_StoreField     (StoreField*      x) = 0;
  virtual void do_ArrayLength    (ArrayLength*     x) = 0;
  virtual void do_LoadIndexed    (LoadIndexed*     x) = 0;
  virtual void do_StoreIndexed   (StoreIndexed*    x) = 0;
  virtual void do_NegateOp       (NegateOp*        x) = 0;
  virtual void do_ArithmeticOp   (ArithmeticOp*    x) = 0;
  virtual void do_ShiftOp        (ShiftOp*         x) = 0;
  virtual void do_LogicOp        (LogicOp*         x) = 0;
  virtual void do_CompareOp      (CompareOp*       x) = 0;
  virtual void do_IfOp           (IfOp*            x) = 0;
  virtual void do_Convert        (Convert*         x) = 0;
  virtual void do_NullCheck      (NullCheck*       x) = 0;
184
  virtual void do_TypeCast       (TypeCast*        x) = 0;
D
duke 已提交
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
  virtual void do_Invoke         (Invoke*          x) = 0;
  virtual void do_NewInstance    (NewInstance*     x) = 0;
  virtual void do_NewTypeArray   (NewTypeArray*    x) = 0;
  virtual void do_NewObjectArray (NewObjectArray*  x) = 0;
  virtual void do_NewMultiArray  (NewMultiArray*   x) = 0;
  virtual void do_CheckCast      (CheckCast*       x) = 0;
  virtual void do_InstanceOf     (InstanceOf*      x) = 0;
  virtual void do_MonitorEnter   (MonitorEnter*    x) = 0;
  virtual void do_MonitorExit    (MonitorExit*     x) = 0;
  virtual void do_Intrinsic      (Intrinsic*       x) = 0;
  virtual void do_BlockBegin     (BlockBegin*      x) = 0;
  virtual void do_Goto           (Goto*            x) = 0;
  virtual void do_If             (If*              x) = 0;
  virtual void do_IfInstanceOf   (IfInstanceOf*    x) = 0;
  virtual void do_TableSwitch    (TableSwitch*     x) = 0;
  virtual void do_LookupSwitch   (LookupSwitch*    x) = 0;
  virtual void do_Return         (Return*          x) = 0;
  virtual void do_Throw          (Throw*           x) = 0;
  virtual void do_Base           (Base*            x) = 0;
  virtual void do_OsrEntry       (OsrEntry*        x) = 0;
  virtual void do_ExceptionObject(ExceptionObject* x) = 0;
  virtual void do_RoundFP        (RoundFP*         x) = 0;
  virtual void do_UnsafeGetRaw   (UnsafeGetRaw*    x) = 0;
  virtual void do_UnsafePutRaw   (UnsafePutRaw*    x) = 0;
  virtual void do_UnsafeGetObject(UnsafeGetObject* x) = 0;
  virtual void do_UnsafePutObject(UnsafePutObject* x) = 0;
211
  virtual void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) = 0;
D
duke 已提交
212 213 214
  virtual void do_UnsafePrefetchRead (UnsafePrefetchRead*  x) = 0;
  virtual void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) = 0;
  virtual void do_ProfileCall    (ProfileCall*     x) = 0;
215
  virtual void do_ProfileReturnType (ProfileReturnType*  x) = 0;
I
iveresov 已提交
216
  virtual void do_ProfileInvoke  (ProfileInvoke*   x) = 0;
217
  virtual void do_RuntimeCall    (RuntimeCall*     x) = 0;
218
  virtual void do_MemBar         (MemBar*          x) = 0;
219 220 221 222
  virtual void do_RangeCheckPredicate(RangeCheckPredicate* x) = 0;
#ifdef ASSERT
  virtual void do_Assert         (Assert*          x) = 0;
#endif
D
duke 已提交
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
};


// Hashing support
//
// Note: This hash functions affect the performance
//       of ValueMap - make changes carefully!

#define HASH1(x1            )                    ((intx)(x1))
#define HASH2(x1, x2        )                    ((HASH1(x1        ) << 7) ^ HASH1(x2))
#define HASH3(x1, x2, x3    )                    ((HASH2(x1, x2    ) << 7) ^ HASH1(x3))
#define HASH4(x1, x2, x3, x4)                    ((HASH3(x1, x2, x3) << 7) ^ HASH1(x4))


// The following macros are used to implement instruction-specific hashing.
// By default, each instruction implements hash() and is_equal(Value), used
// for value numbering/common subexpression elimination. The default imple-
// mentation disables value numbering. Each instruction which can be value-
// numbered, should define corresponding hash() and is_equal(Value) functions
// via the macros below. The f arguments specify all the values/op codes, etc.
// that need to be identical for two instructions to be identical.
//
// Note: The default implementation of hash() returns 0 in order to indicate
//       that the instruction should not be considered for value numbering.
//       The currently used hash functions do not guarantee that never a 0
//       is produced. While this is still correct, it may be a performance
//       bug (no value numbering for that node). However, this situation is
//       so unlikely, that we are not going to handle it specially.

#define HASHING1(class_name, enabled, f1)             \
  virtual intx hash() const {                         \
    return (enabled) ? HASH2(name(), f1) : 0;         \
  }                                                   \
  virtual bool is_equal(Value v) const {              \
    if (!(enabled)  ) return false;                   \
    class_name* _v = v->as_##class_name();            \
    if (_v == NULL  ) return false;                   \
    if (f1 != _v->f1) return false;                   \
    return true;                                      \
  }                                                   \


#define HASHING2(class_name, enabled, f1, f2)         \
  virtual intx hash() const {                         \
    return (enabled) ? HASH3(name(), f1, f2) : 0;     \
  }                                                   \
  virtual bool is_equal(Value v) const {              \
    if (!(enabled)  ) return false;                   \
    class_name* _v = v->as_##class_name();            \
    if (_v == NULL  ) return false;                   \
    if (f1 != _v->f1) return false;                   \
    if (f2 != _v->f2) return false;                   \
    return true;                                      \
  }                                                   \


#define HASHING3(class_name, enabled, f1, f2, f3)     \
  virtual intx hash() const {                          \
    return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \
  }                                                   \
  virtual bool is_equal(Value v) const {              \
    if (!(enabled)  ) return false;                   \
    class_name* _v = v->as_##class_name();            \
    if (_v == NULL  ) return false;                   \
    if (f1 != _v->f1) return false;                   \
    if (f2 != _v->f2) return false;                   \
    if (f3 != _v->f3) return false;                   \
    return true;                                      \
  }                                                   \


// The mother of all instructions...

class Instruction: public CompilationResourceObj {
 private:
  int          _id;                              // the unique instruction id
R
roland 已提交
299 300 301
#ifndef PRODUCT
  int          _printable_bci;                   // the bci of the instruction for printing
#endif
D
duke 已提交
302 303 304 305 306 307 308 309
  int          _use_count;                       // the number of instructions refering to this value (w/o prev/next); only roots can have use count = 0 or > 1
  int          _pin_state;                       // set of PinReason describing the reason for pinning
  ValueType*   _type;                            // the instruction value type
  Instruction* _next;                            // the next instruction if any (NULL for BlockEnd instructions)
  Instruction* _subst;                           // the substitution instruction if any
  LIR_Opr      _operand;                         // LIR specific information
  unsigned int _flags;                           // Flag bits

R
roland 已提交
310 311
  ValueStack*  _state_before;                    // Copy of state with input operands still on stack (or NULL)
  ValueStack*  _exception_state;                 // Copy of state for exception handling
D
duke 已提交
312 313 314
  XHandlers*   _exception_handlers;              // Flat list of exception handlers covering this instruction

  friend class UseCountComputer;
315
  friend class BlockBegin;
D
duke 已提交
316

R
roland 已提交
317 318
  void update_exception_state(ValueStack* state);

319 320 321
 protected:
  BlockBegin*  _block;                           // Block that contains this instruction

D
duke 已提交
322 323 324 325 326
  void set_type(ValueType* type) {
    assert(type != NULL, "type must exist");
    _type = type;
  }

327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
  // Helper class to keep track of which arguments need a null check
  class ArgsNonNullState {
  private:
    int _nonnull_state; // mask identifying which args are nonnull
  public:
    ArgsNonNullState()
      : _nonnull_state(AllBits) {}

    // Does argument number i needs a null check?
    bool arg_needs_null_check(int i) const {
      // No data is kept for arguments starting at position 33 so
      // conservatively assume that they need a null check.
      if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {
        return is_set_nth_bit(_nonnull_state, i);
      }
      return true;
    }

    // Set whether argument number i needs a null check or not
    void set_arg_needs_null_check(int i, bool check) {
      if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {
        if (check) {
          _nonnull_state |= nth_bit(i);
        } else {
          _nonnull_state &= ~(nth_bit(i));
        }
      }
    }
  };

D
duke 已提交
357
 public:
358
  void* operator new(size_t size) throw() {
359 360 361 362 363 364
    Compilation* c = Compilation::current();
    void* res = c->arena()->Amalloc(size);
    ((Instruction*)res)->_id = c->get_next_id();
    return res;
  }

365 366
  static const int no_bci = -99;

D
duke 已提交
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
  enum InstructionFlag {
    NeedsNullCheckFlag = 0,
    CanTrapFlag,
    DirectCompareFlag,
    IsEliminatedFlag,
    IsSafepointFlag,
    IsStaticFlag,
    IsStrictfpFlag,
    NeedsStoreCheckFlag,
    NeedsWriteBarrierFlag,
    PreservesStateFlag,
    TargetIsFinalFlag,
    TargetIsLoadedFlag,
    TargetIsStrictfpFlag,
    UnorderedIsTrueFlag,
    NeedsPatchingFlag,
    ThrowIncompatibleClassChangeErrorFlag,
    ProfileMDOFlag,
R
roland 已提交
385
    IsLinkedInBlockFlag,
386 387 388
    NeedsRangeCheckFlag,
    InWorkListFlag,
    DeoptimizeOnException,
D
duke 已提交
389 390 391 392 393 394 395 396 397
    InstructionLastFlag
  };

 public:
  bool check_flag(InstructionFlag id) const      { return (_flags & (1 << id)) != 0;    }
  void set_flag(InstructionFlag id, bool f)      { _flags = f ? (_flags | (1 << id)) : (_flags & ~(1 << id)); };

  // 'globally' used condition values
  enum Condition {
398
    eql, neq, lss, leq, gtr, geq, aeq, beq
D
duke 已提交
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
  };

  // Instructions may be pinned for many reasons and under certain conditions
  // with enough knowledge it's possible to safely unpin them.
  enum PinReason {
      PinUnknown           = 1 << 0
    , PinExplicitNullCheck = 1 << 3
    , PinStackForStateSplit= 1 << 12
    , PinStateSplitConstructor= 1 << 13
    , PinGlobalValueNumbering= 1 << 14
  };

  static Condition mirror(Condition cond);
  static Condition negate(Condition cond);

  // initialization
415 416 417
  static int number_of_instructions() {
    return Compilation::current()->number_of_instructions();
  }
D
duke 已提交
418 419

  // creation
420
  Instruction(ValueType* type, ValueStack* state_before = NULL, bool type_is_constant = false)
R
roland 已提交
421 422 423 424
  : _use_count(0)
#ifndef PRODUCT
  , _printable_bci(-99)
#endif
D
duke 已提交
425 426 427
  , _pin_state(0)
  , _type(type)
  , _next(NULL)
428
  , _block(NULL)
D
duke 已提交
429 430 431
  , _subst(NULL)
  , _flags(0)
  , _operand(LIR_OprFact::illegalOpr)
R
roland 已提交
432
  , _state_before(state_before)
D
duke 已提交
433 434
  , _exception_handlers(NULL)
  {
R
roland 已提交
435
    check_state(state_before);
D
duke 已提交
436
    assert(type != NULL && (!type->is_constant() || type_is_constant), "type must exist");
R
roland 已提交
437
    update_exception_state(_state_before);
D
duke 已提交
438 439 440 441
  }

  // accessors
  int id() const                                 { return _id; }
R
roland 已提交
442
#ifndef PRODUCT
443
  bool has_printable_bci() const                 { return _printable_bci != -99; }
R
roland 已提交
444
  int printable_bci() const                      { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; }
445
  void set_printable_bci(int bci)                { _printable_bci = bci; }
R
roland 已提交
446
#endif
447
  int dominator_depth();
D
duke 已提交
448 449 450 451
  int use_count() const                          { return _use_count; }
  int pin_state() const                          { return _pin_state; }
  bool is_pinned() const                         { return _pin_state != 0 || PinAllInstructions; }
  ValueType* type() const                        { return _type; }
452 453
  BlockBegin *block() const                      { return _block; }
  Instruction* prev();                           // use carefully, expensive operation
D
duke 已提交
454 455 456 457 458 459 460
  Instruction* next() const                      { return _next; }
  bool has_subst() const                         { return _subst != NULL; }
  Instruction* subst()                           { return _subst == NULL ? this : _subst->subst(); }
  LIR_Opr operand() const                        { return _operand; }

  void set_needs_null_check(bool f)              { set_flag(NeedsNullCheckFlag, f); }
  bool needs_null_check() const                  { return check_flag(NeedsNullCheckFlag); }
R
roland 已提交
461 462
  bool is_linked() const                         { return check_flag(IsLinkedInBlockFlag); }
  bool can_be_linked()                           { return as_Local() == NULL && as_Phi() == NULL; }
D
duke 已提交
463 464

  bool has_uses() const                          { return use_count() > 0; }
R
roland 已提交
465 466 467
  ValueStack* state_before() const               { return _state_before; }
  ValueStack* exception_state() const            { return _exception_state; }
  virtual bool needs_exception_state() const     { return true; }
D
duke 已提交
468 469 470 471 472 473 474 475
  XHandlers* exception_handlers() const          { return _exception_handlers; }

  // manipulation
  void pin(PinReason reason)                     { _pin_state |= reason; }
  void pin()                                     { _pin_state |= PinUnknown; }
  // DANGEROUS: only used by EliminateStores
  void unpin(PinReason reason)                   { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; }

R
roland 已提交
476 477 478 479 480 481
  Instruction* set_next(Instruction* next) {
    assert(next->has_printable_bci(), "_printable_bci should have been set");
    assert(next != NULL, "must not be NULL");
    assert(as_BlockEnd() == NULL, "BlockEnd instructions must have no next");
    assert(next->can_be_linked(), "shouldn't link these instructions into list");

482 483 484
    BlockBegin *block = this->block();
    next->_block = block;

R
roland 已提交
485
    next->set_flag(Instruction::IsLinkedInBlockFlag, true);
D
duke 已提交
486 487 488 489
    _next = next;
    return next;
  }

R
roland 已提交
490 491 492 493 494 495 496
  Instruction* set_next(Instruction* next, int bci) {
#ifndef PRODUCT
    next->set_printable_bci(bci);
#endif
    return set_next(next);
  }

497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
  // when blocks are merged
  void fixup_block_pointers() {
    Instruction *cur = next()->next(); // next()'s block is set in set_next
    while (cur && cur->_block != block()) {
      cur->_block = block();
      cur = cur->next();
    }
  }

  Instruction *insert_after(Instruction *i) {
    Instruction* n = _next;
    set_next(i);
    i->set_next(n);
    return _next;
  }

  Instruction *insert_after_same_bci(Instruction *i) {
#ifndef PRODUCT
    i->set_printable_bci(printable_bci());
#endif
    return insert_after(i);
  }

D
duke 已提交
520 521 522 523 524 525 526
  void set_subst(Instruction* subst)             {
    assert(subst == NULL ||
           type()->base() == subst->type()->base() ||
           subst->type()->base() == illegalType, "type can't change");
    _subst = subst;
  }
  void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; }
R
roland 已提交
527
  void set_exception_state(ValueStack* s)        { check_state(s); _exception_state = s; }
528
  void set_state_before(ValueStack* s)           { check_state(s); _state_before = s; }
D
duke 已提交
529 530 531 532 533 534 535

  // machine-specifics
  void set_operand(LIR_Opr operand)              { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; }
  void clear_operand()                           { _operand = LIR_OprFact::illegalOpr; }

  // generic
  virtual Instruction*      as_Instruction()     { return this; } // to satisfy HASHING1 macro
R
roland 已提交
536
  virtual Phi*              as_Phi()             { return NULL; }
D
duke 已提交
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
  virtual Local*            as_Local()           { return NULL; }
  virtual Constant*         as_Constant()        { return NULL; }
  virtual AccessField*      as_AccessField()     { return NULL; }
  virtual LoadField*        as_LoadField()       { return NULL; }
  virtual StoreField*       as_StoreField()      { return NULL; }
  virtual AccessArray*      as_AccessArray()     { return NULL; }
  virtual ArrayLength*      as_ArrayLength()     { return NULL; }
  virtual AccessIndexed*    as_AccessIndexed()   { return NULL; }
  virtual LoadIndexed*      as_LoadIndexed()     { return NULL; }
  virtual StoreIndexed*     as_StoreIndexed()    { return NULL; }
  virtual NegateOp*         as_NegateOp()        { return NULL; }
  virtual Op2*              as_Op2()             { return NULL; }
  virtual ArithmeticOp*     as_ArithmeticOp()    { return NULL; }
  virtual ShiftOp*          as_ShiftOp()         { return NULL; }
  virtual LogicOp*          as_LogicOp()         { return NULL; }
  virtual CompareOp*        as_CompareOp()       { return NULL; }
  virtual IfOp*             as_IfOp()            { return NULL; }
  virtual Convert*          as_Convert()         { return NULL; }
  virtual NullCheck*        as_NullCheck()       { return NULL; }
  virtual OsrEntry*         as_OsrEntry()        { return NULL; }
  virtual StateSplit*       as_StateSplit()      { return NULL; }
  virtual Invoke*           as_Invoke()          { return NULL; }
  virtual NewInstance*      as_NewInstance()     { return NULL; }
  virtual NewArray*         as_NewArray()        { return NULL; }
  virtual NewTypeArray*     as_NewTypeArray()    { return NULL; }
  virtual NewObjectArray*   as_NewObjectArray()  { return NULL; }
  virtual NewMultiArray*    as_NewMultiArray()   { return NULL; }
  virtual TypeCheck*        as_TypeCheck()       { return NULL; }
  virtual CheckCast*        as_CheckCast()       { return NULL; }
  virtual InstanceOf*       as_InstanceOf()      { return NULL; }
567
  virtual TypeCast*         as_TypeCast()        { return NULL; }
D
duke 已提交
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
  virtual AccessMonitor*    as_AccessMonitor()   { return NULL; }
  virtual MonitorEnter*     as_MonitorEnter()    { return NULL; }
  virtual MonitorExit*      as_MonitorExit()     { return NULL; }
  virtual Intrinsic*        as_Intrinsic()       { return NULL; }
  virtual BlockBegin*       as_BlockBegin()      { return NULL; }
  virtual BlockEnd*         as_BlockEnd()        { return NULL; }
  virtual Goto*             as_Goto()            { return NULL; }
  virtual If*               as_If()              { return NULL; }
  virtual IfInstanceOf*     as_IfInstanceOf()    { return NULL; }
  virtual TableSwitch*      as_TableSwitch()     { return NULL; }
  virtual LookupSwitch*     as_LookupSwitch()    { return NULL; }
  virtual Return*           as_Return()          { return NULL; }
  virtual Throw*            as_Throw()           { return NULL; }
  virtual Base*             as_Base()            { return NULL; }
  virtual RoundFP*          as_RoundFP()         { return NULL; }
  virtual ExceptionObject*  as_ExceptionObject() { return NULL; }
  virtual UnsafeOp*         as_UnsafeOp()        { return NULL; }
585
  virtual ProfileInvoke*    as_ProfileInvoke()   { return NULL; }
586 587 588 589 590
  virtual RangeCheckPredicate* as_RangeCheckPredicate() { return NULL; }

#ifdef ASSERT
  virtual Assert*           as_Assert()          { return NULL; }
#endif
D
duke 已提交
591 592 593 594 595

  virtual void visit(InstructionVisitor* v)      = 0;

  virtual bool can_trap() const                  { return false; }

596
  virtual void input_values_do(ValueVisitor* f)   = 0;
R
roland 已提交
597
  virtual void state_values_do(ValueVisitor* f);
598 599
  virtual void other_values_do(ValueVisitor* f)   { /* usually no other - override on demand */ }
          void       values_do(ValueVisitor* f)   { input_values_do(f); state_values_do(f); other_values_do(f); }
D
duke 已提交
600

601
  virtual ciType* exact_type() const;
D
duke 已提交
602 603 604 605 606 607 608
  virtual ciType* declared_type() const          { return NULL; }

  // hashing
  virtual const char* name() const               = 0;
  HASHING1(Instruction, false, id())             // hashing disabled by default

  // debugging
R
roland 已提交
609
  static void check_state(ValueStack* state)     PRODUCT_RETURN;
D
duke 已提交
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
  void print()                                   PRODUCT_RETURN;
  void print_line()                              PRODUCT_RETURN;
  void print(InstructionPrinter& ip)             PRODUCT_RETURN;
};


// The following macros are used to define base (i.e., non-leaf)
// and leaf instruction classes. They define class-name related
// generic functionality in one place.

#define BASE(class_name, super_class_name)       \
  class class_name: public super_class_name {    \
   public:                                       \
    virtual class_name* as_##class_name()        { return this; }              \


#define LEAF(class_name, super_class_name)       \
  BASE(class_name, super_class_name)             \
   public:                                       \
    virtual const char* name() const             { return #class_name; }       \
    virtual void visit(InstructionVisitor* v)    { v->do_##class_name(this); } \


// Debugging support

635

D
duke 已提交
636
#ifdef ASSERT
637 638 639 640
class AssertValues: public ValueVisitor {
  void visit(Value* x)             { assert((*x) != NULL, "value must exist"); }
};
  #define ASSERT_VALUES                          { AssertValues assert_value; values_do(&assert_value); }
D
duke 已提交
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
#else
  #define ASSERT_VALUES
#endif // ASSERT


// A Phi is a phi function in the sense of SSA form. It stands for
// the value of a local variable at the beginning of a join block.
// A Phi consists of n operands, one for every incoming branch.

LEAF(Phi, Instruction)
 private:
  int         _pf_flags; // the flags of the phi function
  int         _index;    // to value on operand stack (index < 0) or to local
 public:
  // creation
  Phi(ValueType* type, BlockBegin* b, int index)
  : Instruction(type->base())
  , _pf_flags(0)
  , _index(index)
  {
661
    _block = b;
662
    NOT_PRODUCT(set_printable_bci(Value(b)->printable_bci()));
D
duke 已提交
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699
    if (type->is_illegal()) {
      make_illegal();
    }
  }

  // flags
  enum Flag {
    no_flag         = 0,
    visited         = 1 << 0,
    cannot_simplify = 1 << 1
  };

  // accessors
  bool  is_local() const          { return _index >= 0; }
  bool  is_on_stack() const       { return !is_local(); }
  int   local_index() const       { assert(is_local(), ""); return _index; }
  int   stack_index() const       { assert(is_on_stack(), ""); return -(_index+1); }

  Value operand_at(int i) const;
  int   operand_count() const;

  void   set(Flag f)              { _pf_flags |=  f; }
  void   clear(Flag f)            { _pf_flags &= ~f; }
  bool   is_set(Flag f) const     { return (_pf_flags & f) != 0; }

  // Invalidates phis corresponding to merges of locals of two different types
  // (these should never be referenced, otherwise the bytecodes are illegal)
  void   make_illegal() {
    set(cannot_simplify);
    set_type(illegalType);
  }

  bool is_illegal() const {
    return type()->is_illegal();
  }

  // generic
700
  virtual void input_values_do(ValueVisitor* f) {
D
duke 已提交
701 702 703 704 705 706 707 708
  }
};


// A local is a placeholder for an incoming argument to a function call.
LEAF(Local, Instruction)
 private:
  int      _java_index;                          // the local index within the method to which the local belongs
709
  ciType*  _declared_type;
D
duke 已提交
710 711
 public:
  // creation
712
  Local(ciType* declared, ValueType* type, int index)
D
duke 已提交
713 714
    : Instruction(type)
    , _java_index(index)
715
    , _declared_type(declared)
716 717 718
  {
    NOT_PRODUCT(set_printable_bci(-1));
  }
D
duke 已提交
719 720 721 722

  // accessors
  int java_index() const                         { return _java_index; }

723
  virtual ciType* declared_type() const          { return _declared_type; }
724

D
duke 已提交
725
  // generic
726
  virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
D
duke 已提交
727 728 729 730 731 732 733
};


LEAF(Constant, Instruction)
 public:
  // creation
  Constant(ValueType* type):
734
      Instruction(type, NULL, /*type_is_constant*/ true)
R
roland 已提交
735
  {
D
duke 已提交
736 737 738
    assert(type->is_constant(), "must be a constant");
  }

R
roland 已提交
739
  Constant(ValueType* type, ValueStack* state_before):
740
    Instruction(type, state_before, /*type_is_constant*/ true)
R
roland 已提交
741 742
  {
    assert(state_before != NULL, "only used for constants which need patching");
D
duke 已提交
743 744 745 746 747
    assert(type->is_constant(), "must be a constant");
    // since it's patching it needs to be pinned
    pin();
  }

748
  // generic
R
roland 已提交
749
  virtual bool can_trap() const                  { return state_before() != NULL; }
750
  virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
D
duke 已提交
751 752 753 754

  virtual intx hash() const;
  virtual bool is_equal(Value v) const;

755
  virtual ciType* exact_type() const;
R
roland 已提交
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773

  enum CompareResult { not_comparable = -1, cond_false, cond_true };

  virtual CompareResult compare(Instruction::Condition condition, Value right) const;
  BlockBegin* compare(Instruction::Condition cond, Value right,
                      BlockBegin* true_sux, BlockBegin* false_sux) const {
    switch (compare(cond, right)) {
    case not_comparable:
      return NULL;
    case cond_false:
      return false_sux;
    case cond_true:
      return true_sux;
    default:
      ShouldNotReachHere();
      return NULL;
    }
  }
D
duke 已提交
774 775 776 777 778 779 780 781 782 783 784 785
};


BASE(AccessField, Instruction)
 private:
  Value       _obj;
  int         _offset;
  ciField*    _field;
  NullCheck*  _explicit_null_check;              // For explicit null check elimination

 public:
  // creation
R
roland 已提交
786
  AccessField(Value obj, int offset, ciField* field, bool is_static,
787
              ValueStack* state_before, bool needs_patching)
R
roland 已提交
788
  : Instruction(as_ValueType(field->type()->basic_type()), state_before)
D
duke 已提交
789 790 791 792 793 794 795
  , _obj(obj)
  , _offset(offset)
  , _field(field)
  , _explicit_null_check(NULL)
  {
    set_needs_null_check(!is_static);
    set_flag(IsStaticFlag, is_static);
796
    set_flag(NeedsPatchingFlag, needs_patching);
D
duke 已提交
797 798 799 800 801 802 803 804 805 806 807 808 809 810
    ASSERT_VALUES
    // pin of all instructions with memory access
    pin();
  }

  // accessors
  Value obj() const                              { return _obj; }
  int offset() const                             { return _offset; }
  ciField* field() const                         { return _field; }
  BasicType field_type() const                   { return _field->type()->basic_type(); }
  bool is_static() const                         { return check_flag(IsStaticFlag); }
  NullCheck* explicit_null_check() const         { return _explicit_null_check; }
  bool needs_patching() const                    { return check_flag(NeedsPatchingFlag); }

811 812 813 814 815
  // Unresolved getstatic and putstatic can cause initialization.
  // Technically it occurs at the Constant that materializes the base
  // of the static fields but it's simpler to model it here.
  bool is_init_point() const                     { return is_static() && (needs_patching() || !_field->holder()->is_initialized()); }

D
duke 已提交
816
  // manipulation
R
roland 已提交
817

D
duke 已提交
818 819 820 821 822 823 824 825 826
  // Under certain circumstances, if a previous NullCheck instruction
  // proved the target object non-null, we can eliminate the explicit
  // null check and do an implicit one, simply specifying the debug
  // information from the NullCheck. This field should only be consulted
  // if needs_null_check() is true.
  void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }

  // generic
  virtual bool can_trap() const                  { return needs_null_check() || needs_patching(); }
827
  virtual void input_values_do(ValueVisitor* f)   { f->visit(&_obj); }
D
duke 已提交
828 829 830 831 832 833
};


LEAF(LoadField, AccessField)
 public:
  // creation
R
roland 已提交
834
  LoadField(Value obj, int offset, ciField* field, bool is_static,
835 836
            ValueStack* state_before, bool needs_patching)
  : AccessField(obj, offset, field, is_static, state_before, needs_patching)
D
duke 已提交
837 838 839 840 841
  {}

  ciType* declared_type() const;

  // generic
842
  HASHING2(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset())  // cannot be eliminated if needs patching or if volatile
D
duke 已提交
843 844 845 846 847 848 849 850 851
};


LEAF(StoreField, AccessField)
 private:
  Value _value;

 public:
  // creation
R
roland 已提交
852
  StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
853 854
             ValueStack* state_before, bool needs_patching)
  : AccessField(obj, offset, field, is_static, state_before, needs_patching)
D
duke 已提交
855 856 857 858 859 860 861 862 863 864 865 866
  , _value(value)
  {
    set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object());
    ASSERT_VALUES
    pin();
  }

  // accessors
  Value value() const                            { return _value; }
  bool needs_write_barrier() const               { return check_flag(NeedsWriteBarrierFlag); }

  // generic
867
  virtual void input_values_do(ValueVisitor* f)   { AccessField::input_values_do(f); f->visit(&_value); }
D
duke 已提交
868 869 870 871 872 873 874 875 876
};


BASE(AccessArray, Instruction)
 private:
  Value       _array;

 public:
  // creation
R
roland 已提交
877 878
  AccessArray(ValueType* type, Value array, ValueStack* state_before)
  : Instruction(type, state_before)
D
duke 已提交
879
  , _array(array)
R
roland 已提交
880
  {
D
duke 已提交
881 882 883 884 885 886 887 888 889
    set_needs_null_check(true);
    ASSERT_VALUES
    pin(); // instruction with side effect (null exception or range check throwing)
  }

  Value array() const                            { return _array; }

  // generic
  virtual bool can_trap() const                  { return needs_null_check(); }
890
  virtual void input_values_do(ValueVisitor* f)   { f->visit(&_array); }
D
duke 已提交
891 892 893 894 895 896 897 898 899
};


LEAF(ArrayLength, AccessArray)
 private:
  NullCheck*  _explicit_null_check;              // For explicit null check elimination

 public:
  // creation
R
roland 已提交
900 901
  ArrayLength(Value array, ValueStack* state_before)
  : AccessArray(intType, array, state_before)
D
duke 已提交
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923
  , _explicit_null_check(NULL) {}

  // accessors
  NullCheck* explicit_null_check() const         { return _explicit_null_check; }

  // setters
  // See LoadField::set_explicit_null_check for documentation
  void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }

  // generic
  HASHING1(ArrayLength, true, array()->subst())
};


BASE(AccessIndexed, AccessArray)
 private:
  Value     _index;
  Value     _length;
  BasicType _elt_type;

 public:
  // creation
R
roland 已提交
924 925
  AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before)
  : AccessArray(as_ValueType(elt_type), array, state_before)
D
duke 已提交
926 927 928 929
  , _index(index)
  , _length(length)
  , _elt_type(elt_type)
  {
930
    set_flag(Instruction::NeedsRangeCheckFlag, true);
D
duke 已提交
931 932 933 934 935 936 937 938
    ASSERT_VALUES
  }

  // accessors
  Value index() const                            { return _index; }
  Value length() const                           { return _length; }
  BasicType elt_type() const                     { return _elt_type; }

939
  void clear_length()                            { _length = NULL; }
D
duke 已提交
940 941 942 943
  // perform elimination of range checks involving constants
  bool compute_needs_range_check();

  // generic
944
  virtual void input_values_do(ValueVisitor* f)   { AccessArray::input_values_do(f); f->visit(&_index); if (_length != NULL) f->visit(&_length); }
D
duke 已提交
945 946 947 948 949 950 951 952 953
};


LEAF(LoadIndexed, AccessIndexed)
 private:
  NullCheck*  _explicit_null_check;              // For explicit null check elimination

 public:
  // creation
R
roland 已提交
954 955
  LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before)
  : AccessIndexed(array, index, length, elt_type, state_before)
D
duke 已提交
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976
  , _explicit_null_check(NULL) {}

  // accessors
  NullCheck* explicit_null_check() const         { return _explicit_null_check; }

  // setters
  // See LoadField::set_explicit_null_check for documentation
  void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }

  ciType* exact_type() const;
  ciType* declared_type() const;

  // generic
  HASHING2(LoadIndexed, true, array()->subst(), index()->subst())
};


LEAF(StoreIndexed, AccessIndexed)
 private:
  Value       _value;

977 978
  ciMethod* _profiled_method;
  int       _profiled_bci;
D
duke 已提交
979 980
 public:
  // creation
R
roland 已提交
981 982
  StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before)
  : AccessIndexed(array, index, length, elt_type, state_before)
983
  , _value(value), _profiled_method(NULL), _profiled_bci(0)
D
duke 已提交
984 985 986 987 988 989 990 991 992 993 994
  {
    set_flag(NeedsWriteBarrierFlag, (as_ValueType(elt_type)->is_object()));
    set_flag(NeedsStoreCheckFlag, (as_ValueType(elt_type)->is_object()));
    ASSERT_VALUES
    pin();
  }

  // accessors
  Value value() const                            { return _value; }
  bool needs_write_barrier() const               { return check_flag(NeedsWriteBarrierFlag); }
  bool needs_store_check() const                 { return check_flag(NeedsStoreCheckFlag); }
995
  // Helpers for MethodData* profiling
996 997 998 999 1000 1001
  void set_should_profile(bool value)                { set_flag(ProfileMDOFlag, value); }
  void set_profiled_method(ciMethod* method)         { _profiled_method = method;   }
  void set_profiled_bci(int bci)                     { _profiled_bci = bci;         }
  bool      should_profile() const                   { return check_flag(ProfileMDOFlag); }
  ciMethod* profiled_method() const                  { return _profiled_method;     }
  int       profiled_bci() const                     { return _profiled_bci;        }
D
duke 已提交
1002
  // generic
1003
  virtual void input_values_do(ValueVisitor* f)   { AccessIndexed::input_values_do(f); f->visit(&_value); }
D
duke 已提交
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
};


LEAF(NegateOp, Instruction)
 private:
  Value _x;

 public:
  // creation
  NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
    ASSERT_VALUES
  }

  // accessors
  Value x() const                                { return _x; }

  // generic
1021
  virtual void input_values_do(ValueVisitor* f)   { f->visit(&_x); }
D
duke 已提交
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032
};


BASE(Op2, Instruction)
 private:
  Bytecodes::Code _op;
  Value           _x;
  Value           _y;

 public:
  // creation
R
roland 已提交
1033 1034 1035 1036 1037 1038
  Op2(ValueType* type, Bytecodes::Code op, Value x, Value y, ValueStack* state_before = NULL)
  : Instruction(type, state_before)
  , _op(op)
  , _x(x)
  , _y(y)
  {
D
duke 已提交
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
    ASSERT_VALUES
  }

  // accessors
  Bytecodes::Code op() const                     { return _op; }
  Value x() const                                { return _x; }
  Value y() const                                { return _y; }

  // manipulators
  void swap_operands() {
    assert(is_commutative(), "operation must be commutative");
    Value t = _x; _x = _y; _y = t;
  }

  // generic
  virtual bool is_commutative() const            { return false; }
1055
  virtual void input_values_do(ValueVisitor* f)   { f->visit(&_x); f->visit(&_y); }
D
duke 已提交
1056 1057 1058 1059 1060 1061
};


LEAF(ArithmeticOp, Op2)
 public:
  // creation
R
roland 已提交
1062 1063 1064
  ArithmeticOp(Bytecodes::Code op, Value x, Value y, bool is_strictfp, ValueStack* state_before)
  : Op2(x->type()->meet(y->type()), op, x, y, state_before)
  {
D
duke 已提交
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
    set_flag(IsStrictfpFlag, is_strictfp);
    if (can_trap()) pin();
  }

  // accessors
  bool        is_strictfp() const                { return check_flag(IsStrictfpFlag); }

  // generic
  virtual bool is_commutative() const;
  virtual bool can_trap() const;
  HASHING3(Op2, true, op(), x()->subst(), y()->subst())
};


LEAF(ShiftOp, Op2)
 public:
  // creation
  ShiftOp(Bytecodes::Code op, Value x, Value s) : Op2(x->type()->base(), op, x, s) {}

  // generic
  HASHING3(Op2, true, op(), x()->subst(), y()->subst())
};


LEAF(LogicOp, Op2)
 public:
  // creation
  LogicOp(Bytecodes::Code op, Value x, Value y) : Op2(x->type()->meet(y->type()), op, x, y) {}

  // generic
  virtual bool is_commutative() const;
  HASHING3(Op2, true, op(), x()->subst(), y()->subst())
};


LEAF(CompareOp, Op2)
 public:
  // creation
  CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
R
roland 已提交
1104
  : Op2(intType, op, x, y, state_before)
D
duke 已提交
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
  {}

  // generic
  HASHING3(Op2, true, op(), x()->subst(), y()->subst())
};


LEAF(IfOp, Op2)
 private:
  Value _tval;
  Value _fval;

 public:
  // creation
  IfOp(Value x, Condition cond, Value y, Value tval, Value fval)
  : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
  , _tval(tval)
  , _fval(fval)
  {
    ASSERT_VALUES
    assert(tval->type()->tag() == fval->type()->tag(), "types must match");
  }

  // accessors
  virtual bool is_commutative() const;
  Bytecodes::Code op() const                     { ShouldNotCallThis(); return Bytecodes::_illegal; }
  Condition cond() const                         { return (Condition)Op2::op(); }
  Value tval() const                             { return _tval; }
  Value fval() const                             { return _fval; }

  // generic
1136
  virtual void input_values_do(ValueVisitor* f)   { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }
D
duke 已提交
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
};


LEAF(Convert, Instruction)
 private:
  Bytecodes::Code _op;
  Value           _value;

 public:
  // creation
  Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
    ASSERT_VALUES
  }

  // accessors
  Bytecodes::Code op() const                     { return _op; }
  Value value() const                            { return _value; }

  // generic
1156
  virtual void input_values_do(ValueVisitor* f)   { f->visit(&_value); }
D
duke 已提交
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
  HASHING2(Convert, true, op(), value()->subst())
};


LEAF(NullCheck, Instruction)
 private:
  Value       _obj;

 public:
  // creation
R
roland 已提交
1167 1168 1169 1170
  NullCheck(Value obj, ValueStack* state_before)
  : Instruction(obj->type()->base(), state_before)
  , _obj(obj)
  {
D
duke 已提交
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184
    ASSERT_VALUES
    set_can_trap(true);
    assert(_obj->type()->is_object(), "null check must be applied to objects only");
    pin(Instruction::PinExplicitNullCheck);
  }

  // accessors
  Value obj() const                              { return _obj; }

  // setters
  void set_can_trap(bool can_trap)               { set_flag(CanTrapFlag, can_trap); }

  // generic
  virtual bool can_trap() const                  { return check_flag(CanTrapFlag); /* null-check elimination sets to false */ }
1185
  virtual void input_values_do(ValueVisitor* f)   { f->visit(&_obj); }
D
duke 已提交
1186 1187 1188 1189
  HASHING1(NullCheck, true, obj()->subst())
};


1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212
// This node is supposed to cast the type of another node to a more precise
// declared type.
LEAF(TypeCast, Instruction)
 private:
  ciType* _declared_type;
  Value   _obj;

 public:
  // The type of this node is the same type as the object type (and it might be constant).
  TypeCast(ciType* type, Value obj, ValueStack* state_before)
  : Instruction(obj->type(), state_before, obj->type()->is_constant()),
    _declared_type(type),
    _obj(obj) {}

  // accessors
  ciType* declared_type() const                  { return _declared_type; }
  Value   obj() const                            { return _obj; }

  // generic
  virtual void input_values_do(ValueVisitor* f)  { f->visit(&_obj); }
};


D
duke 已提交
1213 1214 1215 1216 1217 1218 1219 1220 1221
BASE(StateSplit, Instruction)
 private:
  ValueStack* _state;

 protected:
  static void substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block);

 public:
  // creation
R
roland 已提交
1222 1223 1224 1225
  StateSplit(ValueType* type, ValueStack* state_before = NULL)
  : Instruction(type, state_before)
  , _state(NULL)
  {
D
duke 已提交
1226 1227 1228 1229 1230 1231 1232 1233
    pin(PinStateSplitConstructor);
  }

  // accessors
  ValueStack* state() const                      { return _state; }
  IRScope* scope() const;                        // the state's scope

  // manipulation
R
roland 已提交
1234
  void set_state(ValueStack* state)              { assert(_state == NULL, "overwriting existing state"); check_state(state); _state = state; }
D
duke 已提交
1235 1236

  // generic
1237 1238
  virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
  virtual void state_values_do(ValueVisitor* f);
D
duke 已提交
1239 1240 1241 1242 1243
};


LEAF(Invoke, StateSplit)
 private:
1244 1245 1246 1247 1248 1249
  Bytecodes::Code _code;
  Value           _recv;
  Values*         _args;
  BasicTypeList*  _signature;
  int             _vtable_index;
  ciMethod*       _target;
D
duke 已提交
1250 1251 1252 1253

 public:
  // creation
  Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
1254
         int vtable_index, ciMethod* target, ValueStack* state_before);
D
duke 已提交
1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265

  // accessors
  Bytecodes::Code code() const                   { return _code; }
  Value receiver() const                         { return _recv; }
  bool has_receiver() const                      { return receiver() != NULL; }
  int number_of_arguments() const                { return _args->length(); }
  Value argument_at(int i) const                 { return _args->at(i); }
  int vtable_index() const                       { return _vtable_index; }
  BasicTypeList* signature() const               { return _signature; }
  ciMethod* target() const                       { return _target; }

1266 1267
  ciType* declared_type() const;

D
duke 已提交
1268 1269 1270 1271 1272 1273
  // Returns false if target is not loaded
  bool target_is_final() const                   { return check_flag(TargetIsFinalFlag); }
  bool target_is_loaded() const                  { return check_flag(TargetIsLoadedFlag); }
  // Returns false if target is not loaded
  bool target_is_strictfp() const                { return check_flag(TargetIsStrictfpFlag); }

1274 1275
  // JSR 292 support
  bool is_invokedynamic() const                  { return code() == Bytecodes::_invokedynamic; }
1276
  bool is_method_handle_intrinsic() const        { return target()->is_method_handle_intrinsic(); }
1277

R
roland 已提交
1278 1279
  virtual bool needs_exception_state() const     { return false; }

D
duke 已提交
1280 1281
  // generic
  virtual bool can_trap() const                  { return true; }
1282
  virtual void input_values_do(ValueVisitor* f) {
D
duke 已提交
1283
    StateSplit::input_values_do(f);
1284 1285
    if (has_receiver()) f->visit(&_recv);
    for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
D
duke 已提交
1286
  }
1287
  virtual void state_values_do(ValueVisitor *f);
D
duke 已提交
1288 1289 1290 1291 1292 1293 1294 1295 1296
};


LEAF(NewInstance, StateSplit)
 private:
  ciInstanceKlass* _klass;

 public:
  // creation
R
roland 已提交
1297 1298 1299 1300
  NewInstance(ciInstanceKlass* klass, ValueStack* state_before)
  : StateSplit(instanceType, state_before)
  , _klass(klass)
  {}
D
duke 已提交
1301 1302 1303 1304

  // accessors
  ciInstanceKlass* klass() const                 { return _klass; }

R
roland 已提交
1305 1306
  virtual bool needs_exception_state() const     { return false; }

D
duke 已提交
1307 1308 1309
  // generic
  virtual bool can_trap() const                  { return true; }
  ciType* exact_type() const;
1310
  ciType* declared_type() const;
D
duke 已提交
1311 1312 1313 1314 1315 1316 1317 1318 1319
};


BASE(NewArray, StateSplit)
 private:
  Value       _length;

 public:
  // creation
R
roland 已提交
1320 1321 1322 1323
  NewArray(Value length, ValueStack* state_before)
  : StateSplit(objectType, state_before)
  , _length(length)
  {
D
duke 已提交
1324 1325 1326 1327 1328 1329
    // Do not ASSERT_VALUES since length is NULL for NewMultiArray
  }

  // accessors
  Value length() const                           { return _length; }

R
roland 已提交
1330 1331
  virtual bool needs_exception_state() const     { return false; }

1332
  ciType* exact_type() const                     { return NULL; }
1333 1334
  ciType* declared_type() const;

D
duke 已提交
1335 1336
  // generic
  virtual bool can_trap() const                  { return true; }
1337
  virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_length); }
D
duke 已提交
1338 1339 1340 1341 1342 1343 1344 1345 1346
};


LEAF(NewTypeArray, NewArray)
 private:
  BasicType _elt_type;

 public:
  // creation
R
roland 已提交
1347 1348 1349 1350
  NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before)
  : NewArray(length, state_before)
  , _elt_type(elt_type)
  {}
D
duke 已提交
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388

  // accessors
  BasicType elt_type() const                     { return _elt_type; }
  ciType* exact_type() const;
};


LEAF(NewObjectArray, NewArray)
 private:
  ciKlass* _klass;

 public:
  // creation
  NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before) : NewArray(length, state_before), _klass(klass) {}

  // accessors
  ciKlass* klass() const                         { return _klass; }
  ciType* exact_type() const;
};


LEAF(NewMultiArray, NewArray)
 private:
  ciKlass* _klass;
  Values*  _dims;

 public:
  // creation
  NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(NULL, state_before), _klass(klass), _dims(dims) {
    ASSERT_VALUES
  }

  // accessors
  ciKlass* klass() const                         { return _klass; }
  Values* dims() const                           { return _dims; }
  int rank() const                               { return dims()->length(); }

  // generic
1389
  virtual void input_values_do(ValueVisitor* f) {
D
duke 已提交
1390 1391 1392 1393 1394 1395 1396
    // NOTE: we do not call NewArray::input_values_do since "length"
    // is meaningless for a multi-dimensional array; passing the
    // zeroth element down to NewArray as its length is a bad idea
    // since there will be a copy in the "dims" array which doesn't
    // get updated, and the value must not be traversed twice. Was bug
    // - kbr 4/10/2001
    StateSplit::input_values_do(f);
1397
    for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));
D
duke 已提交
1398 1399 1400 1401 1402 1403 1404 1405 1406
  }
};


BASE(TypeCheck, StateSplit)
 private:
  ciKlass*    _klass;
  Value       _obj;

1407 1408 1409
  ciMethod* _profiled_method;
  int       _profiled_bci;

D
duke 已提交
1410 1411
 public:
  // creation
1412
  TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)
R
roland 已提交
1413
  : StateSplit(type, state_before), _klass(klass), _obj(obj),
1414
    _profiled_method(NULL), _profiled_bci(0) {
D
duke 已提交
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429
    ASSERT_VALUES
    set_direct_compare(false);
  }

  // accessors
  ciKlass* klass() const                         { return _klass; }
  Value obj() const                              { return _obj; }
  bool is_loaded() const                         { return klass() != NULL; }
  bool direct_compare() const                    { return check_flag(DirectCompareFlag); }

  // manipulation
  void set_direct_compare(bool flag)             { set_flag(DirectCompareFlag, flag); }

  // generic
  virtual bool can_trap() const                  { return true; }
1430
  virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_obj); }
1431

1432
  // Helpers for MethodData* profiling
1433 1434 1435 1436 1437 1438
  void set_should_profile(bool value)                { set_flag(ProfileMDOFlag, value); }
  void set_profiled_method(ciMethod* method)         { _profiled_method = method;   }
  void set_profiled_bci(int bci)                     { _profiled_bci = bci;         }
  bool      should_profile() const                   { return check_flag(ProfileMDOFlag); }
  ciMethod* profiled_method() const                  { return _profiled_method;     }
  int       profiled_bci() const                     { return _profiled_bci;        }
D
duke 已提交
1439 1440 1441 1442 1443 1444 1445
};


LEAF(CheckCast, TypeCheck)
 public:
  // creation
  CheckCast(ciKlass* klass, Value obj, ValueStack* state_before)
1446
  : TypeCheck(klass, obj, objectType, state_before) {}
D
duke 已提交
1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462

  void set_incompatible_class_change_check() {
    set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
  }
  bool is_incompatible_class_change_check() const {
    return check_flag(ThrowIncompatibleClassChangeErrorFlag);
  }

  ciType* declared_type() const;
};


LEAF(InstanceOf, TypeCheck)
 public:
  // creation
  InstanceOf(ciKlass* klass, Value obj, ValueStack* state_before) : TypeCheck(klass, obj, intType, state_before) {}
R
roland 已提交
1463 1464

  virtual bool needs_exception_state() const     { return false; }
D
duke 已提交
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474
};


BASE(AccessMonitor, StateSplit)
 private:
  Value       _obj;
  int         _monitor_no;

 public:
  // creation
R
roland 已提交
1475 1476
  AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = NULL)
  : StateSplit(illegalType, state_before)
D
duke 已提交
1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488
  , _obj(obj)
  , _monitor_no(monitor_no)
  {
    set_needs_null_check(true);
    ASSERT_VALUES
  }

  // accessors
  Value obj() const                              { return _obj; }
  int monitor_no() const                         { return _monitor_no; }

  // generic
1489
  virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_obj); }
D
duke 已提交
1490 1491 1492 1493 1494 1495
};


LEAF(MonitorEnter, AccessMonitor)
 public:
  // creation
R
roland 已提交
1496 1497
  MonitorEnter(Value obj, int monitor_no, ValueStack* state_before)
  : AccessMonitor(obj, monitor_no, state_before)
D
duke 已提交
1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509
  {
    ASSERT_VALUES
  }

  // generic
  virtual bool can_trap() const                  { return true; }
};


LEAF(MonitorExit, AccessMonitor)
 public:
  // creation
R
roland 已提交
1510 1511 1512 1513 1514
  MonitorExit(Value obj, int monitor_no)
  : AccessMonitor(obj, monitor_no, NULL)
  {
    ASSERT_VALUES
  }
D
duke 已提交
1515 1516 1517 1518 1519 1520 1521 1522
};


LEAF(Intrinsic, StateSplit)
 private:
  vmIntrinsics::ID _id;
  Values*          _args;
  Value            _recv;
1523
  ArgsNonNullState _nonnull_state;
D
duke 已提交
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536

 public:
  // preserves_state can be set to true for Intrinsics
  // which are guaranteed to preserve register state across any slow
  // cases; setting it to true does not mean that the Intrinsic can
  // not trap, only that if we continue execution in the same basic
  // block after the Intrinsic, all of the registers are intact. This
  // allows load elimination and common expression elimination to be
  // performed across the Intrinsic.  The default value is false.
  Intrinsic(ValueType* type,
            vmIntrinsics::ID id,
            Values* args,
            bool has_receiver,
R
roland 已提交
1537
            ValueStack* state_before,
D
duke 已提交
1538 1539
            bool preserves_state,
            bool cantrap = true)
R
roland 已提交
1540
  : StateSplit(type, state_before)
D
duke 已提交
1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568
  , _id(id)
  , _args(args)
  , _recv(NULL)
  {
    assert(args != NULL, "args must exist");
    ASSERT_VALUES
    set_flag(PreservesStateFlag, preserves_state);
    set_flag(CanTrapFlag,        cantrap);
    if (has_receiver) {
      _recv = argument_at(0);
    }
    set_needs_null_check(has_receiver);

    // some intrinsics can't trap, so don't force them to be pinned
    if (!can_trap()) {
      unpin(PinStateSplitConstructor);
    }
  }

  // accessors
  vmIntrinsics::ID id() const                    { return _id; }
  int number_of_arguments() const                { return _args->length(); }
  Value argument_at(int i) const                 { return _args->at(i); }

  bool has_receiver() const                      { return (_recv != NULL); }
  Value receiver() const                         { assert(has_receiver(), "must have receiver"); return _recv; }
  bool preserves_state() const                   { return check_flag(PreservesStateFlag); }

1569 1570
  bool arg_needs_null_check(int i) const {
    return _nonnull_state.arg_needs_null_check(i);
1571 1572 1573
  }

  void set_arg_needs_null_check(int i, bool check) {
1574
    _nonnull_state.set_arg_needs_null_check(i, check);
1575 1576
  }

D
duke 已提交
1577 1578
  // generic
  virtual bool can_trap() const                  { return check_flag(CanTrapFlag); }
1579
  virtual void input_values_do(ValueVisitor* f) {
D
duke 已提交
1580
    StateSplit::input_values_do(f);
1581
    for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
D
duke 已提交
1582 1583 1584 1585 1586 1587 1588 1589 1590
  }
};


class LIR_List;

LEAF(BlockBegin, StateSplit)
 private:
  int        _block_id;                          // the unique block id
R
roland 已提交
1591
  int        _bci;                               // start-bci of block
D
duke 已提交
1592 1593
  int        _depth_first_number;                // number of this block in a depth-first ordering
  int        _linear_scan_number;                // number of this block in linear-scan ordering
1594
  int        _dominator_depth;
D
duke 已提交
1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605
  int        _loop_depth;                        // the loop nesting level of this block
  int        _loop_index;                        // number of the innermost loop of this block
  int        _flags;                             // the flags associated with this block

  // fields used by BlockListBuilder
  int        _total_preds;                       // number of predecessors found by BlockListBuilder
  BitMap     _stores_to_locals;                  // bit is set when a local variable is stored in the block

  // SSA specific fields: (factor out later)
  BlockList   _successors;                       // the successors of this block
  BlockList   _predecessors;                     // the predecessors of this block
1606
  BlockList   _dominates;                        // list of blocks that are dominated by this block
D
duke 已提交
1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633
  BlockBegin* _dominator;                        // the dominator of this block
  // SSA specific ends
  BlockEnd*  _end;                               // the last instruction of this block
  BlockList  _exception_handlers;                // the exception handlers potentially invoked by this block
  ValueStackStack* _exception_states;            // only for xhandler entries: states of all instructions that have an edge to this xhandler
  int        _exception_handler_pco;             // if this block is the start of an exception handler,
                                                 // this records the PC offset in the assembly code of the
                                                 // first instruction in this block
  Label      _label;                             // the label associated with this block
  LIR_List*  _lir;                               // the low level intermediate representation for this block

  BitMap      _live_in;                          // set of live LIR_Opr registers at entry to this block
  BitMap      _live_out;                         // set of live LIR_Opr registers at exit from this block
  BitMap      _live_gen;                         // set of registers used before any redefinition in this block
  BitMap      _live_kill;                        // set of registers defined in this block

  BitMap      _fpu_register_usage;
  intArray*   _fpu_stack_state;                  // For x86 FPU code generation with UseLinearScan
  int         _first_lir_instruction_id;         // ID of first LIR instruction in this block
  int         _last_lir_instruction_id;          // ID of last LIR instruction in this block

  void iterate_preorder (boolArray& mark, BlockClosure* closure);
  void iterate_postorder(boolArray& mark, BlockClosure* closure);

  friend class SuxAndWeightAdjuster;

 public:
1634
   void* operator new(size_t size) throw() {
1635 1636 1637 1638 1639 1640 1641
    Compilation* c = Compilation::current();
    void* res = c->arena()->Amalloc(size);
    ((BlockBegin*)res)->_id = c->get_next_id();
    ((BlockBegin*)res)->_block_id = c->get_next_block_id();
    return res;
  }

D
duke 已提交
1642
  // initialization/counting
1643 1644 1645
  static int  number_of_blocks() {
    return Compilation::current()->number_of_blocks();
  }
D
duke 已提交
1646 1647 1648 1649

  // creation
  BlockBegin(int bci)
  : StateSplit(illegalType)
R
roland 已提交
1650
  , _bci(bci)
D
duke 已提交
1651 1652 1653 1654
  , _depth_first_number(-1)
  , _linear_scan_number(-1)
  , _loop_depth(0)
  , _flags(0)
1655
  , _dominator_depth(-1)
D
duke 已提交
1656 1657 1658 1659
  , _dominator(NULL)
  , _end(NULL)
  , _predecessors(2)
  , _successors(2)
1660
  , _dominates(2)
D
duke 已提交
1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676
  , _exception_handlers(1)
  , _exception_states(NULL)
  , _exception_handler_pco(-1)
  , _lir(NULL)
  , _loop_index(-1)
  , _live_in()
  , _live_out()
  , _live_gen()
  , _live_kill()
  , _fpu_register_usage()
  , _fpu_stack_state(NULL)
  , _first_lir_instruction_id(-1)
  , _last_lir_instruction_id(-1)
  , _total_preds(0)
  , _stores_to_locals()
  {
1677
    _block = this;
R
roland 已提交
1678 1679 1680
#ifndef PRODUCT
    set_printable_bci(bci);
#endif
D
duke 已提交
1681 1682 1683 1684
  }

  // accessors
  int block_id() const                           { return _block_id; }
R
roland 已提交
1685
  int bci() const                                { return _bci; }
D
duke 已提交
1686
  BlockList* successors()                        { return &_successors; }
1687
  BlockList* dominates()                         { return &_dominates; }
D
duke 已提交
1688 1689
  BlockBegin* dominator() const                  { return _dominator; }
  int loop_depth() const                         { return _loop_depth; }
1690
  int dominator_depth() const                    { return _dominator_depth; }
D
duke 已提交
1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710
  int depth_first_number() const                 { return _depth_first_number; }
  int linear_scan_number() const                 { return _linear_scan_number; }
  BlockEnd* end() const                          { return _end; }
  Label* label()                                 { return &_label; }
  LIR_List* lir() const                          { return _lir; }
  int exception_handler_pco() const              { return _exception_handler_pco; }
  BitMap& live_in()                              { return _live_in;        }
  BitMap& live_out()                             { return _live_out;       }
  BitMap& live_gen()                             { return _live_gen;       }
  BitMap& live_kill()                            { return _live_kill;      }
  BitMap& fpu_register_usage()                   { return _fpu_register_usage; }
  intArray* fpu_stack_state() const              { return _fpu_stack_state;    }
  int first_lir_instruction_id() const           { return _first_lir_instruction_id; }
  int last_lir_instruction_id() const            { return _last_lir_instruction_id; }
  int total_preds() const                        { return _total_preds; }
  BitMap& stores_to_locals()                     { return _stores_to_locals; }

  // manipulation
  void set_dominator(BlockBegin* dom)            { _dominator = dom; }
  void set_loop_depth(int d)                     { _loop_depth = d; }
1711
  void set_dominator_depth(int d)                { _dominator_depth = d; }
D
duke 已提交
1712 1713 1714
  void set_depth_first_number(int dfn)           { _depth_first_number = dfn; }
  void set_linear_scan_number(int lsn)           { _linear_scan_number = lsn; }
  void set_end(BlockEnd* end);
1715
  void clear_end();
D
duke 已提交
1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733
  void disconnect_from_graph();
  static void disconnect_edge(BlockBegin* from, BlockBegin* to);
  BlockBegin* insert_block_between(BlockBegin* sux);
  void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
  void set_lir(LIR_List* lir)                    { _lir = lir; }
  void set_exception_handler_pco(int pco)        { _exception_handler_pco = pco; }
  void set_live_in       (BitMap map)            { _live_in = map;        }
  void set_live_out      (BitMap map)            { _live_out = map;       }
  void set_live_gen      (BitMap map)            { _live_gen = map;       }
  void set_live_kill     (BitMap map)            { _live_kill = map;      }
  void set_fpu_register_usage(BitMap map)        { _fpu_register_usage = map; }
  void set_fpu_stack_state(intArray* state)      { _fpu_stack_state = state;  }
  void set_first_lir_instruction_id(int id)      { _first_lir_instruction_id = id;  }
  void set_last_lir_instruction_id(int id)       { _last_lir_instruction_id = id;  }
  void increment_total_preds(int n = 1)          { _total_preds += n; }
  void init_stores_to_locals(int locals_count)   { _stores_to_locals = BitMap(locals_count); _stores_to_locals.clear(); }

  // generic
1734
  virtual void state_values_do(ValueVisitor* f);
D
duke 已提交
1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769

  // successors and predecessors
  int number_of_sux() const;
  BlockBegin* sux_at(int i) const;
  void add_successor(BlockBegin* sux);
  void remove_successor(BlockBegin* pred);
  bool is_successor(BlockBegin* sux) const       { return _successors.contains(sux); }

  void add_predecessor(BlockBegin* pred);
  void remove_predecessor(BlockBegin* pred);
  bool is_predecessor(BlockBegin* pred) const    { return _predecessors.contains(pred); }
  int number_of_preds() const                    { return _predecessors.length(); }
  BlockBegin* pred_at(int i) const               { return _predecessors[i]; }

  // exception handlers potentially invoked by this block
  void add_exception_handler(BlockBegin* b);
  bool is_exception_handler(BlockBegin* b) const { return _exception_handlers.contains(b); }
  int  number_of_exception_handlers() const      { return _exception_handlers.length(); }
  BlockBegin* exception_handler_at(int i) const  { return _exception_handlers.at(i); }

  // states of the instructions that have an edge to this exception handler
  int number_of_exception_states()               { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states == NULL ? 0 : _exception_states->length(); }
  ValueStack* exception_state_at(int idx) const  { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states->at(idx); }
  int add_exception_state(ValueStack* state);

  // flags
  enum Flag {
    no_flag                       = 0,
    std_entry_flag                = 1 << 0,
    osr_entry_flag                = 1 << 1,
    exception_entry_flag          = 1 << 2,
    subroutine_entry_flag         = 1 << 3,
    backward_branch_target_flag   = 1 << 4,
    is_on_work_list_flag          = 1 << 5,
    was_visited_flag              = 1 << 6,
1770 1771 1772
    parser_loop_header_flag       = 1 << 7,  // set by parser to identify blocks where phi functions can not be created on demand
    critical_edge_split_flag      = 1 << 8, // set for all blocks that are introduced when critical edges are split
    linear_scan_loop_header_flag  = 1 << 9, // set during loop-detection for LinearScan
1773 1774
    linear_scan_loop_end_flag     = 1 << 10, // set during loop-detection for LinearScan
    donot_eliminate_range_checks  = 1 << 11  // Should be try to eliminate range checks in this block
D
duke 已提交
1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788
  };

  void set(Flag f)                               { _flags |= f; }
  void clear(Flag f)                             { _flags &= ~f; }
  bool is_set(Flag f) const                      { return (_flags & f) != 0; }
  bool is_entry_block() const {
    const int entry_mask = std_entry_flag | osr_entry_flag | exception_entry_flag;
    return (_flags & entry_mask) != 0;
  }

  // iteration
  void iterate_preorder   (BlockClosure* closure);
  void iterate_postorder  (BlockClosure* closure);

1789
  void block_values_do(ValueVisitor* f);
D
duke 已提交
1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822

  // loops
  void set_loop_index(int ix)                    { _loop_index = ix;        }
  int  loop_index() const                        { return _loop_index;      }

  // merging
  bool try_merge(ValueStack* state);             // try to merge states at block begin
  void merge(ValueStack* state)                  { bool b = try_merge(state); assert(b, "merge failed"); }

  // debugging
  void print_block()                             PRODUCT_RETURN;
  void print_block(InstructionPrinter& ip, bool live_only = false) PRODUCT_RETURN;
};


BASE(BlockEnd, StateSplit)
 private:
  BlockList*  _sux;

 protected:
  BlockList* sux() const                         { return _sux; }

  void set_sux(BlockList* sux) {
#ifdef ASSERT
    assert(sux != NULL, "sux must exist");
    for (int i = sux->length() - 1; i >= 0; i--) assert(sux->at(i) != NULL, "sux must exist");
#endif
    _sux = sux;
  }

 public:
  // creation
  BlockEnd(ValueType* type, ValueStack* state_before, bool is_safepoint)
R
roland 已提交
1823
  : StateSplit(type, state_before)
D
duke 已提交
1824
  , _sux(NULL)
R
roland 已提交
1825
  {
D
duke 已提交
1826 1827 1828 1829 1830
    set_flag(IsSafepointFlag, is_safepoint);
  }

  // accessors
  bool is_safepoint() const                      { return check_flag(IsSafepointFlag); }
1831 1832
  // For compatibility with old code, for new code use block()
  BlockBegin* begin() const                      { return _block; }
D
duke 已提交
1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847

  // manipulation
  void set_begin(BlockBegin* begin);

  // successors
  int number_of_sux() const                      { return _sux != NULL ? _sux->length() : 0; }
  BlockBegin* sux_at(int i) const                { return _sux->at(i); }
  BlockBegin* default_sux() const                { return sux_at(number_of_sux() - 1); }
  BlockBegin** addr_sux_at(int i) const          { return _sux->adr_at(i); }
  int sux_index(BlockBegin* sux) const           { return _sux->find(sux); }
  void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
};


LEAF(Goto, BlockEnd)
I
iveresov 已提交
1848 1849 1850 1851 1852 1853 1854 1855 1856
 public:
  enum Direction {
    none,            // Just a regular goto
    taken, not_taken // Goto produced from If
  };
 private:
  ciMethod*   _profiled_method;
  int         _profiled_bci;
  Direction   _direction;
D
duke 已提交
1857 1858
 public:
  // creation
I
iveresov 已提交
1859 1860 1861 1862 1863
  Goto(BlockBegin* sux, ValueStack* state_before, bool is_safepoint = false)
    : BlockEnd(illegalType, state_before, is_safepoint)
    , _direction(none)
    , _profiled_method(NULL)
    , _profiled_bci(0) {
D
duke 已提交
1864 1865 1866 1867 1868
    BlockList* s = new BlockList(1);
    s->append(sux);
    set_sux(s);
  }

I
iveresov 已提交
1869 1870 1871 1872
  Goto(BlockBegin* sux, bool is_safepoint) : BlockEnd(illegalType, NULL, is_safepoint)
                                           , _direction(none)
                                           , _profiled_method(NULL)
                                           , _profiled_bci(0) {
D
duke 已提交
1873 1874 1875 1876 1877
    BlockList* s = new BlockList(1);
    s->append(sux);
    set_sux(s);
  }

I
iveresov 已提交
1878 1879 1880 1881 1882 1883 1884 1885 1886
  bool should_profile() const                    { return check_flag(ProfileMDOFlag); }
  ciMethod* profiled_method() const              { return _profiled_method; } // set only for profiled branches
  int profiled_bci() const                       { return _profiled_bci; }
  Direction direction() const                    { return _direction; }

  void set_should_profile(bool value)            { set_flag(ProfileMDOFlag, value); }
  void set_profiled_method(ciMethod* method)     { _profiled_method = method; }
  void set_profiled_bci(int bci)                 { _profiled_bci = bci; }
  void set_direction(Direction d)                { _direction = d; }
D
duke 已提交
1887 1888
};

1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956
#ifdef ASSERT
LEAF(Assert, Instruction)
  private:
  Value       _x;
  Condition   _cond;
  Value       _y;
  char        *_message;

 public:
  // creation
  // unordered_is_true is valid for float/double compares only
   Assert(Value x, Condition cond, bool unordered_is_true, Value y);

  // accessors
  Value x() const                                { return _x; }
  Condition cond() const                         { return _cond; }
  bool unordered_is_true() const                 { return check_flag(UnorderedIsTrueFlag); }
  Value y() const                                { return _y; }
  const char *message() const                    { return _message; }

  // generic
  virtual void input_values_do(ValueVisitor* f)  { f->visit(&_x); f->visit(&_y); }
};
#endif

LEAF(RangeCheckPredicate, StateSplit)
 private:
  Value       _x;
  Condition   _cond;
  Value       _y;

  void check_state();

 public:
  // creation
  // unordered_is_true is valid for float/double compares only
   RangeCheckPredicate(Value x, Condition cond, bool unordered_is_true, Value y, ValueStack* state) : StateSplit(illegalType)
  , _x(x)
  , _cond(cond)
  , _y(y)
  {
    ASSERT_VALUES
    set_flag(UnorderedIsTrueFlag, unordered_is_true);
    assert(x->type()->tag() == y->type()->tag(), "types must match");
    this->set_state(state);
    check_state();
  }

  // Always deoptimize
  RangeCheckPredicate(ValueStack* state) : StateSplit(illegalType)
  {
    this->set_state(state);
    _x = _y = NULL;
    check_state();
  }

  // accessors
  Value x() const                                { return _x; }
  Condition cond() const                         { return _cond; }
  bool unordered_is_true() const                 { return check_flag(UnorderedIsTrueFlag); }
  Value y() const                                { return _y; }

  void always_fail()                             { _x = _y = NULL; }

  // generic
  virtual void input_values_do(ValueVisitor* f)  { StateSplit::input_values_do(f); f->visit(&_x); f->visit(&_y); }
  HASHING3(RangeCheckPredicate, true, x()->subst(), y()->subst(), cond())
};
D
duke 已提交
1957 1958 1959 1960 1961 1962 1963 1964

LEAF(If, BlockEnd)
 private:
  Value       _x;
  Condition   _cond;
  Value       _y;
  ciMethod*   _profiled_method;
  int         _profiled_bci; // Canonicalizer may alter bci of If node
I
iveresov 已提交
1965 1966
  bool        _swapped;      // Is the order reversed with respect to the original If in the
                             // bytecode stream?
D
duke 已提交
1967 1968 1969 1970 1971 1972 1973 1974 1975 1976
 public:
  // creation
  // unordered_is_true is valid for float/double compares only
  If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint)
    : BlockEnd(illegalType, state_before, is_safepoint)
  , _x(x)
  , _cond(cond)
  , _y(y)
  , _profiled_method(NULL)
  , _profiled_bci(0)
I
iveresov 已提交
1977
  , _swapped(false)
D
duke 已提交
1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998
  {
    ASSERT_VALUES
    set_flag(UnorderedIsTrueFlag, unordered_is_true);
    assert(x->type()->tag() == y->type()->tag(), "types must match");
    BlockList* s = new BlockList(2);
    s->append(tsux);
    s->append(fsux);
    set_sux(s);
  }

  // accessors
  Value x() const                                { return _x; }
  Condition cond() const                         { return _cond; }
  bool unordered_is_true() const                 { return check_flag(UnorderedIsTrueFlag); }
  Value y() const                                { return _y; }
  BlockBegin* sux_for(bool is_true) const        { return sux_at(is_true ? 0 : 1); }
  BlockBegin* tsux() const                       { return sux_for(true); }
  BlockBegin* fsux() const                       { return sux_for(false); }
  BlockBegin* usux() const                       { return sux_for(unordered_is_true()); }
  bool should_profile() const                    { return check_flag(ProfileMDOFlag); }
  ciMethod* profiled_method() const              { return _profiled_method; } // set only for profiled branches
I
iveresov 已提交
1999 2000
  int profiled_bci() const                       { return _profiled_bci; }    // set for profiled branches and tiered
  bool is_swapped() const                        { return _swapped; }
D
duke 已提交
2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018

  // manipulation
  void swap_operands() {
    Value t = _x; _x = _y; _y = t;
    _cond = mirror(_cond);
  }

  void swap_sux() {
    assert(number_of_sux() == 2, "wrong number of successors");
    BlockList* s = sux();
    BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
    _cond = negate(_cond);
    set_flag(UnorderedIsTrueFlag, !check_flag(UnorderedIsTrueFlag));
  }

  void set_should_profile(bool value)             { set_flag(ProfileMDOFlag, value); }
  void set_profiled_method(ciMethod* method)      { _profiled_method = method; }
  void set_profiled_bci(int bci)                  { _profiled_bci = bci;       }
I
iveresov 已提交
2019
  void set_swapped(bool value)                    { _swapped = value;         }
D
duke 已提交
2020
  // generic
2021
  virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }
D
duke 已提交
2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074
};


LEAF(IfInstanceOf, BlockEnd)
 private:
  ciKlass* _klass;
  Value    _obj;
  bool     _test_is_instance;                    // jump if instance
  int      _instanceof_bci;

 public:
  IfInstanceOf(ciKlass* klass, Value obj, bool test_is_instance, int instanceof_bci, BlockBegin* tsux, BlockBegin* fsux)
  : BlockEnd(illegalType, NULL, false) // temporary set to false
  , _klass(klass)
  , _obj(obj)
  , _test_is_instance(test_is_instance)
  , _instanceof_bci(instanceof_bci)
  {
    ASSERT_VALUES
    assert(instanceof_bci >= 0, "illegal bci");
    BlockList* s = new BlockList(2);
    s->append(tsux);
    s->append(fsux);
    set_sux(s);
  }

  // accessors
  //
  // Note 1: If test_is_instance() is true, IfInstanceOf tests if obj *is* an
  //         instance of klass; otherwise it tests if it is *not* and instance
  //         of klass.
  //
  // Note 2: IfInstanceOf instructions are created by combining an InstanceOf
  //         and an If instruction. The IfInstanceOf bci() corresponds to the
  //         bci that the If would have had; the (this->) instanceof_bci() is
  //         the bci of the original InstanceOf instruction.
  ciKlass* klass() const                         { return _klass; }
  Value obj() const                              { return _obj; }
  int instanceof_bci() const                     { return _instanceof_bci; }
  bool test_is_instance() const                  { return _test_is_instance; }
  BlockBegin* sux_for(bool is_true) const        { return sux_at(is_true ? 0 : 1); }
  BlockBegin* tsux() const                       { return sux_for(true); }
  BlockBegin* fsux() const                       { return sux_for(false); }

  // manipulation
  void swap_sux() {
    assert(number_of_sux() == 2, "wrong number of successors");
    BlockList* s = sux();
    BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
    _test_is_instance = !_test_is_instance;
  }

  // generic
2075
  virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_obj); }
D
duke 已提交
2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095
};


BASE(Switch, BlockEnd)
 private:
  Value       _tag;

 public:
  // creation
  Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
  : BlockEnd(illegalType, state_before, is_safepoint)
  , _tag(tag) {
    ASSERT_VALUES
    set_sux(sux);
  }

  // accessors
  Value tag() const                              { return _tag; }
  int length() const                             { return number_of_sux() - 1; }

R
roland 已提交
2096 2097
  virtual bool needs_exception_state() const     { return false; }

D
duke 已提交
2098
  // generic
2099
  virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_tag); }
D
duke 已提交
2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151
};


LEAF(TableSwitch, Switch)
 private:
  int _lo_key;

 public:
  // creation
  TableSwitch(Value tag, BlockList* sux, int lo_key, ValueStack* state_before, bool is_safepoint)
    : Switch(tag, sux, state_before, is_safepoint)
  , _lo_key(lo_key) {}

  // accessors
  int lo_key() const                             { return _lo_key; }
  int hi_key() const                             { return _lo_key + length() - 1; }
};


LEAF(LookupSwitch, Switch)
 private:
  intArray* _keys;

 public:
  // creation
  LookupSwitch(Value tag, BlockList* sux, intArray* keys, ValueStack* state_before, bool is_safepoint)
  : Switch(tag, sux, state_before, is_safepoint)
  , _keys(keys) {
    assert(keys != NULL, "keys must exist");
    assert(keys->length() == length(), "sux & keys have incompatible lengths");
  }

  // accessors
  int key_at(int i) const                        { return _keys->at(i); }
};


LEAF(Return, BlockEnd)
 private:
  Value _result;

 public:
  // creation
  Return(Value result) :
    BlockEnd(result == NULL ? voidType : result->type()->base(), NULL, true),
    _result(result) {}

  // accessors
  Value result() const                           { return _result; }
  bool has_result() const                        { return result() != NULL; }

  // generic
2152
  virtual void input_values_do(ValueVisitor* f) {
D
duke 已提交
2153
    BlockEnd::input_values_do(f);
2154
    if (has_result()) f->visit(&_result);
D
duke 已提交
2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173
  }
};


LEAF(Throw, BlockEnd)
 private:
  Value _exception;

 public:
  // creation
  Throw(Value exception, ValueStack* state_before) : BlockEnd(illegalType, state_before, true), _exception(exception) {
    ASSERT_VALUES
  }

  // accessors
  Value exception() const                        { return _exception; }

  // generic
  virtual bool can_trap() const                  { return true; }
2174
  virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_exception); }
D
duke 已提交
2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199
};


LEAF(Base, BlockEnd)
 public:
  // creation
  Base(BlockBegin* std_entry, BlockBegin* osr_entry) : BlockEnd(illegalType, NULL, false) {
    assert(std_entry->is_set(BlockBegin::std_entry_flag), "std entry must be flagged");
    assert(osr_entry == NULL || osr_entry->is_set(BlockBegin::osr_entry_flag), "osr entry must be flagged");
    BlockList* s = new BlockList(2);
    if (osr_entry != NULL) s->append(osr_entry);
    s->append(std_entry); // must be default sux!
    set_sux(s);
  }

  // accessors
  BlockBegin* std_entry() const                  { return default_sux(); }
  BlockBegin* osr_entry() const                  { return number_of_sux() < 2 ? NULL : sux_at(0); }
};


LEAF(OsrEntry, Instruction)
 public:
  // creation
#ifdef _LP64
2200
  OsrEntry() : Instruction(longType) { pin(); }
D
duke 已提交
2201
#else
2202
  OsrEntry() : Instruction(intType)  { pin(); }
D
duke 已提交
2203 2204 2205
#endif

  // generic
2206
  virtual void input_values_do(ValueVisitor* f)   { }
D
duke 已提交
2207 2208 2209 2210 2211 2212 2213
};


// Models the incoming exception at a catch site
LEAF(ExceptionObject, Instruction)
 public:
  // creation
2214
  ExceptionObject() : Instruction(objectType) {
D
duke 已提交
2215 2216 2217 2218
    pin();
  }

  // generic
2219
  virtual void input_values_do(ValueVisitor* f)   { }
D
duke 已提交
2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242
};


// Models needed rounding for floating-point values on Intel.
// Currently only used to represent rounding of double-precision
// values stored into local variables, but could be used to model
// intermediate rounding of single-precision values as well.
LEAF(RoundFP, Instruction)
 private:
  Value _input;             // floating-point value to be rounded

 public:
  RoundFP(Value input)
  : Instruction(input->type()) // Note: should not be used for constants
  , _input(input)
  {
    ASSERT_VALUES
  }

  // accessors
  Value input() const                            { return _input; }

  // generic
2243
  virtual void input_values_do(ValueVisitor* f)   { f->visit(&_input); }
D
duke 已提交
2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267
};


BASE(UnsafeOp, Instruction)
 private:
  BasicType _basic_type;    // ValueType can not express byte-sized integers

 protected:
  // creation
  UnsafeOp(BasicType basic_type, bool is_put)
  : Instruction(is_put ? voidType : as_ValueType(basic_type))
  , _basic_type(basic_type)
  {
    //Note:  Unsafe ops are not not guaranteed to throw NPE.
    // Convservatively, Unsafe operations must be pinned though we could be
    // looser about this if we wanted to..
    pin();
  }

 public:
  // accessors
  BasicType basic_type()                         { return _basic_type; }

  // generic
2268
  virtual void input_values_do(ValueVisitor* f)   { }
D
duke 已提交
2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311
};


BASE(UnsafeRawOp, UnsafeOp)
 private:
  Value _base;                                   // Base address (a Java long)
  Value _index;                                  // Index if computed by optimizer; initialized to NULL
  int   _log2_scale;                             // Scale factor: 0, 1, 2, or 3.
                                                 // Indicates log2 of number of bytes (1, 2, 4, or 8)
                                                 // to scale index by.

 protected:
  UnsafeRawOp(BasicType basic_type, Value addr, bool is_put)
  : UnsafeOp(basic_type, is_put)
  , _base(addr)
  , _index(NULL)
  , _log2_scale(0)
  {
    // Can not use ASSERT_VALUES because index may be NULL
    assert(addr != NULL && addr->type()->is_long(), "just checking");
  }

  UnsafeRawOp(BasicType basic_type, Value base, Value index, int log2_scale, bool is_put)
  : UnsafeOp(basic_type, is_put)
  , _base(base)
  , _index(index)
  , _log2_scale(log2_scale)
  {
  }

 public:
  // accessors
  Value base()                                   { return _base; }
  Value index()                                  { return _index; }
  bool  has_index()                              { return (_index != NULL); }
  int   log2_scale()                             { return _log2_scale; }

  // setters
  void set_base (Value base)                     { _base  = base; }
  void set_index(Value index)                    { _index = index; }
  void set_log2_scale(int log2_scale)            { _log2_scale = log2_scale; }

  // generic
2312 2313 2314
  virtual void input_values_do(ValueVisitor* f)   { UnsafeOp::input_values_do(f);
                                                   f->visit(&_base);
                                                   if (has_index()) f->visit(&_index); }
D
duke 已提交
2315 2316 2317 2318 2319
};


LEAF(UnsafeGetRaw, UnsafeRawOp)
 private:
2320
 bool _may_be_unaligned, _is_wide;  // For OSREntry
D
duke 已提交
2321 2322

 public:
2323
 UnsafeGetRaw(BasicType basic_type, Value addr, bool may_be_unaligned, bool is_wide = false)
D
duke 已提交
2324 2325
  : UnsafeRawOp(basic_type, addr, false) {
    _may_be_unaligned = may_be_unaligned;
2326
    _is_wide = is_wide;
D
duke 已提交
2327 2328
  }

2329
 UnsafeGetRaw(BasicType basic_type, Value base, Value index, int log2_scale, bool may_be_unaligned, bool is_wide = false)
D
duke 已提交
2330 2331
  : UnsafeRawOp(basic_type, base, index, log2_scale, false) {
    _may_be_unaligned = may_be_unaligned;
2332
    _is_wide = is_wide;
D
duke 已提交
2333 2334
  }

2335 2336
  bool may_be_unaligned()                         { return _may_be_unaligned; }
  bool is_wide()                                  { return _is_wide; }
D
duke 已提交
2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364
};


LEAF(UnsafePutRaw, UnsafeRawOp)
 private:
  Value _value;                                  // Value to be stored

 public:
  UnsafePutRaw(BasicType basic_type, Value addr, Value value)
  : UnsafeRawOp(basic_type, addr, true)
  , _value(value)
  {
    assert(value != NULL, "just checking");
    ASSERT_VALUES
  }

  UnsafePutRaw(BasicType basic_type, Value base, Value index, int log2_scale, Value value)
  : UnsafeRawOp(basic_type, base, index, log2_scale, true)
  , _value(value)
  {
    assert(value != NULL, "just checking");
    ASSERT_VALUES
  }

  // accessors
  Value value()                                  { return _value; }

  // generic
2365 2366
  virtual void input_values_do(ValueVisitor* f)   { UnsafeRawOp::input_values_do(f);
                                                   f->visit(&_value); }
D
duke 已提交
2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385
};


BASE(UnsafeObjectOp, UnsafeOp)
 private:
  Value _object;                                 // Object to be fetched from or mutated
  Value _offset;                                 // Offset within object
  bool  _is_volatile;                            // true if volatile - dl/JSR166
 public:
  UnsafeObjectOp(BasicType basic_type, Value object, Value offset, bool is_put, bool is_volatile)
    : UnsafeOp(basic_type, is_put), _object(object), _offset(offset), _is_volatile(is_volatile)
  {
  }

  // accessors
  Value object()                                 { return _object; }
  Value offset()                                 { return _offset; }
  bool  is_volatile()                            { return _is_volatile; }
  // generic
2386 2387 2388
  virtual void input_values_do(ValueVisitor* f)   { UnsafeOp::input_values_do(f);
                                                   f->visit(&_object);
                                                   f->visit(&_offset); }
D
duke 已提交
2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416
};


LEAF(UnsafeGetObject, UnsafeObjectOp)
 public:
  UnsafeGetObject(BasicType basic_type, Value object, Value offset, bool is_volatile)
  : UnsafeObjectOp(basic_type, object, offset, false, is_volatile)
  {
    ASSERT_VALUES
  }
};


LEAF(UnsafePutObject, UnsafeObjectOp)
 private:
  Value _value;                                  // Value to be stored
 public:
  UnsafePutObject(BasicType basic_type, Value object, Value offset, Value value, bool is_volatile)
  : UnsafeObjectOp(basic_type, object, offset, true, is_volatile)
    , _value(value)
  {
    ASSERT_VALUES
  }

  // accessors
  Value value()                                  { return _value; }

  // generic
2417 2418
  virtual void input_values_do(ValueVisitor* f)   { UnsafeObjectOp::input_values_do(f);
                                                   f->visit(&_value); }
D
duke 已提交
2419 2420
};

2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441
LEAF(UnsafeGetAndSetObject, UnsafeObjectOp)
 private:
  Value _value;                                  // Value to be stored
  bool  _is_add;
 public:
  UnsafeGetAndSetObject(BasicType basic_type, Value object, Value offset, Value value, bool is_add)
  : UnsafeObjectOp(basic_type, object, offset, false, false)
    , _value(value)
    , _is_add(is_add)
  {
    ASSERT_VALUES
  }

  // accessors
  bool is_add() const                            { return _is_add; }
  Value value()                                  { return _value; }

  // generic
  virtual void input_values_do(ValueVisitor* f)   { UnsafeObjectOp::input_values_do(f);
                                                   f->visit(&_value); }
};
D
duke 已提交
2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472

BASE(UnsafePrefetch, UnsafeObjectOp)
 public:
  UnsafePrefetch(Value object, Value offset)
  : UnsafeObjectOp(T_VOID, object, offset, false, false)
  {
  }
};


LEAF(UnsafePrefetchRead, UnsafePrefetch)
 public:
  UnsafePrefetchRead(Value object, Value offset)
  : UnsafePrefetch(object, offset)
  {
    ASSERT_VALUES
  }
};


LEAF(UnsafePrefetchWrite, UnsafePrefetch)
 public:
  UnsafePrefetchWrite(Value object, Value offset)
  : UnsafePrefetch(object, offset)
  {
    ASSERT_VALUES
  }
};

LEAF(ProfileCall, Instruction)
 private:
2473 2474 2475 2476 2477 2478 2479 2480
  ciMethod*        _method;
  int              _bci_of_invoke;
  ciMethod*        _callee;         // the method that is called at the given bci
  Value            _recv;
  ciKlass*         _known_holder;
  Values*          _obj_args;       // arguments for type profiling
  ArgsNonNullState _nonnull_state;  // Do we know whether some arguments are never null?
  bool             _inlined;        // Are we profiling a call that is inlined
D
duke 已提交
2481 2482

 public:
2483
  ProfileCall(ciMethod* method, int bci, ciMethod* callee, Value recv, ciKlass* known_holder, Values* obj_args, bool inlined)
D
duke 已提交
2484 2485 2486
    : Instruction(voidType)
    , _method(method)
    , _bci_of_invoke(bci)
2487
    , _callee(callee)
D
duke 已提交
2488 2489
    , _recv(recv)
    , _known_holder(known_holder)
2490 2491
    , _obj_args(obj_args)
    , _inlined(inlined)
D
duke 已提交
2492 2493 2494 2495 2496
  {
    // The ProfileCall has side-effects and must occur precisely where located
    pin();
  }

2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507
  ciMethod* method()             const { return _method; }
  int bci_of_invoke()            const { return _bci_of_invoke; }
  ciMethod* callee()             const { return _callee; }
  Value recv()                   const { return _recv; }
  ciKlass* known_holder()        const { return _known_holder; }
  int nb_profiled_args()         const { return _obj_args == NULL ? 0 : _obj_args->length(); }
  Value profiled_arg_at(int i)   const { return _obj_args->at(i); }
  bool arg_needs_null_check(int i) const {
    return _nonnull_state.arg_needs_null_check(i);
  }
  bool inlined()                 const { return _inlined; }
D
duke 已提交
2508

2509 2510 2511
  void set_arg_needs_null_check(int i, bool check) {
    _nonnull_state.set_arg_needs_null_check(i, check);
  }
D
duke 已提交
2512

2513 2514 2515 2516 2517 2518 2519 2520 2521
  virtual void input_values_do(ValueVisitor* f)   {
    if (_recv != NULL) {
      f->visit(&_recv);
    }
    for (int i = 0; i < nb_profiled_args(); i++) {
      f->visit(_obj_args->adr_at(i));
    }
  }
};
2522

2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554
LEAF(ProfileReturnType, Instruction)
 private:
  ciMethod*        _method;
  ciMethod*        _callee;
  int              _bci_of_invoke;
  Value            _ret;

 public:
  ProfileReturnType(ciMethod* method, int bci, ciMethod* callee, Value ret)
    : Instruction(voidType)
    , _method(method)
    , _callee(callee)
    , _bci_of_invoke(bci)
    , _ret(ret)
  {
    set_needs_null_check(true);
    // The ProfileType has side-effects and must occur precisely where located
    pin();
  }

  ciMethod* method()             const { return _method; }
  ciMethod* callee()             const { return _callee; }
  int bci_of_invoke()            const { return _bci_of_invoke; }
  Value ret()                    const { return _ret; }

  virtual void input_values_do(ValueVisitor* f)   {
    if (_ret != NULL) {
      f->visit(&_ret);
    }
  }
};

2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585
// Call some C runtime function that doesn't safepoint,
// optionally passing the current thread as the first argument.
LEAF(RuntimeCall, Instruction)
 private:
  const char* _entry_name;
  address     _entry;
  Values*     _args;
  bool        _pass_thread;  // Pass the JavaThread* as an implicit first argument

 public:
  RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true)
    : Instruction(type)
    , _entry(entry)
    , _args(args)
    , _entry_name(entry_name)
    , _pass_thread(pass_thread) {
    ASSERT_VALUES
    pin();
  }

  const char* entry_name() const  { return _entry_name; }
  address entry() const           { return _entry; }
  int number_of_arguments() const { return _args->length(); }
  Value argument_at(int i) const  { return _args->at(i); }
  bool pass_thread() const        { return _pass_thread; }

  virtual void input_values_do(ValueVisitor* f)   {
    for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
  }
};

I
iveresov 已提交
2586
// Use to trip invocation counter of an inlined method
D
duke 已提交
2587

I
iveresov 已提交
2588
LEAF(ProfileInvoke, Instruction)
D
duke 已提交
2589
 private:
I
iveresov 已提交
2590 2591
  ciMethod*   _inlinee;
  ValueStack* _state;
D
duke 已提交
2592 2593

 public:
I
iveresov 已提交
2594
  ProfileInvoke(ciMethod* inlinee,  ValueStack* state)
D
duke 已提交
2595
    : Instruction(voidType)
I
iveresov 已提交
2596 2597
    , _inlinee(inlinee)
    , _state(state)
D
duke 已提交
2598
  {
I
iveresov 已提交
2599
    // The ProfileInvoke has side-effects and must occur precisely where located QQQ???
D
duke 已提交
2600 2601 2602
    pin();
  }

I
iveresov 已提交
2603 2604 2605 2606
  ciMethod* inlinee()      { return _inlinee; }
  ValueStack* state()      { return _state; }
  virtual void input_values_do(ValueVisitor*)   {}
  virtual void state_values_do(ValueVisitor*);
D
duke 已提交
2607 2608
};

2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625
LEAF(MemBar, Instruction)
 private:
  LIR_Code _code;

 public:
  MemBar(LIR_Code code)
    : Instruction(voidType)
    , _code(code)
  {
    pin();
  }

  LIR_Code code()           { return _code; }

  virtual void input_values_do(ValueVisitor*)   {}
};

D
duke 已提交
2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649
class BlockPair: public CompilationResourceObj {
 private:
  BlockBegin* _from;
  BlockBegin* _to;
 public:
  BlockPair(BlockBegin* from, BlockBegin* to): _from(from), _to(to) {}
  BlockBegin* from() const { return _from; }
  BlockBegin* to() const   { return _to;   }
  bool is_same(BlockBegin* from, BlockBegin* to) const { return  _from == from && _to == to; }
  bool is_same(BlockPair* p) const { return  _from == p->from() && _to == p->to(); }
  void set_to(BlockBegin* b)   { _to = b; }
  void set_from(BlockBegin* b) { _from = b; }
};


define_array(BlockPairArray, BlockPair*)
define_stack(BlockPairList, BlockPairArray)


inline int         BlockBegin::number_of_sux() const            { assert(_end == NULL || _end->number_of_sux() == _successors.length(), "mismatch"); return _successors.length(); }
inline BlockBegin* BlockBegin::sux_at(int i) const              { assert(_end == NULL || _end->sux_at(i) == _successors.at(i), "mismatch");          return _successors.at(i); }
inline void        BlockBegin::add_successor(BlockBegin* sux)   { assert(_end == NULL, "Would create mismatch with successors of BlockEnd");         _successors.append(sux); }

#undef ASSERT_VALUES
2650 2651

#endif // SHARE_VM_C1_C1_INSTRUCTION_HPP