103 //
104 // LV -P> JO
105 // OF -P> JO (the object whose oop is stored in the field)
106 // JO -F> OF
107 //
108 // Then, for each node which is GlobalEscape, anything it could point to
109 // is marked GlobalEscape. Finally, for any node marked ArgEscape, anything
110 // it could point to is marked ArgEscape.
111 //
112
113 class Compile;
114 class Node;
115 class CallNode;
116 class PhiNode;
117 class PhaseTransform;
118 class PointsToNode;
119 class Type;
120 class TypePtr;
121 class VectorSet;
122
123 // Wrapper for GrowableArray
124 class PointsToList {
125 GrowableArray<PointsToNode*> _list; // List of nodes this node points to
126 public:
127 uint count() const { return _list.length(); }
128 PointsToNode* element(uint e) const { return _list.at(e); }
129
130 bool add(PointsToNode* elem) {
131 // Returns TRUE if elem is added.
132 bool missed = !_list.contains(elem);
133 if (missed)
134 _list.append(elem); // Add new element
135 return missed;
136 }
137 };
138
139 class JavaObjectNode;
140 class LocalVarNode;
141 class FieldNode;
142 class ArraycopyNode;
143
144 // ConnectionGraph nodes
145 class PointsToNode : public ResourceObj {
146 PointsToList _edges; // List of nodes this node points to
147 PointsToList _uses; // List of nodes which point to this node
148
149 const u1 _type; // NodeType
150 u1 _flags; // NodeFlags
151 u1 _escape; // EscapeState of object
152 u1 _fields_escape; // EscapeState of object's fields
153
154 const Node* _node; // Ideal node corresponding to this PointsTo node.
155 const uint _idx; // Cached ideal node's _idx
156
157 public:
158 typedef enum {
159 UnknownType = 0,
160 JavaObject = 1,
161 LocalVar = 2,
162 Field = 3,
163 Arraycopy = 4
164 } NodeType;
165
166 typedef enum {
167 UnknownEscape = 0,
168 NoEscape = 1, // An object does not escape method or thread and it is
169 // not passed to call. It could be replaced with scalar.
170 ArgEscape = 2, // An object does not escape method or thread but it is
171 // passed as argument to call or referenced by argument
172 // and it does not escape during call.
173 GlobalEscape = 3 // An object escapes the method or thread.
174 } EscapeState;
175
176 typedef enum {
177 ScalarReplaceable = 1, // Not escaped object could be replaced with scalar
178 PointsToUnknown = 2, // Has edge to phantom_object
179 ArraycopySrc = 4, // Has edge from Arraycopy node
180 ArraycopyDst = 8 // Has edge to Arraycopy node
181 } NodeFlags;
182
183
184 PointsToNode(Node* n, EscapeState es, NodeType type):
185 _node(n),
186 _idx(n->_idx),
187 _type((u1)type),
188 _escape((u1)es),
189 _fields_escape((u1)es),
190 _flags(ScalarReplaceable) {
191 assert(n != NULL && es != UnknownEscape, "sanity");
192 }
193
194 Node* ideal_node() const { return (Node*)_node; }
195 int idx() const { return _idx; }
196
197 bool is_JavaObject() const { return _type == (u1)JavaObject; }
198 bool is_LocalVar() const { return _type == (u1)LocalVar; }
199 bool is_Field() const { return _type == (u1)Field; }
200 bool is_Arraycopy() const { return _type == (u1)Arraycopy; }
201
202 JavaObjectNode* as_JavaObject() { assert(is_JavaObject(),""); return (JavaObjectNode*)this; }
203 LocalVarNode* as_LocalVar() { assert(is_LocalVar(),""); return (LocalVarNode*)this; }
204 FieldNode* as_Field() { assert(is_Field(),""); return (FieldNode*)this; }
205 ArraycopyNode* as_Arraycopy() { assert(is_Arraycopy(),""); return (ArraycopyNode*)this; }
206
207 EscapeState escape_state() const { return (EscapeState)_escape; }
208 void set_escape_state(EscapeState state) { _escape = (u1)state; }
209
210 EscapeState fields_escape_state() const { return (EscapeState)_fields_escape; }
211 void set_fields_escape_state(EscapeState state) { _fields_escape = (u1)state; }
212
213 bool has_unknown_ptr() const { return (_flags & PointsToUnknown) != 0; }
214 void set_has_unknown_ptr() { _flags |= PointsToUnknown; }
215
216 bool arraycopy_src() const { return (_flags & ArraycopySrc) != 0; }
217 void set_arraycopy_src() { _flags |= ArraycopySrc; }
218 bool arraycopy_dst() const { return (_flags & ArraycopyDst) != 0; }
219 void set_arraycopy_dst() { _flags |= ArraycopyDst; }
220
221 bool scalar_replaceable() const { return (_flags & ScalarReplaceable) != 0;}
222 void set_scalar_replaceable(bool v) {
223 if (v)
224 _flags |= ScalarReplaceable;
225 else
226 _flags &= ~ScalarReplaceable;
227 }
228
229 uint edge_count() const { return _edges.count(); }
230 PointsToNode* edge(uint e) const { return _edges.element(e); }
231 bool add_edge(PointsToNode* edge) { return _edges.add(edge); }
232
233 uint use_count() const { return _uses.count(); }
234 PointsToNode* use(uint e) const { return _uses.element(e); }
235 bool add_use(PointsToNode* use) { return _uses.add(use); }
236
237 // Mark base edge use to distinguish from stored value edge.
238 bool add_base_use(FieldNode* use) { return _uses.add((PointsToNode*)((intptr_t)use + 1)); }
239 static bool is_base_use(PointsToNode* use) { return (((intptr_t)use) & 1); }
240 static PointsToNode* get_use_node(PointsToNode* use) { return (PointsToNode*)(((intptr_t)use) & ~1); }
241
242 // Return true if this node points to specified node or nodes it points to.
243 bool points_to(JavaObjectNode* ptn) const;
244
245 // Return true if nodes points only to non-escaped allocations.
246 bool not_escaped_allocation();
247
248 // Return true if one node points to an other.
249 bool meet(PointsToNode* ptn);
250
251 #ifndef PRODUCT
252 NodeType node_type() const { return (NodeType)_type;}
253 void dump(bool print_state=true) const;
254 #endif
255
256 };
257
258 class LocalVarNode: public PointsToNode {
259 public:
260 LocalVarNode(Node* n, EscapeState es):
261 PointsToNode(n, es, LocalVar) {}
262 };
263
264 class JavaObjectNode: public PointsToNode {
265 public:
266 JavaObjectNode(Node* n, EscapeState es):
267 PointsToNode(n, es, JavaObject) {
268 if (es > NoEscape)
269 set_scalar_replaceable(false);
270 }
271 };
272
273 class FieldNode: public PointsToNode {
274 PointsToList _bases; // List of JavaObject nodes which point to this node
275 const int _offset; // Field's offset.
276 const bool _is_oop; // Field points to object
277 bool _has_unknown_base; // Has phantom_object base
278 public:
279 FieldNode(Node* n, EscapeState es, int offs, bool is_oop):
280 PointsToNode(n, es, Field),
281 _offset(offs), _is_oop(is_oop),
282 _has_unknown_base(false) {}
283
284 int offset() const { return _offset;}
285 bool is_oop() const { return _is_oop;}
286 bool has_unknown_base() const { return _has_unknown_base; }
287 void set_has_unknown_base() { _has_unknown_base = true; }
288
289 uint base_count() const { return _bases.count(); }
290 PointsToNode* base(uint e) const { return _bases.element(e); }
291 bool add_base(PointsToNode* base) { return _bases.add(base); }
292 #ifdef ASSERT
293 // Return true if bases points to this java object.
294 bool has_base(JavaObjectNode* ptn) const;
295 #endif
296
297 };
298
299 class ArraycopyNode: public PointsToNode {
300 public:
301 ArraycopyNode(Node* n, EscapeState es):
302 PointsToNode(n, es, Arraycopy) {}
303 };
304
305 // Iterators for PointsTo node's edges:
306 // for (EdgeIterator i(n); i.has_next(); i.next()) {
307 // PointsToNode* u = i.get();
308 class PointsToIterator: public StackObj {
309 protected:
310 const PointsToNode* node;
311 const uint cnt;
312 uint i;
313 public:
314 inline PointsToIterator(const PointsToNode* n, uint cnt) : node(n), cnt(cnt), i(0) { }
315 inline bool has_next() const { return i < cnt; }
316 inline void next() { i++; }
317 PointsToNode* get() const { ShouldNotCallThis(); return NULL; }
318 };
319
320 class EdgeIterator: public PointsToIterator {
321 public:
322 inline EdgeIterator(const PointsToNode* n) : PointsToIterator(n, n->edge_count()) { }
323 inline PointsToNode* get() const { return node->edge(i); }
324 };
325
326 class UseIterator: public PointsToIterator {
327 public:
328 inline UseIterator(const PointsToNode* n) : PointsToIterator(n, n->use_count()) { }
329 inline PointsToNode* get() const { return node->use(i); }
330 };
331
332 class BaseIterator: public PointsToIterator {
333 public:
334 inline BaseIterator(const FieldNode* n) : PointsToIterator(n, n->base_count()) { }
343
344 GrowableArray<PointsToNode*> _worklist; // Nodes to be processed
345
346 bool _collecting; // Indicates whether escape information
347 // is still being collected. If false,
348 // no new nodes will be processed.
349
350 bool _verify; // verify graph
351
352 JavaObjectNode* phantom_obj; // Unknown object
353 JavaObjectNode* null_obj;
354 Node* _pcmp_neq; // ConI(#CC_GT)
355 Node* _pcmp_eq; // ConI(#CC_EQ)
356
357 Compile* _compile; // Compile object for current compilation
358 PhaseIterGVN* _igvn; // Value numbering
359
360 Unique_Node_List ideal_nodes; // Used by CG construction and types splitting.
361
362 // Address of an element in _nodes. Used when the element is to be modified
363 PointsToNode* ptnode_adr(uint idx) const {
364 // There should be no new ideal nodes during ConnectionGraph build,
365 // growableArray::at() will throw assert otherwise.
366 return _nodes.at(idx);
367 }
368 uint nodes_size() const { return _nodes.length(); }
369
370 // Add nodes to ConnectionGraph.
371 void add_local_var(Node* n, PointsToNode::EscapeState es);
372 void add_java_object(Node* n, PointsToNode::EscapeState es);
373 void add_field(Node* n, PointsToNode::EscapeState es, int offset);
374 void add_arraycopy(Node* n, PointsToNode::EscapeState es, PointsToNode* src, PointsToNode* dst);
375
376 // Compute the escape state for arguments to a call.
377 void process_call_arguments(CallNode *call, PhaseGVN *igvn);
378
379 // Add PointsToNode node corresponding to a call
380 void add_call_node(CallNode* call);
381
382 // Map ideal node to existing PointsTo node (usually phantom_object).
383 void map_ideal_node(Node *n, PointsToNode* ptn) {
384 assert(ptn != NULL, "only existing PointsTo node");
385 _nodes.at_put(n->_idx, ptn);
386 }
387
388 // Create PointsToNode node and add it to Connection Graph.
389 void add_node_to_connection_graph(Node *n, Unique_Node_List *delayed_worklist);
390
391 // Add final simple edges to graph.
392 void add_final_edges(Node *n);
393
394 // Finish Graph construction.
395 bool complete_connection_graph(GrowableArray<PointsToNode*>& ptnodes_worklist,
396 GrowableArray<JavaObjectNode*>& non_escaped_worklist,
397 GrowableArray<JavaObjectNode*>& java_objects_worklist,
433
434 // Set the escape state of an object and its fields.
435 void set_escape_state(PointsToNode* ptn, PointsToNode::EscapeState esc) {
436 // Don't change non-escaping state of NULL pointer.
437 if (ptn != null_obj) {
438 if (ptn->escape_state() < esc)
439 ptn->set_escape_state(esc);
440 if (ptn->fields_escape_state() < esc)
441 ptn->set_fields_escape_state(esc);
442 }
443 }
444 void set_fields_escape_state(PointsToNode* ptn, PointsToNode::EscapeState esc) {
445 // Don't change non-escaping state of NULL pointer.
446 if (ptn != null_obj) {
447 if (ptn->fields_escape_state() < esc)
448 ptn->set_fields_escape_state(esc);
449 }
450 }
451
452 // Propagate GlobalEscape and ArgEscape escape states to all nodes
453 // and check that we still have non escaped java objects.
454 bool find_non_escaped_objects(GrowableArray<PointsToNode*>& ptnodes_worklist,
455 GrowableArray<JavaObjectNode*>& non_escaped_worklist);
456
457 // Adjust scalar_replaceable state after Connection Graph is built.
458 void adjust_scalar_replaceable_state(JavaObjectNode* jobj);
459
460 // Optimize ideal graph.
461 void optimize_ideal_graph(GrowableArray<Node*>& ptr_cmp_worklist,
462 GrowableArray<Node*>& storestore_worklist);
463 // Optimize objects compare.
464 Node* optimize_ptr_compare(Node* n);
465
466 // Returns unique corresponding java object or NULL.
467 JavaObjectNode* unique_java_object(Node *n);
468
469 // Add an edge of the specified type pointing to the specified target.
470 bool add_edge(PointsToNode* from, PointsToNode* to) {
471 assert(!from->is_Field() || from->as_Field()->is_oop(), "sanity");
472
473 if (to == phantom_obj) {
525 } else {
526 assert(ptn != NULL, "node should be registered");
527 }
528 add_edge(ptnode_adr(n->_idx), ptn);
529 }
530
531 // Helper functions
532 bool is_oop_field(Node* n, int offset);
533 static Node* get_addp_base(Node *addp);
534 static Node* find_second_addp(Node* addp, Node* n);
535
536 // offset of a field reference
537 int address_offset(Node* adr, PhaseTransform *phase);
538
539
540 // Propagate unique types created for unescaped allocated objects
541 // through the graph
542 void split_unique_types(GrowableArray<Node *> &alloc_worklist);
543
544 // Helper methods for unique types split.
545 bool split_AddP(Node *addp, Node *base, PhaseGVN *igvn);
546
547 PhiNode *create_split_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, PhaseGVN *igvn, bool &new_created);
548 PhiNode *split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, PhaseGVN *igvn);
549
550 void move_inst_mem(Node* n, GrowableArray<PhiNode *> &orig_phis, PhaseGVN *igvn);
551 Node* find_inst_mem(Node* mem, int alias_idx,GrowableArray<PhiNode *> &orig_phi_worklist, PhaseGVN *igvn);
552 Node* step_through_mergemem(MergeMemNode *mmem, int alias_idx, const TypeOopPtr *toop);
553
554
555 GrowableArray<MergeMemNode*> _mergemem_worklist; // List of all MergeMem nodes
556
557 Node_Array _node_map; // used for bookeeping during type splitting
558 // Used for the following purposes:
559 // Memory Phi - most recent unique Phi split out
560 // from this Phi
561 // MemNode - new memory input for this node
562 // ChecCastPP - allocation that this is a cast of
563 // allocation - CheckCastPP of the allocation
564
565 // manage entries in _node_map
566
567 void set_map(Node* from, Node* to) {
568 ideal_nodes.push(from);
569 _node_map.map(from->_idx, to);
570 }
571
|
103 //
104 // LV -P> JO
105 // OF -P> JO (the object whose oop is stored in the field)
106 // JO -F> OF
107 //
108 // Then, for each node which is GlobalEscape, anything it could point to
109 // is marked GlobalEscape. Finally, for any node marked ArgEscape, anything
110 // it could point to is marked ArgEscape.
111 //
112
113 class Compile;
114 class Node;
115 class CallNode;
116 class PhiNode;
117 class PhaseTransform;
118 class PointsToNode;
119 class Type;
120 class TypePtr;
121 class VectorSet;
122
123 class JavaObjectNode;
124 class LocalVarNode;
125 class FieldNode;
126 class ArraycopyNode;
127
128 // ConnectionGraph nodes
129 class PointsToNode : public ResourceObj {
130 GrowableArray<PointsToNode*> _edges; // List of nodes this node points to
131 GrowableArray<PointsToNode*> _uses; // List of nodes which point to this node
132
133 const u1 _type; // NodeType
134 u1 _flags; // NodeFlags
135 u1 _escape; // EscapeState of object
136 u1 _fields_escape; // EscapeState of object's fields
137
138 Node* const _node; // Ideal node corresponding to this PointsTo node.
139 const int _idx; // Cached ideal node's _idx
140
141 public:
142 typedef enum {
143 UnknownType = 0,
144 JavaObject = 1,
145 LocalVar = 2,
146 Field = 3,
147 Arraycopy = 4
148 } NodeType;
149
150 typedef enum {
151 UnknownEscape = 0,
152 NoEscape = 1, // An object does not escape method or thread and it is
153 // not passed to call. It could be replaced with scalar.
154 ArgEscape = 2, // An object does not escape method or thread but it is
155 // passed as argument to call or referenced by argument
156 // and it does not escape during call.
157 GlobalEscape = 3 // An object escapes the method or thread.
158 } EscapeState;
159
160 typedef enum {
161 ScalarReplaceable = 1, // Not escaped object could be replaced with scalar
162 PointsToUnknown = 2, // Has edge to phantom_object
163 ArraycopySrc = 4, // Has edge from Arraycopy node
164 ArraycopyDst = 8 // Has edge to Arraycopy node
165 } NodeFlags;
166
167
168 PointsToNode(Compile *C, Node* n, EscapeState es, NodeType type):
169 _edges(C->comp_arena(), 2, 0, NULL),
170 _uses (C->comp_arena(), 2, 0, NULL),
171 _node(n),
172 _idx(n->_idx),
173 _type((u1)type),
174 _escape((u1)es),
175 _fields_escape((u1)es),
176 _flags(ScalarReplaceable) {
177 assert(n != NULL && es != UnknownEscape, "sanity");
178 }
179
180 Node* ideal_node() const { return _node; }
181 int idx() const { return _idx; }
182
183 bool is_JavaObject() const { return _type == (u1)JavaObject; }
184 bool is_LocalVar() const { return _type == (u1)LocalVar; }
185 bool is_Field() const { return _type == (u1)Field; }
186 bool is_Arraycopy() const { return _type == (u1)Arraycopy; }
187
188 JavaObjectNode* as_JavaObject() { assert(is_JavaObject(),""); return (JavaObjectNode*)this; }
189 LocalVarNode* as_LocalVar() { assert(is_LocalVar(),""); return (LocalVarNode*)this; }
190 FieldNode* as_Field() { assert(is_Field(),""); return (FieldNode*)this; }
191 ArraycopyNode* as_Arraycopy() { assert(is_Arraycopy(),""); return (ArraycopyNode*)this; }
192
193 EscapeState escape_state() const { return (EscapeState)_escape; }
194 void set_escape_state(EscapeState state) { _escape = (u1)state; }
195
196 EscapeState fields_escape_state() const { return (EscapeState)_fields_escape; }
197 void set_fields_escape_state(EscapeState state) { _fields_escape = (u1)state; }
198
199 bool has_unknown_ptr() const { return (_flags & PointsToUnknown) != 0; }
200 void set_has_unknown_ptr() { _flags |= PointsToUnknown; }
201
202 bool arraycopy_src() const { return (_flags & ArraycopySrc) != 0; }
203 void set_arraycopy_src() { _flags |= ArraycopySrc; }
204 bool arraycopy_dst() const { return (_flags & ArraycopyDst) != 0; }
205 void set_arraycopy_dst() { _flags |= ArraycopyDst; }
206
207 bool scalar_replaceable() const { return (_flags & ScalarReplaceable) != 0;}
208 void set_scalar_replaceable(bool v) {
209 if (v)
210 _flags |= ScalarReplaceable;
211 else
212 _flags &= ~ScalarReplaceable;
213 }
214
215 int edge_count() const { return _edges.length(); }
216 PointsToNode* edge(int e) const { return _edges.at(e); }
217 bool add_edge(PointsToNode* edge) { return _edges.append_if_missing(edge); }
218
219 int use_count() const { return _uses.length(); }
220 PointsToNode* use(int e) const { return _uses.at(e); }
221 bool add_use(PointsToNode* use) { return _uses.append_if_missing(use); }
222
223 // Mark base edge use to distinguish from stored value edge.
224 bool add_base_use(FieldNode* use) { return _uses.append_if_missing((PointsToNode*)((intptr_t)use + 1)); }
225 static bool is_base_use(PointsToNode* use) { return (((intptr_t)use) & 1); }
226 static PointsToNode* get_use_node(PointsToNode* use) { return (PointsToNode*)(((intptr_t)use) & ~1); }
227
228 // Return true if this node points to specified node or nodes it points to.
229 bool points_to(JavaObjectNode* ptn) const;
230
231 // Return true if this node points only to non-escaping allocations.
232 bool non_escaping_allocation();
233
234 // Return true if one node points to an other.
235 bool meet(PointsToNode* ptn);
236
237 #ifndef PRODUCT
238 NodeType node_type() const { return (NodeType)_type;}
239 void dump(bool print_state=true) const;
240 #endif
241
242 };
243
244 class LocalVarNode: public PointsToNode {
245 public:
246 LocalVarNode(Compile *C, Node* n, EscapeState es):
247 PointsToNode(C, n, es, LocalVar) {}
248 };
249
250 class JavaObjectNode: public PointsToNode {
251 public:
252 JavaObjectNode(Compile *C, Node* n, EscapeState es):
253 PointsToNode(C, n, es, JavaObject) {
254 if (es > NoEscape)
255 set_scalar_replaceable(false);
256 }
257 };
258
259 class FieldNode: public PointsToNode {
260 GrowableArray<PointsToNode*> _bases; // List of JavaObject nodes which point to this node
261 const int _offset; // Field's offset.
262 const bool _is_oop; // Field points to object
263 bool _has_unknown_base; // Has phantom_object base
264 public:
265 FieldNode(Compile *C, Node* n, EscapeState es, int offs, bool is_oop):
266 PointsToNode(C, n, es, Field),
267 _offset(offs), _is_oop(is_oop),
268 _has_unknown_base(false) {}
269
270 int offset() const { return _offset;}
271 bool is_oop() const { return _is_oop;}
272 bool has_unknown_base() const { return _has_unknown_base; }
273 void set_has_unknown_base() { _has_unknown_base = true; }
274
275 int base_count() const { return _bases.length(); }
276 PointsToNode* base(int e) const { return _bases.at(e); }
277 bool add_base(PointsToNode* base) { return _bases.append_if_missing(base); }
278 #ifdef ASSERT
279 // Return true if bases points to this java object.
280 bool has_base(JavaObjectNode* ptn) const;
281 #endif
282
283 };
284
285 class ArraycopyNode: public PointsToNode {
286 public:
287 ArraycopyNode(Compile *C, Node* n, EscapeState es):
288 PointsToNode(C, n, es, Arraycopy) {}
289 };
290
291 // Iterators for PointsTo node's edges:
292 // for (EdgeIterator i(n); i.has_next(); i.next()) {
293 // PointsToNode* u = i.get();
294 class PointsToIterator: public StackObj {
295 protected:
296 const PointsToNode* node;
297 const int cnt;
298 int i;
299 public:
300 inline PointsToIterator(const PointsToNode* n, int cnt) : node(n), cnt(cnt), i(0) { }
301 inline bool has_next() const { return i < cnt; }
302 inline void next() { i++; }
303 PointsToNode* get() const { ShouldNotCallThis(); return NULL; }
304 };
305
306 class EdgeIterator: public PointsToIterator {
307 public:
308 inline EdgeIterator(const PointsToNode* n) : PointsToIterator(n, n->edge_count()) { }
309 inline PointsToNode* get() const { return node->edge(i); }
310 };
311
312 class UseIterator: public PointsToIterator {
313 public:
314 inline UseIterator(const PointsToNode* n) : PointsToIterator(n, n->use_count()) { }
315 inline PointsToNode* get() const { return node->use(i); }
316 };
317
318 class BaseIterator: public PointsToIterator {
319 public:
320 inline BaseIterator(const FieldNode* n) : PointsToIterator(n, n->base_count()) { }
329
330 GrowableArray<PointsToNode*> _worklist; // Nodes to be processed
331
332 bool _collecting; // Indicates whether escape information
333 // is still being collected. If false,
334 // no new nodes will be processed.
335
336 bool _verify; // verify graph
337
338 JavaObjectNode* phantom_obj; // Unknown object
339 JavaObjectNode* null_obj;
340 Node* _pcmp_neq; // ConI(#CC_GT)
341 Node* _pcmp_eq; // ConI(#CC_EQ)
342
343 Compile* _compile; // Compile object for current compilation
344 PhaseIterGVN* _igvn; // Value numbering
345
346 Unique_Node_List ideal_nodes; // Used by CG construction and types splitting.
347
348 // Address of an element in _nodes. Used when the element is to be modified
349 PointsToNode* ptnode_adr(int idx) const {
350 // There should be no new ideal nodes during ConnectionGraph build,
351 // growableArray::at() will throw assert otherwise.
352 return _nodes.at(idx);
353 }
354 uint nodes_size() const { return _nodes.length(); }
355
356 // Add nodes to ConnectionGraph.
357 void add_local_var(Node* n, PointsToNode::EscapeState es);
358 void add_java_object(Node* n, PointsToNode::EscapeState es);
359 void add_field(Node* n, PointsToNode::EscapeState es, int offset);
360 void add_arraycopy(Node* n, PointsToNode::EscapeState es, PointsToNode* src, PointsToNode* dst);
361
362 // Compute the escape state for arguments to a call.
363 void process_call_arguments(CallNode *call);
364
365 // Add PointsToNode node corresponding to a call
366 void add_call_node(CallNode* call);
367
368 // Map ideal node to existing PointsTo node (usually phantom_object).
369 void map_ideal_node(Node *n, PointsToNode* ptn) {
370 assert(ptn != NULL, "only existing PointsTo node");
371 _nodes.at_put(n->_idx, ptn);
372 }
373
374 // Create PointsToNode node and add it to Connection Graph.
375 void add_node_to_connection_graph(Node *n, Unique_Node_List *delayed_worklist);
376
377 // Add final simple edges to graph.
378 void add_final_edges(Node *n);
379
380 // Finish Graph construction.
381 bool complete_connection_graph(GrowableArray<PointsToNode*>& ptnodes_worklist,
382 GrowableArray<JavaObjectNode*>& non_escaped_worklist,
383 GrowableArray<JavaObjectNode*>& java_objects_worklist,
419
420 // Set the escape state of an object and its fields.
421 void set_escape_state(PointsToNode* ptn, PointsToNode::EscapeState esc) {
422 // Don't change non-escaping state of NULL pointer.
423 if (ptn != null_obj) {
424 if (ptn->escape_state() < esc)
425 ptn->set_escape_state(esc);
426 if (ptn->fields_escape_state() < esc)
427 ptn->set_fields_escape_state(esc);
428 }
429 }
430 void set_fields_escape_state(PointsToNode* ptn, PointsToNode::EscapeState esc) {
431 // Don't change non-escaping state of NULL pointer.
432 if (ptn != null_obj) {
433 if (ptn->fields_escape_state() < esc)
434 ptn->set_fields_escape_state(esc);
435 }
436 }
437
438 // Propagate GlobalEscape and ArgEscape escape states to all nodes
439 // and check that we still have non-escaping java objects.
440 bool find_non_escaped_objects(GrowableArray<PointsToNode*>& ptnodes_worklist,
441 GrowableArray<JavaObjectNode*>& non_escaped_worklist);
442
443 // Adjust scalar_replaceable state after Connection Graph is built.
444 void adjust_scalar_replaceable_state(JavaObjectNode* jobj);
445
446 // Optimize ideal graph.
447 void optimize_ideal_graph(GrowableArray<Node*>& ptr_cmp_worklist,
448 GrowableArray<Node*>& storestore_worklist);
449 // Optimize objects compare.
450 Node* optimize_ptr_compare(Node* n);
451
452 // Returns unique corresponding java object or NULL.
453 JavaObjectNode* unique_java_object(Node *n);
454
455 // Add an edge of the specified type pointing to the specified target.
456 bool add_edge(PointsToNode* from, PointsToNode* to) {
457 assert(!from->is_Field() || from->as_Field()->is_oop(), "sanity");
458
459 if (to == phantom_obj) {
511 } else {
512 assert(ptn != NULL, "node should be registered");
513 }
514 add_edge(ptnode_adr(n->_idx), ptn);
515 }
516
517 // Helper functions
518 bool is_oop_field(Node* n, int offset);
519 static Node* get_addp_base(Node *addp);
520 static Node* find_second_addp(Node* addp, Node* n);
521
522 // offset of a field reference
523 int address_offset(Node* adr, PhaseTransform *phase);
524
525
526 // Propagate unique types created for unescaped allocated objects
527 // through the graph
528 void split_unique_types(GrowableArray<Node *> &alloc_worklist);
529
530 // Helper methods for unique types split.
531 bool split_AddP(Node *addp, Node *base);
532
533 PhiNode *create_split_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, bool &new_created);
534 PhiNode *split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist);
535
536 void move_inst_mem(Node* n, GrowableArray<PhiNode *> &orig_phis);
537 Node* find_inst_mem(Node* mem, int alias_idx,GrowableArray<PhiNode *> &orig_phi_worklist);
538 Node* step_through_mergemem(MergeMemNode *mmem, int alias_idx, const TypeOopPtr *toop);
539
540
541 GrowableArray<MergeMemNode*> _mergemem_worklist; // List of all MergeMem nodes
542
543 Node_Array _node_map; // used for bookeeping during type splitting
544 // Used for the following purposes:
545 // Memory Phi - most recent unique Phi split out
546 // from this Phi
547 // MemNode - new memory input for this node
548 // ChecCastPP - allocation that this is a cast of
549 // allocation - CheckCastPP of the allocation
550
551 // manage entries in _node_map
552
553 void set_map(Node* from, Node* to) {
554 ideal_nodes.push(from);
555 _node_map.map(from->_idx, to);
556 }
557
|