Fri, 22 Feb 2008 17:55:13 -0800
6650373: Assert in methodOopDesc::make_adapters()
Summary: AdapterHandlerLibrary::get_create_adapter_index() returns incorrect value (-2) when CodeCache is full.
Reviewed-by: sgoldman
1 /*
2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
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 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 // Portions of code courtesy of Clifford Click
27 class MultiNode;
28 class PhaseCCP;
29 class PhaseTransform;
31 //------------------------------MemNode----------------------------------------
32 // Load or Store, possibly throwing a NULL pointer exception
33 class MemNode : public Node {
34 protected:
35 #ifdef ASSERT
36 const TypePtr* _adr_type; // What kind of memory is being addressed?
37 #endif
38 virtual uint size_of() const; // Size is bigger (ASSERT only)
39 public:
40 enum { Control, // When is it safe to do this load?
41 Memory, // Chunk of memory is being loaded from
42 Address, // Actually address, derived from base
43 ValueIn, // Value to store
44 OopStore // Preceeding oop store, only in StoreCM
45 };
46 protected:
47 MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at )
48 : Node(c0,c1,c2 ) {
49 init_class_id(Class_Mem);
50 debug_only(_adr_type=at; adr_type();)
51 }
52 MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at, Node *c3 )
53 : Node(c0,c1,c2,c3) {
54 init_class_id(Class_Mem);
55 debug_only(_adr_type=at; adr_type();)
56 }
57 MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at, Node *c3, Node *c4)
58 : Node(c0,c1,c2,c3,c4) {
59 init_class_id(Class_Mem);
60 debug_only(_adr_type=at; adr_type();)
61 }
63 // Helpers for the optimizer. Documented in memnode.cpp.
64 static bool detect_ptr_independence(Node* p1, AllocateNode* a1,
65 Node* p2, AllocateNode* a2,
66 PhaseTransform* phase);
67 static bool adr_phi_is_loop_invariant(Node* adr_phi, Node* cast);
69 public:
70 // This one should probably be a phase-specific function:
71 static bool detect_dominating_control(Node* dom, Node* sub);
73 // Is this Node a MemNode or some descendent? Default is YES.
74 virtual Node *Ideal_DU_postCCP( PhaseCCP *ccp );
76 virtual const class TypePtr *adr_type() const; // returns bottom_type of address
78 // Shared code for Ideal methods:
79 Node *Ideal_common(PhaseGVN *phase, bool can_reshape); // Return -1 for short-circuit NULL.
81 // Helper function for adr_type() implementations.
82 static const TypePtr* calculate_adr_type(const Type* t, const TypePtr* cross_check = NULL);
84 // Raw access function, to allow copying of adr_type efficiently in
85 // product builds and retain the debug info for debug builds.
86 const TypePtr *raw_adr_type() const {
87 #ifdef ASSERT
88 return _adr_type;
89 #else
90 return 0;
91 #endif
92 }
94 // Map a load or store opcode to its corresponding store opcode.
95 // (Return -1 if unknown.)
96 virtual int store_Opcode() const { return -1; }
98 // What is the type of the value in memory? (T_VOID mean "unspecified".)
99 virtual BasicType memory_type() const = 0;
100 virtual int memory_size() const { return type2aelembytes[memory_type()]; }
102 // Search through memory states which precede this node (load or store).
103 // Look for an exact match for the address, with no intervening
104 // aliased stores.
105 Node* find_previous_store(PhaseTransform* phase);
107 // Can this node (load or store) accurately see a stored value in
108 // the given memory state? (The state may or may not be in(Memory).)
109 Node* can_see_stored_value(Node* st, PhaseTransform* phase) const;
111 #ifndef PRODUCT
112 static void dump_adr_type(const Node* mem, const TypePtr* adr_type, outputStream *st);
113 virtual void dump_spec(outputStream *st) const;
114 #endif
115 };
117 //------------------------------LoadNode---------------------------------------
118 // Load value; requires Memory and Address
119 class LoadNode : public MemNode {
120 protected:
121 virtual uint cmp( const Node &n ) const;
122 virtual uint size_of() const; // Size is bigger
123 const Type* const _type; // What kind of value is loaded?
124 public:
126 LoadNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *rt )
127 : MemNode(c,mem,adr,at), _type(rt) {
128 init_class_id(Class_Load);
129 }
131 // Polymorphic factory method:
132 static LoadNode* make( Compile *C, Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *rt, BasicType bt );
134 virtual uint hash() const; // Check the type
136 // Handle algebraic identities here. If we have an identity, return the Node
137 // we are equivalent to. We look for Load of a Store.
138 virtual Node *Identity( PhaseTransform *phase );
140 // If the load is from Field memory and the pointer is non-null, we can
141 // zero out the control input.
142 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
144 // Recover original value from boxed values
145 Node *eliminate_autobox(PhaseGVN *phase);
147 // Compute a new Type for this node. Basically we just do the pre-check,
148 // then call the virtual add() to set the type.
149 virtual const Type *Value( PhaseTransform *phase ) const;
151 virtual uint ideal_reg() const;
152 virtual const Type *bottom_type() const;
153 // Following method is copied from TypeNode:
154 void set_type(const Type* t) {
155 assert(t != NULL, "sanity");
156 debug_only(uint check_hash = (VerifyHashTableKeys && _hash_lock) ? hash() : NO_HASH);
157 *(const Type**)&_type = t; // cast away const-ness
158 // If this node is in the hash table, make sure it doesn't need a rehash.
159 assert(check_hash == NO_HASH || check_hash == hash(), "type change must preserve hash code");
160 }
161 const Type* type() const { assert(_type != NULL, "sanity"); return _type; };
163 // Do not match memory edge
164 virtual uint match_edge(uint idx) const;
166 // Map a load opcode to its corresponding store opcode.
167 virtual int store_Opcode() const = 0;
169 #ifndef PRODUCT
170 virtual void dump_spec(outputStream *st) const;
171 #endif
172 protected:
173 const Type* load_array_final_field(const TypeKlassPtr *tkls,
174 ciKlass* klass) const;
175 };
177 //------------------------------LoadBNode--------------------------------------
178 // Load a byte (8bits signed) from memory
179 class LoadBNode : public LoadNode {
180 public:
181 LoadBNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti = TypeInt::BYTE )
182 : LoadNode(c,mem,adr,at,ti) {}
183 virtual int Opcode() const;
184 virtual uint ideal_reg() const { return Op_RegI; }
185 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
186 virtual int store_Opcode() const { return Op_StoreB; }
187 virtual BasicType memory_type() const { return T_BYTE; }
188 };
190 //------------------------------LoadCNode--------------------------------------
191 // Load a char (16bits unsigned) from memory
192 class LoadCNode : public LoadNode {
193 public:
194 LoadCNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti = TypeInt::CHAR )
195 : LoadNode(c,mem,adr,at,ti) {}
196 virtual int Opcode() const;
197 virtual uint ideal_reg() const { return Op_RegI; }
198 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
199 virtual int store_Opcode() const { return Op_StoreC; }
200 virtual BasicType memory_type() const { return T_CHAR; }
201 };
203 //------------------------------LoadINode--------------------------------------
204 // Load an integer from memory
205 class LoadINode : public LoadNode {
206 public:
207 LoadINode( Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti = TypeInt::INT )
208 : LoadNode(c,mem,adr,at,ti) {}
209 virtual int Opcode() const;
210 virtual uint ideal_reg() const { return Op_RegI; }
211 virtual int store_Opcode() const { return Op_StoreI; }
212 virtual BasicType memory_type() const { return T_INT; }
213 };
215 //------------------------------LoadRangeNode----------------------------------
216 // Load an array length from the array
217 class LoadRangeNode : public LoadINode {
218 public:
219 LoadRangeNode( Node *c, Node *mem, Node *adr, const TypeInt *ti = TypeInt::POS )
220 : LoadINode(c,mem,adr,TypeAryPtr::RANGE,ti) {}
221 virtual int Opcode() const;
222 virtual const Type *Value( PhaseTransform *phase ) const;
223 virtual Node *Identity( PhaseTransform *phase );
224 };
226 //------------------------------LoadLNode--------------------------------------
227 // Load a long from memory
228 class LoadLNode : public LoadNode {
229 virtual uint hash() const { return LoadNode::hash() + _require_atomic_access; }
230 virtual uint cmp( const Node &n ) const {
231 return _require_atomic_access == ((LoadLNode&)n)._require_atomic_access
232 && LoadNode::cmp(n);
233 }
234 virtual uint size_of() const { return sizeof(*this); }
235 const bool _require_atomic_access; // is piecewise load forbidden?
237 public:
238 LoadLNode( Node *c, Node *mem, Node *adr, const TypePtr* at,
239 const TypeLong *tl = TypeLong::LONG,
240 bool require_atomic_access = false )
241 : LoadNode(c,mem,adr,at,tl)
242 , _require_atomic_access(require_atomic_access)
243 {}
244 virtual int Opcode() const;
245 virtual uint ideal_reg() const { return Op_RegL; }
246 virtual int store_Opcode() const { return Op_StoreL; }
247 virtual BasicType memory_type() const { return T_LONG; }
248 bool require_atomic_access() { return _require_atomic_access; }
249 static LoadLNode* make_atomic(Compile *C, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, const Type* rt);
250 #ifndef PRODUCT
251 virtual void dump_spec(outputStream *st) const {
252 LoadNode::dump_spec(st);
253 if (_require_atomic_access) st->print(" Atomic!");
254 }
255 #endif
256 };
258 //------------------------------LoadL_unalignedNode----------------------------
259 // Load a long from unaligned memory
260 class LoadL_unalignedNode : public LoadLNode {
261 public:
262 LoadL_unalignedNode( Node *c, Node *mem, Node *adr, const TypePtr* at )
263 : LoadLNode(c,mem,adr,at) {}
264 virtual int Opcode() const;
265 };
267 //------------------------------LoadFNode--------------------------------------
268 // Load a float (64 bits) from memory
269 class LoadFNode : public LoadNode {
270 public:
271 LoadFNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *t = Type::FLOAT )
272 : LoadNode(c,mem,adr,at,t) {}
273 virtual int Opcode() const;
274 virtual uint ideal_reg() const { return Op_RegF; }
275 virtual int store_Opcode() const { return Op_StoreF; }
276 virtual BasicType memory_type() const { return T_FLOAT; }
277 };
279 //------------------------------LoadDNode--------------------------------------
280 // Load a double (64 bits) from memory
281 class LoadDNode : public LoadNode {
282 public:
283 LoadDNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *t = Type::DOUBLE )
284 : LoadNode(c,mem,adr,at,t) {}
285 virtual int Opcode() const;
286 virtual uint ideal_reg() const { return Op_RegD; }
287 virtual int store_Opcode() const { return Op_StoreD; }
288 virtual BasicType memory_type() const { return T_DOUBLE; }
289 };
291 //------------------------------LoadD_unalignedNode----------------------------
292 // Load a double from unaligned memory
293 class LoadD_unalignedNode : public LoadDNode {
294 public:
295 LoadD_unalignedNode( Node *c, Node *mem, Node *adr, const TypePtr* at )
296 : LoadDNode(c,mem,adr,at) {}
297 virtual int Opcode() const;
298 };
300 //------------------------------LoadPNode--------------------------------------
301 // Load a pointer from memory (either object or array)
302 class LoadPNode : public LoadNode {
303 public:
304 LoadPNode( Node *c, Node *mem, Node *adr, const TypePtr *at, const TypePtr* t )
305 : LoadNode(c,mem,adr,at,t) {}
306 virtual int Opcode() const;
307 virtual uint ideal_reg() const { return Op_RegP; }
308 virtual int store_Opcode() const { return Op_StoreP; }
309 virtual BasicType memory_type() const { return T_ADDRESS; }
310 // depends_only_on_test is almost always true, and needs to be almost always
311 // true to enable key hoisting & commoning optimizations. However, for the
312 // special case of RawPtr loads from TLS top & end, the control edge carries
313 // the dependence preventing hoisting past a Safepoint instead of the memory
314 // edge. (An unfortunate consequence of having Safepoints not set Raw
315 // Memory; itself an unfortunate consequence of having Nodes which produce
316 // results (new raw memory state) inside of loops preventing all manner of
317 // other optimizations). Basically, it's ugly but so is the alternative.
318 // See comment in macro.cpp, around line 125 expand_allocate_common().
319 virtual bool depends_only_on_test() const { return adr_type() != TypeRawPtr::BOTTOM; }
320 };
322 //------------------------------LoadKlassNode----------------------------------
323 // Load a Klass from an object
324 class LoadKlassNode : public LoadPNode {
325 public:
326 LoadKlassNode( Node *c, Node *mem, Node *adr, const TypePtr *at, const TypeKlassPtr *tk = TypeKlassPtr::OBJECT )
327 : LoadPNode(c,mem,adr,at,tk) {}
328 virtual int Opcode() const;
329 virtual const Type *Value( PhaseTransform *phase ) const;
330 virtual Node *Identity( PhaseTransform *phase );
331 virtual bool depends_only_on_test() const { return true; }
332 };
334 //------------------------------LoadSNode--------------------------------------
335 // Load a short (16bits signed) from memory
336 class LoadSNode : public LoadNode {
337 public:
338 LoadSNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti = TypeInt::SHORT )
339 : LoadNode(c,mem,adr,at,ti) {}
340 virtual int Opcode() const;
341 virtual uint ideal_reg() const { return Op_RegI; }
342 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
343 virtual int store_Opcode() const { return Op_StoreC; }
344 virtual BasicType memory_type() const { return T_SHORT; }
345 };
347 //------------------------------StoreNode--------------------------------------
348 // Store value; requires Store, Address and Value
349 class StoreNode : public MemNode {
350 protected:
351 virtual uint cmp( const Node &n ) const;
352 virtual bool depends_only_on_test() const { return false; }
354 Node *Ideal_masked_input (PhaseGVN *phase, uint mask);
355 Node *Ideal_sign_extended_input(PhaseGVN *phase, int num_bits);
357 public:
358 StoreNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val )
359 : MemNode(c,mem,adr,at,val) {
360 init_class_id(Class_Store);
361 }
362 StoreNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, Node *oop_store )
363 : MemNode(c,mem,adr,at,val,oop_store) {
364 init_class_id(Class_Store);
365 }
367 // Polymorphic factory method:
368 static StoreNode* make( Compile *C, Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, BasicType bt );
370 virtual uint hash() const; // Check the type
372 // If the store is to Field memory and the pointer is non-null, we can
373 // zero out the control input.
374 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
376 // Compute a new Type for this node. Basically we just do the pre-check,
377 // then call the virtual add() to set the type.
378 virtual const Type *Value( PhaseTransform *phase ) const;
380 // Check for identity function on memory (Load then Store at same address)
381 virtual Node *Identity( PhaseTransform *phase );
383 // Do not match memory edge
384 virtual uint match_edge(uint idx) const;
386 virtual const Type *bottom_type() const; // returns Type::MEMORY
388 // Map a store opcode to its corresponding own opcode, trivially.
389 virtual int store_Opcode() const { return Opcode(); }
391 // have all possible loads of the value stored been optimized away?
392 bool value_never_loaded(PhaseTransform *phase) const;
393 };
395 //------------------------------StoreBNode-------------------------------------
396 // Store byte to memory
397 class StoreBNode : public StoreNode {
398 public:
399 StoreBNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {}
400 virtual int Opcode() const;
401 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
402 virtual BasicType memory_type() const { return T_BYTE; }
403 };
405 //------------------------------StoreCNode-------------------------------------
406 // Store char/short to memory
407 class StoreCNode : public StoreNode {
408 public:
409 StoreCNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {}
410 virtual int Opcode() const;
411 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
412 virtual BasicType memory_type() const { return T_CHAR; }
413 };
415 //------------------------------StoreINode-------------------------------------
416 // Store int to memory
417 class StoreINode : public StoreNode {
418 public:
419 StoreINode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {}
420 virtual int Opcode() const;
421 virtual BasicType memory_type() const { return T_INT; }
422 };
424 //------------------------------StoreLNode-------------------------------------
425 // Store long to memory
426 class StoreLNode : public StoreNode {
427 virtual uint hash() const { return StoreNode::hash() + _require_atomic_access; }
428 virtual uint cmp( const Node &n ) const {
429 return _require_atomic_access == ((StoreLNode&)n)._require_atomic_access
430 && StoreNode::cmp(n);
431 }
432 virtual uint size_of() const { return sizeof(*this); }
433 const bool _require_atomic_access; // is piecewise store forbidden?
435 public:
436 StoreLNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val,
437 bool require_atomic_access = false )
438 : StoreNode(c,mem,adr,at,val)
439 , _require_atomic_access(require_atomic_access)
440 {}
441 virtual int Opcode() const;
442 virtual BasicType memory_type() const { return T_LONG; }
443 bool require_atomic_access() { return _require_atomic_access; }
444 static StoreLNode* make_atomic(Compile *C, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, Node* val);
445 #ifndef PRODUCT
446 virtual void dump_spec(outputStream *st) const {
447 StoreNode::dump_spec(st);
448 if (_require_atomic_access) st->print(" Atomic!");
449 }
450 #endif
451 };
453 //------------------------------StoreFNode-------------------------------------
454 // Store float to memory
455 class StoreFNode : public StoreNode {
456 public:
457 StoreFNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {}
458 virtual int Opcode() const;
459 virtual BasicType memory_type() const { return T_FLOAT; }
460 };
462 //------------------------------StoreDNode-------------------------------------
463 // Store double to memory
464 class StoreDNode : public StoreNode {
465 public:
466 StoreDNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {}
467 virtual int Opcode() const;
468 virtual BasicType memory_type() const { return T_DOUBLE; }
469 };
471 //------------------------------StorePNode-------------------------------------
472 // Store pointer to memory
473 class StorePNode : public StoreNode {
474 public:
475 StorePNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {}
476 virtual int Opcode() const;
477 virtual BasicType memory_type() const { return T_ADDRESS; }
478 };
480 //------------------------------StoreCMNode-----------------------------------
481 // Store card-mark byte to memory for CM
482 // The last StoreCM before a SafePoint must be preserved and occur after its "oop" store
483 // Preceeding equivalent StoreCMs may be eliminated.
484 class StoreCMNode : public StoreNode {
485 public:
486 StoreCMNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, Node *oop_store ) : StoreNode(c,mem,adr,at,val,oop_store) {}
487 virtual int Opcode() const;
488 virtual Node *Identity( PhaseTransform *phase );
489 virtual const Type *Value( PhaseTransform *phase ) const;
490 virtual BasicType memory_type() const { return T_VOID; } // unspecific
491 };
493 //------------------------------LoadPLockedNode---------------------------------
494 // Load-locked a pointer from memory (either object or array).
495 // On Sparc & Intel this is implemented as a normal pointer load.
496 // On PowerPC and friends it's a real load-locked.
497 class LoadPLockedNode : public LoadPNode {
498 public:
499 LoadPLockedNode( Node *c, Node *mem, Node *adr )
500 : LoadPNode(c,mem,adr,TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM) {}
501 virtual int Opcode() const;
502 virtual int store_Opcode() const { return Op_StorePConditional; }
503 virtual bool depends_only_on_test() const { return true; }
504 };
506 //------------------------------LoadLLockedNode---------------------------------
507 // Load-locked a pointer from memory (either object or array).
508 // On Sparc & Intel this is implemented as a normal long load.
509 class LoadLLockedNode : public LoadLNode {
510 public:
511 LoadLLockedNode( Node *c, Node *mem, Node *adr )
512 : LoadLNode(c,mem,adr,TypeRawPtr::BOTTOM, TypeLong::LONG) {}
513 virtual int Opcode() const;
514 virtual int store_Opcode() const { return Op_StoreLConditional; }
515 };
517 //------------------------------SCMemProjNode---------------------------------------
518 // This class defines a projection of the memory state of a store conditional node.
519 // These nodes return a value, but also update memory.
520 class SCMemProjNode : public ProjNode {
521 public:
522 enum {SCMEMPROJCON = (uint)-2};
523 SCMemProjNode( Node *src) : ProjNode( src, SCMEMPROJCON) { }
524 virtual int Opcode() const;
525 virtual bool is_CFG() const { return false; }
526 virtual const Type *bottom_type() const {return Type::MEMORY;}
527 virtual const TypePtr *adr_type() const { return in(0)->in(MemNode::Memory)->adr_type();}
528 virtual uint ideal_reg() const { return 0;} // memory projections don't have a register
529 virtual const Type *Value( PhaseTransform *phase ) const;
530 #ifndef PRODUCT
531 virtual void dump_spec(outputStream *st) const {};
532 #endif
533 };
535 //------------------------------LoadStoreNode---------------------------
536 class LoadStoreNode : public Node {
537 public:
538 enum {
539 ExpectedIn = MemNode::ValueIn+1 // One more input than MemNode
540 };
541 LoadStoreNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex);
542 virtual bool depends_only_on_test() const { return false; }
543 virtual const Type *bottom_type() const { return TypeInt::BOOL; }
544 virtual uint ideal_reg() const { return Op_RegI; }
545 virtual uint match_edge(uint idx) const { return idx == MemNode::Address || idx == MemNode::ValueIn; }
546 };
548 //------------------------------StorePConditionalNode---------------------------
549 // Conditionally store pointer to memory, if no change since prior
550 // load-locked. Sets flags for success or failure of the store.
551 class StorePConditionalNode : public LoadStoreNode {
552 public:
553 StorePConditionalNode( Node *c, Node *mem, Node *adr, Node *val, Node *ll ) : LoadStoreNode(c, mem, adr, val, ll) { }
554 virtual int Opcode() const;
555 // Produces flags
556 virtual uint ideal_reg() const { return Op_RegFlags; }
557 };
559 //------------------------------StoreLConditionalNode---------------------------
560 // Conditionally store long to memory, if no change since prior
561 // load-locked. Sets flags for success or failure of the store.
562 class StoreLConditionalNode : public LoadStoreNode {
563 public:
564 StoreLConditionalNode( Node *c, Node *mem, Node *adr, Node *val, Node *ll ) : LoadStoreNode(c, mem, adr, val, ll) { }
565 virtual int Opcode() const;
566 };
569 //------------------------------CompareAndSwapLNode---------------------------
570 class CompareAndSwapLNode : public LoadStoreNode {
571 public:
572 CompareAndSwapLNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex) : LoadStoreNode(c, mem, adr, val, ex) { }
573 virtual int Opcode() const;
574 };
577 //------------------------------CompareAndSwapINode---------------------------
578 class CompareAndSwapINode : public LoadStoreNode {
579 public:
580 CompareAndSwapINode( Node *c, Node *mem, Node *adr, Node *val, Node *ex) : LoadStoreNode(c, mem, adr, val, ex) { }
581 virtual int Opcode() const;
582 };
585 //------------------------------CompareAndSwapPNode---------------------------
586 class CompareAndSwapPNode : public LoadStoreNode {
587 public:
588 CompareAndSwapPNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex) : LoadStoreNode(c, mem, adr, val, ex) { }
589 virtual int Opcode() const;
590 };
592 //------------------------------ClearArray-------------------------------------
593 class ClearArrayNode: public Node {
594 public:
595 ClearArrayNode( Node *ctrl, Node *arymem, Node *word_cnt, Node *base ) : Node(ctrl,arymem,word_cnt,base) {}
596 virtual int Opcode() const;
597 virtual const Type *bottom_type() const { return Type::MEMORY; }
598 // ClearArray modifies array elements, and so affects only the
599 // array memory addressed by the bottom_type of its base address.
600 virtual const class TypePtr *adr_type() const;
601 virtual Node *Identity( PhaseTransform *phase );
602 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
603 virtual uint match_edge(uint idx) const;
605 // Clear the given area of an object or array.
606 // The start offset must always be aligned mod BytesPerInt.
607 // The end offset must always be aligned mod BytesPerLong.
608 // Return the new memory.
609 static Node* clear_memory(Node* control, Node* mem, Node* dest,
610 intptr_t start_offset,
611 intptr_t end_offset,
612 PhaseGVN* phase);
613 static Node* clear_memory(Node* control, Node* mem, Node* dest,
614 intptr_t start_offset,
615 Node* end_offset,
616 PhaseGVN* phase);
617 static Node* clear_memory(Node* control, Node* mem, Node* dest,
618 Node* start_offset,
619 Node* end_offset,
620 PhaseGVN* phase);
621 };
623 //------------------------------StrComp-------------------------------------
624 class StrCompNode: public Node {
625 public:
626 StrCompNode(Node *control,
627 Node* char_array_mem,
628 Node* value_mem,
629 Node* count_mem,
630 Node* offset_mem,
631 Node* s1, Node* s2): Node(control,
632 char_array_mem,
633 value_mem,
634 count_mem,
635 offset_mem,
636 s1, s2) {};
637 virtual int Opcode() const;
638 virtual bool depends_only_on_test() const { return false; }
639 virtual const Type* bottom_type() const { return TypeInt::INT; }
640 // a StrCompNode (conservatively) aliases with everything:
641 virtual const TypePtr* adr_type() const { return TypePtr::BOTTOM; }
642 virtual uint match_edge(uint idx) const;
643 virtual uint ideal_reg() const { return Op_RegI; }
644 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
645 };
647 //------------------------------MemBar-----------------------------------------
648 // There are different flavors of Memory Barriers to match the Java Memory
649 // Model. Monitor-enter and volatile-load act as Aquires: no following ref
650 // can be moved to before them. We insert a MemBar-Acquire after a FastLock or
651 // volatile-load. Monitor-exit and volatile-store act as Release: no
652 // preceeding ref can be moved to after them. We insert a MemBar-Release
653 // before a FastUnlock or volatile-store. All volatiles need to be
654 // serialized, so we follow all volatile-stores with a MemBar-Volatile to
655 // seperate it from any following volatile-load.
656 class MemBarNode: public MultiNode {
657 virtual uint hash() const ; // { return NO_HASH; }
658 virtual uint cmp( const Node &n ) const ; // Always fail, except on self
660 virtual uint size_of() const { return sizeof(*this); }
661 // Memory type this node is serializing. Usually either rawptr or bottom.
662 const TypePtr* _adr_type;
664 public:
665 enum {
666 Precedent = TypeFunc::Parms // optional edge to force precedence
667 };
668 MemBarNode(Compile* C, int alias_idx, Node* precedent);
669 virtual int Opcode() const = 0;
670 virtual const class TypePtr *adr_type() const { return _adr_type; }
671 virtual const Type *Value( PhaseTransform *phase ) const;
672 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
673 virtual uint match_edge(uint idx) const { return 0; }
674 virtual const Type *bottom_type() const { return TypeTuple::MEMBAR; }
675 virtual Node *match( const ProjNode *proj, const Matcher *m );
676 // Factory method. Builds a wide or narrow membar.
677 // Optional 'precedent' becomes an extra edge if not null.
678 static MemBarNode* make(Compile* C, int opcode,
679 int alias_idx = Compile::AliasIdxBot,
680 Node* precedent = NULL);
681 };
683 // "Acquire" - no following ref can move before (but earlier refs can
684 // follow, like an early Load stalled in cache). Requires multi-cpu
685 // visibility. Inserted after a volatile load or FastLock.
686 class MemBarAcquireNode: public MemBarNode {
687 public:
688 MemBarAcquireNode(Compile* C, int alias_idx, Node* precedent)
689 : MemBarNode(C, alias_idx, precedent) {}
690 virtual int Opcode() const;
691 };
693 // "Release" - no earlier ref can move after (but later refs can move
694 // up, like a speculative pipelined cache-hitting Load). Requires
695 // multi-cpu visibility. Inserted before a volatile store or FastUnLock.
696 class MemBarReleaseNode: public MemBarNode {
697 public:
698 MemBarReleaseNode(Compile* C, int alias_idx, Node* precedent)
699 : MemBarNode(C, alias_idx, precedent) {}
700 virtual int Opcode() const;
701 };
703 // Ordering between a volatile store and a following volatile load.
704 // Requires multi-CPU visibility?
705 class MemBarVolatileNode: public MemBarNode {
706 public:
707 MemBarVolatileNode(Compile* C, int alias_idx, Node* precedent)
708 : MemBarNode(C, alias_idx, precedent) {}
709 virtual int Opcode() const;
710 };
712 // Ordering within the same CPU. Used to order unsafe memory references
713 // inside the compiler when we lack alias info. Not needed "outside" the
714 // compiler because the CPU does all the ordering for us.
715 class MemBarCPUOrderNode: public MemBarNode {
716 public:
717 MemBarCPUOrderNode(Compile* C, int alias_idx, Node* precedent)
718 : MemBarNode(C, alias_idx, precedent) {}
719 virtual int Opcode() const;
720 virtual uint ideal_reg() const { return 0; } // not matched in the AD file
721 };
723 // Isolation of object setup after an AllocateNode and before next safepoint.
724 // (See comment in memnode.cpp near InitializeNode::InitializeNode for semantics.)
725 class InitializeNode: public MemBarNode {
726 friend class AllocateNode;
728 bool _is_complete;
730 public:
731 enum {
732 Control = TypeFunc::Control,
733 Memory = TypeFunc::Memory, // MergeMem for states affected by this op
734 RawAddress = TypeFunc::Parms+0, // the newly-allocated raw address
735 RawStores = TypeFunc::Parms+1 // zero or more stores (or TOP)
736 };
738 InitializeNode(Compile* C, int adr_type, Node* rawoop);
739 virtual int Opcode() const;
740 virtual uint size_of() const { return sizeof(*this); }
741 virtual uint ideal_reg() const { return 0; } // not matched in the AD file
742 virtual const RegMask &in_RegMask(uint) const; // mask for RawAddress
744 // Manage incoming memory edges via a MergeMem on in(Memory):
745 Node* memory(uint alias_idx);
747 // The raw memory edge coming directly from the Allocation.
748 // The contents of this memory are *always* all-zero-bits.
749 Node* zero_memory() { return memory(Compile::AliasIdxRaw); }
751 // Return the corresponding allocation for this initialization (or null if none).
752 // (Note: Both InitializeNode::allocation and AllocateNode::initialization
753 // are defined in graphKit.cpp, which sets up the bidirectional relation.)
754 AllocateNode* allocation();
756 // Anything other than zeroing in this init?
757 bool is_non_zero();
759 // An InitializeNode must completed before macro expansion is done.
760 // Completion requires that the AllocateNode must be followed by
761 // initialization of the new memory to zero, then to any initializers.
762 bool is_complete() { return _is_complete; }
764 // Mark complete. (Must not yet be complete.)
765 void set_complete(PhaseGVN* phase);
767 #ifdef ASSERT
768 // ensure all non-degenerate stores are ordered and non-overlapping
769 bool stores_are_sane(PhaseTransform* phase);
770 #endif //ASSERT
772 // See if this store can be captured; return offset where it initializes.
773 // Return 0 if the store cannot be moved (any sort of problem).
774 intptr_t can_capture_store(StoreNode* st, PhaseTransform* phase);
776 // Capture another store; reformat it to write my internal raw memory.
777 // Return the captured copy, else NULL if there is some sort of problem.
778 Node* capture_store(StoreNode* st, intptr_t start, PhaseTransform* phase);
780 // Find captured store which corresponds to the range [start..start+size).
781 // Return my own memory projection (meaning the initial zero bits)
782 // if there is no such store. Return NULL if there is a problem.
783 Node* find_captured_store(intptr_t start, int size_in_bytes, PhaseTransform* phase);
785 // Called when the associated AllocateNode is expanded into CFG.
786 Node* complete_stores(Node* rawctl, Node* rawmem, Node* rawptr,
787 intptr_t header_size, Node* size_in_bytes,
788 PhaseGVN* phase);
790 private:
791 void remove_extra_zeroes();
793 // Find out where a captured store should be placed (or already is placed).
794 int captured_store_insertion_point(intptr_t start, int size_in_bytes,
795 PhaseTransform* phase);
797 static intptr_t get_store_offset(Node* st, PhaseTransform* phase);
799 Node* make_raw_address(intptr_t offset, PhaseTransform* phase);
801 bool detect_init_independence(Node* n, bool st_is_pinned, int& count);
803 void coalesce_subword_stores(intptr_t header_size, Node* size_in_bytes,
804 PhaseGVN* phase);
806 intptr_t find_next_fullword_store(uint i, PhaseGVN* phase);
807 };
809 //------------------------------MergeMem---------------------------------------
810 // (See comment in memnode.cpp near MergeMemNode::MergeMemNode for semantics.)
811 class MergeMemNode: public Node {
812 virtual uint hash() const ; // { return NO_HASH; }
813 virtual uint cmp( const Node &n ) const ; // Always fail, except on self
814 friend class MergeMemStream;
815 MergeMemNode(Node* def); // clients use MergeMemNode::make
817 public:
818 // If the input is a whole memory state, clone it with all its slices intact.
819 // Otherwise, make a new memory state with just that base memory input.
820 // In either case, the result is a newly created MergeMem.
821 static MergeMemNode* make(Compile* C, Node* base_memory);
823 virtual int Opcode() const;
824 virtual Node *Identity( PhaseTransform *phase );
825 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
826 virtual uint ideal_reg() const { return NotAMachineReg; }
827 virtual uint match_edge(uint idx) const { return 0; }
828 virtual const RegMask &out_RegMask() const;
829 virtual const Type *bottom_type() const { return Type::MEMORY; }
830 virtual const TypePtr *adr_type() const { return TypePtr::BOTTOM; }
831 // sparse accessors
832 // Fetch the previously stored "set_memory_at", or else the base memory.
833 // (Caller should clone it if it is a phi-nest.)
834 Node* memory_at(uint alias_idx) const;
835 // set the memory, regardless of its previous value
836 void set_memory_at(uint alias_idx, Node* n);
837 // the "base" is the memory that provides the non-finite support
838 Node* base_memory() const { return in(Compile::AliasIdxBot); }
839 // warning: setting the base can implicitly set any of the other slices too
840 void set_base_memory(Node* def);
841 // sentinel value which denotes a copy of the base memory:
842 Node* empty_memory() const { return in(Compile::AliasIdxTop); }
843 static Node* make_empty_memory(); // where the sentinel comes from
844 bool is_empty_memory(Node* n) const { assert((n == empty_memory()) == n->is_top(), "sanity"); return n->is_top(); }
845 // hook for the iterator, to perform any necessary setup
846 void iteration_setup(const MergeMemNode* other = NULL);
847 // push sentinels until I am at least as long as the other (semantic no-op)
848 void grow_to_match(const MergeMemNode* other);
849 bool verify_sparse() const PRODUCT_RETURN0;
850 #ifndef PRODUCT
851 virtual void dump_spec(outputStream *st) const;
852 #endif
853 };
855 class MergeMemStream : public StackObj {
856 private:
857 MergeMemNode* _mm;
858 const MergeMemNode* _mm2; // optional second guy, contributes non-empty iterations
859 Node* _mm_base; // loop-invariant base memory of _mm
860 int _idx;
861 int _cnt;
862 Node* _mem;
863 Node* _mem2;
864 int _cnt2;
866 void init(MergeMemNode* mm, const MergeMemNode* mm2 = NULL) {
867 // subsume_node will break sparseness at times, whenever a memory slice
868 // folds down to a copy of the base ("fat") memory. In such a case,
869 // the raw edge will update to base, although it should be top.
870 // This iterator will recognize either top or base_memory as an
871 // "empty" slice. See is_empty, is_empty2, and next below.
872 //
873 // The sparseness property is repaired in MergeMemNode::Ideal.
874 // As long as access to a MergeMem goes through this iterator
875 // or the memory_at accessor, flaws in the sparseness will
876 // never be observed.
877 //
878 // Also, iteration_setup repairs sparseness.
879 assert(mm->verify_sparse(), "please, no dups of base");
880 assert(mm2==NULL || mm2->verify_sparse(), "please, no dups of base");
882 _mm = mm;
883 _mm_base = mm->base_memory();
884 _mm2 = mm2;
885 _cnt = mm->req();
886 _idx = Compile::AliasIdxBot-1; // start at the base memory
887 _mem = NULL;
888 _mem2 = NULL;
889 }
891 #ifdef ASSERT
892 Node* check_memory() const {
893 if (at_base_memory())
894 return _mm->base_memory();
895 else if ((uint)_idx < _mm->req() && !_mm->in(_idx)->is_top())
896 return _mm->memory_at(_idx);
897 else
898 return _mm_base;
899 }
900 Node* check_memory2() const {
901 return at_base_memory()? _mm2->base_memory(): _mm2->memory_at(_idx);
902 }
903 #endif
905 static bool match_memory(Node* mem, const MergeMemNode* mm, int idx) PRODUCT_RETURN0;
906 void assert_synch() const {
907 assert(!_mem || _idx >= _cnt || match_memory(_mem, _mm, _idx),
908 "no side-effects except through the stream");
909 }
911 public:
913 // expected usages:
914 // for (MergeMemStream mms(mem->is_MergeMem()); next_non_empty(); ) { ... }
915 // for (MergeMemStream mms(mem1, mem2); next_non_empty2(); ) { ... }
917 // iterate over one merge
918 MergeMemStream(MergeMemNode* mm) {
919 mm->iteration_setup();
920 init(mm);
921 debug_only(_cnt2 = 999);
922 }
923 // iterate in parallel over two merges
924 // only iterates through non-empty elements of mm2
925 MergeMemStream(MergeMemNode* mm, const MergeMemNode* mm2) {
926 assert(mm2, "second argument must be a MergeMem also");
927 ((MergeMemNode*)mm2)->iteration_setup(); // update hidden state
928 mm->iteration_setup(mm2);
929 init(mm, mm2);
930 _cnt2 = mm2->req();
931 }
932 #ifdef ASSERT
933 ~MergeMemStream() {
934 assert_synch();
935 }
936 #endif
938 MergeMemNode* all_memory() const {
939 return _mm;
940 }
941 Node* base_memory() const {
942 assert(_mm_base == _mm->base_memory(), "no update to base memory, please");
943 return _mm_base;
944 }
945 const MergeMemNode* all_memory2() const {
946 assert(_mm2 != NULL, "");
947 return _mm2;
948 }
949 bool at_base_memory() const {
950 return _idx == Compile::AliasIdxBot;
951 }
952 int alias_idx() const {
953 assert(_mem, "must call next 1st");
954 return _idx;
955 }
957 const TypePtr* adr_type() const {
958 return Compile::current()->get_adr_type(alias_idx());
959 }
961 const TypePtr* adr_type(Compile* C) const {
962 return C->get_adr_type(alias_idx());
963 }
964 bool is_empty() const {
965 assert(_mem, "must call next 1st");
966 assert(_mem->is_top() == (_mem==_mm->empty_memory()), "correct sentinel");
967 return _mem->is_top();
968 }
969 bool is_empty2() const {
970 assert(_mem2, "must call next 1st");
971 assert(_mem2->is_top() == (_mem2==_mm2->empty_memory()), "correct sentinel");
972 return _mem2->is_top();
973 }
974 Node* memory() const {
975 assert(!is_empty(), "must not be empty");
976 assert_synch();
977 return _mem;
978 }
979 // get the current memory, regardless of empty or non-empty status
980 Node* force_memory() const {
981 assert(!is_empty() || !at_base_memory(), "");
982 // Use _mm_base to defend against updates to _mem->base_memory().
983 Node *mem = _mem->is_top() ? _mm_base : _mem;
984 assert(mem == check_memory(), "");
985 return mem;
986 }
987 Node* memory2() const {
988 assert(_mem2 == check_memory2(), "");
989 return _mem2;
990 }
991 void set_memory(Node* mem) {
992 if (at_base_memory()) {
993 // Note that this does not change the invariant _mm_base.
994 _mm->set_base_memory(mem);
995 } else {
996 _mm->set_memory_at(_idx, mem);
997 }
998 _mem = mem;
999 assert_synch();
1000 }
1002 // Recover from a side effect to the MergeMemNode.
1003 void set_memory() {
1004 _mem = _mm->in(_idx);
1005 }
1007 bool next() { return next(false); }
1008 bool next2() { return next(true); }
1010 bool next_non_empty() { return next_non_empty(false); }
1011 bool next_non_empty2() { return next_non_empty(true); }
1012 // next_non_empty2 can yield states where is_empty() is true
1014 private:
1015 // find the next item, which might be empty
1016 bool next(bool have_mm2) {
1017 assert((_mm2 != NULL) == have_mm2, "use other next");
1018 assert_synch();
1019 if (++_idx < _cnt) {
1020 // Note: This iterator allows _mm to be non-sparse.
1021 // It behaves the same whether _mem is top or base_memory.
1022 _mem = _mm->in(_idx);
1023 if (have_mm2)
1024 _mem2 = _mm2->in((_idx < _cnt2) ? _idx : Compile::AliasIdxTop);
1025 return true;
1026 }
1027 return false;
1028 }
1030 // find the next non-empty item
1031 bool next_non_empty(bool have_mm2) {
1032 while (next(have_mm2)) {
1033 if (!is_empty()) {
1034 // make sure _mem2 is filled in sensibly
1035 if (have_mm2 && _mem2->is_top()) _mem2 = _mm2->base_memory();
1036 return true;
1037 } else if (have_mm2 && !is_empty2()) {
1038 return true; // is_empty() == true
1039 }
1040 }
1041 return false;
1042 }
1043 };
1045 //------------------------------Prefetch---------------------------------------
1047 // Non-faulting prefetch load. Prefetch for many reads.
1048 class PrefetchReadNode : public Node {
1049 public:
1050 PrefetchReadNode(Node *abio, Node *adr) : Node(0,abio,adr) {}
1051 virtual int Opcode() const;
1052 virtual uint ideal_reg() const { return NotAMachineReg; }
1053 virtual uint match_edge(uint idx) const { return idx==2; }
1054 virtual const Type *bottom_type() const { return Type::ABIO; }
1055 };
1057 // Non-faulting prefetch load. Prefetch for many reads & many writes.
1058 class PrefetchWriteNode : public Node {
1059 public:
1060 PrefetchWriteNode(Node *abio, Node *adr) : Node(0,abio,adr) {}
1061 virtual int Opcode() const;
1062 virtual uint ideal_reg() const { return NotAMachineReg; }
1063 virtual uint match_edge(uint idx) const { return idx==2; }
1064 virtual const Type *bottom_type() const { return Type::ABIO; }
1065 };