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