Tue, 11 Mar 2008 19:00:38 -0700
6667615: (Escape Analysis) extend MDO to cache arguments escape state
Summary: Use MDO to cache arguments escape state determined by the byte code escape analyzer.
Reviewed-by: never
1 /*
2 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
26 #include "incls/_precompiled.incl"
27 #include "incls/_bcEscapeAnalyzer.cpp.incl"
30 #ifndef PRODUCT
31 #define TRACE_BCEA(level, code) \
32 if (EstimateArgEscape && BCEATraceLevel >= level) { \
33 code; \
34 }
35 #else
36 #define TRACE_BCEA(level, code)
37 #endif
39 // Maintain a map of which aguments a local variable or
40 // stack slot may contain. In addition to tracking
41 // arguments, it tracks two special values, "allocated"
42 // which represents any object allocated in the current
43 // method, and "unknown" which is any other object.
44 // Up to 30 arguments are handled, with the last one
45 // representing summary information for any extra arguments
46 class BCEscapeAnalyzer::ArgumentMap {
47 uint _bits;
48 enum {MAXBIT = 29,
49 ALLOCATED = 1,
50 UNKNOWN = 2};
52 uint int_to_bit(uint e) const {
53 if (e > MAXBIT)
54 e = MAXBIT;
55 return (1 << (e + 2));
56 }
58 public:
59 ArgumentMap() { _bits = 0;}
60 void set_bits(uint bits) { _bits = bits;}
61 uint get_bits() const { return _bits;}
62 void clear() { _bits = 0;}
63 void set_all() { _bits = ~0u; }
64 bool is_empty() const { return _bits == 0; }
65 bool contains(uint var) const { return (_bits & int_to_bit(var)) != 0; }
66 bool is_singleton(uint var) const { return (_bits == int_to_bit(var)); }
67 bool contains_unknown() const { return (_bits & UNKNOWN) != 0; }
68 bool contains_allocated() const { return (_bits & ALLOCATED) != 0; }
69 bool contains_vars() const { return (_bits & (((1 << MAXBIT) -1) << 2)) != 0; }
70 void set(uint var) { _bits = int_to_bit(var); }
71 void add(uint var) { _bits |= int_to_bit(var); }
72 void add_unknown() { _bits = UNKNOWN; }
73 void add_allocated() { _bits = ALLOCATED; }
74 void set_union(const ArgumentMap &am) { _bits |= am._bits; }
75 void set_intersect(const ArgumentMap &am) { _bits |= am._bits; }
76 void set_difference(const ArgumentMap &am) { _bits &= ~am._bits; }
77 void operator=(const ArgumentMap &am) { _bits = am._bits; }
78 bool operator==(const ArgumentMap &am) { return _bits == am._bits; }
79 bool operator!=(const ArgumentMap &am) { return _bits != am._bits; }
80 };
82 class BCEscapeAnalyzer::StateInfo {
83 public:
84 ArgumentMap *_vars;
85 ArgumentMap *_stack;
86 short _stack_height;
87 short _max_stack;
88 bool _initialized;
89 ArgumentMap empty_map;
91 StateInfo() {
92 empty_map.clear();
93 }
95 ArgumentMap raw_pop() { assert(_stack_height > 0, "stack underflow"); return _stack[--_stack_height]; }
96 ArgumentMap apop() { return raw_pop(); }
97 void spop() { raw_pop(); }
98 void lpop() { spop(); spop(); }
99 void raw_push(ArgumentMap i) { assert(_stack_height < _max_stack, "stack overflow"); _stack[_stack_height++] = i; }
100 void apush(ArgumentMap i) { raw_push(i); }
101 void spush() { raw_push(empty_map); }
102 void lpush() { spush(); spush(); }
104 };
106 void BCEscapeAnalyzer::set_returned(ArgumentMap vars) {
107 for (int i = 0; i < _arg_size; i++) {
108 if (vars.contains(i))
109 _arg_returned.set_bit(i);
110 }
111 _return_local = _return_local && !(vars.contains_unknown() || vars.contains_allocated());
112 _return_allocated = _return_allocated && vars.contains_allocated() && !(vars.contains_unknown() || vars.contains_vars());
113 }
115 // return true if any element of vars is an argument
116 bool BCEscapeAnalyzer::is_argument(ArgumentMap vars) {
117 for (int i = 0; i < _arg_size; i++) {
118 if (vars.contains(i))
119 return true;
120 }
121 return false;
122 }
124 // return true if any element of vars is an arg_stack argument
125 bool BCEscapeAnalyzer::is_arg_stack(ArgumentMap vars){
126 if (_conservative)
127 return true;
128 for (int i = 0; i < _arg_size; i++) {
129 if (vars.contains(i) && _arg_stack.at(i))
130 return true;
131 }
132 return false;
133 }
135 void BCEscapeAnalyzer::clear_bits(ArgumentMap vars, BitMap &bm) {
136 for (int i = 0; i < _arg_size; i++) {
137 if (vars.contains(i)) {
138 bm.clear_bit(i);
139 }
140 }
141 }
143 void BCEscapeAnalyzer::set_method_escape(ArgumentMap vars) {
144 clear_bits(vars, _arg_local);
145 }
147 void BCEscapeAnalyzer::set_global_escape(ArgumentMap vars) {
148 clear_bits(vars, _arg_local);
149 clear_bits(vars, _arg_stack);
150 if (vars.contains_allocated())
151 _allocated_escapes = true;
152 }
154 void BCEscapeAnalyzer::set_dirty(ArgumentMap vars) {
155 clear_bits(vars, _dirty);
156 }
158 void BCEscapeAnalyzer::set_modified(ArgumentMap vars, int offs, int size) {
160 for (int i = 0; i < _arg_size; i++) {
161 if (vars.contains(i)) {
162 set_arg_modified(i, offs, size);
163 }
164 }
165 if (vars.contains_unknown())
166 _unknown_modified = true;
167 }
169 bool BCEscapeAnalyzer::is_recursive_call(ciMethod* callee) {
170 for (BCEscapeAnalyzer* scope = this; scope != NULL; scope = scope->_parent) {
171 if (scope->method() == callee) {
172 return true;
173 }
174 }
175 return false;
176 }
178 bool BCEscapeAnalyzer::is_arg_modified(int arg, int offset, int size_in_bytes) {
179 if (offset == OFFSET_ANY)
180 return _arg_modified[arg] != 0;
181 assert(arg >= 0 && arg < _arg_size, "must be an argument.");
182 bool modified = false;
183 int l = offset / HeapWordSize;
184 int h = round_to(offset + size_in_bytes, HeapWordSize) / HeapWordSize;
185 if (l > ARG_OFFSET_MAX)
186 l = ARG_OFFSET_MAX;
187 if (h > ARG_OFFSET_MAX+1)
188 h = ARG_OFFSET_MAX + 1;
189 for (int i = l; i < h; i++) {
190 modified = modified || (_arg_modified[arg] & (1 << i)) != 0;
191 }
192 return modified;
193 }
195 void BCEscapeAnalyzer::set_arg_modified(int arg, int offset, int size_in_bytes) {
196 if (offset == OFFSET_ANY) {
197 _arg_modified[arg] = (uint) -1;
198 return;
199 }
200 assert(arg >= 0 && arg < _arg_size, "must be an argument.");
201 int l = offset / HeapWordSize;
202 int h = round_to(offset + size_in_bytes, HeapWordSize) / HeapWordSize;
203 if (l > ARG_OFFSET_MAX)
204 l = ARG_OFFSET_MAX;
205 if (h > ARG_OFFSET_MAX+1)
206 h = ARG_OFFSET_MAX + 1;
207 for (int i = l; i < h; i++) {
208 _arg_modified[arg] |= (1 << i);
209 }
210 }
212 void BCEscapeAnalyzer::invoke(StateInfo &state, Bytecodes::Code code, ciMethod* target, ciKlass* holder) {
213 int i;
215 // retrieve information about the callee
216 ciInstanceKlass* klass = target->holder();
217 ciInstanceKlass* calling_klass = method()->holder();
218 ciInstanceKlass* callee_holder = ciEnv::get_instance_klass_for_declared_method_holder(holder);
219 ciInstanceKlass* actual_recv = callee_holder;
221 // compute size of arguments
222 int arg_size = target->arg_size();
223 if (!target->is_loaded() && code == Bytecodes::_invokestatic) {
224 arg_size--;
225 }
226 int arg_base = MAX2(state._stack_height - arg_size, 0);
228 // direct recursive calls are skipped if they can be bound statically without introducing
229 // dependencies and if parameters are passed at the same position as in the current method
230 // other calls are skipped if there are no unescaped arguments passed to them
231 bool directly_recursive = (method() == target) &&
232 (code != Bytecodes::_invokevirtual || target->is_final_method() || state._stack[arg_base] .is_empty());
234 // check if analysis of callee can safely be skipped
235 bool skip_callee = true;
236 for (i = state._stack_height - 1; i >= arg_base && skip_callee; i--) {
237 ArgumentMap arg = state._stack[i];
238 skip_callee = !is_argument(arg) || !is_arg_stack(arg) || (directly_recursive && arg.is_singleton(i - arg_base));
239 }
240 if (skip_callee) {
241 TRACE_BCEA(3, tty->print_cr("[EA] skipping method %s::%s", holder->name()->as_utf8(), target->name()->as_utf8()));
242 for (i = 0; i < arg_size; i++) {
243 set_method_escape(state.raw_pop());
244 }
245 _unknown_modified = true; // assume the worst since we don't analyze the called method
246 return;
247 }
249 // determine actual method (use CHA if necessary)
250 ciMethod* inline_target = NULL;
251 if (target->is_loaded() && klass->is_loaded()
252 && (klass->is_initialized() || klass->is_interface() && target->holder()->is_initialized())
253 && target->will_link(klass, callee_holder, code)) {
254 if (code == Bytecodes::_invokestatic
255 || code == Bytecodes::_invokespecial
256 || code == Bytecodes::_invokevirtual && target->is_final_method()) {
257 inline_target = target;
258 } else {
259 inline_target = target->find_monomorphic_target(calling_klass, callee_holder, actual_recv);
260 }
261 }
263 if (inline_target != NULL && !is_recursive_call(inline_target)) {
264 // analyze callee
265 BCEscapeAnalyzer analyzer(inline_target, this);
267 // adjust escape state of actual parameters
268 bool must_record_dependencies = false;
269 for (i = arg_size - 1; i >= 0; i--) {
270 ArgumentMap arg = state.raw_pop();
271 if (!is_argument(arg))
272 continue;
273 for (int j = 0; j < _arg_size; j++) {
274 if (arg.contains(j)) {
275 _arg_modified[j] |= analyzer._arg_modified[i];
276 }
277 }
278 if (!is_arg_stack(arg)) {
279 // arguments have already been recognized as escaping
280 } else if (analyzer.is_arg_stack(i) && !analyzer.is_arg_returned(i)) {
281 set_method_escape(arg);
282 must_record_dependencies = true;
283 } else {
284 set_global_escape(arg);
285 }
286 }
287 _unknown_modified = _unknown_modified || analyzer.has_non_arg_side_affects();
289 // record dependencies if at least one parameter retained stack-allocatable
290 if (must_record_dependencies) {
291 if (code == Bytecodes::_invokeinterface || code == Bytecodes::_invokevirtual && !target->is_final_method()) {
292 _dependencies.append(actual_recv);
293 _dependencies.append(inline_target);
294 }
295 _dependencies.appendAll(analyzer.dependencies());
296 }
297 } else {
298 TRACE_BCEA(1, tty->print_cr("[EA] virtual method %s is not monomorphic.",
299 target->name()->as_utf8()));
300 // conservatively mark all actual parameters as escaping globally
301 for (i = 0; i < arg_size; i++) {
302 ArgumentMap arg = state.raw_pop();
303 if (!is_argument(arg))
304 continue;
305 set_modified(arg, OFFSET_ANY, type2size[T_INT]*HeapWordSize);
306 set_global_escape(arg);
307 }
308 _unknown_modified = true; // assume the worst since we don't know the called method
309 }
310 }
312 bool BCEscapeAnalyzer::contains(uint arg_set1, uint arg_set2) {
313 return ((~arg_set1) | arg_set2) == 0;
314 }
317 void BCEscapeAnalyzer::iterate_one_block(ciBlock *blk, StateInfo &state, GrowableArray<ciBlock *> &successors) {
319 blk->set_processed();
320 ciBytecodeStream s(method());
321 int limit_bci = blk->limit_bci();
322 bool fall_through = false;
323 ArgumentMap allocated_obj;
324 allocated_obj.add_allocated();
325 ArgumentMap unknown_obj;
326 unknown_obj.add_unknown();
327 ArgumentMap empty_map;
329 s.reset_to_bci(blk->start_bci());
330 while (s.next() != ciBytecodeStream::EOBC() && s.cur_bci() < limit_bci) {
331 fall_through = true;
332 switch (s.cur_bc()) {
333 case Bytecodes::_nop:
334 break;
335 case Bytecodes::_aconst_null:
336 state.apush(empty_map);
337 break;
338 case Bytecodes::_iconst_m1:
339 case Bytecodes::_iconst_0:
340 case Bytecodes::_iconst_1:
341 case Bytecodes::_iconst_2:
342 case Bytecodes::_iconst_3:
343 case Bytecodes::_iconst_4:
344 case Bytecodes::_iconst_5:
345 case Bytecodes::_fconst_0:
346 case Bytecodes::_fconst_1:
347 case Bytecodes::_fconst_2:
348 case Bytecodes::_bipush:
349 case Bytecodes::_sipush:
350 state.spush();
351 break;
352 case Bytecodes::_lconst_0:
353 case Bytecodes::_lconst_1:
354 case Bytecodes::_dconst_0:
355 case Bytecodes::_dconst_1:
356 state.lpush();
357 break;
358 case Bytecodes::_ldc:
359 case Bytecodes::_ldc_w:
360 case Bytecodes::_ldc2_w:
361 if (type2size[s.get_constant().basic_type()] == 1) {
362 state.spush();
363 } else {
364 state.lpush();
365 }
366 break;
367 case Bytecodes::_aload:
368 state.apush(state._vars[s.get_index()]);
369 break;
370 case Bytecodes::_iload:
371 case Bytecodes::_fload:
372 case Bytecodes::_iload_0:
373 case Bytecodes::_iload_1:
374 case Bytecodes::_iload_2:
375 case Bytecodes::_iload_3:
376 case Bytecodes::_fload_0:
377 case Bytecodes::_fload_1:
378 case Bytecodes::_fload_2:
379 case Bytecodes::_fload_3:
380 state.spush();
381 break;
382 case Bytecodes::_lload:
383 case Bytecodes::_dload:
384 case Bytecodes::_lload_0:
385 case Bytecodes::_lload_1:
386 case Bytecodes::_lload_2:
387 case Bytecodes::_lload_3:
388 case Bytecodes::_dload_0:
389 case Bytecodes::_dload_1:
390 case Bytecodes::_dload_2:
391 case Bytecodes::_dload_3:
392 state.lpush();
393 break;
394 case Bytecodes::_aload_0:
395 state.apush(state._vars[0]);
396 break;
397 case Bytecodes::_aload_1:
398 state.apush(state._vars[1]);
399 break;
400 case Bytecodes::_aload_2:
401 state.apush(state._vars[2]);
402 break;
403 case Bytecodes::_aload_3:
404 state.apush(state._vars[3]);
405 break;
406 case Bytecodes::_iaload:
407 case Bytecodes::_faload:
408 case Bytecodes::_baload:
409 case Bytecodes::_caload:
410 case Bytecodes::_saload:
411 state.spop();
412 set_method_escape(state.apop());
413 state.spush();
414 break;
415 case Bytecodes::_laload:
416 case Bytecodes::_daload:
417 state.spop();
418 set_method_escape(state.apop());
419 state.lpush();
420 break;
421 case Bytecodes::_aaload:
422 { state.spop();
423 ArgumentMap array = state.apop();
424 set_method_escape(array);
425 state.apush(unknown_obj);
426 set_dirty(array);
427 }
428 break;
429 case Bytecodes::_istore:
430 case Bytecodes::_fstore:
431 case Bytecodes::_istore_0:
432 case Bytecodes::_istore_1:
433 case Bytecodes::_istore_2:
434 case Bytecodes::_istore_3:
435 case Bytecodes::_fstore_0:
436 case Bytecodes::_fstore_1:
437 case Bytecodes::_fstore_2:
438 case Bytecodes::_fstore_3:
439 state.spop();
440 break;
441 case Bytecodes::_lstore:
442 case Bytecodes::_dstore:
443 case Bytecodes::_lstore_0:
444 case Bytecodes::_lstore_1:
445 case Bytecodes::_lstore_2:
446 case Bytecodes::_lstore_3:
447 case Bytecodes::_dstore_0:
448 case Bytecodes::_dstore_1:
449 case Bytecodes::_dstore_2:
450 case Bytecodes::_dstore_3:
451 state.lpop();
452 break;
453 case Bytecodes::_astore:
454 state._vars[s.get_index()] = state.apop();
455 break;
456 case Bytecodes::_astore_0:
457 state._vars[0] = state.apop();
458 break;
459 case Bytecodes::_astore_1:
460 state._vars[1] = state.apop();
461 break;
462 case Bytecodes::_astore_2:
463 state._vars[2] = state.apop();
464 break;
465 case Bytecodes::_astore_3:
466 state._vars[3] = state.apop();
467 break;
468 case Bytecodes::_iastore:
469 case Bytecodes::_fastore:
470 case Bytecodes::_bastore:
471 case Bytecodes::_castore:
472 case Bytecodes::_sastore:
473 {
474 state.spop();
475 state.spop();
476 ArgumentMap arr = state.apop();
477 set_method_escape(arr);
478 set_modified(arr, OFFSET_ANY, type2size[T_INT]*HeapWordSize);
479 break;
480 }
481 case Bytecodes::_lastore:
482 case Bytecodes::_dastore:
483 {
484 state.lpop();
485 state.spop();
486 ArgumentMap arr = state.apop();
487 set_method_escape(arr);
488 set_modified(arr, OFFSET_ANY, type2size[T_LONG]*HeapWordSize);
489 break;
490 }
491 case Bytecodes::_aastore:
492 {
493 set_global_escape(state.apop());
494 state.spop();
495 ArgumentMap arr = state.apop();
496 set_modified(arr, OFFSET_ANY, type2size[T_OBJECT]*HeapWordSize);
497 break;
498 }
499 case Bytecodes::_pop:
500 state.raw_pop();
501 break;
502 case Bytecodes::_pop2:
503 state.raw_pop();
504 state.raw_pop();
505 break;
506 case Bytecodes::_dup:
507 { ArgumentMap w1 = state.raw_pop();
508 state.raw_push(w1);
509 state.raw_push(w1);
510 }
511 break;
512 case Bytecodes::_dup_x1:
513 { ArgumentMap w1 = state.raw_pop();
514 ArgumentMap w2 = state.raw_pop();
515 state.raw_push(w1);
516 state.raw_push(w2);
517 state.raw_push(w1);
518 }
519 break;
520 case Bytecodes::_dup_x2:
521 { ArgumentMap w1 = state.raw_pop();
522 ArgumentMap w2 = state.raw_pop();
523 ArgumentMap w3 = state.raw_pop();
524 state.raw_push(w1);
525 state.raw_push(w3);
526 state.raw_push(w2);
527 state.raw_push(w1);
528 }
529 break;
530 case Bytecodes::_dup2:
531 { ArgumentMap w1 = state.raw_pop();
532 ArgumentMap w2 = state.raw_pop();
533 state.raw_push(w2);
534 state.raw_push(w1);
535 state.raw_push(w2);
536 state.raw_push(w1);
537 }
538 break;
539 case Bytecodes::_dup2_x1:
540 { ArgumentMap w1 = state.raw_pop();
541 ArgumentMap w2 = state.raw_pop();
542 ArgumentMap w3 = state.raw_pop();
543 state.raw_push(w2);
544 state.raw_push(w1);
545 state.raw_push(w3);
546 state.raw_push(w2);
547 state.raw_push(w1);
548 }
549 break;
550 case Bytecodes::_dup2_x2:
551 { ArgumentMap w1 = state.raw_pop();
552 ArgumentMap w2 = state.raw_pop();
553 ArgumentMap w3 = state.raw_pop();
554 ArgumentMap w4 = state.raw_pop();
555 state.raw_push(w2);
556 state.raw_push(w1);
557 state.raw_push(w4);
558 state.raw_push(w3);
559 state.raw_push(w2);
560 state.raw_push(w1);
561 }
562 break;
563 case Bytecodes::_swap:
564 { ArgumentMap w1 = state.raw_pop();
565 ArgumentMap w2 = state.raw_pop();
566 state.raw_push(w1);
567 state.raw_push(w2);
568 }
569 break;
570 case Bytecodes::_iadd:
571 case Bytecodes::_fadd:
572 case Bytecodes::_isub:
573 case Bytecodes::_fsub:
574 case Bytecodes::_imul:
575 case Bytecodes::_fmul:
576 case Bytecodes::_idiv:
577 case Bytecodes::_fdiv:
578 case Bytecodes::_irem:
579 case Bytecodes::_frem:
580 case Bytecodes::_iand:
581 case Bytecodes::_ior:
582 case Bytecodes::_ixor:
583 state.spop();
584 state.spop();
585 state.spush();
586 break;
587 case Bytecodes::_ladd:
588 case Bytecodes::_dadd:
589 case Bytecodes::_lsub:
590 case Bytecodes::_dsub:
591 case Bytecodes::_lmul:
592 case Bytecodes::_dmul:
593 case Bytecodes::_ldiv:
594 case Bytecodes::_ddiv:
595 case Bytecodes::_lrem:
596 case Bytecodes::_drem:
597 case Bytecodes::_land:
598 case Bytecodes::_lor:
599 case Bytecodes::_lxor:
600 state.lpop();
601 state.lpop();
602 state.lpush();
603 break;
604 case Bytecodes::_ishl:
605 case Bytecodes::_ishr:
606 case Bytecodes::_iushr:
607 state.spop();
608 state.spop();
609 state.spush();
610 break;
611 case Bytecodes::_lshl:
612 case Bytecodes::_lshr:
613 case Bytecodes::_lushr:
614 state.spop();
615 state.lpop();
616 state.lpush();
617 break;
618 case Bytecodes::_ineg:
619 case Bytecodes::_fneg:
620 state.spop();
621 state.spush();
622 break;
623 case Bytecodes::_lneg:
624 case Bytecodes::_dneg:
625 state.lpop();
626 state.lpush();
627 break;
628 case Bytecodes::_iinc:
629 break;
630 case Bytecodes::_i2l:
631 case Bytecodes::_i2d:
632 case Bytecodes::_f2l:
633 case Bytecodes::_f2d:
634 state.spop();
635 state.lpush();
636 break;
637 case Bytecodes::_i2f:
638 case Bytecodes::_f2i:
639 state.spop();
640 state.spush();
641 break;
642 case Bytecodes::_l2i:
643 case Bytecodes::_l2f:
644 case Bytecodes::_d2i:
645 case Bytecodes::_d2f:
646 state.lpop();
647 state.spush();
648 break;
649 case Bytecodes::_l2d:
650 case Bytecodes::_d2l:
651 state.lpop();
652 state.lpush();
653 break;
654 case Bytecodes::_i2b:
655 case Bytecodes::_i2c:
656 case Bytecodes::_i2s:
657 state.spop();
658 state.spush();
659 break;
660 case Bytecodes::_lcmp:
661 case Bytecodes::_dcmpl:
662 case Bytecodes::_dcmpg:
663 state.lpop();
664 state.lpop();
665 state.spush();
666 break;
667 case Bytecodes::_fcmpl:
668 case Bytecodes::_fcmpg:
669 state.spop();
670 state.spop();
671 state.spush();
672 break;
673 case Bytecodes::_ifeq:
674 case Bytecodes::_ifne:
675 case Bytecodes::_iflt:
676 case Bytecodes::_ifge:
677 case Bytecodes::_ifgt:
678 case Bytecodes::_ifle:
679 {
680 state.spop();
681 int dest_bci = s.get_dest();
682 assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
683 assert(s.next_bci() == limit_bci, "branch must end block");
684 successors.push(_methodBlocks->block_containing(dest_bci));
685 break;
686 }
687 case Bytecodes::_if_icmpeq:
688 case Bytecodes::_if_icmpne:
689 case Bytecodes::_if_icmplt:
690 case Bytecodes::_if_icmpge:
691 case Bytecodes::_if_icmpgt:
692 case Bytecodes::_if_icmple:
693 {
694 state.spop();
695 state.spop();
696 int dest_bci = s.get_dest();
697 assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
698 assert(s.next_bci() == limit_bci, "branch must end block");
699 successors.push(_methodBlocks->block_containing(dest_bci));
700 break;
701 }
702 case Bytecodes::_if_acmpeq:
703 case Bytecodes::_if_acmpne:
704 {
705 set_method_escape(state.apop());
706 set_method_escape(state.apop());
707 int dest_bci = s.get_dest();
708 assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
709 assert(s.next_bci() == limit_bci, "branch must end block");
710 successors.push(_methodBlocks->block_containing(dest_bci));
711 break;
712 }
713 case Bytecodes::_goto:
714 {
715 int dest_bci = s.get_dest();
716 assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
717 assert(s.next_bci() == limit_bci, "branch must end block");
718 successors.push(_methodBlocks->block_containing(dest_bci));
719 fall_through = false;
720 break;
721 }
722 case Bytecodes::_jsr:
723 {
724 int dest_bci = s.get_dest();
725 assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
726 assert(s.next_bci() == limit_bci, "branch must end block");
727 state.apush(empty_map);
728 successors.push(_methodBlocks->block_containing(dest_bci));
729 fall_through = false;
730 break;
731 }
732 case Bytecodes::_ret:
733 // we don't track the destination of a "ret" instruction
734 assert(s.next_bci() == limit_bci, "branch must end block");
735 fall_through = false;
736 break;
737 case Bytecodes::_return:
738 assert(s.next_bci() == limit_bci, "return must end block");
739 fall_through = false;
740 break;
741 case Bytecodes::_tableswitch:
742 {
743 state.spop();
744 Bytecode_tableswitch* switch_ = Bytecode_tableswitch_at(s.cur_bcp());
745 int len = switch_->length();
746 int dest_bci;
747 for (int i = 0; i < len; i++) {
748 dest_bci = s.cur_bci() + switch_->dest_offset_at(i);
749 assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
750 successors.push(_methodBlocks->block_containing(dest_bci));
751 }
752 dest_bci = s.cur_bci() + switch_->default_offset();
753 assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
754 successors.push(_methodBlocks->block_containing(dest_bci));
755 assert(s.next_bci() == limit_bci, "branch must end block");
756 fall_through = false;
757 break;
758 }
759 case Bytecodes::_lookupswitch:
760 {
761 state.spop();
762 Bytecode_lookupswitch* switch_ = Bytecode_lookupswitch_at(s.cur_bcp());
763 int len = switch_->number_of_pairs();
764 int dest_bci;
765 for (int i = 0; i < len; i++) {
766 dest_bci = s.cur_bci() + switch_->pair_at(i)->offset();
767 assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
768 successors.push(_methodBlocks->block_containing(dest_bci));
769 }
770 dest_bci = s.cur_bci() + switch_->default_offset();
771 assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
772 successors.push(_methodBlocks->block_containing(dest_bci));
773 fall_through = false;
774 break;
775 }
776 case Bytecodes::_ireturn:
777 case Bytecodes::_freturn:
778 state.spop();
779 fall_through = false;
780 break;
781 case Bytecodes::_lreturn:
782 case Bytecodes::_dreturn:
783 state.lpop();
784 fall_through = false;
785 break;
786 case Bytecodes::_areturn:
787 set_returned(state.apop());
788 fall_through = false;
789 break;
790 case Bytecodes::_getstatic:
791 case Bytecodes::_getfield:
792 { bool will_link;
793 ciField* field = s.get_field(will_link);
794 BasicType field_type = field->type()->basic_type();
795 if (s.cur_bc() != Bytecodes::_getstatic) {
796 set_method_escape(state.apop());
797 }
798 if (field_type == T_OBJECT || field_type == T_ARRAY) {
799 state.apush(unknown_obj);
800 } else if (type2size[field_type] == 1) {
801 state.spush();
802 } else {
803 state.lpush();
804 }
805 }
806 break;
807 case Bytecodes::_putstatic:
808 case Bytecodes::_putfield:
809 { bool will_link;
810 ciField* field = s.get_field(will_link);
811 BasicType field_type = field->type()->basic_type();
812 if (field_type == T_OBJECT || field_type == T_ARRAY) {
813 set_global_escape(state.apop());
814 } else if (type2size[field_type] == 1) {
815 state.spop();
816 } else {
817 state.lpop();
818 }
819 if (s.cur_bc() != Bytecodes::_putstatic) {
820 ArgumentMap p = state.apop();
821 set_method_escape(p);
822 set_modified(p, will_link ? field->offset() : OFFSET_ANY, type2size[field_type]*HeapWordSize);
823 }
824 }
825 break;
826 case Bytecodes::_invokevirtual:
827 case Bytecodes::_invokespecial:
828 case Bytecodes::_invokestatic:
829 case Bytecodes::_invokeinterface:
830 { bool will_link;
831 ciMethod* target = s.get_method(will_link);
832 ciKlass* holder = s.get_declared_method_holder();
833 invoke(state, s.cur_bc(), target, holder);
834 ciType* return_type = target->return_type();
835 if (!return_type->is_primitive_type()) {
836 state.apush(unknown_obj);
837 } else if (return_type->is_one_word()) {
838 state.spush();
839 } else if (return_type->is_two_word()) {
840 state.lpush();
841 }
842 }
843 break;
844 case Bytecodes::_xxxunusedxxx:
845 ShouldNotReachHere();
846 break;
847 case Bytecodes::_new:
848 state.apush(allocated_obj);
849 break;
850 case Bytecodes::_newarray:
851 case Bytecodes::_anewarray:
852 state.spop();
853 state.apush(allocated_obj);
854 break;
855 case Bytecodes::_multianewarray:
856 { int i = s.cur_bcp()[3];
857 while (i-- > 0) state.spop();
858 state.apush(allocated_obj);
859 }
860 break;
861 case Bytecodes::_arraylength:
862 set_method_escape(state.apop());
863 state.spush();
864 break;
865 case Bytecodes::_athrow:
866 set_global_escape(state.apop());
867 fall_through = false;
868 break;
869 case Bytecodes::_checkcast:
870 { ArgumentMap obj = state.apop();
871 set_method_escape(obj);
872 state.apush(obj);
873 }
874 break;
875 case Bytecodes::_instanceof:
876 set_method_escape(state.apop());
877 state.spush();
878 break;
879 case Bytecodes::_monitorenter:
880 case Bytecodes::_monitorexit:
881 state.apop();
882 break;
883 case Bytecodes::_wide:
884 ShouldNotReachHere();
885 break;
886 case Bytecodes::_ifnull:
887 case Bytecodes::_ifnonnull:
888 {
889 set_method_escape(state.apop());
890 int dest_bci = s.get_dest();
891 assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
892 assert(s.next_bci() == limit_bci, "branch must end block");
893 successors.push(_methodBlocks->block_containing(dest_bci));
894 break;
895 }
896 case Bytecodes::_goto_w:
897 {
898 int dest_bci = s.get_far_dest();
899 assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
900 assert(s.next_bci() == limit_bci, "branch must end block");
901 successors.push(_methodBlocks->block_containing(dest_bci));
902 fall_through = false;
903 break;
904 }
905 case Bytecodes::_jsr_w:
906 {
907 int dest_bci = s.get_far_dest();
908 assert(_methodBlocks->is_block_start(dest_bci), "branch destination must start a block");
909 assert(s.next_bci() == limit_bci, "branch must end block");
910 state.apush(empty_map);
911 successors.push(_methodBlocks->block_containing(dest_bci));
912 fall_through = false;
913 break;
914 }
915 case Bytecodes::_breakpoint:
916 break;
917 default:
918 ShouldNotReachHere();
919 break;
920 }
922 }
923 if (fall_through) {
924 int fall_through_bci = s.cur_bci();
925 if (fall_through_bci < _method->code_size()) {
926 assert(_methodBlocks->is_block_start(fall_through_bci), "must fall through to block start.");
927 successors.push(_methodBlocks->block_containing(fall_through_bci));
928 }
929 }
930 }
932 void BCEscapeAnalyzer::merge_block_states(StateInfo *blockstates, ciBlock *dest, StateInfo *s_state) {
933 StateInfo *d_state = blockstates + dest->index();
934 int nlocals = _method->max_locals();
936 // exceptions may cause transfer of control to handlers in the middle of a
937 // block, so we don't merge the incoming state of exception handlers
938 if (dest->is_handler())
939 return;
940 if (!d_state->_initialized ) {
941 // destination not initialized, just copy
942 for (int i = 0; i < nlocals; i++) {
943 d_state->_vars[i] = s_state->_vars[i];
944 }
945 for (int i = 0; i < s_state->_stack_height; i++) {
946 d_state->_stack[i] = s_state->_stack[i];
947 }
948 d_state->_stack_height = s_state->_stack_height;
949 d_state->_max_stack = s_state->_max_stack;
950 d_state->_initialized = true;
951 } else if (!dest->processed()) {
952 // we have not yet walked the bytecodes of dest, we can merge
953 // the states
954 assert(d_state->_stack_height == s_state->_stack_height, "computed stack heights must match");
955 for (int i = 0; i < nlocals; i++) {
956 d_state->_vars[i].set_union(s_state->_vars[i]);
957 }
958 for (int i = 0; i < s_state->_stack_height; i++) {
959 d_state->_stack[i].set_union(s_state->_stack[i]);
960 }
961 } else {
962 // the bytecodes of dest have already been processed, mark any
963 // arguments in the source state which are not in the dest state
964 // as global escape.
965 // Future refinement: we only need to mark these variable to the
966 // maximum escape of any variables in dest state
967 assert(d_state->_stack_height == s_state->_stack_height, "computed stack heights must match");
968 ArgumentMap extra_vars;
969 for (int i = 0; i < nlocals; i++) {
970 ArgumentMap t;
971 t = s_state->_vars[i];
972 t.set_difference(d_state->_vars[i]);
973 extra_vars.set_union(t);
974 }
975 for (int i = 0; i < s_state->_stack_height; i++) {
976 ArgumentMap t;
977 //extra_vars |= !d_state->_vars[i] & s_state->_vars[i];
978 t.clear();
979 t = s_state->_stack[i];
980 t.set_difference(d_state->_stack[i]);
981 extra_vars.set_union(t);
982 }
983 set_global_escape(extra_vars);
984 }
985 }
987 void BCEscapeAnalyzer::iterate_blocks(Arena *arena) {
988 int numblocks = _methodBlocks->num_blocks();
989 int stkSize = _method->max_stack();
990 int numLocals = _method->max_locals();
991 StateInfo state;
993 int datacount = (numblocks + 1) * (stkSize + numLocals);
994 int datasize = datacount * sizeof(ArgumentMap);
995 StateInfo *blockstates = (StateInfo *) arena->Amalloc(numblocks * sizeof(StateInfo));
996 ArgumentMap *statedata = (ArgumentMap *) arena->Amalloc(datasize);
997 for (int i = 0; i < datacount; i++) ::new ((void*)&statedata[i]) ArgumentMap();
998 ArgumentMap *dp = statedata;
999 state._vars = dp;
1000 dp += numLocals;
1001 state._stack = dp;
1002 dp += stkSize;
1003 state._initialized = false;
1004 state._max_stack = stkSize;
1005 for (int i = 0; i < numblocks; i++) {
1006 blockstates[i]._vars = dp;
1007 dp += numLocals;
1008 blockstates[i]._stack = dp;
1009 dp += stkSize;
1010 blockstates[i]._initialized = false;
1011 blockstates[i]._stack_height = 0;
1012 blockstates[i]._max_stack = stkSize;
1013 }
1014 GrowableArray<ciBlock *> worklist(arena, numblocks / 4, 0, NULL);
1015 GrowableArray<ciBlock *> successors(arena, 4, 0, NULL);
1017 _methodBlocks->clear_processed();
1019 // initialize block 0 state from method signature
1020 ArgumentMap allVars; // all oop arguments to method
1021 ciSignature* sig = method()->signature();
1022 int j = 0;
1023 ciBlock* first_blk = _methodBlocks->block_containing(0);
1024 int fb_i = first_blk->index();
1025 if (!method()->is_static()) {
1026 // record information for "this"
1027 blockstates[fb_i]._vars[j].set(j);
1028 allVars.add(j);
1029 j++;
1030 }
1031 for (int i = 0; i < sig->count(); i++) {
1032 ciType* t = sig->type_at(i);
1033 if (!t->is_primitive_type()) {
1034 blockstates[fb_i]._vars[j].set(j);
1035 allVars.add(j);
1036 }
1037 j += t->size();
1038 }
1039 blockstates[fb_i]._initialized = true;
1040 assert(j == _arg_size, "just checking");
1042 ArgumentMap unknown_map;
1043 unknown_map.add_unknown();
1045 worklist.push(first_blk);
1046 while(worklist.length() > 0) {
1047 ciBlock *blk = worklist.pop();
1048 StateInfo *blkState = blockstates + blk->index();
1049 if (blk->is_handler() || blk->is_ret_target()) {
1050 // for an exception handler or a target of a ret instruction, we assume the worst case,
1051 // that any variable could contain any argument
1052 for (int i = 0; i < numLocals; i++) {
1053 state._vars[i] = allVars;
1054 }
1055 if (blk->is_handler()) {
1056 state._stack_height = 1;
1057 } else {
1058 state._stack_height = blkState->_stack_height;
1059 }
1060 for (int i = 0; i < state._stack_height; i++) {
1061 // ??? should this be unknown_map ???
1062 state._stack[i] = allVars;
1063 }
1064 } else {
1065 for (int i = 0; i < numLocals; i++) {
1066 state._vars[i] = blkState->_vars[i];
1067 }
1068 for (int i = 0; i < blkState->_stack_height; i++) {
1069 state._stack[i] = blkState->_stack[i];
1070 }
1071 state._stack_height = blkState->_stack_height;
1072 }
1073 iterate_one_block(blk, state, successors);
1074 // if this block has any exception handlers, push them
1075 // onto successor list
1076 if (blk->has_handler()) {
1077 DEBUG_ONLY(int handler_count = 0;)
1078 int blk_start = blk->start_bci();
1079 int blk_end = blk->limit_bci();
1080 for (int i = 0; i < numblocks; i++) {
1081 ciBlock *b = _methodBlocks->block(i);
1082 if (b->is_handler()) {
1083 int ex_start = b->ex_start_bci();
1084 int ex_end = b->ex_limit_bci();
1085 if ((ex_start >= blk_start && ex_start < blk_end) ||
1086 (ex_end > blk_start && ex_end <= blk_end)) {
1087 successors.push(b);
1088 }
1089 DEBUG_ONLY(handler_count++;)
1090 }
1091 }
1092 assert(handler_count > 0, "must find at least one handler");
1093 }
1094 // merge computed variable state with successors
1095 while(successors.length() > 0) {
1096 ciBlock *succ = successors.pop();
1097 merge_block_states(blockstates, succ, &state);
1098 if (!succ->processed())
1099 worklist.push(succ);
1100 }
1101 }
1102 }
1104 bool BCEscapeAnalyzer::do_analysis() {
1105 Arena* arena = CURRENT_ENV->arena();
1106 // identify basic blocks
1107 _methodBlocks = _method->get_method_blocks();
1109 iterate_blocks(arena);
1110 // TEMPORARY
1111 return true;
1112 }
1114 vmIntrinsics::ID BCEscapeAnalyzer::known_intrinsic() {
1115 vmIntrinsics::ID iid = method()->intrinsic_id();
1117 if (iid == vmIntrinsics::_getClass ||
1118 iid == vmIntrinsics::_fillInStackTrace ||
1119 iid == vmIntrinsics::_hashCode)
1120 return iid;
1121 else
1122 return vmIntrinsics::_none;
1123 }
1125 bool BCEscapeAnalyzer::compute_escape_for_intrinsic(vmIntrinsics::ID iid) {
1126 ArgumentMap arg;
1127 arg.clear();
1128 switch (iid) {
1129 case vmIntrinsics::_getClass:
1130 _return_local = false;
1131 break;
1132 case vmIntrinsics::_fillInStackTrace:
1133 arg.set(0); // 'this'
1134 set_returned(arg);
1135 break;
1136 case vmIntrinsics::_hashCode:
1137 // initialized state is correct
1138 break;
1139 default:
1140 assert(false, "unexpected intrinsic");
1141 }
1142 return true;
1143 }
1145 void BCEscapeAnalyzer::initialize() {
1146 int i;
1148 // clear escape information (method may have been deoptimized)
1149 methodData()->clear_escape_info();
1151 // initialize escape state of object parameters
1152 ciSignature* sig = method()->signature();
1153 int j = 0;
1154 if (!method()->is_static()) {
1155 _arg_local.set_bit(0);
1156 _arg_stack.set_bit(0);
1157 j++;
1158 }
1159 for (i = 0; i < sig->count(); i++) {
1160 ciType* t = sig->type_at(i);
1161 if (!t->is_primitive_type()) {
1162 _arg_local.set_bit(j);
1163 _arg_stack.set_bit(j);
1164 }
1165 j += t->size();
1166 }
1167 assert(j == _arg_size, "just checking");
1169 // start with optimistic assumption
1170 ciType *rt = _method->return_type();
1171 if (rt->is_primitive_type()) {
1172 _return_local = false;
1173 _return_allocated = false;
1174 } else {
1175 _return_local = true;
1176 _return_allocated = true;
1177 }
1178 _allocated_escapes = false;
1179 _unknown_modified = false;
1180 }
1182 void BCEscapeAnalyzer::clear_escape_info() {
1183 ciSignature* sig = method()->signature();
1184 int arg_count = sig->count();
1185 ArgumentMap var;
1186 if (!method()->is_static()) {
1187 arg_count++; // allow for "this"
1188 }
1189 for (int i = 0; i < arg_count; i++) {
1190 set_arg_modified(i, OFFSET_ANY, 4);
1191 var.clear();
1192 var.set(i);
1193 set_modified(var, OFFSET_ANY, 4);
1194 set_global_escape(var);
1195 }
1196 _arg_local.clear();
1197 _arg_stack.clear();
1198 _arg_returned.clear();
1199 _return_local = false;
1200 _return_allocated = false;
1201 _allocated_escapes = true;
1202 _unknown_modified = true;
1203 }
1206 void BCEscapeAnalyzer::compute_escape_info() {
1207 int i;
1208 assert(!methodData()->has_escape_info(), "do not overwrite escape info");
1210 vmIntrinsics::ID iid = known_intrinsic();
1212 // check if method can be analyzed
1213 if (iid == vmIntrinsics::_none && (method()->is_abstract() || method()->is_native() || !method()->holder()->is_initialized()
1214 || _level > MaxBCEAEstimateLevel
1215 || method()->code_size() > MaxBCEAEstimateSize)) {
1216 if (BCEATraceLevel >= 1) {
1217 tty->print("Skipping method because: ");
1218 if (method()->is_abstract())
1219 tty->print_cr("method is abstract.");
1220 else if (method()->is_native())
1221 tty->print_cr("method is native.");
1222 else if (!method()->holder()->is_initialized())
1223 tty->print_cr("class of method is not initialized.");
1224 else if (_level > MaxBCEAEstimateLevel)
1225 tty->print_cr("level (%d) exceeds MaxBCEAEstimateLevel (%d).",
1226 _level, MaxBCEAEstimateLevel);
1227 else if (method()->code_size() > MaxBCEAEstimateSize)
1228 tty->print_cr("code size (%d) exceeds MaxBCEAEstimateSize.",
1229 method()->code_size(), MaxBCEAEstimateSize);
1230 else
1231 ShouldNotReachHere();
1232 }
1233 clear_escape_info();
1235 return;
1236 }
1238 if (BCEATraceLevel >= 1) {
1239 tty->print("[EA] estimating escape information for");
1240 if (iid != vmIntrinsics::_none)
1241 tty->print(" intrinsic");
1242 method()->print_short_name();
1243 tty->print_cr(" (%d bytes)", method()->code_size());
1244 }
1246 bool success;
1248 initialize();
1250 // do not scan method if it has no object parameters
1251 if (_arg_local.is_empty()) {
1252 methodData()->set_eflag(methodDataOopDesc::estimated);
1253 return;
1254 }
1256 if (iid != vmIntrinsics::_none)
1257 success = compute_escape_for_intrinsic(iid);
1258 else {
1259 success = do_analysis();
1260 }
1262 // dump result of bytecode analysis
1263 #ifndef PRODUCT
1264 if (BCEATraceLevel >= 3) {
1265 tty->print("[EA] estimated escape information for");
1266 if (iid != vmIntrinsics::_none)
1267 tty->print(" intrinsic");
1268 method()->print_short_name();
1269 tty->print_cr(has_dependencies() ? " (not stored)" : "");
1270 tty->print(" non-escaping args: ");
1271 _arg_local.print_on(tty);
1272 tty->print(" stack-allocatable args: ");
1273 _arg_stack.print_on(tty);
1274 if (_return_local) {
1275 tty->print(" returned args: ");
1276 _arg_returned.print_on(tty);
1277 } else if (is_return_allocated()) {
1278 tty->print_cr(" allocated return values");
1279 } else {
1280 tty->print_cr(" non-local return values");
1281 }
1282 tty->print(" modified args: ");
1283 for (int i = 0; i < _arg_size; i++) {
1284 if (_arg_modified[i] == 0)
1285 tty->print(" 0");
1286 else
1287 tty->print(" 0x%x", _arg_modified[i]);
1288 }
1289 tty->cr();
1290 tty->print(" flags: ");
1291 if (_unknown_modified)
1292 tty->print(" unknown_modified");
1293 if (_return_allocated)
1294 tty->print(" return_allocated");
1295 tty->cr();
1296 }
1298 #endif
1299 // don't store interprocedural escape information if it introduces dependencies
1300 // or if method data is empty
1301 //
1302 if (!has_dependencies() && !methodData()->is_empty()) {
1303 for (i = 0; i < _arg_size; i++) {
1304 if (_arg_local.at(i)) {
1305 assert(_arg_stack.at(i), "inconsistent escape info");
1306 methodData()->set_arg_local(i);
1307 methodData()->set_arg_stack(i);
1308 } else if (_arg_stack.at(i)) {
1309 methodData()->set_arg_stack(i);
1310 }
1311 if (_arg_returned.at(i)) {
1312 methodData()->set_arg_returned(i);
1313 }
1314 methodData()->set_arg_modified(i, _arg_modified[i]);
1315 }
1316 if (_return_local) {
1317 methodData()->set_eflag(methodDataOopDesc::return_local);
1318 }
1319 methodData()->set_eflag(methodDataOopDesc::estimated);
1320 }
1321 }
1323 void BCEscapeAnalyzer::read_escape_info() {
1324 assert(methodData()->has_escape_info(), "no escape info available");
1326 // read escape information from method descriptor
1327 for (int i = 0; i < _arg_size; i++) {
1328 _arg_local.at_put(i, methodData()->is_arg_local(i));
1329 _arg_stack.at_put(i, methodData()->is_arg_stack(i));
1330 _arg_returned.at_put(i, methodData()->is_arg_returned(i));
1331 _arg_modified[i] = methodData()->arg_modified(i);
1332 }
1333 _return_local = methodData()->eflag_set(methodDataOopDesc::return_local);
1335 // dump result of loaded escape information
1336 #ifndef PRODUCT
1337 if (BCEATraceLevel >= 4) {
1338 tty->print(" non-escaping args: ");
1339 _arg_local.print_on(tty);
1340 tty->print(" stack-allocatable args: ");
1341 _arg_stack.print_on(tty);
1342 if (_return_local) {
1343 tty->print(" returned args: ");
1344 _arg_returned.print_on(tty);
1345 } else {
1346 tty->print_cr(" non-local return values");
1347 }
1348 tty->print(" modified args: ");
1349 for (int i = 0; i < _arg_size; i++) {
1350 if (_arg_modified[i] == 0)
1351 tty->print(" 0");
1352 else
1353 tty->print(" 0x%x", _arg_modified[i]);
1354 }
1355 tty->cr();
1356 }
1357 #endif
1359 }
1362 BCEscapeAnalyzer::BCEscapeAnalyzer(ciMethod* method, BCEscapeAnalyzer* parent)
1363 : _conservative(method == NULL || !EstimateArgEscape)
1364 , _method(method)
1365 , _methodData(method ? method->method_data() : NULL)
1366 , _arg_size(method ? method->arg_size() : 0)
1367 , _stack()
1368 , _arg_local(_arg_size)
1369 , _arg_stack(_arg_size)
1370 , _arg_returned(_arg_size)
1371 , _dirty(_arg_size)
1372 , _return_local(false)
1373 , _return_allocated(false)
1374 , _allocated_escapes(false)
1375 , _unknown_modified(false)
1376 , _dependencies()
1377 , _parent(parent)
1378 , _level(parent == NULL ? 0 : parent->level() + 1) {
1379 if (!_conservative) {
1380 _arg_local.clear();
1381 _arg_stack.clear();
1382 _arg_returned.clear();
1383 _dirty.clear();
1384 Arena* arena = CURRENT_ENV->arena();
1385 _arg_modified = (uint *) arena->Amalloc(_arg_size * sizeof(uint));
1386 Copy::zero_to_bytes(_arg_modified, _arg_size * sizeof(uint));
1388 if (methodData() == NULL)
1389 return;
1390 bool printit = _method->should_print_assembly();
1391 if (methodData()->has_escape_info()) {
1392 TRACE_BCEA(2, tty->print_cr("[EA] Reading previous results for %s.%s",
1393 method->holder()->name()->as_utf8(),
1394 method->name()->as_utf8()));
1395 read_escape_info();
1396 } else {
1397 TRACE_BCEA(2, tty->print_cr("[EA] computing results for %s.%s",
1398 method->holder()->name()->as_utf8(),
1399 method->name()->as_utf8()));
1401 compute_escape_info();
1402 methodData()->update_escape_info();
1403 }
1404 }
1405 }
1407 void BCEscapeAnalyzer::copy_dependencies(Dependencies *deps) {
1408 if(!has_dependencies())
1409 return;
1410 for (int i = 0; i < _dependencies.length(); i+=2) {
1411 ciKlass *k = _dependencies[i]->as_klass();
1412 ciMethod *m = _dependencies[i+1]->as_method();
1413 deps->assert_unique_concrete_method(k, m);
1414 }
1415 }