Mercurial > hg > truffle
annotate src/share/vm/opto/callnode.cpp @ 247:02a35ad4adf8
6723160: Nightly failure: Error: meet not symmetric
Summary: Add missing _instance_id settings and other EA fixes.
Reviewed-by: rasbold
author | kvn |
---|---|
date | Wed, 16 Jul 2008 16:04:39 -0700 |
parents | 9c2ecc2ffb12 |
children | ab075d07f1ba |
rev | line source |
---|---|
0 | 1 /* |
196 | 2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. |
0 | 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 */ | |
24 | |
25 // Portions of code courtesy of Clifford Click | |
26 | |
27 // Optimization - Graph Style | |
28 | |
29 #include "incls/_precompiled.incl" | |
30 #include "incls/_callnode.cpp.incl" | |
31 | |
32 //============================================================================= | |
33 uint StartNode::size_of() const { return sizeof(*this); } | |
34 uint StartNode::cmp( const Node &n ) const | |
35 { return _domain == ((StartNode&)n)._domain; } | |
36 const Type *StartNode::bottom_type() const { return _domain; } | |
37 const Type *StartNode::Value(PhaseTransform *phase) const { return _domain; } | |
38 #ifndef PRODUCT | |
39 void StartNode::dump_spec(outputStream *st) const { st->print(" #"); _domain->dump_on(st);} | |
40 #endif | |
41 | |
42 //------------------------------Ideal------------------------------------------ | |
43 Node *StartNode::Ideal(PhaseGVN *phase, bool can_reshape){ | |
44 return remove_dead_region(phase, can_reshape) ? this : NULL; | |
45 } | |
46 | |
47 //------------------------------calling_convention----------------------------- | |
48 void StartNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const { | |
49 Matcher::calling_convention( sig_bt, parm_regs, argcnt, false ); | |
50 } | |
51 | |
52 //------------------------------Registers-------------------------------------- | |
53 const RegMask &StartNode::in_RegMask(uint) const { | |
54 return RegMask::Empty; | |
55 } | |
56 | |
57 //------------------------------match------------------------------------------ | |
58 // Construct projections for incoming parameters, and their RegMask info | |
59 Node *StartNode::match( const ProjNode *proj, const Matcher *match ) { | |
60 switch (proj->_con) { | |
61 case TypeFunc::Control: | |
62 case TypeFunc::I_O: | |
63 case TypeFunc::Memory: | |
64 return new (match->C, 1) MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj); | |
65 case TypeFunc::FramePtr: | |
66 return new (match->C, 1) MachProjNode(this,proj->_con,Matcher::c_frame_ptr_mask, Op_RegP); | |
67 case TypeFunc::ReturnAdr: | |
68 return new (match->C, 1) MachProjNode(this,proj->_con,match->_return_addr_mask,Op_RegP); | |
69 case TypeFunc::Parms: | |
70 default: { | |
71 uint parm_num = proj->_con - TypeFunc::Parms; | |
72 const Type *t = _domain->field_at(proj->_con); | |
73 if (t->base() == Type::Half) // 2nd half of Longs and Doubles | |
74 return new (match->C, 1) ConNode(Type::TOP); | |
75 uint ideal_reg = Matcher::base2reg[t->base()]; | |
76 RegMask &rm = match->_calling_convention_mask[parm_num]; | |
77 return new (match->C, 1) MachProjNode(this,proj->_con,rm,ideal_reg); | |
78 } | |
79 } | |
80 return NULL; | |
81 } | |
82 | |
83 //------------------------------StartOSRNode---------------------------------- | |
84 // The method start node for an on stack replacement adapter | |
85 | |
86 //------------------------------osr_domain----------------------------- | |
87 const TypeTuple *StartOSRNode::osr_domain() { | |
88 const Type **fields = TypeTuple::fields(2); | |
89 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // address of osr buffer | |
90 | |
91 return TypeTuple::make(TypeFunc::Parms+1, fields); | |
92 } | |
93 | |
94 //============================================================================= | |
95 const char * const ParmNode::names[TypeFunc::Parms+1] = { | |
96 "Control", "I_O", "Memory", "FramePtr", "ReturnAdr", "Parms" | |
97 }; | |
98 | |
99 #ifndef PRODUCT | |
100 void ParmNode::dump_spec(outputStream *st) const { | |
101 if( _con < TypeFunc::Parms ) { | |
102 st->print(names[_con]); | |
103 } else { | |
104 st->print("Parm%d: ",_con-TypeFunc::Parms); | |
105 // Verbose and WizardMode dump bottom_type for all nodes | |
106 if( !Verbose && !WizardMode ) bottom_type()->dump_on(st); | |
107 } | |
108 } | |
109 #endif | |
110 | |
111 uint ParmNode::ideal_reg() const { | |
112 switch( _con ) { | |
113 case TypeFunc::Control : // fall through | |
114 case TypeFunc::I_O : // fall through | |
115 case TypeFunc::Memory : return 0; | |
116 case TypeFunc::FramePtr : // fall through | |
117 case TypeFunc::ReturnAdr: return Op_RegP; | |
118 default : assert( _con > TypeFunc::Parms, "" ); | |
119 // fall through | |
120 case TypeFunc::Parms : { | |
121 // Type of argument being passed | |
122 const Type *t = in(0)->as_Start()->_domain->field_at(_con); | |
123 return Matcher::base2reg[t->base()]; | |
124 } | |
125 } | |
126 ShouldNotReachHere(); | |
127 return 0; | |
128 } | |
129 | |
130 //============================================================================= | |
131 ReturnNode::ReturnNode(uint edges, Node *cntrl, Node *i_o, Node *memory, Node *frameptr, Node *retadr ) : Node(edges) { | |
132 init_req(TypeFunc::Control,cntrl); | |
133 init_req(TypeFunc::I_O,i_o); | |
134 init_req(TypeFunc::Memory,memory); | |
135 init_req(TypeFunc::FramePtr,frameptr); | |
136 init_req(TypeFunc::ReturnAdr,retadr); | |
137 } | |
138 | |
139 Node *ReturnNode::Ideal(PhaseGVN *phase, bool can_reshape){ | |
140 return remove_dead_region(phase, can_reshape) ? this : NULL; | |
141 } | |
142 | |
143 const Type *ReturnNode::Value( PhaseTransform *phase ) const { | |
144 return ( phase->type(in(TypeFunc::Control)) == Type::TOP) | |
145 ? Type::TOP | |
146 : Type::BOTTOM; | |
147 } | |
148 | |
149 // Do we Match on this edge index or not? No edges on return nodes | |
150 uint ReturnNode::match_edge(uint idx) const { | |
151 return 0; | |
152 } | |
153 | |
154 | |
155 #ifndef PRODUCT | |
156 void ReturnNode::dump_req() const { | |
157 // Dump the required inputs, enclosed in '(' and ')' | |
158 uint i; // Exit value of loop | |
159 for( i=0; i<req(); i++ ) { // For all required inputs | |
160 if( i == TypeFunc::Parms ) tty->print("returns"); | |
161 if( in(i) ) tty->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx); | |
162 else tty->print("_ "); | |
163 } | |
164 } | |
165 #endif | |
166 | |
167 //============================================================================= | |
168 RethrowNode::RethrowNode( | |
169 Node* cntrl, | |
170 Node* i_o, | |
171 Node* memory, | |
172 Node* frameptr, | |
173 Node* ret_adr, | |
174 Node* exception | |
175 ) : Node(TypeFunc::Parms + 1) { | |
176 init_req(TypeFunc::Control , cntrl ); | |
177 init_req(TypeFunc::I_O , i_o ); | |
178 init_req(TypeFunc::Memory , memory ); | |
179 init_req(TypeFunc::FramePtr , frameptr ); | |
180 init_req(TypeFunc::ReturnAdr, ret_adr); | |
181 init_req(TypeFunc::Parms , exception); | |
182 } | |
183 | |
184 Node *RethrowNode::Ideal(PhaseGVN *phase, bool can_reshape){ | |
185 return remove_dead_region(phase, can_reshape) ? this : NULL; | |
186 } | |
187 | |
188 const Type *RethrowNode::Value( PhaseTransform *phase ) const { | |
189 return (phase->type(in(TypeFunc::Control)) == Type::TOP) | |
190 ? Type::TOP | |
191 : Type::BOTTOM; | |
192 } | |
193 | |
194 uint RethrowNode::match_edge(uint idx) const { | |
195 return 0; | |
196 } | |
197 | |
198 #ifndef PRODUCT | |
199 void RethrowNode::dump_req() const { | |
200 // Dump the required inputs, enclosed in '(' and ')' | |
201 uint i; // Exit value of loop | |
202 for( i=0; i<req(); i++ ) { // For all required inputs | |
203 if( i == TypeFunc::Parms ) tty->print("exception"); | |
204 if( in(i) ) tty->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx); | |
205 else tty->print("_ "); | |
206 } | |
207 } | |
208 #endif | |
209 | |
210 //============================================================================= | |
211 // Do we Match on this edge index or not? Match only target address & method | |
212 uint TailCallNode::match_edge(uint idx) const { | |
213 return TypeFunc::Parms <= idx && idx <= TypeFunc::Parms+1; | |
214 } | |
215 | |
216 //============================================================================= | |
217 // Do we Match on this edge index or not? Match only target address & oop | |
218 uint TailJumpNode::match_edge(uint idx) const { | |
219 return TypeFunc::Parms <= idx && idx <= TypeFunc::Parms+1; | |
220 } | |
221 | |
222 //============================================================================= | |
223 JVMState::JVMState(ciMethod* method, JVMState* caller) { | |
224 assert(method != NULL, "must be valid call site"); | |
225 _method = method; | |
226 debug_only(_bci = -99); // random garbage value | |
227 debug_only(_map = (SafePointNode*)-1); | |
228 _caller = caller; | |
229 _depth = 1 + (caller == NULL ? 0 : caller->depth()); | |
230 _locoff = TypeFunc::Parms; | |
231 _stkoff = _locoff + _method->max_locals(); | |
232 _monoff = _stkoff + _method->max_stack(); | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
233 _scloff = _monoff; |
0 | 234 _endoff = _monoff; |
235 _sp = 0; | |
236 } | |
237 JVMState::JVMState(int stack_size) { | |
238 _method = NULL; | |
239 _bci = InvocationEntryBci; | |
240 debug_only(_map = (SafePointNode*)-1); | |
241 _caller = NULL; | |
242 _depth = 1; | |
243 _locoff = TypeFunc::Parms; | |
244 _stkoff = _locoff; | |
245 _monoff = _stkoff + stack_size; | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
246 _scloff = _monoff; |
0 | 247 _endoff = _monoff; |
248 _sp = 0; | |
249 } | |
250 | |
251 //--------------------------------of_depth------------------------------------- | |
252 JVMState* JVMState::of_depth(int d) const { | |
253 const JVMState* jvmp = this; | |
254 assert(0 < d && (uint)d <= depth(), "oob"); | |
255 for (int skip = depth() - d; skip > 0; skip--) { | |
256 jvmp = jvmp->caller(); | |
257 } | |
258 assert(jvmp->depth() == (uint)d, "found the right one"); | |
259 return (JVMState*)jvmp; | |
260 } | |
261 | |
262 //-----------------------------same_calls_as----------------------------------- | |
263 bool JVMState::same_calls_as(const JVMState* that) const { | |
264 if (this == that) return true; | |
265 if (this->depth() != that->depth()) return false; | |
266 const JVMState* p = this; | |
267 const JVMState* q = that; | |
268 for (;;) { | |
269 if (p->_method != q->_method) return false; | |
270 if (p->_method == NULL) return true; // bci is irrelevant | |
271 if (p->_bci != q->_bci) return false; | |
272 p = p->caller(); | |
273 q = q->caller(); | |
274 if (p == q) return true; | |
275 assert(p != NULL && q != NULL, "depth check ensures we don't run off end"); | |
276 } | |
277 } | |
278 | |
279 //------------------------------debug_start------------------------------------ | |
280 uint JVMState::debug_start() const { | |
281 debug_only(JVMState* jvmroot = of_depth(1)); | |
282 assert(jvmroot->locoff() <= this->locoff(), "youngest JVMState must be last"); | |
283 return of_depth(1)->locoff(); | |
284 } | |
285 | |
286 //-------------------------------debug_end------------------------------------- | |
287 uint JVMState::debug_end() const { | |
288 debug_only(JVMState* jvmroot = of_depth(1)); | |
289 assert(jvmroot->endoff() <= this->endoff(), "youngest JVMState must be last"); | |
290 return endoff(); | |
291 } | |
292 | |
293 //------------------------------debug_depth------------------------------------ | |
294 uint JVMState::debug_depth() const { | |
295 uint total = 0; | |
296 for (const JVMState* jvmp = this; jvmp != NULL; jvmp = jvmp->caller()) { | |
297 total += jvmp->debug_size(); | |
298 } | |
299 return total; | |
300 } | |
301 | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
302 #ifndef PRODUCT |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
303 |
0 | 304 //------------------------------format_helper---------------------------------- |
305 // Given an allocation (a Chaitin object) and a Node decide if the Node carries | |
306 // any defined value or not. If it does, print out the register or constant. | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
307 static void format_helper( PhaseRegAlloc *regalloc, outputStream* st, Node *n, const char *msg, uint i, GrowableArray<SafePointScalarObjectNode*> *scobjs ) { |
0 | 308 if (n == NULL) { st->print(" NULL"); return; } |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
309 if (n->is_SafePointScalarObject()) { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
310 // Scalar replacement. |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
311 SafePointScalarObjectNode* spobj = n->as_SafePointScalarObject(); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
312 scobjs->append_if_missing(spobj); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
313 int sco_n = scobjs->find(spobj); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
314 assert(sco_n >= 0, ""); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
315 st->print(" %s%d]=#ScObj" INT32_FORMAT, msg, i, sco_n); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
316 return; |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
317 } |
0 | 318 if( OptoReg::is_valid(regalloc->get_reg_first(n))) { // Check for undefined |
319 char buf[50]; | |
320 regalloc->dump_register(n,buf); | |
321 st->print(" %s%d]=%s",msg,i,buf); | |
322 } else { // No register, but might be constant | |
323 const Type *t = n->bottom_type(); | |
324 switch (t->base()) { | |
325 case Type::Int: | |
326 st->print(" %s%d]=#"INT32_FORMAT,msg,i,t->is_int()->get_con()); | |
327 break; | |
328 case Type::AnyPtr: | |
329 assert( t == TypePtr::NULL_PTR, "" ); | |
330 st->print(" %s%d]=#NULL",msg,i); | |
331 break; | |
332 case Type::AryPtr: | |
333 case Type::KlassPtr: | |
334 case Type::InstPtr: | |
335 st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,t->isa_oopptr()->const_oop()); | |
336 break; | |
337 case Type::RawPtr: | |
338 st->print(" %s%d]=#Raw" INTPTR_FORMAT,msg,i,t->is_rawptr()); | |
339 break; | |
340 case Type::DoubleCon: | |
341 st->print(" %s%d]=#%fD",msg,i,t->is_double_constant()->_d); | |
342 break; | |
343 case Type::FloatCon: | |
344 st->print(" %s%d]=#%fF",msg,i,t->is_float_constant()->_f); | |
345 break; | |
346 case Type::Long: | |
347 st->print(" %s%d]=#"INT64_FORMAT,msg,i,t->is_long()->get_con()); | |
348 break; | |
349 case Type::Half: | |
350 case Type::Top: | |
351 st->print(" %s%d]=_",msg,i); | |
352 break; | |
353 default: ShouldNotReachHere(); | |
354 } | |
355 } | |
356 } | |
357 | |
358 //------------------------------format----------------------------------------- | |
359 void JVMState::format(PhaseRegAlloc *regalloc, const Node *n, outputStream* st) const { | |
360 st->print(" #"); | |
361 if( _method ) { | |
362 _method->print_short_name(st); | |
363 st->print(" @ bci:%d ",_bci); | |
364 } else { | |
365 st->print_cr(" runtime stub "); | |
366 return; | |
367 } | |
368 if (n->is_MachSafePoint()) { | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
369 GrowableArray<SafePointScalarObjectNode*> scobjs; |
0 | 370 MachSafePointNode *mcall = n->as_MachSafePoint(); |
371 uint i; | |
372 // Print locals | |
373 for( i = 0; i < (uint)loc_size(); i++ ) | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
374 format_helper( regalloc, st, mcall->local(this, i), "L[", i, &scobjs ); |
0 | 375 // Print stack |
376 for (i = 0; i < (uint)stk_size(); i++) { | |
377 if ((uint)(_stkoff + i) >= mcall->len()) | |
378 st->print(" oob "); | |
379 else | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
380 format_helper( regalloc, st, mcall->stack(this, i), "STK[", i, &scobjs ); |
0 | 381 } |
382 for (i = 0; (int)i < nof_monitors(); i++) { | |
383 Node *box = mcall->monitor_box(this, i); | |
384 Node *obj = mcall->monitor_obj(this, i); | |
385 if ( OptoReg::is_valid(regalloc->get_reg_first(box)) ) { | |
386 while( !box->is_BoxLock() ) box = box->in(1); | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
387 format_helper( regalloc, st, box, "MON-BOX[", i, &scobjs ); |
0 | 388 } else { |
389 OptoReg::Name box_reg = BoxLockNode::stack_slot(box); | |
390 st->print(" MON-BOX%d=%s+%d", | |
391 i, | |
392 OptoReg::regname(OptoReg::c_frame_pointer), | |
393 regalloc->reg2offset(box_reg)); | |
394 } | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
395 format_helper( regalloc, st, obj, "MON-OBJ[", i, &scobjs ); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
396 } |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
397 |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
398 for (i = 0; i < (uint)scobjs.length(); i++) { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
399 // Scalar replaced objects. |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
400 st->print_cr(""); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
401 st->print(" # ScObj" INT32_FORMAT " ", i); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
402 SafePointScalarObjectNode* spobj = scobjs.at(i); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
403 ciKlass* cik = spobj->bottom_type()->is_oopptr()->klass(); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
404 assert(cik->is_instance_klass() || |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
405 cik->is_array_klass(), "Not supported allocation."); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
406 ciInstanceKlass *iklass = NULL; |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
407 if (cik->is_instance_klass()) { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
408 cik->print_name_on(st); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
409 iklass = cik->as_instance_klass(); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
410 } else if (cik->is_type_array_klass()) { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
411 cik->as_array_klass()->base_element_type()->print_name_on(st); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
412 st->print("[%d]=", spobj->n_fields()); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
413 } else if (cik->is_obj_array_klass()) { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
414 ciType* cie = cik->as_array_klass()->base_element_type(); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
415 int ndim = 1; |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
416 while (cie->is_obj_array_klass()) { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
417 ndim += 1; |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
418 cie = cie->as_array_klass()->base_element_type(); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
419 } |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
420 cie->print_name_on(st); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
421 while (ndim-- > 0) { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
422 st->print("[]"); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
423 } |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
424 st->print("[%d]=", spobj->n_fields()); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
425 } |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
426 st->print("{"); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
427 uint nf = spobj->n_fields(); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
428 if (nf > 0) { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
429 uint first_ind = spobj->first_index(); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
430 Node* fld_node = mcall->in(first_ind); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
431 ciField* cifield; |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
432 if (iklass != NULL) { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
433 st->print(" ["); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
434 cifield = iklass->nonstatic_field_at(0); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
435 cifield->print_name_on(st); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
436 format_helper( regalloc, st, fld_node, ":", 0, &scobjs ); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
437 } else { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
438 format_helper( regalloc, st, fld_node, "[", 0, &scobjs ); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
439 } |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
440 for (uint j = 1; j < nf; j++) { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
441 fld_node = mcall->in(first_ind+j); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
442 if (iklass != NULL) { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
443 st->print(", ["); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
444 cifield = iklass->nonstatic_field_at(j); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
445 cifield->print_name_on(st); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
446 format_helper( regalloc, st, fld_node, ":", j, &scobjs ); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
447 } else { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
448 format_helper( regalloc, st, fld_node, ", [", j, &scobjs ); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
449 } |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
450 } |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
451 } |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
452 st->print(" }"); |
0 | 453 } |
454 } | |
455 st->print_cr(""); | |
456 if (caller() != NULL) caller()->format(regalloc, n, st); | |
457 } | |
458 | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
459 |
0 | 460 void JVMState::dump_spec(outputStream *st) const { |
461 if (_method != NULL) { | |
462 bool printed = false; | |
463 if (!Verbose) { | |
464 // The JVMS dumps make really, really long lines. | |
465 // Take out the most boring parts, which are the package prefixes. | |
466 char buf[500]; | |
467 stringStream namest(buf, sizeof(buf)); | |
468 _method->print_short_name(&namest); | |
469 if (namest.count() < sizeof(buf)) { | |
470 const char* name = namest.base(); | |
471 if (name[0] == ' ') ++name; | |
472 const char* endcn = strchr(name, ':'); // end of class name | |
473 if (endcn == NULL) endcn = strchr(name, '('); | |
474 if (endcn == NULL) endcn = name + strlen(name); | |
475 while (endcn > name && endcn[-1] != '.' && endcn[-1] != '/') | |
476 --endcn; | |
477 st->print(" %s", endcn); | |
478 printed = true; | |
479 } | |
480 } | |
481 if (!printed) | |
482 _method->print_short_name(st); | |
483 st->print(" @ bci:%d",_bci); | |
484 } else { | |
485 st->print(" runtime stub"); | |
486 } | |
487 if (caller() != NULL) caller()->dump_spec(st); | |
488 } | |
489 | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
490 |
0 | 491 void JVMState::dump_on(outputStream* st) const { |
492 if (_map && !((uintptr_t)_map & 1)) { | |
493 if (_map->len() > _map->req()) { // _map->has_exceptions() | |
494 Node* ex = _map->in(_map->req()); // _map->next_exception() | |
495 // skip the first one; it's already being printed | |
496 while (ex != NULL && ex->len() > ex->req()) { | |
497 ex = ex->in(ex->req()); // ex->next_exception() | |
498 ex->dump(1); | |
499 } | |
500 } | |
501 _map->dump(2); | |
502 } | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
503 st->print("JVMS depth=%d loc=%d stk=%d mon=%d scalar=%d end=%d mondepth=%d sp=%d bci=%d method=", |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
504 depth(), locoff(), stkoff(), monoff(), scloff(), endoff(), monitor_depth(), sp(), bci()); |
0 | 505 if (_method == NULL) { |
506 st->print_cr("(none)"); | |
507 } else { | |
508 _method->print_name(st); | |
509 st->cr(); | |
510 if (bci() >= 0 && bci() < _method->code_size()) { | |
511 st->print(" bc: "); | |
512 _method->print_codes_on(bci(), bci()+1, st); | |
513 } | |
514 } | |
515 if (caller() != NULL) { | |
516 caller()->dump_on(st); | |
517 } | |
518 } | |
519 | |
520 // Extra way to dump a jvms from the debugger, | |
521 // to avoid a bug with C++ member function calls. | |
522 void dump_jvms(JVMState* jvms) { | |
523 jvms->dump(); | |
524 } | |
525 #endif | |
526 | |
527 //--------------------------clone_shallow-------------------------------------- | |
528 JVMState* JVMState::clone_shallow(Compile* C) const { | |
529 JVMState* n = has_method() ? new (C) JVMState(_method, _caller) : new (C) JVMState(0); | |
530 n->set_bci(_bci); | |
531 n->set_locoff(_locoff); | |
532 n->set_stkoff(_stkoff); | |
533 n->set_monoff(_monoff); | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
534 n->set_scloff(_scloff); |
0 | 535 n->set_endoff(_endoff); |
536 n->set_sp(_sp); | |
537 n->set_map(_map); | |
538 return n; | |
539 } | |
540 | |
541 //---------------------------clone_deep---------------------------------------- | |
542 JVMState* JVMState::clone_deep(Compile* C) const { | |
543 JVMState* n = clone_shallow(C); | |
544 for (JVMState* p = n; p->_caller != NULL; p = p->_caller) { | |
545 p->_caller = p->_caller->clone_shallow(C); | |
546 } | |
547 assert(n->depth() == depth(), "sanity"); | |
548 assert(n->debug_depth() == debug_depth(), "sanity"); | |
549 return n; | |
550 } | |
551 | |
552 //============================================================================= | |
553 uint CallNode::cmp( const Node &n ) const | |
554 { return _tf == ((CallNode&)n)._tf && _jvms == ((CallNode&)n)._jvms; } | |
555 #ifndef PRODUCT | |
556 void CallNode::dump_req() const { | |
557 // Dump the required inputs, enclosed in '(' and ')' | |
558 uint i; // Exit value of loop | |
559 for( i=0; i<req(); i++ ) { // For all required inputs | |
560 if( i == TypeFunc::Parms ) tty->print("("); | |
561 if( in(i) ) tty->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx); | |
562 else tty->print("_ "); | |
563 } | |
564 tty->print(")"); | |
565 } | |
566 | |
567 void CallNode::dump_spec(outputStream *st) const { | |
568 st->print(" "); | |
569 tf()->dump_on(st); | |
570 if (_cnt != COUNT_UNKNOWN) st->print(" C=%f",_cnt); | |
571 if (jvms() != NULL) jvms()->dump_spec(st); | |
572 } | |
573 #endif | |
574 | |
575 const Type *CallNode::bottom_type() const { return tf()->range(); } | |
576 const Type *CallNode::Value(PhaseTransform *phase) const { | |
577 if (phase->type(in(0)) == Type::TOP) return Type::TOP; | |
578 return tf()->range(); | |
579 } | |
580 | |
581 //------------------------------calling_convention----------------------------- | |
582 void CallNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const { | |
583 // Use the standard compiler calling convention | |
584 Matcher::calling_convention( sig_bt, parm_regs, argcnt, true ); | |
585 } | |
586 | |
587 | |
588 //------------------------------match------------------------------------------ | |
589 // Construct projections for control, I/O, memory-fields, ..., and | |
590 // return result(s) along with their RegMask info | |
591 Node *CallNode::match( const ProjNode *proj, const Matcher *match ) { | |
592 switch (proj->_con) { | |
593 case TypeFunc::Control: | |
594 case TypeFunc::I_O: | |
595 case TypeFunc::Memory: | |
596 return new (match->C, 1) MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj); | |
597 | |
598 case TypeFunc::Parms+1: // For LONG & DOUBLE returns | |
599 assert(tf()->_range->field_at(TypeFunc::Parms+1) == Type::HALF, ""); | |
600 // 2nd half of doubles and longs | |
601 return new (match->C, 1) MachProjNode(this,proj->_con, RegMask::Empty, (uint)OptoReg::Bad); | |
602 | |
603 case TypeFunc::Parms: { // Normal returns | |
604 uint ideal_reg = Matcher::base2reg[tf()->range()->field_at(TypeFunc::Parms)->base()]; | |
605 OptoRegPair regs = is_CallRuntime() | |
606 ? match->c_return_value(ideal_reg,true) // Calls into C runtime | |
607 : match-> return_value(ideal_reg,true); // Calls into compiled Java code | |
608 RegMask rm = RegMask(regs.first()); | |
609 if( OptoReg::is_valid(regs.second()) ) | |
610 rm.Insert( regs.second() ); | |
611 return new (match->C, 1) MachProjNode(this,proj->_con,rm,ideal_reg); | |
612 } | |
613 | |
614 case TypeFunc::ReturnAdr: | |
615 case TypeFunc::FramePtr: | |
616 default: | |
617 ShouldNotReachHere(); | |
618 } | |
619 return NULL; | |
620 } | |
621 | |
622 // Do we Match on this edge index or not? Match no edges | |
623 uint CallNode::match_edge(uint idx) const { | |
624 return 0; | |
625 } | |
626 | |
65 | 627 // |
74
2a9af0b9cb1c
6674600: (Escape Analysis) Optimize memory graph for instance's fields
kvn
parents:
66
diff
changeset
|
628 // Determine whether the call could modify the field of the specified |
2a9af0b9cb1c
6674600: (Escape Analysis) Optimize memory graph for instance's fields
kvn
parents:
66
diff
changeset
|
629 // instance at the specified offset. |
65 | 630 // |
631 bool CallNode::may_modify(const TypePtr *addr_t, PhaseTransform *phase) { | |
632 const TypeOopPtr *adrInst_t = addr_t->isa_oopptr(); | |
633 | |
247 | 634 // If not an OopPtr or not an instance type, assume the worst. |
635 // Note: currently this method is called only for instance types. | |
636 if (adrInst_t == NULL || !adrInst_t->is_known_instance()) { | |
65 | 637 return true; |
638 } | |
247 | 639 // The instance_id is set only for scalar-replaceable allocations which |
640 // are not passed as arguments according to Escape Analysis. | |
65 | 641 return false; |
642 } | |
643 | |
644 // Does this call have a direct reference to n other than debug information? | |
645 bool CallNode::has_non_debug_use(Node *n) { | |
646 const TypeTuple * d = tf()->domain(); | |
647 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) { | |
648 Node *arg = in(i); | |
649 if (arg == n) { | |
650 return true; | |
651 } | |
652 } | |
653 return false; | |
654 } | |
655 | |
656 // Returns the unique CheckCastPP of a call | |
657 // or 'this' if there are several CheckCastPP | |
658 // or returns NULL if there is no one. | |
659 Node *CallNode::result_cast() { | |
660 Node *cast = NULL; | |
661 | |
662 Node *p = proj_out(TypeFunc::Parms); | |
663 if (p == NULL) | |
664 return NULL; | |
665 | |
666 for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) { | |
667 Node *use = p->fast_out(i); | |
668 if (use->is_CheckCastPP()) { | |
669 if (cast != NULL) { | |
670 return this; // more than 1 CheckCastPP | |
671 } | |
672 cast = use; | |
673 } | |
674 } | |
675 return cast; | |
676 } | |
677 | |
678 | |
0 | 679 //============================================================================= |
680 uint CallJavaNode::size_of() const { return sizeof(*this); } | |
681 uint CallJavaNode::cmp( const Node &n ) const { | |
682 CallJavaNode &call = (CallJavaNode&)n; | |
683 return CallNode::cmp(call) && _method == call._method; | |
684 } | |
685 #ifndef PRODUCT | |
686 void CallJavaNode::dump_spec(outputStream *st) const { | |
687 if( _method ) _method->print_short_name(st); | |
688 CallNode::dump_spec(st); | |
689 } | |
690 #endif | |
691 | |
692 //============================================================================= | |
693 uint CallStaticJavaNode::size_of() const { return sizeof(*this); } | |
694 uint CallStaticJavaNode::cmp( const Node &n ) const { | |
695 CallStaticJavaNode &call = (CallStaticJavaNode&)n; | |
696 return CallJavaNode::cmp(call); | |
697 } | |
698 | |
699 //----------------------------uncommon_trap_request---------------------------- | |
700 // If this is an uncommon trap, return the request code, else zero. | |
701 int CallStaticJavaNode::uncommon_trap_request() const { | |
702 if (_name != NULL && !strcmp(_name, "uncommon_trap")) { | |
703 return extract_uncommon_trap_request(this); | |
704 } | |
705 return 0; | |
706 } | |
707 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) { | |
708 #ifndef PRODUCT | |
709 if (!(call->req() > TypeFunc::Parms && | |
710 call->in(TypeFunc::Parms) != NULL && | |
711 call->in(TypeFunc::Parms)->is_Con())) { | |
712 assert(_in_dump_cnt != 0, "OK if dumping"); | |
713 tty->print("[bad uncommon trap]"); | |
714 return 0; | |
715 } | |
716 #endif | |
717 return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con(); | |
718 } | |
719 | |
720 #ifndef PRODUCT | |
721 void CallStaticJavaNode::dump_spec(outputStream *st) const { | |
722 st->print("# Static "); | |
723 if (_name != NULL) { | |
724 st->print("%s", _name); | |
725 int trap_req = uncommon_trap_request(); | |
726 if (trap_req != 0) { | |
727 char buf[100]; | |
728 st->print("(%s)", | |
729 Deoptimization::format_trap_request(buf, sizeof(buf), | |
730 trap_req)); | |
731 } | |
732 st->print(" "); | |
733 } | |
734 CallJavaNode::dump_spec(st); | |
735 } | |
736 #endif | |
737 | |
738 //============================================================================= | |
739 uint CallDynamicJavaNode::size_of() const { return sizeof(*this); } | |
740 uint CallDynamicJavaNode::cmp( const Node &n ) const { | |
741 CallDynamicJavaNode &call = (CallDynamicJavaNode&)n; | |
742 return CallJavaNode::cmp(call); | |
743 } | |
744 #ifndef PRODUCT | |
745 void CallDynamicJavaNode::dump_spec(outputStream *st) const { | |
746 st->print("# Dynamic "); | |
747 CallJavaNode::dump_spec(st); | |
748 } | |
749 #endif | |
750 | |
751 //============================================================================= | |
752 uint CallRuntimeNode::size_of() const { return sizeof(*this); } | |
753 uint CallRuntimeNode::cmp( const Node &n ) const { | |
754 CallRuntimeNode &call = (CallRuntimeNode&)n; | |
755 return CallNode::cmp(call) && !strcmp(_name,call._name); | |
756 } | |
757 #ifndef PRODUCT | |
758 void CallRuntimeNode::dump_spec(outputStream *st) const { | |
759 st->print("# "); | |
760 st->print(_name); | |
761 CallNode::dump_spec(st); | |
762 } | |
763 #endif | |
764 | |
765 //------------------------------calling_convention----------------------------- | |
766 void CallRuntimeNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const { | |
767 Matcher::c_calling_convention( sig_bt, parm_regs, argcnt ); | |
768 } | |
769 | |
770 //============================================================================= | |
771 //------------------------------calling_convention----------------------------- | |
772 | |
773 | |
774 //============================================================================= | |
775 #ifndef PRODUCT | |
776 void CallLeafNode::dump_spec(outputStream *st) const { | |
777 st->print("# "); | |
778 st->print(_name); | |
779 CallNode::dump_spec(st); | |
780 } | |
781 #endif | |
782 | |
783 //============================================================================= | |
784 | |
785 void SafePointNode::set_local(JVMState* jvms, uint idx, Node *c) { | |
786 assert(verify_jvms(jvms), "jvms must match"); | |
787 int loc = jvms->locoff() + idx; | |
788 if (in(loc)->is_top() && idx > 0 && !c->is_top() ) { | |
789 // If current local idx is top then local idx - 1 could | |
790 // be a long/double that needs to be killed since top could | |
791 // represent the 2nd half ofthe long/double. | |
792 uint ideal = in(loc -1)->ideal_reg(); | |
793 if (ideal == Op_RegD || ideal == Op_RegL) { | |
794 // set other (low index) half to top | |
795 set_req(loc - 1, in(loc)); | |
796 } | |
797 } | |
798 set_req(loc, c); | |
799 } | |
800 | |
801 uint SafePointNode::size_of() const { return sizeof(*this); } | |
802 uint SafePointNode::cmp( const Node &n ) const { | |
803 return (&n == this); // Always fail except on self | |
804 } | |
805 | |
806 //-------------------------set_next_exception---------------------------------- | |
807 void SafePointNode::set_next_exception(SafePointNode* n) { | |
808 assert(n == NULL || n->Opcode() == Op_SafePoint, "correct value for next_exception"); | |
809 if (len() == req()) { | |
810 if (n != NULL) add_prec(n); | |
811 } else { | |
812 set_prec(req(), n); | |
813 } | |
814 } | |
815 | |
816 | |
817 //----------------------------next_exception----------------------------------- | |
818 SafePointNode* SafePointNode::next_exception() const { | |
819 if (len() == req()) { | |
820 return NULL; | |
821 } else { | |
822 Node* n = in(req()); | |
823 assert(n == NULL || n->Opcode() == Op_SafePoint, "no other uses of prec edges"); | |
824 return (SafePointNode*) n; | |
825 } | |
826 } | |
827 | |
828 | |
829 //------------------------------Ideal------------------------------------------ | |
830 // Skip over any collapsed Regions | |
831 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
832 if (remove_dead_region(phase, can_reshape)) return this; | |
833 | |
834 return NULL; | |
835 } | |
836 | |
837 //------------------------------Identity--------------------------------------- | |
838 // Remove obviously duplicate safepoints | |
839 Node *SafePointNode::Identity( PhaseTransform *phase ) { | |
840 | |
841 // If you have back to back safepoints, remove one | |
842 if( in(TypeFunc::Control)->is_SafePoint() ) | |
843 return in(TypeFunc::Control); | |
844 | |
845 if( in(0)->is_Proj() ) { | |
846 Node *n0 = in(0)->in(0); | |
847 // Check if he is a call projection (except Leaf Call) | |
848 if( n0->is_Catch() ) { | |
849 n0 = n0->in(0)->in(0); | |
850 assert( n0->is_Call(), "expect a call here" ); | |
851 } | |
852 if( n0->is_Call() && n0->as_Call()->guaranteed_safepoint() ) { | |
853 // Useless Safepoint, so remove it | |
854 return in(TypeFunc::Control); | |
855 } | |
856 } | |
857 | |
858 return this; | |
859 } | |
860 | |
861 //------------------------------Value------------------------------------------ | |
862 const Type *SafePointNode::Value( PhaseTransform *phase ) const { | |
863 if( phase->type(in(0)) == Type::TOP ) return Type::TOP; | |
864 if( phase->eqv( in(0), this ) ) return Type::TOP; // Dead infinite loop | |
865 return Type::CONTROL; | |
866 } | |
867 | |
868 #ifndef PRODUCT | |
869 void SafePointNode::dump_spec(outputStream *st) const { | |
870 st->print(" SafePoint "); | |
871 } | |
872 #endif | |
873 | |
874 const RegMask &SafePointNode::in_RegMask(uint idx) const { | |
875 if( idx < TypeFunc::Parms ) return RegMask::Empty; | |
876 // Values outside the domain represent debug info | |
877 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]); | |
878 } | |
879 const RegMask &SafePointNode::out_RegMask() const { | |
880 return RegMask::Empty; | |
881 } | |
882 | |
883 | |
884 void SafePointNode::grow_stack(JVMState* jvms, uint grow_by) { | |
885 assert((int)grow_by > 0, "sanity"); | |
886 int monoff = jvms->monoff(); | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
887 int scloff = jvms->scloff(); |
0 | 888 int endoff = jvms->endoff(); |
889 assert(endoff == (int)req(), "no other states or debug info after me"); | |
890 Node* top = Compile::current()->top(); | |
891 for (uint i = 0; i < grow_by; i++) { | |
892 ins_req(monoff, top); | |
893 } | |
894 jvms->set_monoff(monoff + grow_by); | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
895 jvms->set_scloff(scloff + grow_by); |
0 | 896 jvms->set_endoff(endoff + grow_by); |
897 } | |
898 | |
899 void SafePointNode::push_monitor(const FastLockNode *lock) { | |
900 // Add a LockNode, which points to both the original BoxLockNode (the | |
901 // stack space for the monitor) and the Object being locked. | |
902 const int MonitorEdges = 2; | |
903 assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges"); | |
904 assert(req() == jvms()->endoff(), "correct sizing"); | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
905 int nextmon = jvms()->scloff(); |
0 | 906 if (GenerateSynchronizationCode) { |
907 add_req(lock->box_node()); | |
908 add_req(lock->obj_node()); | |
909 } else { | |
910 add_req(NULL); | |
911 add_req(NULL); | |
912 } | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
913 jvms()->set_scloff(nextmon+MonitorEdges); |
0 | 914 jvms()->set_endoff(req()); |
915 } | |
916 | |
917 void SafePointNode::pop_monitor() { | |
918 // Delete last monitor from debug info | |
919 debug_only(int num_before_pop = jvms()->nof_monitors()); | |
920 const int MonitorEdges = (1<<JVMState::logMonitorEdges); | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
921 int scloff = jvms()->scloff(); |
0 | 922 int endoff = jvms()->endoff(); |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
923 int new_scloff = scloff - MonitorEdges; |
0 | 924 int new_endoff = endoff - MonitorEdges; |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
925 jvms()->set_scloff(new_scloff); |
0 | 926 jvms()->set_endoff(new_endoff); |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
927 while (scloff > new_scloff) del_req(--scloff); |
0 | 928 assert(jvms()->nof_monitors() == num_before_pop-1, ""); |
929 } | |
930 | |
931 Node *SafePointNode::peek_monitor_box() const { | |
932 int mon = jvms()->nof_monitors() - 1; | |
933 assert(mon >= 0, "most have a monitor"); | |
934 return monitor_box(jvms(), mon); | |
935 } | |
936 | |
937 Node *SafePointNode::peek_monitor_obj() const { | |
938 int mon = jvms()->nof_monitors() - 1; | |
939 assert(mon >= 0, "most have a monitor"); | |
940 return monitor_obj(jvms(), mon); | |
941 } | |
942 | |
943 // Do we Match on this edge index or not? Match no edges | |
944 uint SafePointNode::match_edge(uint idx) const { | |
945 if( !needs_polling_address_input() ) | |
946 return 0; | |
947 | |
948 return (TypeFunc::Parms == idx); | |
949 } | |
950 | |
63
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
951 //============== SafePointScalarObjectNode ============== |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
952 |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
953 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp, |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
954 #ifdef ASSERT |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
955 AllocateNode* alloc, |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
956 #endif |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
957 uint first_index, |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
958 uint n_fields) : |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
959 TypeNode(tp, 1), // 1 control input -- seems required. Get from root. |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
960 #ifdef ASSERT |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
961 _alloc(alloc), |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
962 #endif |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
963 _first_index(first_index), |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
964 _n_fields(n_fields) |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
965 { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
966 init_class_id(Class_SafePointScalarObject); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
967 } |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
968 |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
969 |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
970 uint SafePointScalarObjectNode::ideal_reg() const { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
971 return 0; // No matching to machine instruction |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
972 } |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
973 |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
974 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
975 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
976 } |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
977 |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
978 const RegMask &SafePointScalarObjectNode::out_RegMask() const { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
979 return RegMask::Empty; |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
980 } |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
981 |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
982 uint SafePointScalarObjectNode::match_edge(uint idx) const { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
983 return 0; |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
984 } |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
985 |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
986 SafePointScalarObjectNode* |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
987 SafePointScalarObjectNode::clone(int jvms_adj, Dict* sosn_map) const { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
988 void* cached = (*sosn_map)[(void*)this]; |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
989 if (cached != NULL) { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
990 return (SafePointScalarObjectNode*)cached; |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
991 } |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
992 Compile* C = Compile::current(); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
993 SafePointScalarObjectNode* res = (SafePointScalarObjectNode*)Node::clone(); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
994 res->_first_index += jvms_adj; |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
995 sosn_map->Insert((void*)this, (void*)res); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
996 return res; |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
997 } |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
998 |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
999 |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
1000 #ifndef PRODUCT |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
1001 void SafePointScalarObjectNode::dump_spec(outputStream *st) const { |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
1002 st->print(" # fields@[%d..%d]", first_index(), |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
1003 first_index() + n_fields() - 1); |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
1004 } |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
1005 |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
1006 #endif |
eac007780a58
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents:
39
diff
changeset
|
1007 |
0 | 1008 //============================================================================= |
1009 uint AllocateNode::size_of() const { return sizeof(*this); } | |
1010 | |
1011 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype, | |
1012 Node *ctrl, Node *mem, Node *abio, | |
1013 Node *size, Node *klass_node, Node *initial_test) | |
1014 : CallNode(atype, NULL, TypeRawPtr::BOTTOM) | |
1015 { | |
1016 init_class_id(Class_Allocate); | |
1017 init_flags(Flag_is_macro); | |
39
76256d272075
6667612: (Escape Analysis) disable loop cloning if it has a scalar replaceable allocation
kvn
parents:
0
diff
changeset
|
1018 _is_scalar_replaceable = false; |
0 | 1019 Node *topnode = C->top(); |
1020 | |
1021 init_req( TypeFunc::Control , ctrl ); | |
1022 init_req( TypeFunc::I_O , abio ); | |
1023 init_req( TypeFunc::Memory , mem ); | |
1024 init_req( TypeFunc::ReturnAdr, topnode ); | |
1025 init_req( TypeFunc::FramePtr , topnode ); | |
1026 init_req( AllocSize , size); | |
1027 init_req( KlassNode , klass_node); | |
1028 init_req( InitialTest , initial_test); | |
1029 init_req( ALength , topnode); | |
1030 C->add_macro_node(this); | |
1031 } | |
1032 | |
1033 //============================================================================= | |
1034 uint AllocateArrayNode::size_of() const { return sizeof(*this); } | |
1035 | |
1036 //============================================================================= | |
1037 uint LockNode::size_of() const { return sizeof(*this); } | |
1038 | |
1039 // Redundant lock elimination | |
1040 // | |
1041 // There are various patterns of locking where we release and | |
1042 // immediately reacquire a lock in a piece of code where no operations | |
1043 // occur in between that would be observable. In those cases we can | |
1044 // skip releasing and reacquiring the lock without violating any | |
1045 // fairness requirements. Doing this around a loop could cause a lock | |
1046 // to be held for a very long time so we concentrate on non-looping | |
1047 // control flow. We also require that the operations are fully | |
1048 // redundant meaning that we don't introduce new lock operations on | |
1049 // some paths so to be able to eliminate it on others ala PRE. This | |
1050 // would probably require some more extensive graph manipulation to | |
1051 // guarantee that the memory edges were all handled correctly. | |
1052 // | |
1053 // Assuming p is a simple predicate which can't trap in any way and s | |
1054 // is a synchronized method consider this code: | |
1055 // | |
1056 // s(); | |
1057 // if (p) | |
1058 // s(); | |
1059 // else | |
1060 // s(); | |
1061 // s(); | |
1062 // | |
1063 // 1. The unlocks of the first call to s can be eliminated if the | |
1064 // locks inside the then and else branches are eliminated. | |
1065 // | |
1066 // 2. The unlocks of the then and else branches can be eliminated if | |
1067 // the lock of the final call to s is eliminated. | |
1068 // | |
1069 // Either of these cases subsumes the simple case of sequential control flow | |
1070 // | |
1071 // Addtionally we can eliminate versions without the else case: | |
1072 // | |
1073 // s(); | |
1074 // if (p) | |
1075 // s(); | |
1076 // s(); | |
1077 // | |
1078 // 3. In this case we eliminate the unlock of the first s, the lock | |
1079 // and unlock in the then case and the lock in the final s. | |
1080 // | |
1081 // Note also that in all these cases the then/else pieces don't have | |
1082 // to be trivial as long as they begin and end with synchronization | |
1083 // operations. | |
1084 // | |
1085 // s(); | |
1086 // if (p) | |
1087 // s(); | |
1088 // f(); | |
1089 // s(); | |
1090 // s(); | |
1091 // | |
1092 // The code will work properly for this case, leaving in the unlock | |
1093 // before the call to f and the relock after it. | |
1094 // | |
1095 // A potentially interesting case which isn't handled here is when the | |
1096 // locking is partially redundant. | |
1097 // | |
1098 // s(); | |
1099 // if (p) | |
1100 // s(); | |
1101 // | |
1102 // This could be eliminated putting unlocking on the else case and | |
1103 // eliminating the first unlock and the lock in the then side. | |
1104 // Alternatively the unlock could be moved out of the then side so it | |
1105 // was after the merge and the first unlock and second lock | |
1106 // eliminated. This might require less manipulation of the memory | |
1107 // state to get correct. | |
1108 // | |
1109 // Additionally we might allow work between a unlock and lock before | |
1110 // giving up eliminating the locks. The current code disallows any | |
1111 // conditional control flow between these operations. A formulation | |
1112 // similar to partial redundancy elimination computing the | |
1113 // availability of unlocking and the anticipatability of locking at a | |
1114 // program point would allow detection of fully redundant locking with | |
1115 // some amount of work in between. I'm not sure how often I really | |
1116 // think that would occur though. Most of the cases I've seen | |
1117 // indicate it's likely non-trivial work would occur in between. | |
1118 // There may be other more complicated constructs where we could | |
1119 // eliminate locking but I haven't seen any others appear as hot or | |
1120 // interesting. | |
1121 // | |
1122 // Locking and unlocking have a canonical form in ideal that looks | |
1123 // roughly like this: | |
1124 // | |
1125 // <obj> | |
1126 // | \\------+ | |
1127 // | \ \ | |
1128 // | BoxLock \ | |
1129 // | | | \ | |
1130 // | | \ \ | |
1131 // | | FastLock | |
1132 // | | / | |
1133 // | | / | |
1134 // | | | | |
1135 // | |
1136 // Lock | |
1137 // | | |
1138 // Proj #0 | |
1139 // | | |
1140 // MembarAcquire | |
1141 // | | |
1142 // Proj #0 | |
1143 // | |
1144 // MembarRelease | |
1145 // | | |
1146 // Proj #0 | |
1147 // | | |
1148 // Unlock | |
1149 // | | |
1150 // Proj #0 | |
1151 // | |
1152 // | |
1153 // This code proceeds by processing Lock nodes during PhaseIterGVN | |
1154 // and searching back through its control for the proper code | |
1155 // patterns. Once it finds a set of lock and unlock operations to | |
1156 // eliminate they are marked as eliminatable which causes the | |
1157 // expansion of the Lock and Unlock macro nodes to make the operation a NOP | |
1158 // | |
1159 //============================================================================= | |
1160 | |
1161 // | |
1162 // Utility function to skip over uninteresting control nodes. Nodes skipped are: | |
1163 // - copy regions. (These may not have been optimized away yet.) | |
1164 // - eliminated locking nodes | |
1165 // | |
1166 static Node *next_control(Node *ctrl) { | |
1167 if (ctrl == NULL) | |
1168 return NULL; | |
1169 while (1) { | |
1170 if (ctrl->is_Region()) { | |
1171 RegionNode *r = ctrl->as_Region(); | |
1172 Node *n = r->is_copy(); | |
1173 if (n == NULL) | |
1174 break; // hit a region, return it | |
1175 else | |
1176 ctrl = n; | |
1177 } else if (ctrl->is_Proj()) { | |
1178 Node *in0 = ctrl->in(0); | |
1179 if (in0->is_AbstractLock() && in0->as_AbstractLock()->is_eliminated()) { | |
1180 ctrl = in0->in(0); | |
1181 } else { | |
1182 break; | |
1183 } | |
1184 } else { | |
1185 break; // found an interesting control | |
1186 } | |
1187 } | |
1188 return ctrl; | |
1189 } | |
1190 // | |
1191 // Given a control, see if it's the control projection of an Unlock which | |
1192 // operating on the same object as lock. | |
1193 // | |
1194 bool AbstractLockNode::find_matching_unlock(const Node* ctrl, LockNode* lock, | |
1195 GrowableArray<AbstractLockNode*> &lock_ops) { | |
1196 ProjNode *ctrl_proj = (ctrl->is_Proj()) ? ctrl->as_Proj() : NULL; | |
1197 if (ctrl_proj != NULL && ctrl_proj->_con == TypeFunc::Control) { | |
1198 Node *n = ctrl_proj->in(0); | |
1199 if (n != NULL && n->is_Unlock()) { | |
1200 UnlockNode *unlock = n->as_Unlock(); | |
1201 if ((lock->obj_node() == unlock->obj_node()) && | |
1202 (lock->box_node() == unlock->box_node()) && !unlock->is_eliminated()) { | |
1203 lock_ops.append(unlock); | |
1204 return true; | |
1205 } | |
1206 } | |
1207 } | |
1208 return false; | |
1209 } | |
1210 | |
1211 // | |
1212 // Find the lock matching an unlock. Returns null if a safepoint | |
1213 // or complicated control is encountered first. | |
1214 LockNode *AbstractLockNode::find_matching_lock(UnlockNode* unlock) { | |
1215 LockNode *lock_result = NULL; | |
1216 // find the matching lock, or an intervening safepoint | |
1217 Node *ctrl = next_control(unlock->in(0)); | |
1218 while (1) { | |
1219 assert(ctrl != NULL, "invalid control graph"); | |
1220 assert(!ctrl->is_Start(), "missing lock for unlock"); | |
1221 if (ctrl->is_top()) break; // dead control path | |
1222 if (ctrl->is_Proj()) ctrl = ctrl->in(0); | |
1223 if (ctrl->is_SafePoint()) { | |
1224 break; // found a safepoint (may be the lock we are searching for) | |
1225 } else if (ctrl->is_Region()) { | |
1226 // Check for a simple diamond pattern. Punt on anything more complicated | |
1227 if (ctrl->req() == 3 && ctrl->in(1) != NULL && ctrl->in(2) != NULL) { | |
1228 Node *in1 = next_control(ctrl->in(1)); | |
1229 Node *in2 = next_control(ctrl->in(2)); | |
1230 if (((in1->is_IfTrue() && in2->is_IfFalse()) || | |
1231 (in2->is_IfTrue() && in1->is_IfFalse())) && (in1->in(0) == in2->in(0))) { | |
1232 ctrl = next_control(in1->in(0)->in(0)); | |
1233 } else { | |
1234 break; | |
1235 } | |
1236 } else { | |
1237 break; | |
1238 } | |
1239 } else { | |
1240 ctrl = next_control(ctrl->in(0)); // keep searching | |
1241 } | |
1242 } | |
1243 if (ctrl->is_Lock()) { | |
1244 LockNode *lock = ctrl->as_Lock(); | |
1245 if ((lock->obj_node() == unlock->obj_node()) && | |
1246 (lock->box_node() == unlock->box_node())) { | |
1247 lock_result = lock; | |
1248 } | |
1249 } | |
1250 return lock_result; | |
1251 } | |
1252 | |
1253 // This code corresponds to case 3 above. | |
1254 | |
1255 bool AbstractLockNode::find_lock_and_unlock_through_if(Node* node, LockNode* lock, | |
1256 GrowableArray<AbstractLockNode*> &lock_ops) { | |
1257 Node* if_node = node->in(0); | |
1258 bool if_true = node->is_IfTrue(); | |
1259 | |
1260 if (if_node->is_If() && if_node->outcnt() == 2 && (if_true || node->is_IfFalse())) { | |
1261 Node *lock_ctrl = next_control(if_node->in(0)); | |
1262 if (find_matching_unlock(lock_ctrl, lock, lock_ops)) { | |
1263 Node* lock1_node = NULL; | |
1264 ProjNode* proj = if_node->as_If()->proj_out(!if_true); | |
1265 if (if_true) { | |
1266 if (proj->is_IfFalse() && proj->outcnt() == 1) { | |
1267 lock1_node = proj->unique_out(); | |
1268 } | |
1269 } else { | |
1270 if (proj->is_IfTrue() && proj->outcnt() == 1) { | |
1271 lock1_node = proj->unique_out(); | |
1272 } | |
1273 } | |
1274 if (lock1_node != NULL && lock1_node->is_Lock()) { | |
1275 LockNode *lock1 = lock1_node->as_Lock(); | |
1276 if ((lock->obj_node() == lock1->obj_node()) && | |
1277 (lock->box_node() == lock1->box_node()) && !lock1->is_eliminated()) { | |
1278 lock_ops.append(lock1); | |
1279 return true; | |
1280 } | |
1281 } | |
1282 } | |
1283 } | |
1284 | |
1285 lock_ops.trunc_to(0); | |
1286 return false; | |
1287 } | |
1288 | |
1289 bool AbstractLockNode::find_unlocks_for_region(const RegionNode* region, LockNode* lock, | |
1290 GrowableArray<AbstractLockNode*> &lock_ops) { | |
1291 // check each control merging at this point for a matching unlock. | |
1292 // in(0) should be self edge so skip it. | |
1293 for (int i = 1; i < (int)region->req(); i++) { | |
1294 Node *in_node = next_control(region->in(i)); | |
1295 if (in_node != NULL) { | |
1296 if (find_matching_unlock(in_node, lock, lock_ops)) { | |
1297 // found a match so keep on checking. | |
1298 continue; | |
1299 } else if (find_lock_and_unlock_through_if(in_node, lock, lock_ops)) { | |
1300 continue; | |
1301 } | |
1302 | |
1303 // If we fall through to here then it was some kind of node we | |
1304 // don't understand or there wasn't a matching unlock, so give | |
1305 // up trying to merge locks. | |
1306 lock_ops.trunc_to(0); | |
1307 return false; | |
1308 } | |
1309 } | |
1310 return true; | |
1311 | |
1312 } | |
1313 | |
1314 #ifndef PRODUCT | |
1315 // | |
1316 // Create a counter which counts the number of times this lock is acquired | |
1317 // | |
1318 void AbstractLockNode::create_lock_counter(JVMState* state) { | |
1319 _counter = OptoRuntime::new_named_counter(state, NamedCounter::LockCounter); | |
1320 } | |
1321 #endif | |
1322 | |
1323 void AbstractLockNode::set_eliminated() { | |
1324 _eliminate = true; | |
1325 #ifndef PRODUCT | |
1326 if (_counter) { | |
1327 // Update the counter to indicate that this lock was eliminated. | |
1328 // The counter update code will stay around even though the | |
1329 // optimizer will eliminate the lock operation itself. | |
1330 _counter->set_tag(NamedCounter::EliminatedLockCounter); | |
1331 } | |
1332 #endif | |
1333 } | |
1334 | |
1335 //============================================================================= | |
1336 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
1337 | |
66
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1338 // perform any generic optimizations first (returns 'this' or NULL) |
0 | 1339 Node *result = SafePointNode::Ideal(phase, can_reshape); |
1340 | |
1341 // Now see if we can optimize away this lock. We don't actually | |
1342 // remove the locking here, we simply set the _eliminate flag which | |
1343 // prevents macro expansion from expanding the lock. Since we don't | |
1344 // modify the graph, the value returned from this function is the | |
1345 // one computed above. | |
66
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1346 if (result == NULL && can_reshape && EliminateLocks && !is_eliminated()) { |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1347 // |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1348 // If we are locking an unescaped object, the lock/unlock is unnecessary |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1349 // |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1350 ConnectionGraph *cgr = Compile::current()->congraph(); |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1351 PointsToNode::EscapeState es = PointsToNode::GlobalEscape; |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1352 if (cgr != NULL) |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1353 es = cgr->escape_state(obj_node(), phase); |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1354 if (es != PointsToNode::UnknownEscape && es != PointsToNode::GlobalEscape) { |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1355 // Mark it eliminated to update any counters |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1356 this->set_eliminated(); |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1357 return result; |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1358 } |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1359 |
0 | 1360 // |
1361 // Try lock coarsening | |
1362 // | |
1363 PhaseIterGVN* iter = phase->is_IterGVN(); | |
1364 if (iter != NULL) { | |
1365 | |
1366 GrowableArray<AbstractLockNode*> lock_ops; | |
1367 | |
1368 Node *ctrl = next_control(in(0)); | |
1369 | |
1370 // now search back for a matching Unlock | |
1371 if (find_matching_unlock(ctrl, this, lock_ops)) { | |
1372 // found an unlock directly preceding this lock. This is the | |
1373 // case of single unlock directly control dependent on a | |
1374 // single lock which is the trivial version of case 1 or 2. | |
1375 } else if (ctrl->is_Region() ) { | |
1376 if (find_unlocks_for_region(ctrl->as_Region(), this, lock_ops)) { | |
1377 // found lock preceded by multiple unlocks along all paths | |
1378 // joining at this point which is case 3 in description above. | |
1379 } | |
1380 } else { | |
1381 // see if this lock comes from either half of an if and the | |
1382 // predecessors merges unlocks and the other half of the if | |
1383 // performs a lock. | |
1384 if (find_lock_and_unlock_through_if(ctrl, this, lock_ops)) { | |
1385 // found unlock splitting to an if with locks on both branches. | |
1386 } | |
1387 } | |
1388 | |
1389 if (lock_ops.length() > 0) { | |
1390 // add ourselves to the list of locks to be eliminated. | |
1391 lock_ops.append(this); | |
1392 | |
1393 #ifndef PRODUCT | |
1394 if (PrintEliminateLocks) { | |
1395 int locks = 0; | |
1396 int unlocks = 0; | |
1397 for (int i = 0; i < lock_ops.length(); i++) { | |
1398 AbstractLockNode* lock = lock_ops.at(i); | |
66
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1399 if (lock->Opcode() == Op_Lock) |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1400 locks++; |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1401 else |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1402 unlocks++; |
0 | 1403 if (Verbose) { |
1404 lock->dump(1); | |
1405 } | |
1406 } | |
1407 tty->print_cr("***Eliminated %d unlocks and %d locks", unlocks, locks); | |
1408 } | |
1409 #endif | |
1410 | |
1411 // for each of the identified locks, mark them | |
1412 // as eliminatable | |
1413 for (int i = 0; i < lock_ops.length(); i++) { | |
1414 AbstractLockNode* lock = lock_ops.at(i); | |
1415 | |
1416 // Mark it eliminated to update any counters | |
1417 lock->set_eliminated(); | |
1418 } | |
1419 } else if (result != NULL && ctrl->is_Region() && | |
1420 iter->_worklist.member(ctrl)) { | |
1421 // We weren't able to find any opportunities but the region this | |
1422 // lock is control dependent on hasn't been processed yet so put | |
1423 // this lock back on the worklist so we can check again once any | |
1424 // region simplification has occurred. | |
1425 iter->_worklist.push(this); | |
1426 } | |
1427 } | |
1428 } | |
1429 | |
1430 return result; | |
1431 } | |
1432 | |
1433 //============================================================================= | |
1434 uint UnlockNode::size_of() const { return sizeof(*this); } | |
1435 | |
1436 //============================================================================= | |
1437 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) { | |
1438 | |
66
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1439 // perform any generic optimizations first (returns 'this' or NULL) |
0 | 1440 Node * result = SafePointNode::Ideal(phase, can_reshape); |
1441 | |
1442 // Now see if we can optimize away this unlock. We don't actually | |
1443 // remove the unlocking here, we simply set the _eliminate flag which | |
1444 // prevents macro expansion from expanding the unlock. Since we don't | |
1445 // modify the graph, the value returned from this function is the | |
1446 // one computed above. | |
66
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1447 // Escape state is defined after Parse phase. |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1448 if (result == NULL && can_reshape && EliminateLocks && !is_eliminated()) { |
0 | 1449 // |
66
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1450 // If we are unlocking an unescaped object, the lock/unlock is unnecessary. |
0 | 1451 // |
1452 ConnectionGraph *cgr = Compile::current()->congraph(); | |
66
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1453 PointsToNode::EscapeState es = PointsToNode::GlobalEscape; |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1454 if (cgr != NULL) |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1455 es = cgr->escape_state(obj_node(), phase); |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1456 if (es != PointsToNode::UnknownEscape && es != PointsToNode::GlobalEscape) { |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1457 // Mark it eliminated to update any counters |
6dbf1a175d6b
6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents:
65
diff
changeset
|
1458 this->set_eliminated(); |
0 | 1459 } |
1460 } | |
1461 return result; | |
1462 } |