src/share/vm/c1/c1_Instruction.hpp

Tue, 24 Jul 2012 10:51:00 -0700

author
twisti
date
Tue, 24 Jul 2012 10:51:00 -0700
changeset 3969
1d7922586cf6
parent 3836
c8289830e172
child 4037
da91efe96a93
permissions
-rw-r--r--

7023639: JSR 292 method handle invocation needs a fast path for compiled code
6984705: JSR 292 method handle creation should not go through JNI
Summary: remove assembly code for JDK 7 chained method handles
Reviewed-by: jrose, twisti, kvn, mhaupt
Contributed-by: John Rose <john.r.rose@oracle.com>, Christian Thalinger <christian.thalinger@oracle.com>, Michael Haupt <michael.haupt@oracle.com>

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

mercurial