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