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