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