src/share/vm/c1/c1_Instruction.hpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 9041
95a08233f46c
permissions
-rw-r--r--

Merge

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

mercurial