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