src/share/vm/c1/c1_Instruction.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 5921
ce0cc25bc5e2
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

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

mercurial