Mercurial > hg > truffle
annotate src/share/vm/opto/stringopts.cpp @ 17381:40dce17629ac
correct IfNode probabilities in If-Deopt situations
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Wed, 08 Oct 2014 10:49:53 +0200 |
parents | 4ca6dc0799b6 |
children | 52b4284cb496 |
rev | line source |
---|---|
1080 | 1 /* |
12889
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
2 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. |
1080 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1250
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1250
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1250
diff
changeset
|
21 * questions. |
1080 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "compiler/compileLog.hpp" | |
27 #include "opto/addnode.hpp" | |
28 #include "opto/callGenerator.hpp" | |
29 #include "opto/callnode.hpp" | |
30 #include "opto/divnode.hpp" | |
31 #include "opto/graphKit.hpp" | |
32 #include "opto/idealKit.hpp" | |
33 #include "opto/rootnode.hpp" | |
34 #include "opto/runtime.hpp" | |
35 #include "opto/stringopts.hpp" | |
36 #include "opto/subnode.hpp" | |
1080 | 37 |
38 #define __ kit. | |
39 | |
40 class StringConcat : public ResourceObj { | |
41 private: | |
42 PhaseStringOpts* _stringopts; | |
43 Node* _string_alloc; | |
44 AllocateNode* _begin; // The allocation the begins the pattern | |
45 CallStaticJavaNode* _end; // The final call of the pattern. Will either be | |
46 // SB.toString or or String.<init>(SB.toString) | |
47 bool _multiple; // indicates this is a fusion of two or more | |
48 // separate StringBuilders | |
49 | |
50 Node* _arguments; // The list of arguments to be concatenated | |
51 GrowableArray<int> _mode; // into a String along with a mode flag | |
52 // indicating how to treat the value. | |
12889
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
53 Node_List _constructors; // List of constructors (many in case of stacked concat) |
1080 | 54 Node_List _control; // List of control nodes that will be deleted |
55 Node_List _uncommon_traps; // Uncommon traps that needs to be rewritten | |
56 // to restart at the initial JVMState. | |
12889
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
57 |
1080 | 58 public: |
59 // Mode for converting arguments to Strings | |
60 enum { | |
61 StringMode, | |
62 IntMode, | |
2090
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
63 CharMode, |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
64 StringNullCheckMode |
1080 | 65 }; |
66 | |
67 StringConcat(PhaseStringOpts* stringopts, CallStaticJavaNode* end): | |
68 _end(end), | |
69 _begin(NULL), | |
70 _multiple(false), | |
71 _string_alloc(NULL), | |
72 _stringopts(stringopts) { | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
73 _arguments = new (_stringopts->C) Node(1); |
1080 | 74 _arguments->del_req(0); |
75 } | |
76 | |
12889
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
77 bool validate_mem_flow(); |
1080 | 78 bool validate_control_flow(); |
79 | |
80 void merge_add() { | |
81 #if 0 | |
82 // XXX This is place holder code for reusing an existing String | |
83 // allocation but the logic for checking the state safety is | |
84 // probably inadequate at the moment. | |
85 CallProjections endprojs; | |
86 sc->end()->extract_projections(&endprojs, false); | |
87 if (endprojs.resproj != NULL) { | |
88 for (SimpleDUIterator i(endprojs.resproj); i.has_next(); i.next()) { | |
89 CallStaticJavaNode *use = i.get()->isa_CallStaticJava(); | |
90 if (use != NULL && use->method() != NULL && | |
1817
c40600e85311
6986028: assert(_base == Int) failed: Not an Int in CmpINode::sub
never
parents:
1748
diff
changeset
|
91 use->method()->intrinsic_id() == vmIntrinsics::_String_String && |
1080 | 92 use->in(TypeFunc::Parms + 1) == endprojs.resproj) { |
93 // Found useless new String(sb.toString()) so reuse the newly allocated String | |
94 // when creating the result instead of allocating a new one. | |
95 sc->set_string_alloc(use->in(TypeFunc::Parms)); | |
96 sc->set_end(use); | |
97 } | |
98 } | |
99 } | |
100 #endif | |
101 } | |
102 | |
103 StringConcat* merge(StringConcat* other, Node* arg); | |
104 | |
105 void set_allocation(AllocateNode* alloc) { | |
106 _begin = alloc; | |
107 } | |
108 | |
109 void append(Node* value, int mode) { | |
110 _arguments->add_req(value); | |
111 _mode.append(mode); | |
112 } | |
113 void push(Node* value, int mode) { | |
114 _arguments->ins_req(0, value); | |
115 _mode.insert_before(0, mode); | |
116 } | |
6186
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
117 |
1080 | 118 void push_string(Node* value) { |
119 push(value, StringMode); | |
120 } | |
2090
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
121 void push_string_null_check(Node* value) { |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
122 push(value, StringNullCheckMode); |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
123 } |
1080 | 124 void push_int(Node* value) { |
125 push(value, IntMode); | |
126 } | |
127 void push_char(Node* value) { | |
128 push(value, CharMode); | |
129 } | |
130 | |
6186
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
131 static bool is_SB_toString(Node* call) { |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
132 if (call->is_CallStaticJava()) { |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
133 CallStaticJavaNode* csj = call->as_CallStaticJava(); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
134 ciMethod* m = csj->method(); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
135 if (m != NULL && |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
136 (m->intrinsic_id() == vmIntrinsics::_StringBuilder_toString || |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
137 m->intrinsic_id() == vmIntrinsics::_StringBuffer_toString)) { |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
138 return true; |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
139 } |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
140 } |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
141 return false; |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
142 } |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
143 |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
144 static Node* skip_string_null_check(Node* value) { |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
145 // Look for a diamond shaped Null check of toString() result |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
146 // (could be code from String.valueOf()): |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
147 // (Proj == NULL) ? "null":"CastPP(Proj)#NotNULL |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
148 if (value->is_Phi()) { |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
149 int true_path = value->as_Phi()->is_diamond_phi(); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
150 if (true_path != 0) { |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
151 // phi->region->if_proj->ifnode->bool |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
152 BoolNode* b = value->in(0)->in(1)->in(0)->in(1)->as_Bool(); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
153 Node* cmp = b->in(1); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
154 Node* v1 = cmp->in(1); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
155 Node* v2 = cmp->in(2); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
156 // Null check of the return of toString which can simply be skipped. |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
157 if (b->_test._test == BoolTest::ne && |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
158 v2->bottom_type() == TypePtr::NULL_PTR && |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
159 value->in(true_path)->Opcode() == Op_CastPP && |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
160 value->in(true_path)->in(1) == v1 && |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
161 v1->is_Proj() && is_SB_toString(v1->in(0))) { |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
162 return v1; |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
163 } |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
164 } |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
165 } |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
166 return value; |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
167 } |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
168 |
1080 | 169 Node* argument(int i) { |
170 return _arguments->in(i); | |
171 } | |
6186
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
172 Node* argument_uncast(int i) { |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
173 Node* arg = argument(i); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
174 int amode = mode(i); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
175 if (amode == StringConcat::StringMode || |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
176 amode == StringConcat::StringNullCheckMode) { |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
177 arg = skip_string_null_check(arg); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
178 } |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
179 return arg; |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
180 } |
1080 | 181 void set_argument(int i, Node* value) { |
182 _arguments->set_req(i, value); | |
183 } | |
184 int num_arguments() { | |
185 return _mode.length(); | |
186 } | |
187 int mode(int i) { | |
188 return _mode.at(i); | |
189 } | |
190 void add_control(Node* ctrl) { | |
191 assert(!_control.contains(ctrl), "only push once"); | |
192 _control.push(ctrl); | |
193 } | |
12889
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
194 void add_constructor(Node* init) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
195 assert(!_constructors.contains(init), "only push once"); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
196 _constructors.push(init); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
197 } |
1080 | 198 CallStaticJavaNode* end() { return _end; } |
199 AllocateNode* begin() { return _begin; } | |
200 Node* string_alloc() { return _string_alloc; } | |
201 | |
202 void eliminate_unneeded_control(); | |
203 void eliminate_initialize(InitializeNode* init); | |
204 void eliminate_call(CallNode* call); | |
205 | |
206 void maybe_log_transform() { | |
207 CompileLog* log = _stringopts->C->log(); | |
208 if (log != NULL) { | |
209 log->head("replace_string_concat arguments='%d' string_alloc='%d' multiple='%d'", | |
210 num_arguments(), | |
211 _string_alloc != NULL, | |
212 _multiple); | |
213 JVMState* p = _begin->jvms(); | |
214 while (p != NULL) { | |
215 log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method())); | |
216 p = p->caller(); | |
217 } | |
218 log->tail("replace_string_concat"); | |
219 } | |
220 } | |
221 | |
222 void convert_uncommon_traps(GraphKit& kit, const JVMState* jvms) { | |
223 for (uint u = 0; u < _uncommon_traps.size(); u++) { | |
224 Node* uct = _uncommon_traps.at(u); | |
225 | |
226 // Build a new call using the jvms state of the allocate | |
1748 | 227 address call_addr = SharedRuntime::uncommon_trap_blob()->entry_point(); |
1080 | 228 const TypeFunc* call_type = OptoRuntime::uncommon_trap_Type(); |
229 const TypePtr* no_memory_effects = NULL; | |
230 Compile* C = _stringopts->C; | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
231 CallStaticJavaNode* call = new (C) CallStaticJavaNode(call_type, call_addr, "uncommon_trap", |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
232 jvms->bci(), no_memory_effects); |
1080 | 233 for (int e = 0; e < TypeFunc::Parms; e++) { |
234 call->init_req(e, uct->in(e)); | |
235 } | |
236 // Set the trap request to record intrinsic failure if this trap | |
237 // is taken too many times. Ideally we would handle then traps by | |
238 // doing the original bookkeeping in the MDO so that if it caused | |
239 // the code to be thrown out we could still recompile and use the | |
240 // optimization. Failing the uncommon traps doesn't really mean | |
241 // that the optimization is a bad idea but there's no other way to | |
242 // do the MDO updates currently. | |
243 int trap_request = Deoptimization::make_trap_request(Deoptimization::Reason_intrinsic, | |
244 Deoptimization::Action_make_not_entrant); | |
245 call->init_req(TypeFunc::Parms, __ intcon(trap_request)); | |
246 kit.add_safepoint_edges(call); | |
247 | |
248 _stringopts->gvn()->transform(call); | |
249 C->gvn_replace_by(uct, call); | |
7196
2aff40cb4703
7092905: C2: Keep track of the number of dead nodes
bharadwaj
parents:
6804
diff
changeset
|
250 uct->disconnect_inputs(NULL, C); |
1080 | 251 } |
252 } | |
253 | |
254 void cleanup() { | |
255 // disconnect the hook node | |
7196
2aff40cb4703
7092905: C2: Keep track of the number of dead nodes
bharadwaj
parents:
6804
diff
changeset
|
256 _arguments->disconnect_inputs(NULL, _stringopts->C); |
1080 | 257 } |
258 }; | |
259 | |
260 | |
261 void StringConcat::eliminate_unneeded_control() { | |
262 for (uint i = 0; i < _control.size(); i++) { | |
263 Node* n = _control.at(i); | |
6186
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
264 if (n->is_Allocate()) { |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
265 eliminate_initialize(n->as_Allocate()->initialization()); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
266 } |
1080 | 267 if (n->is_Call()) { |
268 if (n != _end) { | |
269 eliminate_call(n->as_Call()); | |
270 } | |
271 } else if (n->is_IfTrue()) { | |
272 Compile* C = _stringopts->C; | |
273 C->gvn_replace_by(n, n->in(0)->in(0)); | |
7473 | 274 // get rid of the other projection |
275 C->gvn_replace_by(n->in(0)->as_If()->proj_out(false), C->top()); | |
1080 | 276 } |
277 } | |
278 } | |
279 | |
280 | |
281 StringConcat* StringConcat::merge(StringConcat* other, Node* arg) { | |
282 StringConcat* result = new StringConcat(_stringopts, _end); | |
283 for (uint x = 0; x < _control.size(); x++) { | |
284 Node* n = _control.at(x); | |
285 if (n->is_Call()) { | |
286 result->_control.push(n); | |
287 } | |
288 } | |
289 for (uint x = 0; x < other->_control.size(); x++) { | |
290 Node* n = other->_control.at(x); | |
291 if (n->is_Call()) { | |
292 result->_control.push(n); | |
293 } | |
294 } | |
295 assert(result->_control.contains(other->_end), "what?"); | |
296 assert(result->_control.contains(_begin), "what?"); | |
297 for (int x = 0; x < num_arguments(); x++) { | |
6186
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
298 Node* argx = argument_uncast(x); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
299 if (argx == arg) { |
1080 | 300 // replace the toString result with the all the arguments that |
301 // made up the other StringConcat | |
302 for (int y = 0; y < other->num_arguments(); y++) { | |
303 result->append(other->argument(y), other->mode(y)); | |
304 } | |
305 } else { | |
6186
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
306 result->append(argx, mode(x)); |
1080 | 307 } |
308 } | |
309 result->set_allocation(other->_begin); | |
12889
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
310 for (uint i = 0; i < _constructors.size(); i++) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
311 result->add_constructor(_constructors.at(i)); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
312 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
313 for (uint i = 0; i < other->_constructors.size(); i++) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
314 result->add_constructor(other->_constructors.at(i)); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
315 } |
1080 | 316 result->_multiple = true; |
317 return result; | |
318 } | |
319 | |
320 | |
321 void StringConcat::eliminate_call(CallNode* call) { | |
322 Compile* C = _stringopts->C; | |
323 CallProjections projs; | |
324 call->extract_projections(&projs, false); | |
325 if (projs.fallthrough_catchproj != NULL) { | |
326 C->gvn_replace_by(projs.fallthrough_catchproj, call->in(TypeFunc::Control)); | |
327 } | |
328 if (projs.fallthrough_memproj != NULL) { | |
329 C->gvn_replace_by(projs.fallthrough_memproj, call->in(TypeFunc::Memory)); | |
330 } | |
331 if (projs.catchall_memproj != NULL) { | |
332 C->gvn_replace_by(projs.catchall_memproj, C->top()); | |
333 } | |
334 if (projs.fallthrough_ioproj != NULL) { | |
335 C->gvn_replace_by(projs.fallthrough_ioproj, call->in(TypeFunc::I_O)); | |
336 } | |
337 if (projs.catchall_ioproj != NULL) { | |
338 C->gvn_replace_by(projs.catchall_ioproj, C->top()); | |
339 } | |
340 if (projs.catchall_catchproj != NULL) { | |
341 // EA can't cope with the partially collapsed graph this | |
342 // creates so put it on the worklist to be collapsed later. | |
343 for (SimpleDUIterator i(projs.catchall_catchproj); i.has_next(); i.next()) { | |
344 Node *use = i.get(); | |
345 int opc = use->Opcode(); | |
346 if (opc == Op_CreateEx || opc == Op_Region) { | |
347 _stringopts->record_dead_node(use); | |
348 } | |
349 } | |
350 C->gvn_replace_by(projs.catchall_catchproj, C->top()); | |
351 } | |
352 if (projs.resproj != NULL) { | |
353 C->gvn_replace_by(projs.resproj, C->top()); | |
354 } | |
355 C->gvn_replace_by(call, C->top()); | |
356 } | |
357 | |
358 void StringConcat::eliminate_initialize(InitializeNode* init) { | |
359 Compile* C = _stringopts->C; | |
360 | |
361 // Eliminate Initialize node. | |
362 assert(init->outcnt() <= 2, "only a control and memory projection expected"); | |
363 assert(init->req() <= InitializeNode::RawStores, "no pending inits"); | |
364 Node *ctrl_proj = init->proj_out(TypeFunc::Control); | |
365 if (ctrl_proj != NULL) { | |
366 C->gvn_replace_by(ctrl_proj, init->in(TypeFunc::Control)); | |
367 } | |
368 Node *mem_proj = init->proj_out(TypeFunc::Memory); | |
369 if (mem_proj != NULL) { | |
370 Node *mem = init->in(TypeFunc::Memory); | |
371 C->gvn_replace_by(mem_proj, mem); | |
372 } | |
373 C->gvn_replace_by(init, C->top()); | |
7196
2aff40cb4703
7092905: C2: Keep track of the number of dead nodes
bharadwaj
parents:
6804
diff
changeset
|
374 init->disconnect_inputs(NULL, C); |
1080 | 375 } |
376 | |
377 Node_List PhaseStringOpts::collect_toString_calls() { | |
378 Node_List string_calls; | |
379 Node_List worklist; | |
380 | |
381 _visited.Clear(); | |
382 | |
383 // Prime the worklist | |
384 for (uint i = 1; i < C->root()->len(); i++) { | |
385 Node* n = C->root()->in(i); | |
386 if (n != NULL && !_visited.test_set(n->_idx)) { | |
387 worklist.push(n); | |
388 } | |
389 } | |
390 | |
391 while (worklist.size() > 0) { | |
392 Node* ctrl = worklist.pop(); | |
6186
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
393 if (StringConcat::is_SB_toString(ctrl)) { |
1080 | 394 CallStaticJavaNode* csj = ctrl->as_CallStaticJava(); |
6186
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
395 string_calls.push(csj); |
1080 | 396 } |
397 if (ctrl->in(0) != NULL && !_visited.test_set(ctrl->in(0)->_idx)) { | |
398 worklist.push(ctrl->in(0)); | |
399 } | |
400 if (ctrl->is_Region()) { | |
401 for (uint i = 1; i < ctrl->len(); i++) { | |
402 if (ctrl->in(i) != NULL && !_visited.test_set(ctrl->in(i)->_idx)) { | |
403 worklist.push(ctrl->in(i)); | |
404 } | |
405 } | |
406 } | |
407 } | |
408 return string_calls; | |
409 } | |
410 | |
411 | |
412 StringConcat* PhaseStringOpts::build_candidate(CallStaticJavaNode* call) { | |
413 ciMethod* m = call->method(); | |
414 ciSymbol* string_sig; | |
415 ciSymbol* int_sig; | |
416 ciSymbol* char_sig; | |
417 if (m->holder() == C->env()->StringBuilder_klass()) { | |
418 string_sig = ciSymbol::String_StringBuilder_signature(); | |
419 int_sig = ciSymbol::int_StringBuilder_signature(); | |
420 char_sig = ciSymbol::char_StringBuilder_signature(); | |
421 } else if (m->holder() == C->env()->StringBuffer_klass()) { | |
422 string_sig = ciSymbol::String_StringBuffer_signature(); | |
423 int_sig = ciSymbol::int_StringBuffer_signature(); | |
424 char_sig = ciSymbol::char_StringBuffer_signature(); | |
425 } else { | |
426 return NULL; | |
427 } | |
428 #ifndef PRODUCT | |
429 if (PrintOptimizeStringConcat) { | |
430 tty->print("considering toString call in "); | |
431 call->jvms()->dump_spec(tty); tty->cr(); | |
432 } | |
433 #endif | |
434 | |
435 StringConcat* sc = new StringConcat(this, call); | |
436 | |
437 AllocateNode* alloc = NULL; | |
438 InitializeNode* init = NULL; | |
439 | |
440 // possible opportunity for StringBuilder fusion | |
441 CallStaticJavaNode* cnode = call; | |
442 while (cnode) { | |
443 Node* recv = cnode->in(TypeFunc::Parms)->uncast(); | |
444 if (recv->is_Proj()) { | |
445 recv = recv->in(0); | |
446 } | |
447 cnode = recv->isa_CallStaticJava(); | |
448 if (cnode == NULL) { | |
449 alloc = recv->isa_Allocate(); | |
450 if (alloc == NULL) { | |
451 break; | |
452 } | |
453 // Find the constructor call | |
454 Node* result = alloc->result_cast(); | |
7473 | 455 if (result == NULL || !result->is_CheckCastPP() || alloc->in(TypeFunc::Memory)->is_top()) { |
1080 | 456 // strange looking allocation |
457 #ifndef PRODUCT | |
458 if (PrintOptimizeStringConcat) { | |
459 tty->print("giving up because allocation looks strange "); | |
460 alloc->jvms()->dump_spec(tty); tty->cr(); | |
461 } | |
462 #endif | |
463 break; | |
464 } | |
465 Node* constructor = NULL; | |
466 for (SimpleDUIterator i(result); i.has_next(); i.next()) { | |
467 CallStaticJavaNode *use = i.get()->isa_CallStaticJava(); | |
1817
c40600e85311
6986028: assert(_base == Int) failed: Not an Int in CmpINode::sub
never
parents:
1748
diff
changeset
|
468 if (use != NULL && |
c40600e85311
6986028: assert(_base == Int) failed: Not an Int in CmpINode::sub
never
parents:
1748
diff
changeset
|
469 use->method() != NULL && |
c40600e85311
6986028: assert(_base == Int) failed: Not an Int in CmpINode::sub
never
parents:
1748
diff
changeset
|
470 !use->method()->is_static() && |
1080 | 471 use->method()->name() == ciSymbol::object_initializer_name() && |
472 use->method()->holder() == m->holder()) { | |
473 // Matched the constructor. | |
474 ciSymbol* sig = use->method()->signature()->as_symbol(); | |
475 if (sig == ciSymbol::void_method_signature() || | |
476 sig == ciSymbol::int_void_signature() || | |
477 sig == ciSymbol::string_void_signature()) { | |
478 if (sig == ciSymbol::string_void_signature()) { | |
479 // StringBuilder(String) so pick this up as the first argument | |
480 assert(use->in(TypeFunc::Parms + 1) != NULL, "what?"); | |
2090
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
481 const Type* type = _gvn->type(use->in(TypeFunc::Parms + 1)); |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
482 if (type == TypePtr::NULL_PTR) { |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
483 // StringBuilder(null) throws exception. |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
484 #ifndef PRODUCT |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
485 if (PrintOptimizeStringConcat) { |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
486 tty->print("giving up because StringBuilder(null) throws exception"); |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
487 alloc->jvms()->dump_spec(tty); tty->cr(); |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
488 } |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
489 #endif |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
490 return NULL; |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
491 } |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
492 // StringBuilder(str) argument needs null check. |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
493 sc->push_string_null_check(use->in(TypeFunc::Parms + 1)); |
1080 | 494 } |
495 // The int variant takes an initial size for the backing | |
496 // array so just treat it like the void version. | |
497 constructor = use; | |
498 } else { | |
499 #ifndef PRODUCT | |
500 if (PrintOptimizeStringConcat) { | |
501 tty->print("unexpected constructor signature: %s", sig->as_utf8()); | |
502 } | |
503 #endif | |
504 } | |
505 break; | |
506 } | |
507 } | |
508 if (constructor == NULL) { | |
509 // couldn't find constructor | |
510 #ifndef PRODUCT | |
511 if (PrintOptimizeStringConcat) { | |
512 tty->print("giving up because couldn't find constructor "); | |
2090
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
513 alloc->jvms()->dump_spec(tty); tty->cr(); |
1080 | 514 } |
515 #endif | |
516 break; | |
517 } | |
518 | |
519 // Walked all the way back and found the constructor call so see | |
520 // if this call converted into a direct string concatenation. | |
521 sc->add_control(call); | |
522 sc->add_control(constructor); | |
523 sc->add_control(alloc); | |
524 sc->set_allocation(alloc); | |
12889
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
525 sc->add_constructor(constructor); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
526 if (sc->validate_control_flow() && sc->validate_mem_flow()) { |
1080 | 527 return sc; |
528 } else { | |
529 return NULL; | |
530 } | |
531 } else if (cnode->method() == NULL) { | |
532 break; | |
1817
c40600e85311
6986028: assert(_base == Int) failed: Not an Int in CmpINode::sub
never
parents:
1748
diff
changeset
|
533 } else if (!cnode->method()->is_static() && |
c40600e85311
6986028: assert(_base == Int) failed: Not an Int in CmpINode::sub
never
parents:
1748
diff
changeset
|
534 cnode->method()->holder() == m->holder() && |
1080 | 535 cnode->method()->name() == ciSymbol::append_name() && |
536 (cnode->method()->signature()->as_symbol() == string_sig || | |
537 cnode->method()->signature()->as_symbol() == char_sig || | |
538 cnode->method()->signature()->as_symbol() == int_sig)) { | |
539 sc->add_control(cnode); | |
540 Node* arg = cnode->in(TypeFunc::Parms + 1); | |
541 if (cnode->method()->signature()->as_symbol() == int_sig) { | |
542 sc->push_int(arg); | |
543 } else if (cnode->method()->signature()->as_symbol() == char_sig) { | |
544 sc->push_char(arg); | |
545 } else { | |
546 if (arg->is_Proj() && arg->in(0)->is_CallStaticJava()) { | |
547 CallStaticJavaNode* csj = arg->in(0)->as_CallStaticJava(); | |
548 if (csj->method() != NULL && | |
6223
ed21db7b3fda
7123926: Some CTW test crash: !_control.contains(ctrl)
kvn
parents:
6186
diff
changeset
|
549 csj->method()->intrinsic_id() == vmIntrinsics::_Integer_toString && |
ed21db7b3fda
7123926: Some CTW test crash: !_control.contains(ctrl)
kvn
parents:
6186
diff
changeset
|
550 arg->outcnt() == 1) { |
ed21db7b3fda
7123926: Some CTW test crash: !_control.contains(ctrl)
kvn
parents:
6186
diff
changeset
|
551 // _control is the list of StringBuilder calls nodes which |
ed21db7b3fda
7123926: Some CTW test crash: !_control.contains(ctrl)
kvn
parents:
6186
diff
changeset
|
552 // will be replaced by new String code after this optimization. |
ed21db7b3fda
7123926: Some CTW test crash: !_control.contains(ctrl)
kvn
parents:
6186
diff
changeset
|
553 // Integer::toString() call is not part of StringBuilder calls |
ed21db7b3fda
7123926: Some CTW test crash: !_control.contains(ctrl)
kvn
parents:
6186
diff
changeset
|
554 // chain. It could be eliminated only if its result is used |
ed21db7b3fda
7123926: Some CTW test crash: !_control.contains(ctrl)
kvn
parents:
6186
diff
changeset
|
555 // only by this SB calls chain. |
ed21db7b3fda
7123926: Some CTW test crash: !_control.contains(ctrl)
kvn
parents:
6186
diff
changeset
|
556 // Another limitation: it should be used only once because |
ed21db7b3fda
7123926: Some CTW test crash: !_control.contains(ctrl)
kvn
parents:
6186
diff
changeset
|
557 // it is unknown that it is used only by this SB calls chain |
ed21db7b3fda
7123926: Some CTW test crash: !_control.contains(ctrl)
kvn
parents:
6186
diff
changeset
|
558 // until all related SB calls nodes are collected. |
ed21db7b3fda
7123926: Some CTW test crash: !_control.contains(ctrl)
kvn
parents:
6186
diff
changeset
|
559 assert(arg->unique_out() == cnode, "sanity"); |
1080 | 560 sc->add_control(csj); |
561 sc->push_int(csj->in(TypeFunc::Parms)); | |
562 continue; | |
563 } | |
564 } | |
565 sc->push_string(arg); | |
566 } | |
567 continue; | |
568 } else { | |
569 // some unhandled signature | |
570 #ifndef PRODUCT | |
571 if (PrintOptimizeStringConcat) { | |
572 tty->print("giving up because encountered unexpected signature "); | |
573 cnode->tf()->dump(); tty->cr(); | |
574 cnode->in(TypeFunc::Parms + 1)->dump(); | |
575 } | |
576 #endif | |
577 break; | |
578 } | |
579 } | |
580 return NULL; | |
581 } | |
582 | |
583 | |
584 PhaseStringOpts::PhaseStringOpts(PhaseGVN* gvn, Unique_Node_List*): | |
585 Phase(StringOpts), | |
586 _gvn(gvn), | |
587 _visited(Thread::current()->resource_area()) { | |
588 | |
589 assert(OptimizeStringConcat, "shouldn't be here"); | |
590 | |
591 size_table_field = C->env()->Integer_klass()->get_field_by_name(ciSymbol::make("sizeTable"), | |
592 ciSymbol::make("[I"), true); | |
593 if (size_table_field == NULL) { | |
594 // Something wrong so give up. | |
595 assert(false, "why can't we find Integer.sizeTable?"); | |
596 return; | |
597 } | |
598 | |
599 // Collect the types needed to talk about the various slices of memory | |
600 char_adr_idx = C->get_alias_index(TypeAryPtr::CHARS); | |
601 | |
602 // For each locally allocated StringBuffer see if the usages can be | |
603 // collapsed into a single String construction. | |
604 | |
605 // Run through the list of allocation looking for SB.toString to see | |
606 // if it's possible to fuse the usage of the SB into a single String | |
607 // construction. | |
608 GrowableArray<StringConcat*> concats; | |
609 Node_List toStrings = collect_toString_calls(); | |
610 while (toStrings.size() > 0) { | |
611 StringConcat* sc = build_candidate(toStrings.pop()->as_CallStaticJava()); | |
612 if (sc != NULL) { | |
613 concats.push(sc); | |
614 } | |
615 } | |
616 | |
617 // try to coalesce separate concats | |
618 restart: | |
619 for (int c = 0; c < concats.length(); c++) { | |
620 StringConcat* sc = concats.at(c); | |
621 for (int i = 0; i < sc->num_arguments(); i++) { | |
6186
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
622 Node* arg = sc->argument_uncast(i); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
623 if (arg->is_Proj() && StringConcat::is_SB_toString(arg->in(0))) { |
1080 | 624 CallStaticJavaNode* csj = arg->in(0)->as_CallStaticJava(); |
6186
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
625 for (int o = 0; o < concats.length(); o++) { |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
626 if (c == o) continue; |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
627 StringConcat* other = concats.at(o); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
628 if (other->end() == csj) { |
1080 | 629 #ifndef PRODUCT |
6186
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
630 if (PrintOptimizeStringConcat) { |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
631 tty->print_cr("considering stacked concats"); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
632 } |
1080 | 633 #endif |
634 | |
6186
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
635 StringConcat* merged = sc->merge(other, arg); |
12889
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
636 if (merged->validate_control_flow() && merged->validate_mem_flow()) { |
1080 | 637 #ifndef PRODUCT |
6186
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
638 if (PrintOptimizeStringConcat) { |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
639 tty->print_cr("stacking would succeed"); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
640 } |
1080 | 641 #endif |
6186
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
642 if (c < o) { |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
643 concats.remove_at(o); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
644 concats.at_put(c, merged); |
1080 | 645 } else { |
6186
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
646 concats.remove_at(c); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
647 concats.at_put(o, merged); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
648 } |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
649 goto restart; |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
650 } else { |
1080 | 651 #ifndef PRODUCT |
6186
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
652 if (PrintOptimizeStringConcat) { |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
653 tty->print_cr("stacking would fail"); |
751bd303aa45
7179138: Incorrect result with String concatenation optimization
kvn
parents:
6057
diff
changeset
|
654 } |
1080 | 655 #endif |
656 } | |
657 } | |
658 } | |
659 } | |
660 } | |
661 } | |
662 | |
663 | |
664 for (int c = 0; c < concats.length(); c++) { | |
665 StringConcat* sc = concats.at(c); | |
666 replace_string_concat(sc); | |
667 } | |
668 | |
669 remove_dead_nodes(); | |
670 } | |
671 | |
672 void PhaseStringOpts::record_dead_node(Node* dead) { | |
673 dead_worklist.push(dead); | |
674 } | |
675 | |
676 void PhaseStringOpts::remove_dead_nodes() { | |
677 // Delete any dead nodes to make things clean enough that escape | |
678 // analysis doesn't get unhappy. | |
679 while (dead_worklist.size() > 0) { | |
680 Node* use = dead_worklist.pop(); | |
681 int opc = use->Opcode(); | |
682 switch (opc) { | |
683 case Op_Region: { | |
684 uint i = 1; | |
685 for (i = 1; i < use->req(); i++) { | |
686 if (use->in(i) != C->top()) { | |
687 break; | |
688 } | |
689 } | |
690 if (i >= use->req()) { | |
691 for (SimpleDUIterator i(use); i.has_next(); i.next()) { | |
692 Node* m = i.get(); | |
693 if (m->is_Phi()) { | |
694 dead_worklist.push(m); | |
695 } | |
696 } | |
697 C->gvn_replace_by(use, C->top()); | |
698 } | |
699 break; | |
700 } | |
701 case Op_AddP: | |
702 case Op_CreateEx: { | |
703 // Recurisvely clean up references to CreateEx so EA doesn't | |
704 // get unhappy about the partially collapsed graph. | |
705 for (SimpleDUIterator i(use); i.has_next(); i.next()) { | |
706 Node* m = i.get(); | |
707 if (m->is_AddP()) { | |
708 dead_worklist.push(m); | |
709 } | |
710 } | |
711 C->gvn_replace_by(use, C->top()); | |
712 break; | |
713 } | |
714 case Op_Phi: | |
715 if (use->in(0) == C->top()) { | |
716 C->gvn_replace_by(use, C->top()); | |
717 } | |
718 break; | |
719 } | |
720 } | |
721 } | |
722 | |
723 | |
12889
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
724 bool StringConcat::validate_mem_flow() { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
725 Compile* C = _stringopts->C; |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
726 |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
727 for (uint i = 0; i < _control.size(); i++) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
728 #ifndef PRODUCT |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
729 Node_List path; |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
730 #endif |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
731 Node* curr = _control.at(i); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
732 if (curr->is_Call() && curr != _begin) { // For all calls except the first allocation |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
733 // Now here's the main invariant in our case: |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
734 // For memory between the constructor, and appends, and toString we should only see bottom memory, |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
735 // produced by the previous call we know about. |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
736 if (!_constructors.contains(curr)) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
737 NOT_PRODUCT(path.push(curr);) |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
738 Node* mem = curr->in(TypeFunc::Memory); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
739 assert(mem != NULL, "calls should have memory edge"); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
740 assert(!mem->is_Phi(), "should be handled by control flow validation"); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
741 NOT_PRODUCT(path.push(mem);) |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
742 while (mem->is_MergeMem()) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
743 for (uint i = 1; i < mem->req(); i++) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
744 if (i != Compile::AliasIdxBot && mem->in(i) != C->top()) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
745 #ifndef PRODUCT |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
746 if (PrintOptimizeStringConcat) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
747 tty->print("fusion has incorrect memory flow (side effects) for "); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
748 _begin->jvms()->dump_spec(tty); tty->cr(); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
749 path.dump(); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
750 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
751 #endif |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
752 return false; |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
753 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
754 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
755 // skip through a potential MergeMem chain, linked through Bot |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
756 mem = mem->in(Compile::AliasIdxBot); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
757 NOT_PRODUCT(path.push(mem);) |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
758 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
759 // now let it fall through, and see if we have a projection |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
760 if (mem->is_Proj()) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
761 // Should point to a previous known call |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
762 Node *prev = mem->in(0); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
763 NOT_PRODUCT(path.push(prev);) |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
764 if (!prev->is_Call() || !_control.contains(prev)) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
765 #ifndef PRODUCT |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
766 if (PrintOptimizeStringConcat) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
767 tty->print("fusion has incorrect memory flow (unknown call) for "); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
768 _begin->jvms()->dump_spec(tty); tty->cr(); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
769 path.dump(); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
770 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
771 #endif |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
772 return false; |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
773 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
774 } else { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
775 assert(mem->is_Store() || mem->is_LoadStore(), err_msg_res("unexpected node type: %s", mem->Name())); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
776 #ifndef PRODUCT |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
777 if (PrintOptimizeStringConcat) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
778 tty->print("fusion has incorrect memory flow (unexpected source) for "); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
779 _begin->jvms()->dump_spec(tty); tty->cr(); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
780 path.dump(); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
781 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
782 #endif |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
783 return false; |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
784 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
785 } else { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
786 // For memory that feeds into constructors it's more complicated. |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
787 // However the advantage is that any side effect that happens between the Allocate/Initialize and |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
788 // the constructor will have to be control-dependent on Initialize. |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
789 // So we actually don't have to do anything, since it's going to be caught by the control flow |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
790 // analysis. |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
791 #ifdef ASSERT |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
792 // Do a quick verification of the control pattern between the constructor and the initialize node |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
793 assert(curr->is_Call(), "constructor should be a call"); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
794 // Go up the control starting from the constructor call |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
795 Node* ctrl = curr->in(0); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
796 IfNode* iff = NULL; |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
797 RegionNode* copy = NULL; |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
798 |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
799 while (true) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
800 // skip known check patterns |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
801 if (ctrl->is_Region()) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
802 if (ctrl->as_Region()->is_copy()) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
803 copy = ctrl->as_Region(); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
804 ctrl = copy->is_copy(); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
805 } else { // a cast |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
806 assert(ctrl->req() == 3 && |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
807 ctrl->in(1) != NULL && ctrl->in(1)->is_Proj() && |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
808 ctrl->in(2) != NULL && ctrl->in(2)->is_Proj() && |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
809 ctrl->in(1)->in(0) == ctrl->in(2)->in(0) && |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
810 ctrl->in(1)->in(0) != NULL && ctrl->in(1)->in(0)->is_If(), |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
811 "must be a simple diamond"); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
812 Node* true_proj = ctrl->in(1)->is_IfTrue() ? ctrl->in(1) : ctrl->in(2); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
813 for (SimpleDUIterator i(true_proj); i.has_next(); i.next()) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
814 Node* use = i.get(); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
815 assert(use == ctrl || use->is_ConstraintCast(), |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
816 err_msg_res("unexpected user: %s", use->Name())); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
817 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
818 |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
819 iff = ctrl->in(1)->in(0)->as_If(); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
820 ctrl = iff->in(0); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
821 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
822 } else if (ctrl->is_IfTrue()) { // null checks, class checks |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
823 iff = ctrl->in(0)->as_If(); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
824 assert(iff->is_If(), "must be if"); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
825 // Verify that the other arm is an uncommon trap |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
826 Node* otherproj = iff->proj_out(1 - ctrl->as_Proj()->_con); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
827 CallStaticJavaNode* call = otherproj->unique_out()->isa_CallStaticJava(); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
828 assert(strcmp(call->_name, "uncommon_trap") == 0, "must be uncommond trap"); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
829 ctrl = iff->in(0); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
830 } else { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
831 break; |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
832 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
833 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
834 |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
835 assert(ctrl->is_Proj(), "must be a projection"); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
836 assert(ctrl->in(0)->is_Initialize(), "should be initialize"); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
837 for (SimpleDUIterator i(ctrl); i.has_next(); i.next()) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
838 Node* use = i.get(); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
839 assert(use == copy || use == iff || use == curr || use->is_CheckCastPP() || use->is_Load(), |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
840 err_msg_res("unexpected user: %s", use->Name())); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
841 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
842 #endif // ASSERT |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
843 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
844 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
845 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
846 |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
847 #ifndef PRODUCT |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
848 if (PrintOptimizeStringConcat) { |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
849 tty->print("fusion has correct memory flow for "); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
850 _begin->jvms()->dump_spec(tty); tty->cr(); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
851 tty->cr(); |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
852 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
853 #endif |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
854 return true; |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
855 } |
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
856 |
1080 | 857 bool StringConcat::validate_control_flow() { |
858 // We found all the calls and arguments now lets see if it's | |
859 // safe to transform the graph as we would expect. | |
860 | |
861 // Check to see if this resulted in too many uncommon traps previously | |
862 if (Compile::current()->too_many_traps(_begin->jvms()->method(), _begin->jvms()->bci(), | |
863 Deoptimization::Reason_intrinsic)) { | |
864 return false; | |
865 } | |
866 | |
867 // Walk backwards over the control flow from toString to the | |
868 // allocation and make sure all the control flow is ok. This | |
869 // means it's either going to be eliminated once the calls are | |
870 // removed or it can safely be transformed into an uncommon | |
871 // trap. | |
872 | |
873 int null_check_count = 0; | |
874 Unique_Node_List ctrl_path; | |
875 | |
876 assert(_control.contains(_begin), "missing"); | |
877 assert(_control.contains(_end), "missing"); | |
878 | |
879 // Collect the nodes that we know about and will eliminate into ctrl_path | |
880 for (uint i = 0; i < _control.size(); i++) { | |
881 // Push the call and it's control projection | |
882 Node* n = _control.at(i); | |
883 if (n->is_Allocate()) { | |
884 AllocateNode* an = n->as_Allocate(); | |
885 InitializeNode* init = an->initialization(); | |
886 ctrl_path.push(init); | |
887 ctrl_path.push(init->as_Multi()->proj_out(0)); | |
888 } | |
889 if (n->is_Call()) { | |
890 CallNode* cn = n->as_Call(); | |
891 ctrl_path.push(cn); | |
892 ctrl_path.push(cn->proj_out(0)); | |
893 ctrl_path.push(cn->proj_out(0)->unique_out()); | |
7421
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
894 if (cn->proj_out(0)->unique_out()->as_Catch()->proj_out(0) != NULL) { |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
895 ctrl_path.push(cn->proj_out(0)->unique_out()->as_Catch()->proj_out(0)); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
896 } |
1080 | 897 } else { |
898 ShouldNotReachHere(); | |
899 } | |
900 } | |
901 | |
12889
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
902 // Skip backwards through the control checking for unexpected control flow |
1080 | 903 Node* ptr = _end; |
904 bool fail = false; | |
905 while (ptr != _begin) { | |
906 if (ptr->is_Call() && ctrl_path.member(ptr)) { | |
907 ptr = ptr->in(0); | |
908 } else if (ptr->is_CatchProj() && ctrl_path.member(ptr)) { | |
909 ptr = ptr->in(0)->in(0)->in(0); | |
910 assert(ctrl_path.member(ptr), "should be a known piece of control"); | |
911 } else if (ptr->is_IfTrue()) { | |
912 IfNode* iff = ptr->in(0)->as_If(); | |
913 BoolNode* b = iff->in(1)->isa_Bool(); | |
7421
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
914 |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
915 if (b == NULL) { |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
916 fail = true; |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
917 break; |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
918 } |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
919 |
1080 | 920 Node* cmp = b->in(1); |
921 Node* v1 = cmp->in(1); | |
922 Node* v2 = cmp->in(2); | |
923 Node* otherproj = iff->proj_out(1 - ptr->as_Proj()->_con); | |
924 | |
925 // Null check of the return of append which can simply be eliminated | |
926 if (b->_test._test == BoolTest::ne && | |
927 v2->bottom_type() == TypePtr::NULL_PTR && | |
928 v1->is_Proj() && ctrl_path.member(v1->in(0))) { | |
929 // NULL check of the return value of the append | |
930 null_check_count++; | |
931 if (otherproj->outcnt() == 1) { | |
932 CallStaticJavaNode* call = otherproj->unique_out()->isa_CallStaticJava(); | |
933 if (call != NULL && call->_name != NULL && strcmp(call->_name, "uncommon_trap") == 0) { | |
934 ctrl_path.push(call); | |
935 } | |
936 } | |
937 _control.push(ptr); | |
938 ptr = ptr->in(0)->in(0); | |
939 continue; | |
940 } | |
941 | |
942 // A test which leads to an uncommon trap which should be safe. | |
943 // Later this trap will be converted into a trap that restarts | |
944 // at the beginning. | |
945 if (otherproj->outcnt() == 1) { | |
946 CallStaticJavaNode* call = otherproj->unique_out()->isa_CallStaticJava(); | |
947 if (call != NULL && call->_name != NULL && strcmp(call->_name, "uncommon_trap") == 0) { | |
948 // control flow leads to uct so should be ok | |
949 _uncommon_traps.push(call); | |
950 ctrl_path.push(call); | |
951 ptr = ptr->in(0)->in(0); | |
952 continue; | |
953 } | |
954 } | |
955 | |
956 #ifndef PRODUCT | |
957 // Some unexpected control flow we don't know how to handle. | |
958 if (PrintOptimizeStringConcat) { | |
959 tty->print_cr("failing with unknown test"); | |
960 b->dump(); | |
961 cmp->dump(); | |
962 v1->dump(); | |
963 v2->dump(); | |
964 tty->cr(); | |
965 } | |
966 #endif | |
3396 | 967 fail = true; |
1080 | 968 break; |
969 } else if (ptr->is_Proj() && ptr->in(0)->is_Initialize()) { | |
970 ptr = ptr->in(0)->in(0); | |
971 } else if (ptr->is_Region()) { | |
972 Node* copy = ptr->as_Region()->is_copy(); | |
973 if (copy != NULL) { | |
974 ptr = copy; | |
975 continue; | |
976 } | |
977 if (ptr->req() == 3 && | |
978 ptr->in(1) != NULL && ptr->in(1)->is_Proj() && | |
979 ptr->in(2) != NULL && ptr->in(2)->is_Proj() && | |
980 ptr->in(1)->in(0) == ptr->in(2)->in(0) && | |
981 ptr->in(1)->in(0) != NULL && ptr->in(1)->in(0)->is_If()) { | |
982 // Simple diamond. | |
983 // XXX should check for possibly merging stores. simple data merges are ok. | |
7473 | 984 // The IGVN will make this simple diamond go away when it |
985 // transforms the Region. Make sure it sees it. | |
986 Compile::current()->record_for_igvn(ptr); | |
1080 | 987 ptr = ptr->in(1)->in(0)->in(0); |
988 continue; | |
989 } | |
990 #ifndef PRODUCT | |
991 if (PrintOptimizeStringConcat) { | |
992 tty->print_cr("fusion would fail for region"); | |
993 _begin->dump(); | |
994 ptr->dump(2); | |
995 } | |
996 #endif | |
997 fail = true; | |
998 break; | |
999 } else { | |
1000 // other unknown control | |
1001 if (!fail) { | |
1002 #ifndef PRODUCT | |
1003 if (PrintOptimizeStringConcat) { | |
1004 tty->print_cr("fusion would fail for"); | |
1005 _begin->dump(); | |
1006 } | |
1007 #endif | |
1008 fail = true; | |
1009 } | |
1010 #ifndef PRODUCT | |
1011 if (PrintOptimizeStringConcat) { | |
1012 ptr->dump(); | |
1013 } | |
1014 #endif | |
1015 ptr = ptr->in(0); | |
1016 } | |
1017 } | |
1018 #ifndef PRODUCT | |
1019 if (PrintOptimizeStringConcat && fail) { | |
1020 tty->cr(); | |
1021 } | |
1022 #endif | |
1023 if (fail) return !fail; | |
1024 | |
1025 // Validate that all these results produced are contained within | |
1026 // this cluster of objects. First collect all the results produced | |
1027 // by calls in the region. | |
1028 _stringopts->_visited.Clear(); | |
1029 Node_List worklist; | |
1030 Node* final_result = _end->proj_out(TypeFunc::Parms); | |
1031 for (uint i = 0; i < _control.size(); i++) { | |
1032 CallNode* cnode = _control.at(i)->isa_Call(); | |
1033 if (cnode != NULL) { | |
1034 _stringopts->_visited.test_set(cnode->_idx); | |
1035 } | |
1036 Node* result = cnode != NULL ? cnode->proj_out(TypeFunc::Parms) : NULL; | |
1037 if (result != NULL && result != final_result) { | |
1038 worklist.push(result); | |
1039 } | |
1040 } | |
1041 | |
1042 Node* last_result = NULL; | |
1043 while (worklist.size() > 0) { | |
1044 Node* result = worklist.pop(); | |
1045 if (_stringopts->_visited.test_set(result->_idx)) | |
1046 continue; | |
1047 for (SimpleDUIterator i(result); i.has_next(); i.next()) { | |
1048 Node *use = i.get(); | |
1049 if (ctrl_path.member(use)) { | |
1050 // already checked this | |
1051 continue; | |
1052 } | |
1053 int opc = use->Opcode(); | |
1054 if (opc == Op_CmpP || opc == Op_Node) { | |
1055 ctrl_path.push(use); | |
1056 continue; | |
1057 } | |
1058 if (opc == Op_CastPP || opc == Op_CheckCastPP) { | |
1059 for (SimpleDUIterator j(use); j.has_next(); j.next()) { | |
1060 worklist.push(j.get()); | |
1061 } | |
1062 worklist.push(use->in(1)); | |
1063 ctrl_path.push(use); | |
1064 continue; | |
1065 } | |
1066 #ifndef PRODUCT | |
1067 if (PrintOptimizeStringConcat) { | |
1068 if (result != last_result) { | |
1069 last_result = result; | |
1070 tty->print_cr("extra uses for result:"); | |
1071 last_result->dump(); | |
1072 } | |
1073 use->dump(); | |
1074 } | |
1075 #endif | |
1076 fail = true; | |
1077 break; | |
1078 } | |
1079 } | |
1080 | |
1081 #ifndef PRODUCT | |
1082 if (PrintOptimizeStringConcat && !fail) { | |
1083 ttyLocker ttyl; | |
1084 tty->cr(); | |
12889
90abdd727e64
8009303: Tiered: incorrect results in VM tests stringconcat with -Xcomp -XX:+DeoptimizeALot on solaris-amd64
iveresov
parents:
7473
diff
changeset
|
1085 tty->print("fusion has correct control flow (%d %d) for ", null_check_count, _uncommon_traps.size()); |
1080 | 1086 _begin->jvms()->dump_spec(tty); tty->cr(); |
1087 for (int i = 0; i < num_arguments(); i++) { | |
1088 argument(i)->dump(); | |
1089 } | |
1090 _control.dump(); | |
1091 tty->cr(); | |
1092 } | |
1093 #endif | |
1094 | |
1095 return !fail; | |
1096 } | |
1097 | |
1098 Node* PhaseStringOpts::fetch_static_field(GraphKit& kit, ciField* field) { | |
6043
df3d4a91f7f6
7161796: PhaseStringOpts::fetch_static_field tries to fetch field from the Klass instead of the mirror
never
parents:
3396
diff
changeset
|
1099 const TypeInstPtr* mirror_type = TypeInstPtr::make(field->holder()->java_mirror()); |
df3d4a91f7f6
7161796: PhaseStringOpts::fetch_static_field tries to fetch field from the Klass instead of the mirror
never
parents:
3396
diff
changeset
|
1100 Node* klass_node = __ makecon(mirror_type); |
1080 | 1101 BasicType bt = field->layout_type(); |
1102 ciType* field_klass = field->type(); | |
1103 | |
1104 const Type *type; | |
1105 if( bt == T_OBJECT ) { | |
1106 if (!field->type()->is_loaded()) { | |
1107 type = TypeInstPtr::BOTTOM; | |
1108 } else if (field->is_constant()) { | |
1109 // This can happen if the constant oop is non-perm. | |
1110 ciObject* con = field->constant_value().as_object(); | |
1111 // Do not "join" in the previous type; it doesn't add value, | |
1112 // and may yield a vacuous result if the field is of interface type. | |
2379
b099aaf51bf8
6962931: move interned strings out of the perm gen
jcoomes
parents:
2090
diff
changeset
|
1113 type = TypeOopPtr::make_from_constant(con, true)->isa_oopptr(); |
1080 | 1114 assert(type != NULL, "field singleton type must be consistent"); |
6043
df3d4a91f7f6
7161796: PhaseStringOpts::fetch_static_field tries to fetch field from the Klass instead of the mirror
never
parents:
3396
diff
changeset
|
1115 return __ makecon(type); |
1080 | 1116 } else { |
1117 type = TypeOopPtr::make_from_klass(field_klass->as_klass()); | |
1118 } | |
1119 } else { | |
1120 type = Type::get_const_basic_type(bt); | |
1121 } | |
1122 | |
1123 return kit.make_load(NULL, kit.basic_plus_adr(klass_node, field->offset_in_bytes()), | |
1124 type, T_OBJECT, | |
14909 | 1125 C->get_alias_index(mirror_type->add_offset(field->offset_in_bytes()))); |
1080 | 1126 } |
1127 | |
1128 Node* PhaseStringOpts::int_stringSize(GraphKit& kit, Node* arg) { | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1129 RegionNode *final_merge = new (C) RegionNode(3); |
1080 | 1130 kit.gvn().set_type(final_merge, Type::CONTROL); |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1131 Node* final_size = new (C) PhiNode(final_merge, TypeInt::INT); |
1080 | 1132 kit.gvn().set_type(final_size, TypeInt::INT); |
1133 | |
1134 IfNode* iff = kit.create_and_map_if(kit.control(), | |
1135 __ Bool(__ CmpI(arg, __ intcon(0x80000000)), BoolTest::ne), | |
1136 PROB_FAIR, COUNT_UNKNOWN); | |
1137 Node* is_min = __ IfFalse(iff); | |
1138 final_merge->init_req(1, is_min); | |
1139 final_size->init_req(1, __ intcon(11)); | |
1140 | |
1141 kit.set_control(__ IfTrue(iff)); | |
1142 if (kit.stopped()) { | |
1143 final_merge->init_req(2, C->top()); | |
1144 final_size->init_req(2, C->top()); | |
1145 } else { | |
1146 | |
1147 // int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i); | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1148 RegionNode *r = new (C) RegionNode(3); |
1080 | 1149 kit.gvn().set_type(r, Type::CONTROL); |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1150 Node *phi = new (C) PhiNode(r, TypeInt::INT); |
1080 | 1151 kit.gvn().set_type(phi, TypeInt::INT); |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1152 Node *size = new (C) PhiNode(r, TypeInt::INT); |
1080 | 1153 kit.gvn().set_type(size, TypeInt::INT); |
1154 Node* chk = __ CmpI(arg, __ intcon(0)); | |
1155 Node* p = __ Bool(chk, BoolTest::lt); | |
1156 IfNode* iff = kit.create_and_map_if(kit.control(), p, PROB_FAIR, COUNT_UNKNOWN); | |
1157 Node* lessthan = __ IfTrue(iff); | |
1158 Node* greaterequal = __ IfFalse(iff); | |
1159 r->init_req(1, lessthan); | |
1160 phi->init_req(1, __ SubI(__ intcon(0), arg)); | |
1161 size->init_req(1, __ intcon(1)); | |
1162 r->init_req(2, greaterequal); | |
1163 phi->init_req(2, arg); | |
1164 size->init_req(2, __ intcon(0)); | |
1165 kit.set_control(r); | |
1166 C->record_for_igvn(r); | |
1167 C->record_for_igvn(phi); | |
1168 C->record_for_igvn(size); | |
1169 | |
1170 // for (int i=0; ; i++) | |
1171 // if (x <= sizeTable[i]) | |
1172 // return i+1; | |
2383
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
2090
diff
changeset
|
1173 |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
2090
diff
changeset
|
1174 // Add loop predicate first. |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
2090
diff
changeset
|
1175 kit.add_predicate(); |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
2090
diff
changeset
|
1176 |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1177 RegionNode *loop = new (C) RegionNode(3); |
1080 | 1178 loop->init_req(1, kit.control()); |
1179 kit.gvn().set_type(loop, Type::CONTROL); | |
1180 | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1181 Node *index = new (C) PhiNode(loop, TypeInt::INT); |
1080 | 1182 index->init_req(1, __ intcon(0)); |
1183 kit.gvn().set_type(index, TypeInt::INT); | |
1184 kit.set_control(loop); | |
1185 Node* sizeTable = fetch_static_field(kit, size_table_field); | |
1186 | |
1187 Node* value = kit.load_array_element(NULL, sizeTable, index, TypeAryPtr::INTS); | |
1188 C->record_for_igvn(value); | |
1189 Node* limit = __ CmpI(phi, value); | |
1190 Node* limitb = __ Bool(limit, BoolTest::le); | |
1191 IfNode* iff2 = kit.create_and_map_if(kit.control(), limitb, PROB_MIN, COUNT_UNKNOWN); | |
1192 Node* lessEqual = __ IfTrue(iff2); | |
1193 Node* greater = __ IfFalse(iff2); | |
1194 | |
1195 loop->init_req(2, greater); | |
1196 index->init_req(2, __ AddI(index, __ intcon(1))); | |
1197 | |
1198 kit.set_control(lessEqual); | |
1199 C->record_for_igvn(loop); | |
1200 C->record_for_igvn(index); | |
1201 | |
1202 final_merge->init_req(2, kit.control()); | |
1203 final_size->init_req(2, __ AddI(__ AddI(index, size), __ intcon(1))); | |
1204 } | |
1205 | |
1206 kit.set_control(final_merge); | |
1207 C->record_for_igvn(final_merge); | |
1208 C->record_for_igvn(final_size); | |
1209 | |
1210 return final_size; | |
1211 } | |
1212 | |
1213 void PhaseStringOpts::int_getChars(GraphKit& kit, Node* arg, Node* char_array, Node* start, Node* end) { | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1214 RegionNode *final_merge = new (C) RegionNode(4); |
1080 | 1215 kit.gvn().set_type(final_merge, Type::CONTROL); |
1216 Node *final_mem = PhiNode::make(final_merge, kit.memory(char_adr_idx), Type::MEMORY, TypeAryPtr::CHARS); | |
1217 kit.gvn().set_type(final_mem, Type::MEMORY); | |
1218 | |
1219 // need to handle Integer.MIN_VALUE specially because negating doesn't make it positive | |
1220 { | |
1221 // i == MIN_VALUE | |
1222 IfNode* iff = kit.create_and_map_if(kit.control(), | |
1223 __ Bool(__ CmpI(arg, __ intcon(0x80000000)), BoolTest::ne), | |
1224 PROB_FAIR, COUNT_UNKNOWN); | |
1225 | |
1226 Node* old_mem = kit.memory(char_adr_idx); | |
1227 | |
1228 kit.set_control(__ IfFalse(iff)); | |
1229 if (kit.stopped()) { | |
1230 // Statically not equal to MIN_VALUE so this path is dead | |
1231 final_merge->init_req(3, kit.control()); | |
1232 } else { | |
1233 copy_string(kit, __ makecon(TypeInstPtr::make(C->env()->the_min_jint_string())), | |
1234 char_array, start); | |
1235 final_merge->init_req(3, kit.control()); | |
1236 final_mem->init_req(3, kit.memory(char_adr_idx)); | |
1237 } | |
1238 | |
1239 kit.set_control(__ IfTrue(iff)); | |
1240 kit.set_memory(old_mem, char_adr_idx); | |
1241 } | |
1242 | |
1243 | |
1244 // Simplified version of Integer.getChars | |
1245 | |
1246 // int q, r; | |
1247 // int charPos = index; | |
1248 Node* charPos = end; | |
1249 | |
1250 // char sign = 0; | |
1251 | |
1252 Node* i = arg; | |
1253 Node* sign = __ intcon(0); | |
1254 | |
1255 // if (i < 0) { | |
1256 // sign = '-'; | |
1257 // i = -i; | |
1258 // } | |
1259 { | |
1260 IfNode* iff = kit.create_and_map_if(kit.control(), | |
1261 __ Bool(__ CmpI(arg, __ intcon(0)), BoolTest::lt), | |
1262 PROB_FAIR, COUNT_UNKNOWN); | |
1263 | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1264 RegionNode *merge = new (C) RegionNode(3); |
1080 | 1265 kit.gvn().set_type(merge, Type::CONTROL); |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1266 i = new (C) PhiNode(merge, TypeInt::INT); |
1080 | 1267 kit.gvn().set_type(i, TypeInt::INT); |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1268 sign = new (C) PhiNode(merge, TypeInt::INT); |
1080 | 1269 kit.gvn().set_type(sign, TypeInt::INT); |
1270 | |
1271 merge->init_req(1, __ IfTrue(iff)); | |
1272 i->init_req(1, __ SubI(__ intcon(0), arg)); | |
1273 sign->init_req(1, __ intcon('-')); | |
1274 merge->init_req(2, __ IfFalse(iff)); | |
1275 i->init_req(2, arg); | |
1276 sign->init_req(2, __ intcon(0)); | |
1277 | |
1278 kit.set_control(merge); | |
1279 | |
1280 C->record_for_igvn(merge); | |
1281 C->record_for_igvn(i); | |
1282 C->record_for_igvn(sign); | |
1283 } | |
1284 | |
1285 // for (;;) { | |
1286 // q = i / 10; | |
1287 // r = i - ((q << 3) + (q << 1)); // r = i-(q*10) ... | |
1288 // buf [--charPos] = digits [r]; | |
1289 // i = q; | |
1290 // if (i == 0) break; | |
1291 // } | |
1292 | |
1293 { | |
2383
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
2090
diff
changeset
|
1294 // Add loop predicate first. |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
2090
diff
changeset
|
1295 kit.add_predicate(); |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
2090
diff
changeset
|
1296 |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1297 RegionNode *head = new (C) RegionNode(3); |
1080 | 1298 head->init_req(1, kit.control()); |
1299 kit.gvn().set_type(head, Type::CONTROL); | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1300 Node *i_phi = new (C) PhiNode(head, TypeInt::INT); |
1080 | 1301 i_phi->init_req(1, i); |
1302 kit.gvn().set_type(i_phi, TypeInt::INT); | |
1303 charPos = PhiNode::make(head, charPos); | |
1304 kit.gvn().set_type(charPos, TypeInt::INT); | |
1305 Node *mem = PhiNode::make(head, kit.memory(char_adr_idx), Type::MEMORY, TypeAryPtr::CHARS); | |
1306 kit.gvn().set_type(mem, Type::MEMORY); | |
1307 kit.set_control(head); | |
1308 kit.set_memory(mem, char_adr_idx); | |
1309 | |
1250 | 1310 Node* q = __ DivI(NULL, i_phi, __ intcon(10)); |
1080 | 1311 Node* r = __ SubI(i_phi, __ AddI(__ LShiftI(q, __ intcon(3)), |
1312 __ LShiftI(q, __ intcon(1)))); | |
1313 Node* m1 = __ SubI(charPos, __ intcon(1)); | |
1314 Node* ch = __ AddI(r, __ intcon('0')); | |
1315 | |
1316 Node* st = __ store_to_memory(kit.control(), kit.array_element_address(char_array, m1, T_CHAR), | |
14909 | 1317 ch, T_CHAR, char_adr_idx); |
1080 | 1318 |
1319 | |
1320 IfNode* iff = kit.create_and_map_if(head, __ Bool(__ CmpI(q, __ intcon(0)), BoolTest::ne), | |
1321 PROB_FAIR, COUNT_UNKNOWN); | |
1322 Node* ne = __ IfTrue(iff); | |
1323 Node* eq = __ IfFalse(iff); | |
1324 | |
1325 head->init_req(2, ne); | |
1326 mem->init_req(2, st); | |
1327 i_phi->init_req(2, q); | |
1328 charPos->init_req(2, m1); | |
1329 | |
1330 charPos = m1; | |
1331 | |
1332 kit.set_control(eq); | |
1333 kit.set_memory(st, char_adr_idx); | |
1334 | |
1335 C->record_for_igvn(head); | |
1336 C->record_for_igvn(mem); | |
1337 C->record_for_igvn(i_phi); | |
1338 C->record_for_igvn(charPos); | |
1339 } | |
1340 | |
1341 { | |
1342 // if (sign != 0) { | |
1343 // buf [--charPos] = sign; | |
1344 // } | |
1345 IfNode* iff = kit.create_and_map_if(kit.control(), | |
1346 __ Bool(__ CmpI(sign, __ intcon(0)), BoolTest::ne), | |
1347 PROB_FAIR, COUNT_UNKNOWN); | |
1348 | |
1349 final_merge->init_req(2, __ IfFalse(iff)); | |
1350 final_mem->init_req(2, kit.memory(char_adr_idx)); | |
1351 | |
1352 kit.set_control(__ IfTrue(iff)); | |
1353 if (kit.stopped()) { | |
1354 final_merge->init_req(1, C->top()); | |
1355 final_mem->init_req(1, C->top()); | |
1356 } else { | |
1357 Node* m1 = __ SubI(charPos, __ intcon(1)); | |
1358 Node* st = __ store_to_memory(kit.control(), kit.array_element_address(char_array, m1, T_CHAR), | |
14909 | 1359 sign, T_CHAR, char_adr_idx); |
1080 | 1360 |
1361 final_merge->init_req(1, kit.control()); | |
1362 final_mem->init_req(1, st); | |
1363 } | |
1364 | |
1365 kit.set_control(final_merge); | |
1366 kit.set_memory(final_mem, char_adr_idx); | |
1367 | |
1368 C->record_for_igvn(final_merge); | |
1369 C->record_for_igvn(final_mem); | |
1370 } | |
1371 } | |
1372 | |
1373 | |
1374 Node* PhaseStringOpts::copy_string(GraphKit& kit, Node* str, Node* char_array, Node* start) { | |
1375 Node* string = str; | |
6057 | 1376 Node* offset = kit.load_String_offset(kit.control(), string); |
1377 Node* count = kit.load_String_length(kit.control(), string); | |
1378 Node* value = kit.load_String_value (kit.control(), string); | |
1080 | 1379 |
1380 // copy the contents | |
1381 if (offset->is_Con() && count->is_Con() && value->is_Con() && count->get_int() < unroll_string_copy_length) { | |
1382 // For small constant strings just emit individual stores. | |
1383 // A length of 6 seems like a good space/speed tradeof. | |
1384 int c = count->get_int(); | |
1385 int o = offset->get_int(); | |
1386 const TypeOopPtr* t = kit.gvn().type(value)->isa_oopptr(); | |
1387 ciTypeArray* value_array = t->const_oop()->as_type_array(); | |
1388 for (int e = 0; e < c; e++) { | |
1389 __ store_to_memory(kit.control(), kit.array_element_address(char_array, start, T_CHAR), | |
14909 | 1390 __ intcon(value_array->char_at(o + e)), T_CHAR, char_adr_idx); |
1080 | 1391 start = __ AddI(start, __ intcon(1)); |
1392 } | |
1393 } else { | |
1394 Node* src_ptr = kit.array_element_address(value, offset, T_CHAR); | |
1395 Node* dst_ptr = kit.array_element_address(char_array, start, T_CHAR); | |
1396 Node* c = count; | |
1397 Node* extra = NULL; | |
1398 #ifdef _LP64 | |
1399 c = __ ConvI2L(c); | |
1400 extra = C->top(); | |
1401 #endif | |
1402 Node* call = kit.make_runtime_call(GraphKit::RC_LEAF|GraphKit::RC_NO_FP, | |
1403 OptoRuntime::fast_arraycopy_Type(), | |
1404 CAST_FROM_FN_PTR(address, StubRoutines::jshort_disjoint_arraycopy()), | |
1405 "jshort_disjoint_arraycopy", TypeAryPtr::CHARS, | |
1406 src_ptr, dst_ptr, c, extra); | |
1407 start = __ AddI(start, count); | |
1408 } | |
1409 return start; | |
1410 } | |
1411 | |
1412 | |
1413 void PhaseStringOpts::replace_string_concat(StringConcat* sc) { | |
1414 // Log a little info about the transformation | |
1415 sc->maybe_log_transform(); | |
1416 | |
1417 // pull the JVMState of the allocation into a SafePointNode to serve as | |
1418 // as a shim for the insertion of the new code. | |
1419 JVMState* jvms = sc->begin()->jvms()->clone_shallow(C); | |
1420 uint size = sc->begin()->req(); | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1421 SafePointNode* map = new (C) SafePointNode(size, jvms); |
1080 | 1422 |
1423 // copy the control and memory state from the final call into our | |
1424 // new starting state. This allows any preceeding tests to feed | |
1425 // into the new section of code. | |
1426 for (uint i1 = 0; i1 < TypeFunc::Parms; i1++) { | |
1427 map->init_req(i1, sc->end()->in(i1)); | |
1428 } | |
1429 // blow away old allocation arguments | |
1430 for (uint i1 = TypeFunc::Parms; i1 < jvms->debug_start(); i1++) { | |
1431 map->init_req(i1, C->top()); | |
1432 } | |
1433 // Copy the rest of the inputs for the JVMState | |
1434 for (uint i1 = jvms->debug_start(); i1 < sc->begin()->req(); i1++) { | |
1435 map->init_req(i1, sc->begin()->in(i1)); | |
1436 } | |
1437 // Make sure the memory state is a MergeMem for parsing. | |
1438 if (!map->in(TypeFunc::Memory)->is_MergeMem()) { | |
1439 map->set_req(TypeFunc::Memory, MergeMemNode::make(C, map->in(TypeFunc::Memory))); | |
1440 } | |
1441 | |
1442 jvms->set_map(map); | |
1443 map->ensure_stack(jvms, jvms->method()->max_stack()); | |
1444 | |
1445 | |
1446 // disconnect all the old StringBuilder calls from the graph | |
1447 sc->eliminate_unneeded_control(); | |
1448 | |
1449 // At this point all the old work has been completely removed from | |
1450 // the graph and the saved JVMState exists at the point where the | |
1451 // final toString call used to be. | |
1452 GraphKit kit(jvms); | |
1453 | |
1454 // There may be uncommon traps which are still using the | |
1455 // intermediate states and these need to be rewritten to point at | |
1456 // the JVMState at the beginning of the transformation. | |
1457 sc->convert_uncommon_traps(kit, jvms); | |
1458 | |
1459 // Now insert the logic to compute the size of the string followed | |
1460 // by all the logic to construct array and resulting string. | |
1461 | |
1462 Node* null_string = __ makecon(TypeInstPtr::make(C->env()->the_null_string())); | |
1463 | |
1464 // Create a region for the overflow checks to merge into. | |
1465 int args = MAX2(sc->num_arguments(), 1); | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1466 RegionNode* overflow = new (C) RegionNode(args); |
1080 | 1467 kit.gvn().set_type(overflow, Type::CONTROL); |
1468 | |
1469 // Create a hook node to hold onto the individual sizes since they | |
1470 // are need for the copying phase. | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1471 Node* string_sizes = new (C) Node(args); |
1080 | 1472 |
1473 Node* length = __ intcon(0); | |
1474 for (int argi = 0; argi < sc->num_arguments(); argi++) { | |
1475 Node* arg = sc->argument(argi); | |
1476 switch (sc->mode(argi)) { | |
1477 case StringConcat::IntMode: { | |
1478 Node* string_size = int_stringSize(kit, arg); | |
1479 | |
1480 // accumulate total | |
1481 length = __ AddI(length, string_size); | |
1482 | |
1483 // Cache this value for the use by int_toString | |
1484 string_sizes->init_req(argi, string_size); | |
1485 break; | |
1486 } | |
2090
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1487 case StringConcat::StringNullCheckMode: { |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1488 const Type* type = kit.gvn().type(arg); |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1489 assert(type != TypePtr::NULL_PTR, "missing check"); |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1490 if (!type->higher_equal(TypeInstPtr::NOTNULL)) { |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1491 // Null check with uncommont trap since |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1492 // StringBuilder(null) throws exception. |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1493 // Use special uncommon trap instead of |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1494 // calling normal do_null_check(). |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1495 Node* p = __ Bool(__ CmpP(arg, kit.null()), BoolTest::ne); |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1496 IfNode* iff = kit.create_and_map_if(kit.control(), p, PROB_MIN, COUNT_UNKNOWN); |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1497 overflow->add_req(__ IfFalse(iff)); |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1498 Node* notnull = __ IfTrue(iff); |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1499 kit.set_control(notnull); // set control for the cast_not_null |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1500 arg = kit.cast_not_null(arg, false); |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1501 sc->set_argument(argi, arg); |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1502 } |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1503 assert(kit.gvn().type(arg)->higher_equal(TypeInstPtr::NOTNULL), "sanity"); |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1504 // Fallthrough to add string length. |
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1505 } |
1080 | 1506 case StringConcat::StringMode: { |
1507 const Type* type = kit.gvn().type(arg); | |
1508 if (type == TypePtr::NULL_PTR) { | |
1509 // replace the argument with the null checked version | |
1510 arg = null_string; | |
1511 sc->set_argument(argi, arg); | |
1512 } else if (!type->higher_equal(TypeInstPtr::NOTNULL)) { | |
1513 // s = s != null ? s : "null"; | |
1514 // length = length + (s.count - s.offset); | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1515 RegionNode *r = new (C) RegionNode(3); |
1080 | 1516 kit.gvn().set_type(r, Type::CONTROL); |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6223
diff
changeset
|
1517 Node *phi = new (C) PhiNode(r, type); |
1080 | 1518 kit.gvn().set_type(phi, phi->bottom_type()); |
1519 Node* p = __ Bool(__ CmpP(arg, kit.null()), BoolTest::ne); | |
1520 IfNode* iff = kit.create_and_map_if(kit.control(), p, PROB_MIN, COUNT_UNKNOWN); | |
1521 Node* notnull = __ IfTrue(iff); | |
1522 Node* isnull = __ IfFalse(iff); | |
1250 | 1523 kit.set_control(notnull); // set control for the cast_not_null |
1080 | 1524 r->init_req(1, notnull); |
1250 | 1525 phi->init_req(1, kit.cast_not_null(arg, false)); |
1080 | 1526 r->init_req(2, isnull); |
1527 phi->init_req(2, null_string); | |
1528 kit.set_control(r); | |
1529 C->record_for_igvn(r); | |
1530 C->record_for_igvn(phi); | |
1531 // replace the argument with the null checked version | |
1532 arg = phi; | |
1533 sc->set_argument(argi, arg); | |
1534 } | |
6057 | 1535 |
1536 Node* count = kit.load_String_length(kit.control(), arg); | |
1537 | |
1080 | 1538 length = __ AddI(length, count); |
1539 string_sizes->init_req(argi, NULL); | |
1540 break; | |
1541 } | |
1542 case StringConcat::CharMode: { | |
1543 // one character only | |
1544 length = __ AddI(length, __ intcon(1)); | |
1545 break; | |
1546 } | |
1547 default: | |
1548 ShouldNotReachHere(); | |
1549 } | |
1550 if (argi > 0) { | |
1551 // Check that the sum hasn't overflowed | |
1552 IfNode* iff = kit.create_and_map_if(kit.control(), | |
1553 __ Bool(__ CmpI(length, __ intcon(0)), BoolTest::lt), | |
1554 PROB_MIN, COUNT_UNKNOWN); | |
1555 kit.set_control(__ IfFalse(iff)); | |
1556 overflow->set_req(argi, __ IfTrue(iff)); | |
1557 } | |
1558 } | |
1559 | |
1560 { | |
1561 // Hook | |
1562 PreserveJVMState pjvms(&kit); | |
1563 kit.set_control(overflow); | |
2090
2ddb2fab82cb
7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
kvn
parents:
1972
diff
changeset
|
1564 C->record_for_igvn(overflow); |
1080 | 1565 kit.uncommon_trap(Deoptimization::Reason_intrinsic, |
1566 Deoptimization::Action_make_not_entrant); | |
1567 } | |
1568 | |
7421
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1569 Node* result; |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1570 if (!kit.stopped()) { |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1571 |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1572 // length now contains the number of characters needed for the |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1573 // char[] so create a new AllocateArray for the char[] |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1574 Node* char_array = NULL; |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1575 { |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1576 PreserveReexecuteState preexecs(&kit); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1577 // The original jvms is for an allocation of either a String or |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1578 // StringBuffer so no stack adjustment is necessary for proper |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1579 // reexecution. If we deoptimize in the slow path the bytecode |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1580 // will be reexecuted and the char[] allocation will be thrown away. |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1581 kit.jvms()->set_should_reexecute(true); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1582 char_array = kit.new_array(__ makecon(TypeKlassPtr::make(ciTypeArrayKlass::make(T_CHAR))), |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1583 length, 1); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1584 } |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1585 |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1586 // Mark the allocation so that zeroing is skipped since the code |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1587 // below will overwrite the entire array |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1588 AllocateArrayNode* char_alloc = AllocateArrayNode::Ideal_array_allocation(char_array, _gvn); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1589 char_alloc->maybe_set_complete(_gvn); |
1080 | 1590 |
7421
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1591 // Now copy the string representations into the final char[] |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1592 Node* start = __ intcon(0); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1593 for (int argi = 0; argi < sc->num_arguments(); argi++) { |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1594 Node* arg = sc->argument(argi); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1595 switch (sc->mode(argi)) { |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1596 case StringConcat::IntMode: { |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1597 Node* end = __ AddI(start, string_sizes->in(argi)); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1598 // getChars words backwards so pass the ending point as well as the start |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1599 int_getChars(kit, arg, char_array, start, end); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1600 start = end; |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1601 break; |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1602 } |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1603 case StringConcat::StringNullCheckMode: |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1604 case StringConcat::StringMode: { |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1605 start = copy_string(kit, arg, char_array, start); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1606 break; |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1607 } |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1608 case StringConcat::CharMode: { |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1609 __ store_to_memory(kit.control(), kit.array_element_address(char_array, start, T_CHAR), |
14909 | 1610 arg, T_CHAR, char_adr_idx); |
7421
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1611 start = __ AddI(start, __ intcon(1)); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1612 break; |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1613 } |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1614 default: |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1615 ShouldNotReachHere(); |
1080 | 1616 } |
1617 } | |
1618 | |
7421
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1619 // If we're not reusing an existing String allocation then allocate one here. |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1620 result = sc->string_alloc(); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1621 if (result == NULL) { |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1622 PreserveReexecuteState preexecs(&kit); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1623 // The original jvms is for an allocation of either a String or |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1624 // StringBuffer so no stack adjustment is necessary for proper |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1625 // reexecution. |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1626 kit.jvms()->set_should_reexecute(true); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1627 result = kit.new_instance(__ makecon(TypeKlassPtr::make(C->env()->String_klass()))); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1628 } |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1629 |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1630 // Intialize the string |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1631 if (java_lang_String::has_offset_field()) { |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1632 kit.store_String_offset(kit.control(), result, __ intcon(0)); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1633 kit.store_String_length(kit.control(), result, length); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1634 } |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1635 kit.store_String_value(kit.control(), result, char_array); |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1636 } else { |
ad5dd04754ee
8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents:
7196
diff
changeset
|
1637 result = C->top(); |
1080 | 1638 } |
1639 // hook up the outgoing control and result | |
1640 kit.replace_call(sc->end(), result); | |
1641 | |
1642 // Unhook any hook nodes | |
7196
2aff40cb4703
7092905: C2: Keep track of the number of dead nodes
bharadwaj
parents:
6804
diff
changeset
|
1643 string_sizes->disconnect_inputs(NULL, C); |
1080 | 1644 sc->cleanup(); |
1645 } |