annotate src/share/vm/opto/macro.cpp @ 66:6dbf1a175d6b

6672848: (Escape Analysis) improve lock elimination with EA Summary: Remove lock/unlock MemBar nodes and specify locks in debug info for deoptimization. Reviewed-by: never
author kvn
date Fri, 14 Mar 2008 16:40:42 -0700
parents eac007780a58
children a8880a78d355
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_macro.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 //
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // Replace any references to "oldref" in inputs to "use" with "newref".
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // Returns the number of replacements made.
a61af66fc99e Initial load
duke
parents:
diff changeset
32 //
a61af66fc99e Initial load
duke
parents:
diff changeset
33 int PhaseMacroExpand::replace_input(Node *use, Node *oldref, Node *newref) {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 int nreplacements = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 uint req = use->req();
a61af66fc99e Initial load
duke
parents:
diff changeset
36 for (uint j = 0; j < use->len(); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 Node *uin = use->in(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
38 if (uin == oldref) {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 if (j < req)
a61af66fc99e Initial load
duke
parents:
diff changeset
40 use->set_req(j, newref);
a61af66fc99e Initial load
duke
parents:
diff changeset
41 else
a61af66fc99e Initial load
duke
parents:
diff changeset
42 use->set_prec(j, newref);
a61af66fc99e Initial load
duke
parents:
diff changeset
43 nreplacements++;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 } else if (j >= req && uin == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47 }
a61af66fc99e Initial load
duke
parents:
diff changeset
48 return nreplacements;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 void PhaseMacroExpand::copy_call_debug_info(CallNode *oldcall, CallNode * newcall) {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // Copy debug information and adjust JVMState information
a61af66fc99e Initial load
duke
parents:
diff changeset
53 uint old_dbg_start = oldcall->tf()->domain()->cnt();
a61af66fc99e Initial load
duke
parents:
diff changeset
54 uint new_dbg_start = newcall->tf()->domain()->cnt();
a61af66fc99e Initial load
duke
parents:
diff changeset
55 int jvms_adj = new_dbg_start - old_dbg_start;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 assert (new_dbg_start == newcall->req(), "argument count mismatch");
63
eac007780a58 6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents: 0
diff changeset
57
eac007780a58 6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents: 0
diff changeset
58 Dict* sosn_map = new Dict(cmpkey,hashkey);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
59 for (uint i = old_dbg_start; i < oldcall->req(); i++) {
63
eac007780a58 6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents: 0
diff changeset
60 Node* old_in = oldcall->in(i);
eac007780a58 6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents: 0
diff changeset
61 // Clone old SafePointScalarObjectNodes, adjusting their field contents.
eac007780a58 6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents: 0
diff changeset
62 if (old_in->is_SafePointScalarObject()) {
eac007780a58 6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents: 0
diff changeset
63 SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject();
eac007780a58 6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents: 0
diff changeset
64 uint old_unique = C->unique();
eac007780a58 6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents: 0
diff changeset
65 Node* new_in = old_sosn->clone(jvms_adj, sosn_map);
eac007780a58 6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents: 0
diff changeset
66 if (old_unique != C->unique()) {
eac007780a58 6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents: 0
diff changeset
67 new_in = transform_later(new_in); // Register new node.
eac007780a58 6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents: 0
diff changeset
68 }
eac007780a58 6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents: 0
diff changeset
69 old_in = new_in;
eac007780a58 6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents: 0
diff changeset
70 }
eac007780a58 6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents: 0
diff changeset
71 newcall->add_req(old_in);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
63
eac007780a58 6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents: 0
diff changeset
73
0
a61af66fc99e Initial load
duke
parents:
diff changeset
74 newcall->set_jvms(oldcall->jvms());
a61af66fc99e Initial load
duke
parents:
diff changeset
75 for (JVMState *jvms = newcall->jvms(); jvms != NULL; jvms = jvms->caller()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 jvms->set_map(newcall);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 jvms->set_locoff(jvms->locoff()+jvms_adj);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 jvms->set_stkoff(jvms->stkoff()+jvms_adj);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 jvms->set_monoff(jvms->monoff()+jvms_adj);
63
eac007780a58 6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint
kvn
parents: 0
diff changeset
80 jvms->set_scloff(jvms->scloff()+jvms_adj);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
81 jvms->set_endoff(jvms->endoff()+jvms_adj);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 Node* PhaseMacroExpand::opt_iff(Node* region, Node* iff) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 IfNode *opt_iff = transform_later(iff)->as_If();
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // Fast path taken; set region slot 2
a61af66fc99e Initial load
duke
parents:
diff changeset
89 Node *fast_taken = transform_later( new (C, 1) IfFalseNode(opt_iff) );
a61af66fc99e Initial load
duke
parents:
diff changeset
90 region->init_req(2,fast_taken); // Capture fast-control
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // Fast path not-taken, i.e. slow path
a61af66fc99e Initial load
duke
parents:
diff changeset
93 Node *slow_taken = transform_later( new (C, 1) IfTrueNode(opt_iff) );
a61af66fc99e Initial load
duke
parents:
diff changeset
94 return slow_taken;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 //--------------------copy_predefined_input_for_runtime_call--------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
98 void PhaseMacroExpand::copy_predefined_input_for_runtime_call(Node * ctrl, CallNode* oldcall, CallNode* call) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // Set fixed predefined input arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
100 call->init_req( TypeFunc::Control, ctrl );
a61af66fc99e Initial load
duke
parents:
diff changeset
101 call->init_req( TypeFunc::I_O , oldcall->in( TypeFunc::I_O) );
a61af66fc99e Initial load
duke
parents:
diff changeset
102 call->init_req( TypeFunc::Memory , oldcall->in( TypeFunc::Memory ) ); // ?????
a61af66fc99e Initial load
duke
parents:
diff changeset
103 call->init_req( TypeFunc::ReturnAdr, oldcall->in( TypeFunc::ReturnAdr ) );
a61af66fc99e Initial load
duke
parents:
diff changeset
104 call->init_req( TypeFunc::FramePtr, oldcall->in( TypeFunc::FramePtr ) );
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 //------------------------------make_slow_call---------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
108 CallNode* PhaseMacroExpand::make_slow_call(CallNode *oldcall, const TypeFunc* slow_call_type, address slow_call, const char* leaf_name, Node* slow_path, Node* parm0, Node* parm1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // Slow-path call
a61af66fc99e Initial load
duke
parents:
diff changeset
111 int size = slow_call_type->domain()->cnt();
a61af66fc99e Initial load
duke
parents:
diff changeset
112 CallNode *call = leaf_name
a61af66fc99e Initial load
duke
parents:
diff changeset
113 ? (CallNode*)new (C, size) CallLeafNode ( slow_call_type, slow_call, leaf_name, TypeRawPtr::BOTTOM )
a61af66fc99e Initial load
duke
parents:
diff changeset
114 : (CallNode*)new (C, size) CallStaticJavaNode( slow_call_type, slow_call, OptoRuntime::stub_name(slow_call), oldcall->jvms()->bci(), TypeRawPtr::BOTTOM );
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // Slow path call has no side-effects, uses few values
a61af66fc99e Initial load
duke
parents:
diff changeset
117 copy_predefined_input_for_runtime_call(slow_path, oldcall, call );
a61af66fc99e Initial load
duke
parents:
diff changeset
118 if (parm0 != NULL) call->init_req(TypeFunc::Parms+0, parm0);
a61af66fc99e Initial load
duke
parents:
diff changeset
119 if (parm1 != NULL) call->init_req(TypeFunc::Parms+1, parm1);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 copy_call_debug_info(oldcall, call);
a61af66fc99e Initial load
duke
parents:
diff changeset
121 call->set_cnt(PROB_UNLIKELY_MAG(4)); // Same effect as RC_UNCOMMON.
a61af66fc99e Initial load
duke
parents:
diff changeset
122 _igvn.hash_delete(oldcall);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 _igvn.subsume_node(oldcall, call);
a61af66fc99e Initial load
duke
parents:
diff changeset
124 transform_later(call);
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 return call;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 void PhaseMacroExpand::extract_call_projections(CallNode *call) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 _fallthroughproj = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 _fallthroughcatchproj = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 _ioproj_fallthrough = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 _ioproj_catchall = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 _catchallcatchproj = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 _memproj_fallthrough = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 _memproj_catchall = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 _resproj = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 for (DUIterator_Fast imax, i = call->fast_outs(imax); i < imax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 ProjNode *pn = call->fast_out(i)->as_Proj();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 switch (pn->_con) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 case TypeFunc::Control:
a61af66fc99e Initial load
duke
parents:
diff changeset
142 {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
a61af66fc99e Initial load
duke
parents:
diff changeset
144 _fallthroughproj = pn;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 DUIterator_Fast jmax, j = pn->fast_outs(jmax);
a61af66fc99e Initial load
duke
parents:
diff changeset
146 const Node *cn = pn->fast_out(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 if (cn->is_Catch()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 ProjNode *cpn = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
149 for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 cpn = cn->fast_out(k)->as_Proj();
a61af66fc99e Initial load
duke
parents:
diff changeset
151 assert(cpn->is_CatchProj(), "must be a CatchProjNode");
a61af66fc99e Initial load
duke
parents:
diff changeset
152 if (cpn->_con == CatchProjNode::fall_through_index)
a61af66fc99e Initial load
duke
parents:
diff changeset
153 _fallthroughcatchproj = cpn;
a61af66fc99e Initial load
duke
parents:
diff changeset
154 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");
a61af66fc99e Initial load
duke
parents:
diff changeset
156 _catchallcatchproj = cpn;
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162 case TypeFunc::I_O:
a61af66fc99e Initial load
duke
parents:
diff changeset
163 if (pn->_is_io_use)
a61af66fc99e Initial load
duke
parents:
diff changeset
164 _ioproj_catchall = pn;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 else
a61af66fc99e Initial load
duke
parents:
diff changeset
166 _ioproj_fallthrough = pn;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 case TypeFunc::Memory:
a61af66fc99e Initial load
duke
parents:
diff changeset
169 if (pn->_is_io_use)
a61af66fc99e Initial load
duke
parents:
diff changeset
170 _memproj_catchall = pn;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 else
a61af66fc99e Initial load
duke
parents:
diff changeset
172 _memproj_fallthrough = pn;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
174 case TypeFunc::Parms:
a61af66fc99e Initial load
duke
parents:
diff changeset
175 _resproj = pn;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
178 assert(false, "unexpected projection from allocation node.");
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 //---------------------------set_eden_pointers-------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
186 void PhaseMacroExpand::set_eden_pointers(Node* &eden_top_adr, Node* &eden_end_adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 if (UseTLAB) { // Private allocation: load from TLS
a61af66fc99e Initial load
duke
parents:
diff changeset
188 Node* thread = transform_later(new (C, 1) ThreadLocalNode());
a61af66fc99e Initial load
duke
parents:
diff changeset
189 int tlab_top_offset = in_bytes(JavaThread::tlab_top_offset());
a61af66fc99e Initial load
duke
parents:
diff changeset
190 int tlab_end_offset = in_bytes(JavaThread::tlab_end_offset());
a61af66fc99e Initial load
duke
parents:
diff changeset
191 eden_top_adr = basic_plus_adr(top()/*not oop*/, thread, tlab_top_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
192 eden_end_adr = basic_plus_adr(top()/*not oop*/, thread, tlab_end_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
193 } else { // Shared allocation: load from globals
a61af66fc99e Initial load
duke
parents:
diff changeset
194 CollectedHeap* ch = Universe::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
195 address top_adr = (address)ch->top_addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
196 address end_adr = (address)ch->end_addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
197 eden_top_adr = makecon(TypeRawPtr::make(top_adr));
a61af66fc99e Initial load
duke
parents:
diff changeset
198 eden_end_adr = basic_plus_adr(eden_top_adr, end_adr - top_adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200 }
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203 Node* PhaseMacroExpand::make_load(Node* ctl, Node* mem, Node* base, int offset, const Type* value_type, BasicType bt) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 Node* adr = basic_plus_adr(base, offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 const TypePtr* adr_type = TypeRawPtr::BOTTOM;
a61af66fc99e Initial load
duke
parents:
diff changeset
206 Node* value = LoadNode::make(C, ctl, mem, adr, adr_type, value_type, bt);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 transform_later(value);
a61af66fc99e Initial load
duke
parents:
diff changeset
208 return value;
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 Node* PhaseMacroExpand::make_store(Node* ctl, Node* mem, Node* base, int offset, Node* value, BasicType bt) {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 Node* adr = basic_plus_adr(base, offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
214 mem = StoreNode::make(C, ctl, mem, adr, NULL, value, bt);
a61af66fc99e Initial load
duke
parents:
diff changeset
215 transform_later(mem);
a61af66fc99e Initial load
duke
parents:
diff changeset
216 return mem;
a61af66fc99e Initial load
duke
parents:
diff changeset
217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
220 //
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // A L L O C A T I O N
a61af66fc99e Initial load
duke
parents:
diff changeset
222 //
a61af66fc99e Initial load
duke
parents:
diff changeset
223 // Allocation attempts to be fast in the case of frequent small objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
224 // It breaks down like this:
a61af66fc99e Initial load
duke
parents:
diff changeset
225 //
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // 1) Size in doublewords is computed. This is a constant for objects and
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // variable for most arrays. Doubleword units are used to avoid size
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // overflow of huge doubleword arrays. We need doublewords in the end for
a61af66fc99e Initial load
duke
parents:
diff changeset
229 // rounding.
a61af66fc99e Initial load
duke
parents:
diff changeset
230 //
a61af66fc99e Initial load
duke
parents:
diff changeset
231 // 2) Size is checked for being 'too large'. Too-large allocations will go
a61af66fc99e Initial load
duke
parents:
diff changeset
232 // the slow path into the VM. The slow path can throw any required
a61af66fc99e Initial load
duke
parents:
diff changeset
233 // exceptions, and does all the special checks for very large arrays. The
a61af66fc99e Initial load
duke
parents:
diff changeset
234 // size test can constant-fold away for objects. For objects with
a61af66fc99e Initial load
duke
parents:
diff changeset
235 // finalizers it constant-folds the otherway: you always go slow with
a61af66fc99e Initial load
duke
parents:
diff changeset
236 // finalizers.
a61af66fc99e Initial load
duke
parents:
diff changeset
237 //
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // 3) If NOT using TLABs, this is the contended loop-back point.
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // Load-Locked the heap top. If using TLABs normal-load the heap top.
a61af66fc99e Initial load
duke
parents:
diff changeset
240 //
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // 4) Check that heap top + size*8 < max. If we fail go the slow ` route.
a61af66fc99e Initial load
duke
parents:
diff changeset
242 // NOTE: "top+size*8" cannot wrap the 4Gig line! Here's why: for largish
a61af66fc99e Initial load
duke
parents:
diff changeset
243 // "size*8" we always enter the VM, where "largish" is a constant picked small
a61af66fc99e Initial load
duke
parents:
diff changeset
244 // enough that there's always space between the eden max and 4Gig (old space is
a61af66fc99e Initial load
duke
parents:
diff changeset
245 // there so it's quite large) and large enough that the cost of entering the VM
a61af66fc99e Initial load
duke
parents:
diff changeset
246 // is dwarfed by the cost to initialize the space.
a61af66fc99e Initial load
duke
parents:
diff changeset
247 //
a61af66fc99e Initial load
duke
parents:
diff changeset
248 // 5) If NOT using TLABs, Store-Conditional the adjusted heap top back
a61af66fc99e Initial load
duke
parents:
diff changeset
249 // down. If contended, repeat at step 3. If using TLABs normal-store
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // adjusted heap top back down; there is no contention.
a61af66fc99e Initial load
duke
parents:
diff changeset
251 //
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // 6) If !ZeroTLAB then Bulk-clear the object/array. Fill in klass & mark
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // fields.
a61af66fc99e Initial load
duke
parents:
diff changeset
254 //
a61af66fc99e Initial load
duke
parents:
diff changeset
255 // 7) Merge with the slow-path; cast the raw memory pointer to the correct
a61af66fc99e Initial load
duke
parents:
diff changeset
256 // oop flavor.
a61af66fc99e Initial load
duke
parents:
diff changeset
257 //
a61af66fc99e Initial load
duke
parents:
diff changeset
258 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
259 // FastAllocateSizeLimit value is in DOUBLEWORDS.
a61af66fc99e Initial load
duke
parents:
diff changeset
260 // Allocations bigger than this always go the slow route.
a61af66fc99e Initial load
duke
parents:
diff changeset
261 // This value must be small enough that allocation attempts that need to
a61af66fc99e Initial load
duke
parents:
diff changeset
262 // trigger exceptions go the slow route. Also, it must be small enough so
a61af66fc99e Initial load
duke
parents:
diff changeset
263 // that heap_top + size_in_bytes does not wrap around the 4Gig limit.
a61af66fc99e Initial load
duke
parents:
diff changeset
264 //=============================================================================j//
a61af66fc99e Initial load
duke
parents:
diff changeset
265 // %%% Here is an old comment from parseHelper.cpp; is it outdated?
a61af66fc99e Initial load
duke
parents:
diff changeset
266 // The allocator will coalesce int->oop copies away. See comment in
a61af66fc99e Initial load
duke
parents:
diff changeset
267 // coalesce.cpp about how this works. It depends critically on the exact
a61af66fc99e Initial load
duke
parents:
diff changeset
268 // code shape produced here, so if you are changing this code shape
a61af66fc99e Initial load
duke
parents:
diff changeset
269 // make sure the GC info for the heap-top is correct in and around the
a61af66fc99e Initial load
duke
parents:
diff changeset
270 // slow-path call.
a61af66fc99e Initial load
duke
parents:
diff changeset
271 //
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 void PhaseMacroExpand::expand_allocate_common(
a61af66fc99e Initial load
duke
parents:
diff changeset
274 AllocateNode* alloc, // allocation node to be expanded
a61af66fc99e Initial load
duke
parents:
diff changeset
275 Node* length, // array length for an array allocation
a61af66fc99e Initial load
duke
parents:
diff changeset
276 const TypeFunc* slow_call_type, // Type of slow call
a61af66fc99e Initial load
duke
parents:
diff changeset
277 address slow_call_address // Address of slow call
a61af66fc99e Initial load
duke
parents:
diff changeset
278 )
a61af66fc99e Initial load
duke
parents:
diff changeset
279 {
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281 Node* ctrl = alloc->in(TypeFunc::Control);
a61af66fc99e Initial load
duke
parents:
diff changeset
282 Node* mem = alloc->in(TypeFunc::Memory);
a61af66fc99e Initial load
duke
parents:
diff changeset
283 Node* i_o = alloc->in(TypeFunc::I_O);
a61af66fc99e Initial load
duke
parents:
diff changeset
284 Node* size_in_bytes = alloc->in(AllocateNode::AllocSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
285 Node* klass_node = alloc->in(AllocateNode::KlassNode);
a61af66fc99e Initial load
duke
parents:
diff changeset
286 Node* initial_slow_test = alloc->in(AllocateNode::InitialTest);
a61af66fc99e Initial load
duke
parents:
diff changeset
287
a61af66fc99e Initial load
duke
parents:
diff changeset
288 Node* eden_top_adr;
a61af66fc99e Initial load
duke
parents:
diff changeset
289 Node* eden_end_adr;
a61af66fc99e Initial load
duke
parents:
diff changeset
290 set_eden_pointers(eden_top_adr, eden_end_adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
291
a61af66fc99e Initial load
duke
parents:
diff changeset
292 uint raw_idx = C->get_alias_index(TypeRawPtr::BOTTOM);
a61af66fc99e Initial load
duke
parents:
diff changeset
293 assert(ctrl != NULL, "must have control");
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // Load Eden::end. Loop invariant and hoisted.
a61af66fc99e Initial load
duke
parents:
diff changeset
296 //
a61af66fc99e Initial load
duke
parents:
diff changeset
297 // Note: We set the control input on "eden_end" and "old_eden_top" when using
a61af66fc99e Initial load
duke
parents:
diff changeset
298 // a TLAB to work around a bug where these values were being moved across
a61af66fc99e Initial load
duke
parents:
diff changeset
299 // a safepoint. These are not oops, so they cannot be include in the oop
a61af66fc99e Initial load
duke
parents:
diff changeset
300 // map, but the can be changed by a GC. The proper way to fix this would
a61af66fc99e Initial load
duke
parents:
diff changeset
301 // be to set the raw memory state when generating a SafepointNode. However
a61af66fc99e Initial load
duke
parents:
diff changeset
302 // this will require extensive changes to the loop optimization in order to
a61af66fc99e Initial load
duke
parents:
diff changeset
303 // prevent a degradation of the optimization.
a61af66fc99e Initial load
duke
parents:
diff changeset
304 // See comment in memnode.hpp, around line 227 in class LoadPNode.
a61af66fc99e Initial load
duke
parents:
diff changeset
305 Node* eden_end = make_load(ctrl, mem, eden_end_adr, 0, TypeRawPtr::BOTTOM, T_ADDRESS);
a61af66fc99e Initial load
duke
parents:
diff changeset
306
a61af66fc99e Initial load
duke
parents:
diff changeset
307 // We need a Region and corresponding Phi's to merge the slow-path and fast-path results.
a61af66fc99e Initial load
duke
parents:
diff changeset
308 // they will not be used if "always_slow" is set
a61af66fc99e Initial load
duke
parents:
diff changeset
309 enum { slow_result_path = 1, fast_result_path = 2 };
a61af66fc99e Initial load
duke
parents:
diff changeset
310 Node *result_region;
a61af66fc99e Initial load
duke
parents:
diff changeset
311 Node *result_phi_rawmem;
a61af66fc99e Initial load
duke
parents:
diff changeset
312 Node *result_phi_rawoop;
a61af66fc99e Initial load
duke
parents:
diff changeset
313 Node *result_phi_i_o;
a61af66fc99e Initial load
duke
parents:
diff changeset
314
a61af66fc99e Initial load
duke
parents:
diff changeset
315 // The initial slow comparison is a size check, the comparison
a61af66fc99e Initial load
duke
parents:
diff changeset
316 // we want to do is a BoolTest::gt
a61af66fc99e Initial load
duke
parents:
diff changeset
317 bool always_slow = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
318 int tv = _igvn.find_int_con(initial_slow_test, -1);
a61af66fc99e Initial load
duke
parents:
diff changeset
319 if (tv >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
320 always_slow = (tv == 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
321 initial_slow_test = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
322 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 initial_slow_test = BoolNode::make_predicate(initial_slow_test, &_igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
324 }
a61af66fc99e Initial load
duke
parents:
diff changeset
325
a61af66fc99e Initial load
duke
parents:
diff changeset
326 if (DTraceAllocProbes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
327 // Force slow-path allocation
a61af66fc99e Initial load
duke
parents:
diff changeset
328 always_slow = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
329 initial_slow_test = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331
a61af66fc99e Initial load
duke
parents:
diff changeset
332 enum { too_big_or_final_path = 1, need_gc_path = 2 };
a61af66fc99e Initial load
duke
parents:
diff changeset
333 Node *slow_region = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
334 Node *toobig_false = ctrl;
a61af66fc99e Initial load
duke
parents:
diff changeset
335
a61af66fc99e Initial load
duke
parents:
diff changeset
336 assert (initial_slow_test == NULL || !always_slow, "arguments must be consistent");
a61af66fc99e Initial load
duke
parents:
diff changeset
337 // generate the initial test if necessary
a61af66fc99e Initial load
duke
parents:
diff changeset
338 if (initial_slow_test != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 slow_region = new (C, 3) RegionNode(3);
a61af66fc99e Initial load
duke
parents:
diff changeset
340
a61af66fc99e Initial load
duke
parents:
diff changeset
341 // Now make the initial failure test. Usually a too-big test but
a61af66fc99e Initial load
duke
parents:
diff changeset
342 // might be a TRUE for finalizers or a fancy class check for
a61af66fc99e Initial load
duke
parents:
diff changeset
343 // newInstance0.
a61af66fc99e Initial load
duke
parents:
diff changeset
344 IfNode *toobig_iff = new (C, 2) IfNode(ctrl, initial_slow_test, PROB_MIN, COUNT_UNKNOWN);
a61af66fc99e Initial load
duke
parents:
diff changeset
345 transform_later(toobig_iff);
a61af66fc99e Initial load
duke
parents:
diff changeset
346 // Plug the failing-too-big test into the slow-path region
a61af66fc99e Initial load
duke
parents:
diff changeset
347 Node *toobig_true = new (C, 1) IfTrueNode( toobig_iff );
a61af66fc99e Initial load
duke
parents:
diff changeset
348 transform_later(toobig_true);
a61af66fc99e Initial load
duke
parents:
diff changeset
349 slow_region ->init_req( too_big_or_final_path, toobig_true );
a61af66fc99e Initial load
duke
parents:
diff changeset
350 toobig_false = new (C, 1) IfFalseNode( toobig_iff );
a61af66fc99e Initial load
duke
parents:
diff changeset
351 transform_later(toobig_false);
a61af66fc99e Initial load
duke
parents:
diff changeset
352 } else { // No initial test, just fall into next case
a61af66fc99e Initial load
duke
parents:
diff changeset
353 toobig_false = ctrl;
a61af66fc99e Initial load
duke
parents:
diff changeset
354 debug_only(slow_region = NodeSentinel);
a61af66fc99e Initial load
duke
parents:
diff changeset
355 }
a61af66fc99e Initial load
duke
parents:
diff changeset
356
a61af66fc99e Initial load
duke
parents:
diff changeset
357 Node *slow_mem = mem; // save the current memory state for slow path
a61af66fc99e Initial load
duke
parents:
diff changeset
358 // generate the fast allocation code unless we know that the initial test will always go slow
a61af66fc99e Initial load
duke
parents:
diff changeset
359 if (!always_slow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
360 // allocate the Region and Phi nodes for the result
a61af66fc99e Initial load
duke
parents:
diff changeset
361 result_region = new (C, 3) RegionNode(3);
a61af66fc99e Initial load
duke
parents:
diff changeset
362 result_phi_rawmem = new (C, 3) PhiNode( result_region, Type::MEMORY, TypeRawPtr::BOTTOM );
a61af66fc99e Initial load
duke
parents:
diff changeset
363 result_phi_rawoop = new (C, 3) PhiNode( result_region, TypeRawPtr::BOTTOM );
a61af66fc99e Initial load
duke
parents:
diff changeset
364 result_phi_i_o = new (C, 3) PhiNode( result_region, Type::ABIO ); // I/O is used for Prefetch
a61af66fc99e Initial load
duke
parents:
diff changeset
365
a61af66fc99e Initial load
duke
parents:
diff changeset
366 // We need a Region for the loop-back contended case.
a61af66fc99e Initial load
duke
parents:
diff changeset
367 enum { fall_in_path = 1, contended_loopback_path = 2 };
a61af66fc99e Initial load
duke
parents:
diff changeset
368 Node *contended_region;
a61af66fc99e Initial load
duke
parents:
diff changeset
369 Node *contended_phi_rawmem;
a61af66fc99e Initial load
duke
parents:
diff changeset
370 if( UseTLAB ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
371 contended_region = toobig_false;
a61af66fc99e Initial load
duke
parents:
diff changeset
372 contended_phi_rawmem = mem;
a61af66fc99e Initial load
duke
parents:
diff changeset
373 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
374 contended_region = new (C, 3) RegionNode(3);
a61af66fc99e Initial load
duke
parents:
diff changeset
375 contended_phi_rawmem = new (C, 3) PhiNode( contended_region, Type::MEMORY, TypeRawPtr::BOTTOM);
a61af66fc99e Initial load
duke
parents:
diff changeset
376 // Now handle the passing-too-big test. We fall into the contended
a61af66fc99e Initial load
duke
parents:
diff changeset
377 // loop-back merge point.
a61af66fc99e Initial load
duke
parents:
diff changeset
378 contended_region ->init_req( fall_in_path, toobig_false );
a61af66fc99e Initial load
duke
parents:
diff changeset
379 contended_phi_rawmem->init_req( fall_in_path, mem );
a61af66fc99e Initial load
duke
parents:
diff changeset
380 transform_later(contended_region);
a61af66fc99e Initial load
duke
parents:
diff changeset
381 transform_later(contended_phi_rawmem);
a61af66fc99e Initial load
duke
parents:
diff changeset
382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
383
a61af66fc99e Initial load
duke
parents:
diff changeset
384 // Load(-locked) the heap top.
a61af66fc99e Initial load
duke
parents:
diff changeset
385 // See note above concerning the control input when using a TLAB
a61af66fc99e Initial load
duke
parents:
diff changeset
386 Node *old_eden_top = UseTLAB
a61af66fc99e Initial load
duke
parents:
diff changeset
387 ? new (C, 3) LoadPNode ( ctrl, contended_phi_rawmem, eden_top_adr, TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM )
a61af66fc99e Initial load
duke
parents:
diff changeset
388 : new (C, 3) LoadPLockedNode( contended_region, contended_phi_rawmem, eden_top_adr );
a61af66fc99e Initial load
duke
parents:
diff changeset
389
a61af66fc99e Initial load
duke
parents:
diff changeset
390 transform_later(old_eden_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
391 // Add to heap top to get a new heap top
a61af66fc99e Initial load
duke
parents:
diff changeset
392 Node *new_eden_top = new (C, 4) AddPNode( top(), old_eden_top, size_in_bytes );
a61af66fc99e Initial load
duke
parents:
diff changeset
393 transform_later(new_eden_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
394 // Check for needing a GC; compare against heap end
a61af66fc99e Initial load
duke
parents:
diff changeset
395 Node *needgc_cmp = new (C, 3) CmpPNode( new_eden_top, eden_end );
a61af66fc99e Initial load
duke
parents:
diff changeset
396 transform_later(needgc_cmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
397 Node *needgc_bol = new (C, 2) BoolNode( needgc_cmp, BoolTest::ge );
a61af66fc99e Initial load
duke
parents:
diff changeset
398 transform_later(needgc_bol);
a61af66fc99e Initial load
duke
parents:
diff changeset
399 IfNode *needgc_iff = new (C, 2) IfNode(contended_region, needgc_bol, PROB_UNLIKELY_MAG(4), COUNT_UNKNOWN );
a61af66fc99e Initial load
duke
parents:
diff changeset
400 transform_later(needgc_iff);
a61af66fc99e Initial load
duke
parents:
diff changeset
401
a61af66fc99e Initial load
duke
parents:
diff changeset
402 // Plug the failing-heap-space-need-gc test into the slow-path region
a61af66fc99e Initial load
duke
parents:
diff changeset
403 Node *needgc_true = new (C, 1) IfTrueNode( needgc_iff );
a61af66fc99e Initial load
duke
parents:
diff changeset
404 transform_later(needgc_true);
a61af66fc99e Initial load
duke
parents:
diff changeset
405 if( initial_slow_test ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
406 slow_region ->init_req( need_gc_path, needgc_true );
a61af66fc99e Initial load
duke
parents:
diff changeset
407 // This completes all paths into the slow merge point
a61af66fc99e Initial load
duke
parents:
diff changeset
408 transform_later(slow_region);
a61af66fc99e Initial load
duke
parents:
diff changeset
409 } else { // No initial slow path needed!
a61af66fc99e Initial load
duke
parents:
diff changeset
410 // Just fall from the need-GC path straight into the VM call.
a61af66fc99e Initial load
duke
parents:
diff changeset
411 slow_region = needgc_true;
a61af66fc99e Initial load
duke
parents:
diff changeset
412 }
a61af66fc99e Initial load
duke
parents:
diff changeset
413 // No need for a GC. Setup for the Store-Conditional
a61af66fc99e Initial load
duke
parents:
diff changeset
414 Node *needgc_false = new (C, 1) IfFalseNode( needgc_iff );
a61af66fc99e Initial load
duke
parents:
diff changeset
415 transform_later(needgc_false);
a61af66fc99e Initial load
duke
parents:
diff changeset
416
a61af66fc99e Initial load
duke
parents:
diff changeset
417 // Grab regular I/O before optional prefetch may change it.
a61af66fc99e Initial load
duke
parents:
diff changeset
418 // Slow-path does no I/O so just set it to the original I/O.
a61af66fc99e Initial load
duke
parents:
diff changeset
419 result_phi_i_o->init_req( slow_result_path, i_o );
a61af66fc99e Initial load
duke
parents:
diff changeset
420
a61af66fc99e Initial load
duke
parents:
diff changeset
421 i_o = prefetch_allocation(i_o, needgc_false, contended_phi_rawmem,
a61af66fc99e Initial load
duke
parents:
diff changeset
422 old_eden_top, new_eden_top, length);
a61af66fc99e Initial load
duke
parents:
diff changeset
423
a61af66fc99e Initial load
duke
parents:
diff changeset
424 // Store (-conditional) the modified eden top back down.
a61af66fc99e Initial load
duke
parents:
diff changeset
425 // StorePConditional produces flags for a test PLUS a modified raw
a61af66fc99e Initial load
duke
parents:
diff changeset
426 // memory state.
a61af66fc99e Initial load
duke
parents:
diff changeset
427 Node *store_eden_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
428 Node *fast_oop_ctrl;
a61af66fc99e Initial load
duke
parents:
diff changeset
429 if( UseTLAB ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
430 store_eden_top = new (C, 4) StorePNode( needgc_false, contended_phi_rawmem, eden_top_adr, TypeRawPtr::BOTTOM, new_eden_top );
a61af66fc99e Initial load
duke
parents:
diff changeset
431 transform_later(store_eden_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
432 fast_oop_ctrl = needgc_false; // No contention, so this is the fast path
a61af66fc99e Initial load
duke
parents:
diff changeset
433 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
434 store_eden_top = new (C, 5) StorePConditionalNode( needgc_false, contended_phi_rawmem, eden_top_adr, new_eden_top, old_eden_top );
a61af66fc99e Initial load
duke
parents:
diff changeset
435 transform_later(store_eden_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
436 Node *contention_check = new (C, 2) BoolNode( store_eden_top, BoolTest::ne );
a61af66fc99e Initial load
duke
parents:
diff changeset
437 transform_later(contention_check);
a61af66fc99e Initial load
duke
parents:
diff changeset
438 store_eden_top = new (C, 1) SCMemProjNode(store_eden_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
439 transform_later(store_eden_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
440
a61af66fc99e Initial load
duke
parents:
diff changeset
441 // If not using TLABs, check to see if there was contention.
a61af66fc99e Initial load
duke
parents:
diff changeset
442 IfNode *contention_iff = new (C, 2) IfNode ( needgc_false, contention_check, PROB_MIN, COUNT_UNKNOWN );
a61af66fc99e Initial load
duke
parents:
diff changeset
443 transform_later(contention_iff);
a61af66fc99e Initial load
duke
parents:
diff changeset
444 Node *contention_true = new (C, 1) IfTrueNode( contention_iff );
a61af66fc99e Initial load
duke
parents:
diff changeset
445 transform_later(contention_true);
a61af66fc99e Initial load
duke
parents:
diff changeset
446 // If contention, loopback and try again.
a61af66fc99e Initial load
duke
parents:
diff changeset
447 contended_region->init_req( contended_loopback_path, contention_true );
a61af66fc99e Initial load
duke
parents:
diff changeset
448 contended_phi_rawmem->init_req( contended_loopback_path, store_eden_top );
a61af66fc99e Initial load
duke
parents:
diff changeset
449
a61af66fc99e Initial load
duke
parents:
diff changeset
450 // Fast-path succeeded with no contention!
a61af66fc99e Initial load
duke
parents:
diff changeset
451 Node *contention_false = new (C, 1) IfFalseNode( contention_iff );
a61af66fc99e Initial load
duke
parents:
diff changeset
452 transform_later(contention_false);
a61af66fc99e Initial load
duke
parents:
diff changeset
453 fast_oop_ctrl = contention_false;
a61af66fc99e Initial load
duke
parents:
diff changeset
454 }
a61af66fc99e Initial load
duke
parents:
diff changeset
455
a61af66fc99e Initial load
duke
parents:
diff changeset
456 // Rename successful fast-path variables to make meaning more obvious
a61af66fc99e Initial load
duke
parents:
diff changeset
457 Node* fast_oop = old_eden_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
458 Node* fast_oop_rawmem = store_eden_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
459 fast_oop_rawmem = initialize_object(alloc,
a61af66fc99e Initial load
duke
parents:
diff changeset
460 fast_oop_ctrl, fast_oop_rawmem, fast_oop,
a61af66fc99e Initial load
duke
parents:
diff changeset
461 klass_node, length, size_in_bytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
462
a61af66fc99e Initial load
duke
parents:
diff changeset
463 if (ExtendedDTraceProbes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
464 // Slow-path call
a61af66fc99e Initial load
duke
parents:
diff changeset
465 int size = TypeFunc::Parms + 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
466 CallLeafNode *call = new (C, size) CallLeafNode(OptoRuntime::dtrace_object_alloc_Type(),
a61af66fc99e Initial load
duke
parents:
diff changeset
467 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc_base),
a61af66fc99e Initial load
duke
parents:
diff changeset
468 "dtrace_object_alloc",
a61af66fc99e Initial load
duke
parents:
diff changeset
469 TypeRawPtr::BOTTOM);
a61af66fc99e Initial load
duke
parents:
diff changeset
470
a61af66fc99e Initial load
duke
parents:
diff changeset
471 // Get base of thread-local storage area
a61af66fc99e Initial load
duke
parents:
diff changeset
472 Node* thread = new (C, 1) ThreadLocalNode();
a61af66fc99e Initial load
duke
parents:
diff changeset
473 transform_later(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
474
a61af66fc99e Initial load
duke
parents:
diff changeset
475 call->init_req(TypeFunc::Parms+0, thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
476 call->init_req(TypeFunc::Parms+1, fast_oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
477 call->init_req( TypeFunc::Control, fast_oop_ctrl );
a61af66fc99e Initial load
duke
parents:
diff changeset
478 call->init_req( TypeFunc::I_O , top() ) ; // does no i/o
a61af66fc99e Initial load
duke
parents:
diff changeset
479 call->init_req( TypeFunc::Memory , fast_oop_rawmem );
a61af66fc99e Initial load
duke
parents:
diff changeset
480 call->init_req( TypeFunc::ReturnAdr, alloc->in(TypeFunc::ReturnAdr) );
a61af66fc99e Initial load
duke
parents:
diff changeset
481 call->init_req( TypeFunc::FramePtr, alloc->in(TypeFunc::FramePtr) );
a61af66fc99e Initial load
duke
parents:
diff changeset
482 transform_later(call);
a61af66fc99e Initial load
duke
parents:
diff changeset
483 fast_oop_ctrl = new (C, 1) ProjNode(call,TypeFunc::Control);
a61af66fc99e Initial load
duke
parents:
diff changeset
484 transform_later(fast_oop_ctrl);
a61af66fc99e Initial load
duke
parents:
diff changeset
485 fast_oop_rawmem = new (C, 1) ProjNode(call,TypeFunc::Memory);
a61af66fc99e Initial load
duke
parents:
diff changeset
486 transform_later(fast_oop_rawmem);
a61af66fc99e Initial load
duke
parents:
diff changeset
487 }
a61af66fc99e Initial load
duke
parents:
diff changeset
488
a61af66fc99e Initial load
duke
parents:
diff changeset
489 // Plug in the successful fast-path into the result merge point
a61af66fc99e Initial load
duke
parents:
diff changeset
490 result_region ->init_req( fast_result_path, fast_oop_ctrl );
a61af66fc99e Initial load
duke
parents:
diff changeset
491 result_phi_rawoop->init_req( fast_result_path, fast_oop );
a61af66fc99e Initial load
duke
parents:
diff changeset
492 result_phi_i_o ->init_req( fast_result_path, i_o );
a61af66fc99e Initial load
duke
parents:
diff changeset
493 result_phi_rawmem->init_req( fast_result_path, fast_oop_rawmem );
a61af66fc99e Initial load
duke
parents:
diff changeset
494 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
495 slow_region = ctrl;
a61af66fc99e Initial load
duke
parents:
diff changeset
496 }
a61af66fc99e Initial load
duke
parents:
diff changeset
497
a61af66fc99e Initial load
duke
parents:
diff changeset
498 // Generate slow-path call
a61af66fc99e Initial load
duke
parents:
diff changeset
499 CallNode *call = new (C, slow_call_type->domain()->cnt())
a61af66fc99e Initial load
duke
parents:
diff changeset
500 CallStaticJavaNode(slow_call_type, slow_call_address,
a61af66fc99e Initial load
duke
parents:
diff changeset
501 OptoRuntime::stub_name(slow_call_address),
a61af66fc99e Initial load
duke
parents:
diff changeset
502 alloc->jvms()->bci(),
a61af66fc99e Initial load
duke
parents:
diff changeset
503 TypePtr::BOTTOM);
a61af66fc99e Initial load
duke
parents:
diff changeset
504 call->init_req( TypeFunc::Control, slow_region );
a61af66fc99e Initial load
duke
parents:
diff changeset
505 call->init_req( TypeFunc::I_O , top() ) ; // does no i/o
a61af66fc99e Initial load
duke
parents:
diff changeset
506 call->init_req( TypeFunc::Memory , slow_mem ); // may gc ptrs
a61af66fc99e Initial load
duke
parents:
diff changeset
507 call->init_req( TypeFunc::ReturnAdr, alloc->in(TypeFunc::ReturnAdr) );
a61af66fc99e Initial load
duke
parents:
diff changeset
508 call->init_req( TypeFunc::FramePtr, alloc->in(TypeFunc::FramePtr) );
a61af66fc99e Initial load
duke
parents:
diff changeset
509
a61af66fc99e Initial load
duke
parents:
diff changeset
510 call->init_req(TypeFunc::Parms+0, klass_node);
a61af66fc99e Initial load
duke
parents:
diff changeset
511 if (length != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
512 call->init_req(TypeFunc::Parms+1, length);
a61af66fc99e Initial load
duke
parents:
diff changeset
513 }
a61af66fc99e Initial load
duke
parents:
diff changeset
514
a61af66fc99e Initial load
duke
parents:
diff changeset
515 // Copy debug information and adjust JVMState information, then replace
a61af66fc99e Initial load
duke
parents:
diff changeset
516 // allocate node with the call
a61af66fc99e Initial load
duke
parents:
diff changeset
517 copy_call_debug_info((CallNode *) alloc, call);
a61af66fc99e Initial load
duke
parents:
diff changeset
518 if (!always_slow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
519 call->set_cnt(PROB_UNLIKELY_MAG(4)); // Same effect as RC_UNCOMMON.
a61af66fc99e Initial load
duke
parents:
diff changeset
520 }
a61af66fc99e Initial load
duke
parents:
diff changeset
521 _igvn.hash_delete(alloc);
a61af66fc99e Initial load
duke
parents:
diff changeset
522 _igvn.subsume_node(alloc, call);
a61af66fc99e Initial load
duke
parents:
diff changeset
523 transform_later(call);
a61af66fc99e Initial load
duke
parents:
diff changeset
524
a61af66fc99e Initial load
duke
parents:
diff changeset
525 // Identify the output projections from the allocate node and
a61af66fc99e Initial load
duke
parents:
diff changeset
526 // adjust any references to them.
a61af66fc99e Initial load
duke
parents:
diff changeset
527 // The control and io projections look like:
a61af66fc99e Initial load
duke
parents:
diff changeset
528 //
a61af66fc99e Initial load
duke
parents:
diff changeset
529 // v---Proj(ctrl) <-----+ v---CatchProj(ctrl)
a61af66fc99e Initial load
duke
parents:
diff changeset
530 // Allocate Catch
a61af66fc99e Initial load
duke
parents:
diff changeset
531 // ^---Proj(io) <-------+ ^---CatchProj(io)
a61af66fc99e Initial load
duke
parents:
diff changeset
532 //
a61af66fc99e Initial load
duke
parents:
diff changeset
533 // We are interested in the CatchProj nodes.
a61af66fc99e Initial load
duke
parents:
diff changeset
534 //
a61af66fc99e Initial load
duke
parents:
diff changeset
535 extract_call_projections(call);
a61af66fc99e Initial load
duke
parents:
diff changeset
536
a61af66fc99e Initial load
duke
parents:
diff changeset
537 // An allocate node has separate memory projections for the uses on the control and i_o paths
a61af66fc99e Initial load
duke
parents:
diff changeset
538 // Replace uses of the control memory projection with result_phi_rawmem (unless we are only generating a slow call)
a61af66fc99e Initial load
duke
parents:
diff changeset
539 if (!always_slow && _memproj_fallthrough != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
540 for (DUIterator_Fast imax, i = _memproj_fallthrough->fast_outs(imax); i < imax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
541 Node *use = _memproj_fallthrough->fast_out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
542 _igvn.hash_delete(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
543 imax -= replace_input(use, _memproj_fallthrough, result_phi_rawmem);
a61af66fc99e Initial load
duke
parents:
diff changeset
544 _igvn._worklist.push(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
545 // back up iterator
a61af66fc99e Initial load
duke
parents:
diff changeset
546 --i;
a61af66fc99e Initial load
duke
parents:
diff changeset
547 }
a61af66fc99e Initial load
duke
parents:
diff changeset
548 }
a61af66fc99e Initial load
duke
parents:
diff changeset
549 // Now change uses of _memproj_catchall to use _memproj_fallthrough and delete _memproj_catchall so
a61af66fc99e Initial load
duke
parents:
diff changeset
550 // we end up with a call that has only 1 memory projection
a61af66fc99e Initial load
duke
parents:
diff changeset
551 if (_memproj_catchall != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
552 if (_memproj_fallthrough == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
553 _memproj_fallthrough = new (C, 1) ProjNode(call, TypeFunc::Memory);
a61af66fc99e Initial load
duke
parents:
diff changeset
554 transform_later(_memproj_fallthrough);
a61af66fc99e Initial load
duke
parents:
diff changeset
555 }
a61af66fc99e Initial load
duke
parents:
diff changeset
556 for (DUIterator_Fast imax, i = _memproj_catchall->fast_outs(imax); i < imax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
557 Node *use = _memproj_catchall->fast_out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
558 _igvn.hash_delete(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
559 imax -= replace_input(use, _memproj_catchall, _memproj_fallthrough);
a61af66fc99e Initial load
duke
parents:
diff changeset
560 _igvn._worklist.push(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
561 // back up iterator
a61af66fc99e Initial load
duke
parents:
diff changeset
562 --i;
a61af66fc99e Initial load
duke
parents:
diff changeset
563 }
a61af66fc99e Initial load
duke
parents:
diff changeset
564 }
a61af66fc99e Initial load
duke
parents:
diff changeset
565
a61af66fc99e Initial load
duke
parents:
diff changeset
566 mem = result_phi_rawmem;
a61af66fc99e Initial load
duke
parents:
diff changeset
567
a61af66fc99e Initial load
duke
parents:
diff changeset
568 // An allocate node has separate i_o projections for the uses on the control and i_o paths
a61af66fc99e Initial load
duke
parents:
diff changeset
569 // Replace uses of the control i_o projection with result_phi_i_o (unless we are only generating a slow call)
a61af66fc99e Initial load
duke
parents:
diff changeset
570 if (_ioproj_fallthrough == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
571 _ioproj_fallthrough = new (C, 1) ProjNode(call, TypeFunc::I_O);
a61af66fc99e Initial load
duke
parents:
diff changeset
572 transform_later(_ioproj_fallthrough);
a61af66fc99e Initial load
duke
parents:
diff changeset
573 } else if (!always_slow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
574 for (DUIterator_Fast imax, i = _ioproj_fallthrough->fast_outs(imax); i < imax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
575 Node *use = _ioproj_fallthrough->fast_out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
576
a61af66fc99e Initial load
duke
parents:
diff changeset
577 _igvn.hash_delete(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
578 imax -= replace_input(use, _ioproj_fallthrough, result_phi_i_o);
a61af66fc99e Initial load
duke
parents:
diff changeset
579 _igvn._worklist.push(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
580 // back up iterator
a61af66fc99e Initial load
duke
parents:
diff changeset
581 --i;
a61af66fc99e Initial load
duke
parents:
diff changeset
582 }
a61af66fc99e Initial load
duke
parents:
diff changeset
583 }
a61af66fc99e Initial load
duke
parents:
diff changeset
584 // Now change uses of _ioproj_catchall to use _ioproj_fallthrough and delete _ioproj_catchall so
a61af66fc99e Initial load
duke
parents:
diff changeset
585 // we end up with a call that has only 1 control projection
a61af66fc99e Initial load
duke
parents:
diff changeset
586 if (_ioproj_catchall != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
587 for (DUIterator_Fast imax, i = _ioproj_catchall->fast_outs(imax); i < imax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
588 Node *use = _ioproj_catchall->fast_out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
589 _igvn.hash_delete(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
590 imax -= replace_input(use, _ioproj_catchall, _ioproj_fallthrough);
a61af66fc99e Initial load
duke
parents:
diff changeset
591 _igvn._worklist.push(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
592 // back up iterator
a61af66fc99e Initial load
duke
parents:
diff changeset
593 --i;
a61af66fc99e Initial load
duke
parents:
diff changeset
594 }
a61af66fc99e Initial load
duke
parents:
diff changeset
595 }
a61af66fc99e Initial load
duke
parents:
diff changeset
596
a61af66fc99e Initial load
duke
parents:
diff changeset
597 // if we generated only a slow call, we are done
a61af66fc99e Initial load
duke
parents:
diff changeset
598 if (always_slow)
a61af66fc99e Initial load
duke
parents:
diff changeset
599 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
600
a61af66fc99e Initial load
duke
parents:
diff changeset
601
a61af66fc99e Initial load
duke
parents:
diff changeset
602 if (_fallthroughcatchproj != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
603 ctrl = _fallthroughcatchproj->clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
604 transform_later(ctrl);
a61af66fc99e Initial load
duke
parents:
diff changeset
605 _igvn.hash_delete(_fallthroughcatchproj);
a61af66fc99e Initial load
duke
parents:
diff changeset
606 _igvn.subsume_node(_fallthroughcatchproj, result_region);
a61af66fc99e Initial load
duke
parents:
diff changeset
607 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
608 ctrl = top();
a61af66fc99e Initial load
duke
parents:
diff changeset
609 }
a61af66fc99e Initial load
duke
parents:
diff changeset
610 Node *slow_result;
a61af66fc99e Initial load
duke
parents:
diff changeset
611 if (_resproj == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
612 // no uses of the allocation result
a61af66fc99e Initial load
duke
parents:
diff changeset
613 slow_result = top();
a61af66fc99e Initial load
duke
parents:
diff changeset
614 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
615 slow_result = _resproj->clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
616 transform_later(slow_result);
a61af66fc99e Initial load
duke
parents:
diff changeset
617 _igvn.hash_delete(_resproj);
a61af66fc99e Initial load
duke
parents:
diff changeset
618 _igvn.subsume_node(_resproj, result_phi_rawoop);
a61af66fc99e Initial load
duke
parents:
diff changeset
619 }
a61af66fc99e Initial load
duke
parents:
diff changeset
620
a61af66fc99e Initial load
duke
parents:
diff changeset
621 // Plug slow-path into result merge point
a61af66fc99e Initial load
duke
parents:
diff changeset
622 result_region ->init_req( slow_result_path, ctrl );
a61af66fc99e Initial load
duke
parents:
diff changeset
623 result_phi_rawoop->init_req( slow_result_path, slow_result);
a61af66fc99e Initial load
duke
parents:
diff changeset
624 result_phi_rawmem->init_req( slow_result_path, _memproj_fallthrough );
a61af66fc99e Initial load
duke
parents:
diff changeset
625 transform_later(result_region);
a61af66fc99e Initial load
duke
parents:
diff changeset
626 transform_later(result_phi_rawoop);
a61af66fc99e Initial load
duke
parents:
diff changeset
627 transform_later(result_phi_rawmem);
a61af66fc99e Initial load
duke
parents:
diff changeset
628 transform_later(result_phi_i_o);
a61af66fc99e Initial load
duke
parents:
diff changeset
629 // This completes all paths into the result merge point
a61af66fc99e Initial load
duke
parents:
diff changeset
630 }
a61af66fc99e Initial load
duke
parents:
diff changeset
631
a61af66fc99e Initial load
duke
parents:
diff changeset
632
a61af66fc99e Initial load
duke
parents:
diff changeset
633 // Helper for PhaseMacroExpand::expand_allocate_common.
a61af66fc99e Initial load
duke
parents:
diff changeset
634 // Initializes the newly-allocated storage.
a61af66fc99e Initial load
duke
parents:
diff changeset
635 Node*
a61af66fc99e Initial load
duke
parents:
diff changeset
636 PhaseMacroExpand::initialize_object(AllocateNode* alloc,
a61af66fc99e Initial load
duke
parents:
diff changeset
637 Node* control, Node* rawmem, Node* object,
a61af66fc99e Initial load
duke
parents:
diff changeset
638 Node* klass_node, Node* length,
a61af66fc99e Initial load
duke
parents:
diff changeset
639 Node* size_in_bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
640 InitializeNode* init = alloc->initialization();
a61af66fc99e Initial load
duke
parents:
diff changeset
641 // Store the klass & mark bits
a61af66fc99e Initial load
duke
parents:
diff changeset
642 Node* mark_node = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
643 // For now only enable fast locking for non-array types
a61af66fc99e Initial load
duke
parents:
diff changeset
644 if (UseBiasedLocking && (length == NULL)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
645 mark_node = make_load(NULL, rawmem, klass_node, Klass::prototype_header_offset_in_bytes() + sizeof(oopDesc), TypeRawPtr::BOTTOM, T_ADDRESS);
a61af66fc99e Initial load
duke
parents:
diff changeset
646 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
647 mark_node = makecon(TypeRawPtr::make((address)markOopDesc::prototype()));
a61af66fc99e Initial load
duke
parents:
diff changeset
648 }
a61af66fc99e Initial load
duke
parents:
diff changeset
649 rawmem = make_store(control, rawmem, object, oopDesc::mark_offset_in_bytes(), mark_node, T_ADDRESS);
a61af66fc99e Initial load
duke
parents:
diff changeset
650 rawmem = make_store(control, rawmem, object, oopDesc::klass_offset_in_bytes(), klass_node, T_OBJECT);
a61af66fc99e Initial load
duke
parents:
diff changeset
651 int header_size = alloc->minimum_header_size(); // conservatively small
a61af66fc99e Initial load
duke
parents:
diff changeset
652
a61af66fc99e Initial load
duke
parents:
diff changeset
653 // Array length
a61af66fc99e Initial load
duke
parents:
diff changeset
654 if (length != NULL) { // Arrays need length field
a61af66fc99e Initial load
duke
parents:
diff changeset
655 rawmem = make_store(control, rawmem, object, arrayOopDesc::length_offset_in_bytes(), length, T_INT);
a61af66fc99e Initial load
duke
parents:
diff changeset
656 // conservatively small header size:
a61af66fc99e Initial load
duke
parents:
diff changeset
657 header_size = sizeof(arrayOopDesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
658 ciKlass* k = _igvn.type(klass_node)->is_klassptr()->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
659 if (k->is_array_klass()) // we know the exact header size in most cases:
a61af66fc99e Initial load
duke
parents:
diff changeset
660 header_size = Klass::layout_helper_header_size(k->layout_helper());
a61af66fc99e Initial load
duke
parents:
diff changeset
661 }
a61af66fc99e Initial load
duke
parents:
diff changeset
662
a61af66fc99e Initial load
duke
parents:
diff changeset
663 // Clear the object body, if necessary.
a61af66fc99e Initial load
duke
parents:
diff changeset
664 if (init == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
665 // The init has somehow disappeared; be cautious and clear everything.
a61af66fc99e Initial load
duke
parents:
diff changeset
666 //
a61af66fc99e Initial load
duke
parents:
diff changeset
667 // This can happen if a node is allocated but an uncommon trap occurs
a61af66fc99e Initial load
duke
parents:
diff changeset
668 // immediately. In this case, the Initialize gets associated with the
a61af66fc99e Initial load
duke
parents:
diff changeset
669 // trap, and may be placed in a different (outer) loop, if the Allocate
a61af66fc99e Initial load
duke
parents:
diff changeset
670 // is in a loop. If (this is rare) the inner loop gets unrolled, then
a61af66fc99e Initial load
duke
parents:
diff changeset
671 // there can be two Allocates to one Initialize. The answer in all these
a61af66fc99e Initial load
duke
parents:
diff changeset
672 // edge cases is safety first. It is always safe to clear immediately
a61af66fc99e Initial load
duke
parents:
diff changeset
673 // within an Allocate, and then (maybe or maybe not) clear some more later.
a61af66fc99e Initial load
duke
parents:
diff changeset
674 if (!ZeroTLAB)
a61af66fc99e Initial load
duke
parents:
diff changeset
675 rawmem = ClearArrayNode::clear_memory(control, rawmem, object,
a61af66fc99e Initial load
duke
parents:
diff changeset
676 header_size, size_in_bytes,
a61af66fc99e Initial load
duke
parents:
diff changeset
677 &_igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
678 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
679 if (!init->is_complete()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
680 // Try to win by zeroing only what the init does not store.
a61af66fc99e Initial load
duke
parents:
diff changeset
681 // We can also try to do some peephole optimizations,
a61af66fc99e Initial load
duke
parents:
diff changeset
682 // such as combining some adjacent subword stores.
a61af66fc99e Initial load
duke
parents:
diff changeset
683 rawmem = init->complete_stores(control, rawmem, object,
a61af66fc99e Initial load
duke
parents:
diff changeset
684 header_size, size_in_bytes, &_igvn);
a61af66fc99e Initial load
duke
parents:
diff changeset
685 }
a61af66fc99e Initial load
duke
parents:
diff changeset
686
a61af66fc99e Initial load
duke
parents:
diff changeset
687 // We have no more use for this link, since the AllocateNode goes away:
a61af66fc99e Initial load
duke
parents:
diff changeset
688 init->set_req(InitializeNode::RawAddress, top());
a61af66fc99e Initial load
duke
parents:
diff changeset
689 // (If we keep the link, it just confuses the register allocator,
a61af66fc99e Initial load
duke
parents:
diff changeset
690 // who thinks he sees a real use of the address by the membar.)
a61af66fc99e Initial load
duke
parents:
diff changeset
691 }
a61af66fc99e Initial load
duke
parents:
diff changeset
692
a61af66fc99e Initial load
duke
parents:
diff changeset
693 return rawmem;
a61af66fc99e Initial load
duke
parents:
diff changeset
694 }
a61af66fc99e Initial load
duke
parents:
diff changeset
695
a61af66fc99e Initial load
duke
parents:
diff changeset
696 // Generate prefetch instructions for next allocations.
a61af66fc99e Initial load
duke
parents:
diff changeset
697 Node* PhaseMacroExpand::prefetch_allocation(Node* i_o, Node*& needgc_false,
a61af66fc99e Initial load
duke
parents:
diff changeset
698 Node*& contended_phi_rawmem,
a61af66fc99e Initial load
duke
parents:
diff changeset
699 Node* old_eden_top, Node* new_eden_top,
a61af66fc99e Initial load
duke
parents:
diff changeset
700 Node* length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
701 if( UseTLAB && AllocatePrefetchStyle == 2 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
702 // Generate prefetch allocation with watermark check.
a61af66fc99e Initial load
duke
parents:
diff changeset
703 // As an allocation hits the watermark, we will prefetch starting
a61af66fc99e Initial load
duke
parents:
diff changeset
704 // at a "distance" away from watermark.
a61af66fc99e Initial load
duke
parents:
diff changeset
705 enum { fall_in_path = 1, pf_path = 2 };
a61af66fc99e Initial load
duke
parents:
diff changeset
706
a61af66fc99e Initial load
duke
parents:
diff changeset
707 Node *pf_region = new (C, 3) RegionNode(3);
a61af66fc99e Initial load
duke
parents:
diff changeset
708 Node *pf_phi_rawmem = new (C, 3) PhiNode( pf_region, Type::MEMORY,
a61af66fc99e Initial load
duke
parents:
diff changeset
709 TypeRawPtr::BOTTOM );
a61af66fc99e Initial load
duke
parents:
diff changeset
710 // I/O is used for Prefetch
a61af66fc99e Initial load
duke
parents:
diff changeset
711 Node *pf_phi_abio = new (C, 3) PhiNode( pf_region, Type::ABIO );
a61af66fc99e Initial load
duke
parents:
diff changeset
712
a61af66fc99e Initial load
duke
parents:
diff changeset
713 Node *thread = new (C, 1) ThreadLocalNode();
a61af66fc99e Initial load
duke
parents:
diff changeset
714 transform_later(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
715
a61af66fc99e Initial load
duke
parents:
diff changeset
716 Node *eden_pf_adr = new (C, 4) AddPNode( top()/*not oop*/, thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
717 _igvn.MakeConX(in_bytes(JavaThread::tlab_pf_top_offset())) );
a61af66fc99e Initial load
duke
parents:
diff changeset
718 transform_later(eden_pf_adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
719
a61af66fc99e Initial load
duke
parents:
diff changeset
720 Node *old_pf_wm = new (C, 3) LoadPNode( needgc_false,
a61af66fc99e Initial load
duke
parents:
diff changeset
721 contended_phi_rawmem, eden_pf_adr,
a61af66fc99e Initial load
duke
parents:
diff changeset
722 TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM );
a61af66fc99e Initial load
duke
parents:
diff changeset
723 transform_later(old_pf_wm);
a61af66fc99e Initial load
duke
parents:
diff changeset
724
a61af66fc99e Initial load
duke
parents:
diff changeset
725 // check against new_eden_top
a61af66fc99e Initial load
duke
parents:
diff changeset
726 Node *need_pf_cmp = new (C, 3) CmpPNode( new_eden_top, old_pf_wm );
a61af66fc99e Initial load
duke
parents:
diff changeset
727 transform_later(need_pf_cmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
728 Node *need_pf_bol = new (C, 2) BoolNode( need_pf_cmp, BoolTest::ge );
a61af66fc99e Initial load
duke
parents:
diff changeset
729 transform_later(need_pf_bol);
a61af66fc99e Initial load
duke
parents:
diff changeset
730 IfNode *need_pf_iff = new (C, 2) IfNode( needgc_false, need_pf_bol,
a61af66fc99e Initial load
duke
parents:
diff changeset
731 PROB_UNLIKELY_MAG(4), COUNT_UNKNOWN );
a61af66fc99e Initial load
duke
parents:
diff changeset
732 transform_later(need_pf_iff);
a61af66fc99e Initial load
duke
parents:
diff changeset
733
a61af66fc99e Initial load
duke
parents:
diff changeset
734 // true node, add prefetchdistance
a61af66fc99e Initial load
duke
parents:
diff changeset
735 Node *need_pf_true = new (C, 1) IfTrueNode( need_pf_iff );
a61af66fc99e Initial load
duke
parents:
diff changeset
736 transform_later(need_pf_true);
a61af66fc99e Initial load
duke
parents:
diff changeset
737
a61af66fc99e Initial load
duke
parents:
diff changeset
738 Node *need_pf_false = new (C, 1) IfFalseNode( need_pf_iff );
a61af66fc99e Initial load
duke
parents:
diff changeset
739 transform_later(need_pf_false);
a61af66fc99e Initial load
duke
parents:
diff changeset
740
a61af66fc99e Initial load
duke
parents:
diff changeset
741 Node *new_pf_wmt = new (C, 4) AddPNode( top(), old_pf_wm,
a61af66fc99e Initial load
duke
parents:
diff changeset
742 _igvn.MakeConX(AllocatePrefetchDistance) );
a61af66fc99e Initial load
duke
parents:
diff changeset
743 transform_later(new_pf_wmt );
a61af66fc99e Initial load
duke
parents:
diff changeset
744 new_pf_wmt->set_req(0, need_pf_true);
a61af66fc99e Initial load
duke
parents:
diff changeset
745
a61af66fc99e Initial load
duke
parents:
diff changeset
746 Node *store_new_wmt = new (C, 4) StorePNode( need_pf_true,
a61af66fc99e Initial load
duke
parents:
diff changeset
747 contended_phi_rawmem, eden_pf_adr,
a61af66fc99e Initial load
duke
parents:
diff changeset
748 TypeRawPtr::BOTTOM, new_pf_wmt );
a61af66fc99e Initial load
duke
parents:
diff changeset
749 transform_later(store_new_wmt);
a61af66fc99e Initial load
duke
parents:
diff changeset
750
a61af66fc99e Initial load
duke
parents:
diff changeset
751 // adding prefetches
a61af66fc99e Initial load
duke
parents:
diff changeset
752 pf_phi_abio->init_req( fall_in_path, i_o );
a61af66fc99e Initial load
duke
parents:
diff changeset
753
a61af66fc99e Initial load
duke
parents:
diff changeset
754 Node *prefetch_adr;
a61af66fc99e Initial load
duke
parents:
diff changeset
755 Node *prefetch;
a61af66fc99e Initial load
duke
parents:
diff changeset
756 uint lines = AllocatePrefetchDistance / AllocatePrefetchStepSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
757 uint step_size = AllocatePrefetchStepSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
758 uint distance = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
759
a61af66fc99e Initial load
duke
parents:
diff changeset
760 for ( uint i = 0; i < lines; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
761 prefetch_adr = new (C, 4) AddPNode( old_pf_wm, new_pf_wmt,
a61af66fc99e Initial load
duke
parents:
diff changeset
762 _igvn.MakeConX(distance) );
a61af66fc99e Initial load
duke
parents:
diff changeset
763 transform_later(prefetch_adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
764 prefetch = new (C, 3) PrefetchWriteNode( i_o, prefetch_adr );
a61af66fc99e Initial load
duke
parents:
diff changeset
765 transform_later(prefetch);
a61af66fc99e Initial load
duke
parents:
diff changeset
766 distance += step_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
767 i_o = prefetch;
a61af66fc99e Initial load
duke
parents:
diff changeset
768 }
a61af66fc99e Initial load
duke
parents:
diff changeset
769 pf_phi_abio->set_req( pf_path, i_o );
a61af66fc99e Initial load
duke
parents:
diff changeset
770
a61af66fc99e Initial load
duke
parents:
diff changeset
771 pf_region->init_req( fall_in_path, need_pf_false );
a61af66fc99e Initial load
duke
parents:
diff changeset
772 pf_region->init_req( pf_path, need_pf_true );
a61af66fc99e Initial load
duke
parents:
diff changeset
773
a61af66fc99e Initial load
duke
parents:
diff changeset
774 pf_phi_rawmem->init_req( fall_in_path, contended_phi_rawmem );
a61af66fc99e Initial load
duke
parents:
diff changeset
775 pf_phi_rawmem->init_req( pf_path, store_new_wmt );
a61af66fc99e Initial load
duke
parents:
diff changeset
776
a61af66fc99e Initial load
duke
parents:
diff changeset
777 transform_later(pf_region);
a61af66fc99e Initial load
duke
parents:
diff changeset
778 transform_later(pf_phi_rawmem);
a61af66fc99e Initial load
duke
parents:
diff changeset
779 transform_later(pf_phi_abio);
a61af66fc99e Initial load
duke
parents:
diff changeset
780
a61af66fc99e Initial load
duke
parents:
diff changeset
781 needgc_false = pf_region;
a61af66fc99e Initial load
duke
parents:
diff changeset
782 contended_phi_rawmem = pf_phi_rawmem;
a61af66fc99e Initial load
duke
parents:
diff changeset
783 i_o = pf_phi_abio;
a61af66fc99e Initial load
duke
parents:
diff changeset
784 } else if( AllocatePrefetchStyle > 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
785 // Insert a prefetch for each allocation only on the fast-path
a61af66fc99e Initial load
duke
parents:
diff changeset
786 Node *prefetch_adr;
a61af66fc99e Initial load
duke
parents:
diff changeset
787 Node *prefetch;
a61af66fc99e Initial load
duke
parents:
diff changeset
788 // Generate several prefetch instructions only for arrays.
a61af66fc99e Initial load
duke
parents:
diff changeset
789 uint lines = (length != NULL) ? AllocatePrefetchLines : 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
790 uint step_size = AllocatePrefetchStepSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
791 uint distance = AllocatePrefetchDistance;
a61af66fc99e Initial load
duke
parents:
diff changeset
792 for ( uint i = 0; i < lines; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
793 prefetch_adr = new (C, 4) AddPNode( old_eden_top, new_eden_top,
a61af66fc99e Initial load
duke
parents:
diff changeset
794 _igvn.MakeConX(distance) );
a61af66fc99e Initial load
duke
parents:
diff changeset
795 transform_later(prefetch_adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
796 prefetch = new (C, 3) PrefetchWriteNode( i_o, prefetch_adr );
a61af66fc99e Initial load
duke
parents:
diff changeset
797 // Do not let it float too high, since if eden_top == eden_end,
a61af66fc99e Initial load
duke
parents:
diff changeset
798 // both might be null.
a61af66fc99e Initial load
duke
parents:
diff changeset
799 if( i == 0 ) { // Set control for first prefetch, next follows it
a61af66fc99e Initial load
duke
parents:
diff changeset
800 prefetch->init_req(0, needgc_false);
a61af66fc99e Initial load
duke
parents:
diff changeset
801 }
a61af66fc99e Initial load
duke
parents:
diff changeset
802 transform_later(prefetch);
a61af66fc99e Initial load
duke
parents:
diff changeset
803 distance += step_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
804 i_o = prefetch;
a61af66fc99e Initial load
duke
parents:
diff changeset
805 }
a61af66fc99e Initial load
duke
parents:
diff changeset
806 }
a61af66fc99e Initial load
duke
parents:
diff changeset
807 return i_o;
a61af66fc99e Initial load
duke
parents:
diff changeset
808 }
a61af66fc99e Initial load
duke
parents:
diff changeset
809
a61af66fc99e Initial load
duke
parents:
diff changeset
810
a61af66fc99e Initial load
duke
parents:
diff changeset
811 void PhaseMacroExpand::expand_allocate(AllocateNode *alloc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
812 expand_allocate_common(alloc, NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
813 OptoRuntime::new_instance_Type(),
a61af66fc99e Initial load
duke
parents:
diff changeset
814 OptoRuntime::new_instance_Java());
a61af66fc99e Initial load
duke
parents:
diff changeset
815 }
a61af66fc99e Initial load
duke
parents:
diff changeset
816
a61af66fc99e Initial load
duke
parents:
diff changeset
817 void PhaseMacroExpand::expand_allocate_array(AllocateArrayNode *alloc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
818 Node* length = alloc->in(AllocateNode::ALength);
a61af66fc99e Initial load
duke
parents:
diff changeset
819 expand_allocate_common(alloc, length,
a61af66fc99e Initial load
duke
parents:
diff changeset
820 OptoRuntime::new_array_Type(),
a61af66fc99e Initial load
duke
parents:
diff changeset
821 OptoRuntime::new_array_Java());
a61af66fc99e Initial load
duke
parents:
diff changeset
822 }
a61af66fc99e Initial load
duke
parents:
diff changeset
823
a61af66fc99e Initial load
duke
parents:
diff changeset
824
a61af66fc99e Initial load
duke
parents:
diff changeset
825 // we have determined that this lock/unlock can be eliminated, we simply
a61af66fc99e Initial load
duke
parents:
diff changeset
826 // eliminate the node without expanding it.
a61af66fc99e Initial load
duke
parents:
diff changeset
827 //
a61af66fc99e Initial load
duke
parents:
diff changeset
828 // Note: The membar's associated with the lock/unlock are currently not
a61af66fc99e Initial load
duke
parents:
diff changeset
829 // eliminated. This should be investigated as a future enhancement.
a61af66fc99e Initial load
duke
parents:
diff changeset
830 //
66
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
831 bool PhaseMacroExpand::eliminate_locking_node(AbstractLockNode *alock) {
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
832
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
833 if (!alock->is_eliminated()) {
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
834 return false;
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
835 }
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
836 // Mark the box lock as eliminated if all correspondent locks are eliminated
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
837 // to construct correct debug info.
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
838 BoxLockNode* box = alock->box_node()->as_BoxLock();
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
839 if (!box->is_eliminated()) {
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
840 bool eliminate = true;
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
841 for (DUIterator_Fast imax, i = box->fast_outs(imax); i < imax; i++) {
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
842 Node *lck = box->fast_out(i);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
843 if (lck->is_Lock() && !lck->as_AbstractLock()->is_eliminated()) {
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
844 eliminate = false;
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
845 break;
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
846 }
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
847 }
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
848 if (eliminate)
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
849 box->set_eliminated();
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
850 }
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
851
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
852 #ifndef PRODUCT
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
853 if (PrintEliminateLocks) {
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
854 if (alock->is_Lock()) {
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
855 tty->print_cr("++++ Eliminating: %d Lock", alock->_idx);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
856 } else {
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
857 tty->print_cr("++++ Eliminating: %d Unlock", alock->_idx);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
858 }
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
859 }
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
860 #endif
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
861
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
862 Node* mem = alock->in(TypeFunc::Memory);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
863 Node* ctrl = alock->in(TypeFunc::Control);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
864
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
865 extract_call_projections(alock);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
866 // There are 2 projections from the lock. The lock node will
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
867 // be deleted when its last use is subsumed below.
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
868 assert(alock->outcnt() == 2 &&
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
869 _fallthroughproj != NULL &&
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
870 _memproj_fallthrough != NULL,
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
871 "Unexpected projections from Lock/Unlock");
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
872
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
873 Node* fallthroughproj = _fallthroughproj;
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
874 Node* memproj_fallthrough = _memproj_fallthrough;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
875
a61af66fc99e Initial load
duke
parents:
diff changeset
876 // The memory projection from a lock/unlock is RawMem
a61af66fc99e Initial load
duke
parents:
diff changeset
877 // The input to a Lock is merged memory, so extract its RawMem input
a61af66fc99e Initial load
duke
parents:
diff changeset
878 // (unless the MergeMem has been optimized away.)
a61af66fc99e Initial load
duke
parents:
diff changeset
879 if (alock->is_Lock()) {
66
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
880 // Seach for MemBarAcquire node and delete it also.
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
881 MemBarNode* membar = fallthroughproj->unique_ctrl_out()->as_MemBar();
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
882 assert(membar != NULL && membar->Opcode() == Op_MemBarAcquire, "");
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
883 Node* ctrlproj = membar->proj_out(TypeFunc::Control);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
884 Node* memproj = membar->proj_out(TypeFunc::Memory);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
885 _igvn.hash_delete(ctrlproj);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
886 _igvn.subsume_node(ctrlproj, fallthroughproj);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
887 _igvn.hash_delete(memproj);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
888 _igvn.subsume_node(memproj, memproj_fallthrough);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
889 }
a61af66fc99e Initial load
duke
parents:
diff changeset
890
66
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
891 // Seach for MemBarRelease node and delete it also.
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
892 if (alock->is_Unlock() && ctrl != NULL && ctrl->is_Proj() &&
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
893 ctrl->in(0)->is_MemBar()) {
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
894 MemBarNode* membar = ctrl->in(0)->as_MemBar();
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
895 assert(membar->Opcode() == Op_MemBarRelease &&
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
896 mem->is_Proj() && membar == mem->in(0), "");
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
897 _igvn.hash_delete(fallthroughproj);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
898 _igvn.subsume_node(fallthroughproj, ctrl);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
899 _igvn.hash_delete(memproj_fallthrough);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
900 _igvn.subsume_node(memproj_fallthrough, mem);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
901 fallthroughproj = ctrl;
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
902 memproj_fallthrough = mem;
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
903 ctrl = membar->in(TypeFunc::Control);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
904 mem = membar->in(TypeFunc::Memory);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
905 }
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
906
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
907 _igvn.hash_delete(fallthroughproj);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
908 _igvn.subsume_node(fallthroughproj, ctrl);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
909 _igvn.hash_delete(memproj_fallthrough);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
910 _igvn.subsume_node(memproj_fallthrough, mem);
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
911 return true;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
912 }
a61af66fc99e Initial load
duke
parents:
diff changeset
913
a61af66fc99e Initial load
duke
parents:
diff changeset
914
a61af66fc99e Initial load
duke
parents:
diff changeset
915 //------------------------------expand_lock_node----------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
916 void PhaseMacroExpand::expand_lock_node(LockNode *lock) {
a61af66fc99e Initial load
duke
parents:
diff changeset
917
66
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
918 if (eliminate_locking_node(lock)) {
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
919 return;
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
920 }
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
921
0
a61af66fc99e Initial load
duke
parents:
diff changeset
922 Node* ctrl = lock->in(TypeFunc::Control);
a61af66fc99e Initial load
duke
parents:
diff changeset
923 Node* mem = lock->in(TypeFunc::Memory);
a61af66fc99e Initial load
duke
parents:
diff changeset
924 Node* obj = lock->obj_node();
a61af66fc99e Initial load
duke
parents:
diff changeset
925 Node* box = lock->box_node();
66
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
926 Node* flock = lock->fastlock_node();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
927
a61af66fc99e Initial load
duke
parents:
diff changeset
928 // Make the merge point
a61af66fc99e Initial load
duke
parents:
diff changeset
929 Node *region = new (C, 3) RegionNode(3);
a61af66fc99e Initial load
duke
parents:
diff changeset
930
a61af66fc99e Initial load
duke
parents:
diff changeset
931 Node *bol = transform_later(new (C, 2) BoolNode(flock,BoolTest::ne));
a61af66fc99e Initial load
duke
parents:
diff changeset
932 Node *iff = new (C, 2) IfNode( ctrl, bol, PROB_MIN, COUNT_UNKNOWN );
a61af66fc99e Initial load
duke
parents:
diff changeset
933 // Optimize test; set region slot 2
a61af66fc99e Initial load
duke
parents:
diff changeset
934 Node *slow_path = opt_iff(region,iff);
a61af66fc99e Initial load
duke
parents:
diff changeset
935
a61af66fc99e Initial load
duke
parents:
diff changeset
936 // Make slow path call
a61af66fc99e Initial load
duke
parents:
diff changeset
937 CallNode *call = make_slow_call( (CallNode *) lock, OptoRuntime::complete_monitor_enter_Type(), OptoRuntime::complete_monitor_locking_Java(), NULL, slow_path, obj, box );
a61af66fc99e Initial load
duke
parents:
diff changeset
938
a61af66fc99e Initial load
duke
parents:
diff changeset
939 extract_call_projections(call);
a61af66fc99e Initial load
duke
parents:
diff changeset
940
a61af66fc99e Initial load
duke
parents:
diff changeset
941 // Slow path can only throw asynchronous exceptions, which are always
a61af66fc99e Initial load
duke
parents:
diff changeset
942 // de-opted. So the compiler thinks the slow-call can never throw an
a61af66fc99e Initial load
duke
parents:
diff changeset
943 // exception. If it DOES throw an exception we would need the debug
a61af66fc99e Initial load
duke
parents:
diff changeset
944 // info removed first (since if it throws there is no monitor).
a61af66fc99e Initial load
duke
parents:
diff changeset
945 assert ( _ioproj_fallthrough == NULL && _ioproj_catchall == NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
946 _memproj_catchall == NULL && _catchallcatchproj == NULL, "Unexpected projection from Lock");
a61af66fc99e Initial load
duke
parents:
diff changeset
947
a61af66fc99e Initial load
duke
parents:
diff changeset
948 // Capture slow path
a61af66fc99e Initial load
duke
parents:
diff changeset
949 // disconnect fall-through projection from call and create a new one
a61af66fc99e Initial load
duke
parents:
diff changeset
950 // hook up users of fall-through projection to region
a61af66fc99e Initial load
duke
parents:
diff changeset
951 Node *slow_ctrl = _fallthroughproj->clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
952 transform_later(slow_ctrl);
a61af66fc99e Initial load
duke
parents:
diff changeset
953 _igvn.hash_delete(_fallthroughproj);
a61af66fc99e Initial load
duke
parents:
diff changeset
954 _fallthroughproj->disconnect_inputs(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
955 region->init_req(1, slow_ctrl);
a61af66fc99e Initial load
duke
parents:
diff changeset
956 // region inputs are now complete
a61af66fc99e Initial load
duke
parents:
diff changeset
957 transform_later(region);
a61af66fc99e Initial load
duke
parents:
diff changeset
958 _igvn.subsume_node(_fallthroughproj, region);
a61af66fc99e Initial load
duke
parents:
diff changeset
959
a61af66fc99e Initial load
duke
parents:
diff changeset
960 // create a Phi for the memory state
a61af66fc99e Initial load
duke
parents:
diff changeset
961 Node *mem_phi = new (C, 3) PhiNode( region, Type::MEMORY, TypeRawPtr::BOTTOM);
a61af66fc99e Initial load
duke
parents:
diff changeset
962 Node *memproj = transform_later( new (C, 1) ProjNode(call, TypeFunc::Memory) );
a61af66fc99e Initial load
duke
parents:
diff changeset
963 mem_phi->init_req(1, memproj );
a61af66fc99e Initial load
duke
parents:
diff changeset
964 mem_phi->init_req(2, mem);
a61af66fc99e Initial load
duke
parents:
diff changeset
965 transform_later(mem_phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
966 _igvn.hash_delete(_memproj_fallthrough);
a61af66fc99e Initial load
duke
parents:
diff changeset
967 _igvn.subsume_node(_memproj_fallthrough, mem_phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
968
a61af66fc99e Initial load
duke
parents:
diff changeset
969
a61af66fc99e Initial load
duke
parents:
diff changeset
970 }
a61af66fc99e Initial load
duke
parents:
diff changeset
971
a61af66fc99e Initial load
duke
parents:
diff changeset
972 //------------------------------expand_unlock_node----------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
973 void PhaseMacroExpand::expand_unlock_node(UnlockNode *unlock) {
a61af66fc99e Initial load
duke
parents:
diff changeset
974
66
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
975 if (eliminate_locking_node(unlock)) {
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
976 return;
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
977 }
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
978
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 63
diff changeset
979 Node* ctrl = unlock->in(TypeFunc::Control);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
980 Node* mem = unlock->in(TypeFunc::Memory);
a61af66fc99e Initial load
duke
parents:
diff changeset
981 Node* obj = unlock->obj_node();
a61af66fc99e Initial load
duke
parents:
diff changeset
982 Node* box = unlock->box_node();
a61af66fc99e Initial load
duke
parents:
diff changeset
983
a61af66fc99e Initial load
duke
parents:
diff changeset
984 // No need for a null check on unlock
a61af66fc99e Initial load
duke
parents:
diff changeset
985
a61af66fc99e Initial load
duke
parents:
diff changeset
986 // Make the merge point
a61af66fc99e Initial load
duke
parents:
diff changeset
987 RegionNode *region = new (C, 3) RegionNode(3);
a61af66fc99e Initial load
duke
parents:
diff changeset
988
a61af66fc99e Initial load
duke
parents:
diff changeset
989 FastUnlockNode *funlock = new (C, 3) FastUnlockNode( ctrl, obj, box );
a61af66fc99e Initial load
duke
parents:
diff changeset
990 funlock = transform_later( funlock )->as_FastUnlock();
a61af66fc99e Initial load
duke
parents:
diff changeset
991 Node *bol = transform_later(new (C, 2) BoolNode(funlock,BoolTest::ne));
a61af66fc99e Initial load
duke
parents:
diff changeset
992 Node *iff = new (C, 2) IfNode( ctrl, bol, PROB_MIN, COUNT_UNKNOWN );
a61af66fc99e Initial load
duke
parents:
diff changeset
993 // Optimize test; set region slot 2
a61af66fc99e Initial load
duke
parents:
diff changeset
994 Node *slow_path = opt_iff(region,iff);
a61af66fc99e Initial load
duke
parents:
diff changeset
995
a61af66fc99e Initial load
duke
parents:
diff changeset
996 CallNode *call = make_slow_call( (CallNode *) unlock, OptoRuntime::complete_monitor_exit_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_unlocking_C), "complete_monitor_unlocking_C", slow_path, obj, box );
a61af66fc99e Initial load
duke
parents:
diff changeset
997
a61af66fc99e Initial load
duke
parents:
diff changeset
998 extract_call_projections(call);
a61af66fc99e Initial load
duke
parents:
diff changeset
999
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 assert ( _ioproj_fallthrough == NULL && _ioproj_catchall == NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 _memproj_catchall == NULL && _catchallcatchproj == NULL, "Unexpected projection from Lock");
a61af66fc99e Initial load
duke
parents:
diff changeset
1002
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 // No exceptions for unlocking
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 // Capture slow path
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 // disconnect fall-through projection from call and create a new one
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 // hook up users of fall-through projection to region
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 Node *slow_ctrl = _fallthroughproj->clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 transform_later(slow_ctrl);
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 _igvn.hash_delete(_fallthroughproj);
a61af66fc99e Initial load
duke
parents:
diff changeset
1010 _fallthroughproj->disconnect_inputs(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 region->init_req(1, slow_ctrl);
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 // region inputs are now complete
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 transform_later(region);
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 _igvn.subsume_node(_fallthroughproj, region);
a61af66fc99e Initial load
duke
parents:
diff changeset
1015
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 // create a Phi for the memory state
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 Node *mem_phi = new (C, 3) PhiNode( region, Type::MEMORY, TypeRawPtr::BOTTOM);
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 Node *memproj = transform_later( new(C, 1) ProjNode(call, TypeFunc::Memory) );
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 mem_phi->init_req(1, memproj );
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 mem_phi->init_req(2, mem);
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 transform_later(mem_phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 _igvn.hash_delete(_memproj_fallthrough);
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 _igvn.subsume_node(_memproj_fallthrough, mem_phi);
a61af66fc99e Initial load
duke
parents:
diff changeset
1024
a61af66fc99e Initial load
duke
parents:
diff changeset
1025
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1027
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 //------------------------------expand_macro_nodes----------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 // Returns true if a failure occurred.
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 bool PhaseMacroExpand::expand_macro_nodes() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 if (C->macro_count() == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 // Make sure expansion will not cause node limit to be exceeded. Worst case is a
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 // macro node gets expanded into about 50 nodes. Allow 50% more for optimization
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 if (C->check_node_count(C->macro_count() * 75, "out of nodes before macro expansion" ) )
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 // expand "macro" nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 // nodes are removed from the macro list as they are processed
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 while (C->macro_count() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 Node * n = C->macro_node(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 assert(n->is_macro(), "only macro nodes expected here");
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 if (_igvn.type(n) == Type::TOP || n->in(0)->is_top() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 // node is unreachable, so don't try to expand it
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 C->remove_macro_node(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 switch (n->class_id()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 case Node::Class_Allocate:
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 expand_allocate(n->as_Allocate());
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 case Node::Class_AllocateArray:
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 expand_allocate_array(n->as_AllocateArray());
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 case Node::Class_Lock:
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 expand_lock_node(n->as_Lock());
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 case Node::Class_Unlock:
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 expand_unlock_node(n->as_Unlock());
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 assert(false, "unknown node type in macro list");
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 if (C->failing()) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 _igvn.optimize();
a61af66fc99e Initial load
duke
parents:
diff changeset
1066 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 }