104 // ComputeCallStack
105 //
106 // Specialization of SignatureIterator - compute the effects of a call
107 //
108 class ComputeCallStack : public SignatureIterator {
109 CellTypeState *_effect;
110 int _idx;
111
112 void setup();
113 void set(CellTypeState state) { _effect[_idx++] = state; }
114 int length() { return _idx; };
115
116 virtual void do_bool () { set(CellTypeState::value); };
117 virtual void do_char () { set(CellTypeState::value); };
118 virtual void do_float () { set(CellTypeState::value); };
119 virtual void do_byte () { set(CellTypeState::value); };
120 virtual void do_short () { set(CellTypeState::value); };
121 virtual void do_int () { set(CellTypeState::value); };
122 virtual void do_void () { set(CellTypeState::bottom);};
123 virtual void do_object(int begin, int end) { set(CellTypeState::ref); };
124 virtual void do_valuetype (int begin, int end) { set(CellTypeState::valuetype); };
125 virtual void do_array (int begin, int end) { set(CellTypeState::ref); };
126
127 void do_double() { set(CellTypeState::value);
128 set(CellTypeState::value); }
129 void do_long () { set(CellTypeState::value);
130 set(CellTypeState::value); }
131
132 public:
133 ComputeCallStack(Symbol* signature) : SignatureIterator(signature) {};
134
135 // Compute methods
136 int compute_for_parameters(bool is_static, CellTypeState *effect) {
137 _idx = 0;
138 _effect = effect;
139
140 if (!is_static) {
141 effect[_idx++] = CellTypeState::refOrValueType;
142 }
143
144 iterate_parameters();
145
146 return length();
147 };
148
149 int compute_for_returntype(CellTypeState *effect) {
150 _idx = 0;
151 _effect = effect;
152 iterate_returntype();
153 set(CellTypeState::bottom); // Always terminate with a bottom state, so ppush works
154
155 return length();
156 }
157 };
158
159 //=========================================================================================
160 // ComputeEntryStack
161 //
162 // Specialization of SignatureIterator - in order to set up first stack frame
163 //
164 class ComputeEntryStack : public SignatureIterator {
165 CellTypeState *_effect;
166 int _idx;
167
168 void setup();
169 void set(CellTypeState state) { _effect[_idx++] = state; }
170 int length() { return _idx; };
171
172 virtual void do_bool () { set(CellTypeState::value); };
173 virtual void do_char () { set(CellTypeState::value); };
174 virtual void do_float () { set(CellTypeState::value); };
175 virtual void do_byte () { set(CellTypeState::value); };
176 virtual void do_short () { set(CellTypeState::value); };
177 virtual void do_int () { set(CellTypeState::value); };
178 virtual void do_void () { set(CellTypeState::bottom);};
179 virtual void do_object(int begin, int end) { set(CellTypeState::make_slot_ref(_idx)); }
180 virtual void do_array (int begin, int end) { set(CellTypeState::make_slot_ref(_idx)); }
181 virtual void do_valuetype(int begin, int end) { set(CellTypeState::make_slot_valuetype(_idx)); }
182
183 void do_double() { set(CellTypeState::value);
184 set(CellTypeState::value); }
185 void do_long () { set(CellTypeState::value);
186 set(CellTypeState::value); }
187
188 public:
189 ComputeEntryStack(Symbol* signature) : SignatureIterator(signature) {};
190
191 // Compute methods
192 int compute_for_parameters(bool is_static, CellTypeState *effect) {
193 _idx = 0;
194 _effect = effect;
195
196 if (!is_static)
197 effect[_idx++] = CellTypeState::make_slot_ref(0);
198
199 iterate_parameters();
200
201 return length();
283 return NULL;
284 }
285
286 // The instruction at bci is changing size by "delta". Update the return map.
287 void RetTable::update_ret_table(int bci, int delta) {
288 RetTableEntry *cur = _first;
289 while(cur) {
290 cur->add_delta(bci, delta);
291 cur = cur->next();
292 }
293 }
294
295 //
296 // Celltype state
297 //
298
299 CellTypeState CellTypeState::bottom = CellTypeState::make_bottom();
300 CellTypeState CellTypeState::uninit = CellTypeState::make_any(uninit_value);
301 CellTypeState CellTypeState::ref = CellTypeState::make_any(ref_conflict);
302 CellTypeState CellTypeState::value = CellTypeState::make_any(val_value);
303 CellTypeState CellTypeState::valuetype = CellTypeState::make_any(valuetype_conflict);
304 CellTypeState CellTypeState::refOrValueType = CellTypeState::make_any(valuetype_conflict | ref_conflict);
305 CellTypeState CellTypeState::refUninit = CellTypeState::make_any(ref_conflict | uninit_value);
306 CellTypeState CellTypeState::top = CellTypeState::make_top();
307 CellTypeState CellTypeState::addr = CellTypeState::make_any(addr_conflict);
308
309 // Commonly used constants
310 static CellTypeState epsilonCTS[1] = { CellTypeState::bottom };
311 static CellTypeState refCTS = CellTypeState::ref;
312 static CellTypeState valCTS = CellTypeState::value;
313 static CellTypeState valuetypeCTS = CellTypeState::valuetype;
314 static CellTypeState vCTS[2] = { CellTypeState::value, CellTypeState::bottom };
315 static CellTypeState rCTS[2] = { CellTypeState::ref, CellTypeState::bottom };
316 static CellTypeState qCTS[2] = { CellTypeState::valuetype, CellTypeState::bottom };
317 static CellTypeState rrCTS[3] = { CellTypeState::ref, CellTypeState::ref, CellTypeState::bottom };
318 static CellTypeState vrCTS[3] = { CellTypeState::value, CellTypeState::ref, CellTypeState::bottom };
319 static CellTypeState vvCTS[3] = { CellTypeState::value, CellTypeState::value, CellTypeState::bottom };
320 static CellTypeState rvrCTS[4] = { CellTypeState::ref, CellTypeState::value, CellTypeState::ref, CellTypeState::bottom };
321 static CellTypeState qvrCTS[4] = { CellTypeState::valuetype, CellTypeState::value, CellTypeState::ref, CellTypeState::bottom };
322 static CellTypeState vvrCTS[4] = { CellTypeState::value, CellTypeState::value, CellTypeState::ref, CellTypeState::bottom };
323 static CellTypeState vvvCTS[4] = { CellTypeState::value, CellTypeState::value, CellTypeState::value, CellTypeState::bottom };
324 static CellTypeState vvvrCTS[5] = { CellTypeState::value, CellTypeState::value, CellTypeState::value, CellTypeState::ref, CellTypeState::bottom };
325 static CellTypeState vvvvCTS[5] = { CellTypeState::value, CellTypeState::value, CellTypeState::value, CellTypeState::value, CellTypeState::bottom };
326
327 char CellTypeState::to_char() const {
328 if (can_be_reference()) {
329 if (can_be_value() || can_be_address() || can_be_valuetype())
330 return '#'; // Conflict that needs to be rewritten
331 else
332 return 'r';
333 } else if (can_be_valuetype()) {
334 if (can_be_value() || can_be_address())
335 return '#'; // Conflict that needs to be rewritten
336 else
337 return 'q';
338 } else if (can_be_value())
339 return 'v';
340 else if (can_be_address())
341 return 'p';
342 else if (can_be_uninit())
343 return ' ';
344 else
345 return '@';
346 }
347
348
349 // Print a detailed CellTypeState. Indicate all bits that are set. If
350 // the CellTypeState represents an address or a reference, print the
351 // value of the additional information.
352 void CellTypeState::print(outputStream *os) {
353 if (can_be_address()) {
354 os->print("(p");
355 } else {
356 os->print("( ");
357 }
358 if (can_be_reference()) {
359 os->print("r");
360 } else {
361 os->print(" ");
362 }
363 if (can_be_value()) {
364 os->print("v");
365 } else {
366 os->print(" ");
367 }
368 if (can_be_valuetype()) {
369 os->print("q");
370 } else {
371 os->print(" ");
372 }
373 if (can_be_uninit()) {
374 os->print("u|");
375 } else {
376 os->print(" |");
377 }
378 if (is_info_top()) {
379 os->print("Top)");
380 } else if (is_info_bottom()) {
381 os->print("Bot)");
382 } else {
383 if (is_reference()) {
384 int info = get_info();
385 int data = info & ~(ref_not_lock_bit | ref_slot_bit);
386 if (info & ref_not_lock_bit) {
387 // Not a monitor lock reference.
388 if (info & ref_slot_bit) {
389 // slot
390 os->print("slot%d)", data);
391 } else {
392 // line
595 case Bytecodes::_jsr:
596 assert(bcs->is_wide()==false, "sanity check");
597 (*jmpFct)(this, bcs->dest(), data);
598
599
600
601 break;
602 case Bytecodes::_jsr_w:
603 (*jmpFct)(this, bcs->dest_w(), data);
604 break;
605 case Bytecodes::_wide:
606 ShouldNotReachHere();
607 return true;
608 break;
609 case Bytecodes::_athrow:
610 case Bytecodes::_ireturn:
611 case Bytecodes::_lreturn:
612 case Bytecodes::_freturn:
613 case Bytecodes::_dreturn:
614 case Bytecodes::_areturn:
615 case Bytecodes::_vreturn:
616 case Bytecodes::_return:
617 case Bytecodes::_ret:
618 break;
619 default:
620 return true;
621 }
622 return false;
623 }
624
625 /* Requires "pc" to be the head of a basic block; returns that basic
626 block. */
627 BasicBlock *GenerateOopMap::get_basic_block_at(int bci) const {
628 BasicBlock* bb = get_basic_block_containing(bci);
629 assert(bb->_bci == bci, "should have found BB");
630 return bb;
631 }
632
633 // Requires "pc" to be the start of an instruction; returns the basic
634 // block containing that instruction. */
635 BasicBlock *GenerateOopMap::get_basic_block_containing(int bci) const {
707 _stack_top = 0;
708 _monitor_top = 0;
709 }
710
711 int GenerateOopMap::methodsig_to_effect(Symbol* signature, bool is_static, CellTypeState* effect) {
712 ComputeEntryStack ces(signature);
713 return ces.compute_for_parameters(is_static, effect);
714 }
715
716 // Return result of merging cts1 and cts2.
717 CellTypeState CellTypeState::merge(CellTypeState cts, int slot) const {
718 CellTypeState result;
719
720 assert(!is_bottom() && !cts.is_bottom(),
721 "merge of bottom values is handled elsewhere");
722
723 result._state = _state | cts._state;
724
725 // If the top bit is set, we don't need to do any more work.
726 if (!result.is_info_top()) {
727 assert((result.can_be_address() || result.can_be_reference() || result.can_be_valuetype()),
728 "only addresses and references have non-top info");
729
730 if (!equal(cts)) {
731 // The two values being merged are different. Raise to top.
732 if (result.is_reference()) {
733 result = CellTypeState::make_slot_ref(slot);
734 } else if (result.is_valuetype()) {
735 result = CellTypeState::make_slot_valuetype(slot);
736 } else {
737 result._state |= info_conflict;
738 }
739 }
740 }
741 assert(result.is_valid_state(), "checking that CTS merge maintains legal state");
742
743 return result;
744 }
745
746 // Merge the variable state for locals and stack from cts into bbts.
747 bool GenerateOopMap::merge_local_state_vectors(CellTypeState* cts,
748 CellTypeState* bbts) {
749 int i;
750 int len = _max_locals + _stack_top;
751 bool change = false;
752
753 for (i = len - 1; i >= 0; i--) {
754 CellTypeState v = cts[i].merge(bbts[i], i);
755 change = change || !v.equal(bbts[i]);
838 bb->_monitor_top = bad_monitors;
839 bb->set_changed(true);
840 _monitor_safe = false;
841 }
842 } else if (!bb->is_reachable()) {
843 // First time we look at this BB
844 copy_state(bb->_state, _state);
845 bb->_stack_top = _stack_top;
846 bb->_monitor_top = _monitor_top;
847 bb->set_changed(true);
848 } else {
849 verify_error("stack height conflict: %d vs. %d", _stack_top, bb->_stack_top);
850 }
851 }
852
853 void GenerateOopMap::merge_state(GenerateOopMap *gom, int bci, int* data) {
854 gom->merge_state_into_bb(gom->get_basic_block_at(bci));
855 }
856
857 void GenerateOopMap::set_var(int localNo, CellTypeState cts) {
858 assert(cts.is_reference() || cts.is_value() || cts.is_address() || cts.is_valuetype(),
859 "wrong celltypestate");
860 if (localNo < 0 || localNo > _max_locals) {
861 verify_error("variable write error: r%d", localNo);
862 return;
863 }
864 vars()[localNo] = cts;
865 }
866
867 CellTypeState GenerateOopMap::get_var(int localNo) {
868 assert(localNo < _max_locals + _nof_refval_conflicts, "variable read error");
869 if (localNo < 0 || localNo > _max_locals) {
870 verify_error("variable read error: r%d", localNo);
871 return valCTS; // just to pick something;
872 }
873 return vars()[localNo];
874 }
875
876 CellTypeState GenerateOopMap::pop() {
877 if ( _stack_top <= 0) {
878 verify_error("stack underflow");
1379 break;
1380 default:
1381 fill_stackmap_for_opcodes(itr, vars(), stack(), _stack_top);
1382 break;
1383 }
1384 }
1385
1386 // abstract interpretation of current opcode
1387 switch(itr->code()) {
1388 case Bytecodes::_nop: break;
1389 case Bytecodes::_goto: break;
1390 case Bytecodes::_goto_w: break;
1391 case Bytecodes::_iinc: break;
1392 case Bytecodes::_return: do_return_monitor_check();
1393 break;
1394
1395 case Bytecodes::_aconst_null:
1396 case Bytecodes::_new: ppush1(CellTypeState::make_line_ref(itr->bci()));
1397 break;
1398
1399 case Bytecodes::_vdefault: ppush1(CellTypeState::make_line_valuetype(itr->bci())); break;
1400 case Bytecodes::_vwithfield: do_vwithfield(itr->get_index_u2_cpcache(), itr->bci()); break;
1401
1402 case Bytecodes::_iconst_m1:
1403 case Bytecodes::_iconst_0:
1404 case Bytecodes::_iconst_1:
1405 case Bytecodes::_iconst_2:
1406 case Bytecodes::_iconst_3:
1407 case Bytecodes::_iconst_4:
1408 case Bytecodes::_iconst_5:
1409 case Bytecodes::_fconst_0:
1410 case Bytecodes::_fconst_1:
1411 case Bytecodes::_fconst_2:
1412 case Bytecodes::_bipush:
1413 case Bytecodes::_sipush: ppush1(valCTS); break;
1414
1415 case Bytecodes::_lconst_0:
1416 case Bytecodes::_lconst_1:
1417 case Bytecodes::_dconst_0:
1418 case Bytecodes::_dconst_1: ppush(vvCTS); break;
1419
1420 case Bytecodes::_ldc2_w: ppush(vvCTS); break;
1421
1422 case Bytecodes::_ldc: // fall through:
1423 case Bytecodes::_ldc_w: do_ldc(itr->bci()); break;
1424
1425 case Bytecodes::_iload:
1426 case Bytecodes::_fload: ppload(vCTS, itr->get_index()); break;
1427
1428 case Bytecodes::_lload:
1429 case Bytecodes::_dload: ppload(vvCTS,itr->get_index()); break;
1430
1431 case Bytecodes::_aload: ppload(rCTS, itr->get_index()); break;
1432
1433 case Bytecodes::_vload: ppload(qCTS, itr->get_index()); break;
1434
1435 case Bytecodes::_iload_0:
1436 case Bytecodes::_fload_0: ppload(vCTS, 0); break;
1437 case Bytecodes::_iload_1:
1438 case Bytecodes::_fload_1: ppload(vCTS, 1); break;
1439 case Bytecodes::_iload_2:
1440 case Bytecodes::_fload_2: ppload(vCTS, 2); break;
1441 case Bytecodes::_iload_3:
1442 case Bytecodes::_fload_3: ppload(vCTS, 3); break;
1443
1444 case Bytecodes::_lload_0:
1445 case Bytecodes::_dload_0: ppload(vvCTS, 0); break;
1446 case Bytecodes::_lload_1:
1447 case Bytecodes::_dload_1: ppload(vvCTS, 1); break;
1448 case Bytecodes::_lload_2:
1449 case Bytecodes::_dload_2: ppload(vvCTS, 2); break;
1450 case Bytecodes::_lload_3:
1451 case Bytecodes::_dload_3: ppload(vvCTS, 3); break;
1452
1453 case Bytecodes::_aload_0: ppload(rCTS, 0); break;
1454 case Bytecodes::_aload_1: ppload(rCTS, 1); break;
1455 case Bytecodes::_aload_2: ppload(rCTS, 2); break;
1456 case Bytecodes::_aload_3: ppload(rCTS, 3); break;
1457
1458 case Bytecodes::_iaload:
1459 case Bytecodes::_faload:
1460 case Bytecodes::_baload:
1461 case Bytecodes::_caload:
1462 case Bytecodes::_saload: pp(vrCTS, vCTS); break;
1463
1464 case Bytecodes::_laload: pp(vrCTS, vvCTS); break;
1465 case Bytecodes::_daload: pp(vrCTS, vvCTS); break;
1466
1467 case Bytecodes::_aaload: pp_new_ref(vrCTS, itr->bci()); break;
1468 case Bytecodes::_vaload: pp_new_valuetype(vrCTS, itr->bci()); break;
1469
1470 case Bytecodes::_istore:
1471 case Bytecodes::_fstore: ppstore(vCTS, itr->get_index()); break;
1472
1473 case Bytecodes::_lstore:
1474 case Bytecodes::_dstore: ppstore(vvCTS, itr->get_index()); break;
1475
1476 case Bytecodes::_astore: do_astore(itr->get_index()); break;
1477 case Bytecodes::_vstore: do_vstore(itr->get_index()); break;
1478
1479 case Bytecodes::_istore_0:
1480 case Bytecodes::_fstore_0: ppstore(vCTS, 0); break;
1481 case Bytecodes::_istore_1:
1482 case Bytecodes::_fstore_1: ppstore(vCTS, 1); break;
1483 case Bytecodes::_istore_2:
1484 case Bytecodes::_fstore_2: ppstore(vCTS, 2); break;
1485 case Bytecodes::_istore_3:
1486 case Bytecodes::_fstore_3: ppstore(vCTS, 3); break;
1487
1488 case Bytecodes::_lstore_0:
1489 case Bytecodes::_dstore_0: ppstore(vvCTS, 0); break;
1490 case Bytecodes::_lstore_1:
1491 case Bytecodes::_dstore_1: ppstore(vvCTS, 1); break;
1492 case Bytecodes::_lstore_2:
1493 case Bytecodes::_dstore_2: ppstore(vvCTS, 2); break;
1494 case Bytecodes::_lstore_3:
1495 case Bytecodes::_dstore_3: ppstore(vvCTS, 3); break;
1496
1497 case Bytecodes::_astore_0: do_astore(0); break;
1498 case Bytecodes::_astore_1: do_astore(1); break;
1499 case Bytecodes::_astore_2: do_astore(2); break;
1500 case Bytecodes::_astore_3: do_astore(3); break;
1501
1502 case Bytecodes::_iastore:
1503 case Bytecodes::_fastore:
1504 case Bytecodes::_bastore:
1505 case Bytecodes::_castore:
1506 case Bytecodes::_sastore: ppop(vvrCTS); break;
1507 case Bytecodes::_lastore:
1508 case Bytecodes::_dastore: ppop(vvvrCTS); break;
1509 case Bytecodes::_aastore: ppop(rvrCTS); break;
1510 case Bytecodes::_vastore: ppop(qvrCTS); break;
1511
1512 case Bytecodes::_pop: ppop_any(1); break;
1513 case Bytecodes::_pop2: ppop_any(2); break;
1514
1515 case Bytecodes::_dup: ppdupswap(1, "11"); break;
1516 case Bytecodes::_dup_x1: ppdupswap(2, "121"); break;
1517 case Bytecodes::_dup_x2: ppdupswap(3, "1321"); break;
1518 case Bytecodes::_dup2: ppdupswap(2, "2121"); break;
1519 case Bytecodes::_dup2_x1: ppdupswap(3, "21321"); break;
1520 case Bytecodes::_dup2_x2: ppdupswap(4, "214321"); break;
1521 case Bytecodes::_swap: ppdupswap(2, "12"); break;
1522
1523 case Bytecodes::_iadd:
1524 case Bytecodes::_fadd:
1525 case Bytecodes::_isub:
1526 case Bytecodes::_fsub:
1527 case Bytecodes::_imul:
1528 case Bytecodes::_fmul:
1529 case Bytecodes::_idiv:
1530 case Bytecodes::_fdiv:
1632 case Bytecodes::_newarray:
1633 case Bytecodes::_anewarray: pp_new_ref(vCTS, itr->bci()); break;
1634 case Bytecodes::_checkcast: do_checkcast(); break;
1635 case Bytecodes::_arraylength:
1636 case Bytecodes::_instanceof: pp(rCTS, vCTS); break;
1637 case Bytecodes::_monitorenter: do_monitorenter(itr->bci()); break;
1638 case Bytecodes::_monitorexit: do_monitorexit(itr->bci()); break;
1639
1640 case Bytecodes::_athrow: // handled by do_exception_edge() BUT ...
1641 // vlh(apple): do_exception_edge() does not get
1642 // called if method has no exception handlers
1643 if ((!_has_exceptions) && (_monitor_top > 0)) {
1644 _monitor_safe = false;
1645 }
1646 break;
1647
1648 case Bytecodes::_areturn: do_return_monitor_check();
1649 ppop1(refCTS);
1650 break;
1651
1652 case Bytecodes::_vreturn: do_return_monitor_check();
1653 ppop1(valuetypeCTS);
1654 break;
1655
1656 case Bytecodes::_ifnull:
1657 case Bytecodes::_ifnonnull: ppop1(refCTS); break;
1658 case Bytecodes::_multianewarray: do_multianewarray(*(itr->bcp()+3), itr->bci()); break;
1659
1660 case Bytecodes::_vbox: pp_new_ref(qCTS, itr->bci()); break;
1661 case Bytecodes::_vunbox: pp_new_valuetype(rCTS, itr->bci()); break;
1662
1663 case Bytecodes::_wide: fatal("Iterator should skip this bytecode"); break;
1664 case Bytecodes::_ret: break;
1665
1666 // Java opcodes
1667 case Bytecodes::_lookupswitch: ppop1(valCTS); break;
1668
1669 default:
1670 tty->print("unexpected opcode: %d\n", itr->code());
1671 ShouldNotReachHere();
1672 break;
1673 }
1674 }
1675
1676 void GenerateOopMap::check_type(CellTypeState expected, CellTypeState actual) {
1677 if (!expected.equal_kind(actual)) {
1678 // dirty hack for invokevirtual
1679 if (expected.equal_kind(CellTypeState::refOrValueType) &&
1680 (actual.equal_kind(CellTypeState::ref) || actual.equal_kind(CellTypeState::valuetype))) return;
1681 verify_error("wrong type on stack (found: %c expected: %c)", actual.to_char(), expected.to_char());
1682 }
1683 }
1684
1685 void GenerateOopMap::ppstore(CellTypeState *in, int loc_no) {
1686 while(!(*in).is_bottom()) {
1687 CellTypeState expected =*in++;
1688 CellTypeState actual = pop();
1689 check_type(expected, actual);
1690 assert(loc_no >= 0, "sanity check");
1691 set_var(loc_no++, actual);
1692 }
1693 }
1694
1695 void GenerateOopMap::ppload(CellTypeState *out, int loc_no) {
1696 while(!(*out).is_bottom()) {
1697 CellTypeState out1 = *out++;
1698 CellTypeState vcts = get_var(loc_no);
1699 assert(out1.can_be_reference() || out1.can_be_value() || out1.can_be_valuetype(),
1700 "can only load refs. and values.");
1701 if (out1.is_reference()) {
1702 assert(loc_no>=0, "sanity check");
1703 if (!vcts.is_reference()) {
1704 // We were asked to push a reference, but the type of the
1705 // variable can be something else
1706 _conflict = true;
1707 if (vcts.can_be_uninit()) {
1708 // It is a ref-uninit conflict (at least). If there are other
1709 // problems, we'll get them in the next round
1710 add_to_ref_init_set(loc_no);
1711 vcts = out1;
1712 } else {
1713 // It wasn't a ref-uninit conflict. So must be a
1714 // ref-val or ref-pc conflict. Split the variable.
1715 record_refval_conflict(loc_no);
1716 vcts = out1;
1717 }
1718 push(out1); // recover...
1719 } else {
1748 while (push_ch != '\0') {
1749 int idx = push_ch - '1';
1750 assert(idx >= 0 && idx < poplen, "wrong arguments");
1751 push(actual[idx]);
1752 push_ch = *out++;
1753 }
1754 }
1755
1756 void GenerateOopMap::ppop1(CellTypeState out) {
1757 CellTypeState actual = pop();
1758 check_type(out, actual);
1759 }
1760
1761 void GenerateOopMap::ppop(CellTypeState *out) {
1762 while (!(*out).is_bottom()) {
1763 ppop1(*out++);
1764 }
1765 }
1766
1767 void GenerateOopMap::ppush1(CellTypeState in) {
1768 assert(in.is_reference() || in.is_value() || in.is_valuetype(), "sanity check");
1769 push(in);
1770 }
1771
1772 void GenerateOopMap::ppush(CellTypeState *in) {
1773 while (!(*in).is_bottom()) {
1774 ppush1(*in++);
1775 }
1776 }
1777
1778 void GenerateOopMap::pp(CellTypeState *in, CellTypeState *out) {
1779 ppop(in);
1780 ppush(out);
1781 }
1782
1783 void GenerateOopMap::pp_new_ref(CellTypeState *in, int bci) {
1784 ppop(in);
1785 ppush1(CellTypeState::make_line_ref(bci));
1786 }
1787
1788 void GenerateOopMap::pp_new_valuetype(CellTypeState *in, int bci) {
1789 ppop(in);
1790 ppush1(CellTypeState::make_line_valuetype(bci));
1791 }
1792
1793 void GenerateOopMap::ppop_any(int poplen) {
1794 if (_stack_top >= poplen) {
1795 _stack_top -= poplen;
1796 } else {
1797 verify_error("stack underflow");
1798 }
1799 }
1800
1801 // Replace all occurences of the state 'match' with the state 'replace'
1802 // in our current state vector.
1803 void GenerateOopMap::replace_all_CTS_matches(CellTypeState match,
1804 CellTypeState replace) {
1805 int i;
1806 int len = _max_locals + _stack_top;
1807 bool change = false;
1808
1809 for (i = len - 1; i >= 0; i--) {
1810 if (match.equal(_state[i])) {
1811 _state[i] = replace;
1812 }
1941
1942 void GenerateOopMap::do_multianewarray(int dims, int bci) {
1943 assert(dims >= 1, "sanity check");
1944 for(int i = dims -1; i >=0; i--) {
1945 ppop1(valCTS);
1946 }
1947 ppush1(CellTypeState::make_line_ref(bci));
1948 }
1949
1950 void GenerateOopMap::do_astore(int idx) {
1951 CellTypeState r_or_p = pop();
1952 if (!r_or_p.is_address() && !r_or_p.is_reference()) {
1953 // We actually expected ref or pc, but we only report that we expected a ref. It does not
1954 // really matter (at least for now)
1955 verify_error("wrong type on stack (found: %c, expected: {pr})", r_or_p.to_char());
1956 return;
1957 }
1958 set_var(idx, r_or_p);
1959 }
1960
1961 void GenerateOopMap::do_vstore(int idx) {
1962 CellTypeState q = pop();
1963 if (!q.is_valuetype()) {
1964 verify_error("wrong type on stack (found: %c, expected: {q})", q.to_char());
1965 return;
1966 }
1967 set_var(idx, q);
1968 }
1969
1970 // Copies bottom/zero terminated CTS string from "src" into "dst".
1971 // Does NOT terminate with a bottom. Returns the number of cells copied.
1972 int GenerateOopMap::copy_cts(CellTypeState *dst, CellTypeState *src) {
1973 int idx = 0;
1974 while (!src[idx].is_bottom()) {
1975 dst[idx] = src[idx];
1976 idx++;
1977 }
1978 return idx;
1979 }
1980
1981 void GenerateOopMap::do_field(int is_get, int is_static, int idx, int bci) {
1982 // Dig up signature for field in constant pool
1983 ConstantPool* cp = method()->constants();
1984 int nameAndTypeIdx = cp->name_and_type_ref_index_at(idx);
1985 int signatureIdx = cp->signature_ref_index_at(nameAndTypeIdx);
1986 Symbol* signature = cp->symbol_at(signatureIdx);
1987
1988 // Parse signature (espcially simple for fields)
1989 assert(signature->utf8_length() > 0, "field signatures cannot have zero length");
1990 // The signature is UFT8 encoded, but the first char is always ASCII for signatures.
1991 char sigch = (char)*(signature->base());
1992 CellTypeState temp[4];
1993 CellTypeState *eff = sigchar_to_effect(sigch, bci, temp);
1994
1995 CellTypeState in[4];
1996 CellTypeState *out;
1997 int i = 0;
1998
1999 if (is_get) {
2000 out = eff;
2001 } else {
2002 out = epsilonCTS;
2003 i = copy_cts(in, eff);
2004 }
2005 if (!is_static) {
2006 in[i++] = CellTypeState::refOrValueType;
2007 }
2008 in[i] = CellTypeState::bottom;
2009 assert(i<=3, "sanity check");
2010 pp(in, out);
2011 }
2012
2013 void GenerateOopMap::do_method(int is_static, int idx, int bci) {
2014 // Dig up signature for field in constant pool
2015 ConstantPool* cp = _method->constants();
2016 Symbol* signature = cp->signature_ref_at(idx);
2017
2018 // Parse method signature
2019 CellTypeState out[4];
2020 CellTypeState in[MAXARGSIZE+1]; // Includes result
2021 ComputeCallStack cse(signature);
2022
2023 // Compute return type
2024 int res_length= cse.compute_for_returntype(out);
2025
2026 // Temporary hack.
2030
2031 assert(res_length<=4, "max value should be vv");
2032
2033 // Compute arguments
2034 int arg_length = cse.compute_for_parameters(is_static != 0, in);
2035 assert(arg_length<=MAXARGSIZE, "too many locals");
2036
2037 // Pop arguments
2038 for (int i = arg_length - 1; i >= 0; i--) ppop1(in[i]);// Do args in reverse order.
2039
2040 // Report results
2041 if (_report_result_for_send == true) {
2042 fill_stackmap_for_opcodes(_itr_send, vars(), stack(), _stack_top);
2043 _report_result_for_send = false;
2044 }
2045
2046 // Push return address
2047 ppush(out);
2048 }
2049
2050 void GenerateOopMap::do_vwithfield(int idx, int bci) {
2051 // Dig up signature for field in constant pool
2052 ConstantPool* cp = method()->constants();
2053 int nameAndTypeIdx = cp->name_and_type_ref_index_at(idx);
2054 int signatureIdx = cp->signature_ref_index_at(nameAndTypeIdx);
2055 Symbol* signature = cp->symbol_at(signatureIdx);
2056
2057 // Parse signature (especially simple for fields)
2058 assert(signature->utf8_length() > 0,
2059 "field signatures cannot have zero length");
2060 // The signature is UFT8 encoded, but the first char is always ASCII for signatures.
2061 char sigch = (char) *(signature->base());
2062 CellTypeState temp[4];
2063 CellTypeState *eff = sigchar_to_effect(sigch, bci, temp);
2064
2065 CellTypeState in[4];
2066 int i = copy_cts(in, eff);
2067 in[i++] = CellTypeState::valuetype;
2068 in[i] = CellTypeState::bottom;
2069 assert(i <= 3, "sanity check");
2070
2071 CellTypeState out[2];
2072 out[0] = CellTypeState::valuetype;
2073 out[1] = CellTypeState::bottom;
2074
2075 pp(in, out);
2076 }
2077
2078 // This is used to parse the signature for fields, since they are very simple...
2079 CellTypeState *GenerateOopMap::sigchar_to_effect(char sigch, int bci, CellTypeState *out) {
2080 // Object and array
2081 if (sigch=='L' || sigch=='[') {
2082 out[0] = CellTypeState::make_line_ref(bci);
2083 out[1] = CellTypeState::bottom;
2084 return out;
2085 }
2086 if (sigch == 'Q') {
2087 out[0] = CellTypeState::make_line_valuetype(bci);
2088 out[1] = CellTypeState::bottom;
2089 return out;
2090 }
2091 if (sigch == 'J' || sigch == 'D' ) return vvCTS; // Long and Double
2092 if (sigch == 'V' ) return epsilonCTS; // Void
2093 return vCTS; // Otherwise
2094 }
2095
2096 long GenerateOopMap::_total_byte_count = 0;
2097 elapsedTimer GenerateOopMap::_total_oopmap_time;
2098
2099 // This function assumes "bcs" is at a "ret" instruction and that the vars
2100 // state is valid for that instruction. Furthermore, the ret instruction
2101 // must be the last instruction in "bb" (we store information about the
2102 // "ret" in "bb").
2103 void GenerateOopMap::ret_jump_targets_do(BytecodeStream *bcs, jmpFct_t jmpFct, int varNo, int *data) {
2104 CellTypeState ra = vars()[varNo];
2105 if (!ra.is_good_address()) {
2106 verify_error("ret returns from two jsr subroutines?");
2107 return;
2108 }
2109 int target = ra.get_info();
2110
|
104 // ComputeCallStack
105 //
106 // Specialization of SignatureIterator - compute the effects of a call
107 //
108 class ComputeCallStack : public SignatureIterator {
109 CellTypeState *_effect;
110 int _idx;
111
112 void setup();
113 void set(CellTypeState state) { _effect[_idx++] = state; }
114 int length() { return _idx; };
115
116 virtual void do_bool () { set(CellTypeState::value); };
117 virtual void do_char () { set(CellTypeState::value); };
118 virtual void do_float () { set(CellTypeState::value); };
119 virtual void do_byte () { set(CellTypeState::value); };
120 virtual void do_short () { set(CellTypeState::value); };
121 virtual void do_int () { set(CellTypeState::value); };
122 virtual void do_void () { set(CellTypeState::bottom);};
123 virtual void do_object(int begin, int end) { set(CellTypeState::ref); };
124 virtual void do_array (int begin, int end) { set(CellTypeState::ref); };
125
126 void do_double() { set(CellTypeState::value);
127 set(CellTypeState::value); }
128 void do_long () { set(CellTypeState::value);
129 set(CellTypeState::value); }
130
131 public:
132 ComputeCallStack(Symbol* signature) : SignatureIterator(signature) {};
133
134 // Compute methods
135 int compute_for_parameters(bool is_static, CellTypeState *effect) {
136 _idx = 0;
137 _effect = effect;
138
139 if (!is_static) {
140 effect[_idx++] = CellTypeState::ref;
141 }
142
143 iterate_parameters();
144
145 return length();
146 };
147
148 int compute_for_returntype(CellTypeState *effect) {
149 _idx = 0;
150 _effect = effect;
151 iterate_returntype();
152 set(CellTypeState::bottom); // Always terminate with a bottom state, so ppush works
153
154 return length();
155 }
156 };
157
158 //=========================================================================================
159 // ComputeEntryStack
160 //
161 // Specialization of SignatureIterator - in order to set up first stack frame
162 //
163 class ComputeEntryStack : public SignatureIterator {
164 CellTypeState *_effect;
165 int _idx;
166
167 void setup();
168 void set(CellTypeState state) { _effect[_idx++] = state; }
169 int length() { return _idx; };
170
171 virtual void do_bool () { set(CellTypeState::value); };
172 virtual void do_char () { set(CellTypeState::value); };
173 virtual void do_float () { set(CellTypeState::value); };
174 virtual void do_byte () { set(CellTypeState::value); };
175 virtual void do_short () { set(CellTypeState::value); };
176 virtual void do_int () { set(CellTypeState::value); };
177 virtual void do_void () { set(CellTypeState::bottom);};
178 virtual void do_object(int begin, int end) { set(CellTypeState::make_slot_ref(_idx)); }
179 virtual void do_array (int begin, int end) { set(CellTypeState::make_slot_ref(_idx)); }
180
181 void do_double() { set(CellTypeState::value);
182 set(CellTypeState::value); }
183 void do_long () { set(CellTypeState::value);
184 set(CellTypeState::value); }
185
186 public:
187 ComputeEntryStack(Symbol* signature) : SignatureIterator(signature) {};
188
189 // Compute methods
190 int compute_for_parameters(bool is_static, CellTypeState *effect) {
191 _idx = 0;
192 _effect = effect;
193
194 if (!is_static)
195 effect[_idx++] = CellTypeState::make_slot_ref(0);
196
197 iterate_parameters();
198
199 return length();
281 return NULL;
282 }
283
284 // The instruction at bci is changing size by "delta". Update the return map.
285 void RetTable::update_ret_table(int bci, int delta) {
286 RetTableEntry *cur = _first;
287 while(cur) {
288 cur->add_delta(bci, delta);
289 cur = cur->next();
290 }
291 }
292
293 //
294 // Celltype state
295 //
296
297 CellTypeState CellTypeState::bottom = CellTypeState::make_bottom();
298 CellTypeState CellTypeState::uninit = CellTypeState::make_any(uninit_value);
299 CellTypeState CellTypeState::ref = CellTypeState::make_any(ref_conflict);
300 CellTypeState CellTypeState::value = CellTypeState::make_any(val_value);
301 CellTypeState CellTypeState::refUninit = CellTypeState::make_any(ref_conflict | uninit_value);
302 CellTypeState CellTypeState::top = CellTypeState::make_top();
303 CellTypeState CellTypeState::addr = CellTypeState::make_any(addr_conflict);
304
305 // Commonly used constants
306 static CellTypeState epsilonCTS[1] = { CellTypeState::bottom };
307 static CellTypeState refCTS = CellTypeState::ref;
308 static CellTypeState valCTS = CellTypeState::value;
309 static CellTypeState vCTS[2] = { CellTypeState::value, CellTypeState::bottom };
310 static CellTypeState rCTS[2] = { CellTypeState::ref, CellTypeState::bottom };
311 static CellTypeState rrCTS[3] = { CellTypeState::ref, CellTypeState::ref, CellTypeState::bottom };
312 static CellTypeState vrCTS[3] = { CellTypeState::value, CellTypeState::ref, CellTypeState::bottom };
313 static CellTypeState vvCTS[3] = { CellTypeState::value, CellTypeState::value, CellTypeState::bottom };
314 static CellTypeState rvrCTS[4] = { CellTypeState::ref, CellTypeState::value, CellTypeState::ref, CellTypeState::bottom };
315 static CellTypeState vvrCTS[4] = { CellTypeState::value, CellTypeState::value, CellTypeState::ref, CellTypeState::bottom };
316 static CellTypeState vvvCTS[4] = { CellTypeState::value, CellTypeState::value, CellTypeState::value, CellTypeState::bottom };
317 static CellTypeState vvvrCTS[5] = { CellTypeState::value, CellTypeState::value, CellTypeState::value, CellTypeState::ref, CellTypeState::bottom };
318 static CellTypeState vvvvCTS[5] = { CellTypeState::value, CellTypeState::value, CellTypeState::value, CellTypeState::value, CellTypeState::bottom };
319
320 char CellTypeState::to_char() const {
321 if (can_be_reference()) {
322 if (can_be_value() || can_be_address())
323 return '#'; // Conflict that needs to be rewritten
324 else
325 return 'r';
326 } else if (can_be_value())
327 return 'v';
328 else if (can_be_address())
329 return 'p';
330 else if (can_be_uninit())
331 return ' ';
332 else
333 return '@';
334 }
335
336
337 // Print a detailed CellTypeState. Indicate all bits that are set. If
338 // the CellTypeState represents an address or a reference, print the
339 // value of the additional information.
340 void CellTypeState::print(outputStream *os) {
341 if (can_be_address()) {
342 os->print("(p");
343 } else {
344 os->print("( ");
345 }
346 if (can_be_reference()) {
347 os->print("r");
348 } else {
349 os->print(" ");
350 }
351 if (can_be_value()) {
352 os->print("v");
353 } else {
354 os->print(" ");
355 }
356 if (can_be_uninit()) {
357 os->print("u|");
358 } else {
359 os->print(" |");
360 }
361 if (is_info_top()) {
362 os->print("Top)");
363 } else if (is_info_bottom()) {
364 os->print("Bot)");
365 } else {
366 if (is_reference()) {
367 int info = get_info();
368 int data = info & ~(ref_not_lock_bit | ref_slot_bit);
369 if (info & ref_not_lock_bit) {
370 // Not a monitor lock reference.
371 if (info & ref_slot_bit) {
372 // slot
373 os->print("slot%d)", data);
374 } else {
375 // line
578 case Bytecodes::_jsr:
579 assert(bcs->is_wide()==false, "sanity check");
580 (*jmpFct)(this, bcs->dest(), data);
581
582
583
584 break;
585 case Bytecodes::_jsr_w:
586 (*jmpFct)(this, bcs->dest_w(), data);
587 break;
588 case Bytecodes::_wide:
589 ShouldNotReachHere();
590 return true;
591 break;
592 case Bytecodes::_athrow:
593 case Bytecodes::_ireturn:
594 case Bytecodes::_lreturn:
595 case Bytecodes::_freturn:
596 case Bytecodes::_dreturn:
597 case Bytecodes::_areturn:
598 case Bytecodes::_return:
599 case Bytecodes::_ret:
600 break;
601 default:
602 return true;
603 }
604 return false;
605 }
606
607 /* Requires "pc" to be the head of a basic block; returns that basic
608 block. */
609 BasicBlock *GenerateOopMap::get_basic_block_at(int bci) const {
610 BasicBlock* bb = get_basic_block_containing(bci);
611 assert(bb->_bci == bci, "should have found BB");
612 return bb;
613 }
614
615 // Requires "pc" to be the start of an instruction; returns the basic
616 // block containing that instruction. */
617 BasicBlock *GenerateOopMap::get_basic_block_containing(int bci) const {
689 _stack_top = 0;
690 _monitor_top = 0;
691 }
692
693 int GenerateOopMap::methodsig_to_effect(Symbol* signature, bool is_static, CellTypeState* effect) {
694 ComputeEntryStack ces(signature);
695 return ces.compute_for_parameters(is_static, effect);
696 }
697
698 // Return result of merging cts1 and cts2.
699 CellTypeState CellTypeState::merge(CellTypeState cts, int slot) const {
700 CellTypeState result;
701
702 assert(!is_bottom() && !cts.is_bottom(),
703 "merge of bottom values is handled elsewhere");
704
705 result._state = _state | cts._state;
706
707 // If the top bit is set, we don't need to do any more work.
708 if (!result.is_info_top()) {
709 assert((result.can_be_address() || result.can_be_reference()),
710 "only addresses and references have non-top info");
711
712 if (!equal(cts)) {
713 // The two values being merged are different. Raise to top.
714 if (result.is_reference()) {
715 result = CellTypeState::make_slot_ref(slot);
716 } else {
717 result._state |= info_conflict;
718 }
719 }
720 }
721 assert(result.is_valid_state(), "checking that CTS merge maintains legal state");
722
723 return result;
724 }
725
726 // Merge the variable state for locals and stack from cts into bbts.
727 bool GenerateOopMap::merge_local_state_vectors(CellTypeState* cts,
728 CellTypeState* bbts) {
729 int i;
730 int len = _max_locals + _stack_top;
731 bool change = false;
732
733 for (i = len - 1; i >= 0; i--) {
734 CellTypeState v = cts[i].merge(bbts[i], i);
735 change = change || !v.equal(bbts[i]);
818 bb->_monitor_top = bad_monitors;
819 bb->set_changed(true);
820 _monitor_safe = false;
821 }
822 } else if (!bb->is_reachable()) {
823 // First time we look at this BB
824 copy_state(bb->_state, _state);
825 bb->_stack_top = _stack_top;
826 bb->_monitor_top = _monitor_top;
827 bb->set_changed(true);
828 } else {
829 verify_error("stack height conflict: %d vs. %d", _stack_top, bb->_stack_top);
830 }
831 }
832
833 void GenerateOopMap::merge_state(GenerateOopMap *gom, int bci, int* data) {
834 gom->merge_state_into_bb(gom->get_basic_block_at(bci));
835 }
836
837 void GenerateOopMap::set_var(int localNo, CellTypeState cts) {
838 assert(cts.is_reference() || cts.is_value() || cts.is_address(),
839 "wrong celltypestate");
840 if (localNo < 0 || localNo > _max_locals) {
841 verify_error("variable write error: r%d", localNo);
842 return;
843 }
844 vars()[localNo] = cts;
845 }
846
847 CellTypeState GenerateOopMap::get_var(int localNo) {
848 assert(localNo < _max_locals + _nof_refval_conflicts, "variable read error");
849 if (localNo < 0 || localNo > _max_locals) {
850 verify_error("variable read error: r%d", localNo);
851 return valCTS; // just to pick something;
852 }
853 return vars()[localNo];
854 }
855
856 CellTypeState GenerateOopMap::pop() {
857 if ( _stack_top <= 0) {
858 verify_error("stack underflow");
1359 break;
1360 default:
1361 fill_stackmap_for_opcodes(itr, vars(), stack(), _stack_top);
1362 break;
1363 }
1364 }
1365
1366 // abstract interpretation of current opcode
1367 switch(itr->code()) {
1368 case Bytecodes::_nop: break;
1369 case Bytecodes::_goto: break;
1370 case Bytecodes::_goto_w: break;
1371 case Bytecodes::_iinc: break;
1372 case Bytecodes::_return: do_return_monitor_check();
1373 break;
1374
1375 case Bytecodes::_aconst_null:
1376 case Bytecodes::_new: ppush1(CellTypeState::make_line_ref(itr->bci()));
1377 break;
1378
1379 case Bytecodes::_defaultvalue: ppush1(CellTypeState::make_line_ref(itr->bci())); break;
1380 case Bytecodes::_withfield: do_withfield(itr->get_index_u2_cpcache(), itr->bci()); break;
1381
1382 case Bytecodes::_iconst_m1:
1383 case Bytecodes::_iconst_0:
1384 case Bytecodes::_iconst_1:
1385 case Bytecodes::_iconst_2:
1386 case Bytecodes::_iconst_3:
1387 case Bytecodes::_iconst_4:
1388 case Bytecodes::_iconst_5:
1389 case Bytecodes::_fconst_0:
1390 case Bytecodes::_fconst_1:
1391 case Bytecodes::_fconst_2:
1392 case Bytecodes::_bipush:
1393 case Bytecodes::_sipush: ppush1(valCTS); break;
1394
1395 case Bytecodes::_lconst_0:
1396 case Bytecodes::_lconst_1:
1397 case Bytecodes::_dconst_0:
1398 case Bytecodes::_dconst_1: ppush(vvCTS); break;
1399
1400 case Bytecodes::_ldc2_w: ppush(vvCTS); break;
1401
1402 case Bytecodes::_ldc: // fall through:
1403 case Bytecodes::_ldc_w: do_ldc(itr->bci()); break;
1404
1405 case Bytecodes::_iload:
1406 case Bytecodes::_fload: ppload(vCTS, itr->get_index()); break;
1407
1408 case Bytecodes::_lload:
1409 case Bytecodes::_dload: ppload(vvCTS,itr->get_index()); break;
1410
1411 case Bytecodes::_aload: ppload(rCTS, itr->get_index()); break;
1412
1413 case Bytecodes::_iload_0:
1414 case Bytecodes::_fload_0: ppload(vCTS, 0); break;
1415 case Bytecodes::_iload_1:
1416 case Bytecodes::_fload_1: ppload(vCTS, 1); break;
1417 case Bytecodes::_iload_2:
1418 case Bytecodes::_fload_2: ppload(vCTS, 2); break;
1419 case Bytecodes::_iload_3:
1420 case Bytecodes::_fload_3: ppload(vCTS, 3); break;
1421
1422 case Bytecodes::_lload_0:
1423 case Bytecodes::_dload_0: ppload(vvCTS, 0); break;
1424 case Bytecodes::_lload_1:
1425 case Bytecodes::_dload_1: ppload(vvCTS, 1); break;
1426 case Bytecodes::_lload_2:
1427 case Bytecodes::_dload_2: ppload(vvCTS, 2); break;
1428 case Bytecodes::_lload_3:
1429 case Bytecodes::_dload_3: ppload(vvCTS, 3); break;
1430
1431 case Bytecodes::_aload_0: ppload(rCTS, 0); break;
1432 case Bytecodes::_aload_1: ppload(rCTS, 1); break;
1433 case Bytecodes::_aload_2: ppload(rCTS, 2); break;
1434 case Bytecodes::_aload_3: ppload(rCTS, 3); break;
1435
1436 case Bytecodes::_iaload:
1437 case Bytecodes::_faload:
1438 case Bytecodes::_baload:
1439 case Bytecodes::_caload:
1440 case Bytecodes::_saload: pp(vrCTS, vCTS); break;
1441
1442 case Bytecodes::_laload: pp(vrCTS, vvCTS); break;
1443 case Bytecodes::_daload: pp(vrCTS, vvCTS); break;
1444
1445 case Bytecodes::_aaload: pp_new_ref(vrCTS, itr->bci()); break;
1446
1447 case Bytecodes::_istore:
1448 case Bytecodes::_fstore: ppstore(vCTS, itr->get_index()); break;
1449
1450 case Bytecodes::_lstore:
1451 case Bytecodes::_dstore: ppstore(vvCTS, itr->get_index()); break;
1452
1453 case Bytecodes::_astore: do_astore(itr->get_index()); break;
1454
1455 case Bytecodes::_istore_0:
1456 case Bytecodes::_fstore_0: ppstore(vCTS, 0); break;
1457 case Bytecodes::_istore_1:
1458 case Bytecodes::_fstore_1: ppstore(vCTS, 1); break;
1459 case Bytecodes::_istore_2:
1460 case Bytecodes::_fstore_2: ppstore(vCTS, 2); break;
1461 case Bytecodes::_istore_3:
1462 case Bytecodes::_fstore_3: ppstore(vCTS, 3); break;
1463
1464 case Bytecodes::_lstore_0:
1465 case Bytecodes::_dstore_0: ppstore(vvCTS, 0); break;
1466 case Bytecodes::_lstore_1:
1467 case Bytecodes::_dstore_1: ppstore(vvCTS, 1); break;
1468 case Bytecodes::_lstore_2:
1469 case Bytecodes::_dstore_2: ppstore(vvCTS, 2); break;
1470 case Bytecodes::_lstore_3:
1471 case Bytecodes::_dstore_3: ppstore(vvCTS, 3); break;
1472
1473 case Bytecodes::_astore_0: do_astore(0); break;
1474 case Bytecodes::_astore_1: do_astore(1); break;
1475 case Bytecodes::_astore_2: do_astore(2); break;
1476 case Bytecodes::_astore_3: do_astore(3); break;
1477
1478 case Bytecodes::_iastore:
1479 case Bytecodes::_fastore:
1480 case Bytecodes::_bastore:
1481 case Bytecodes::_castore:
1482 case Bytecodes::_sastore: ppop(vvrCTS); break;
1483 case Bytecodes::_lastore:
1484 case Bytecodes::_dastore: ppop(vvvrCTS); break;
1485 case Bytecodes::_aastore: ppop(rvrCTS); break;
1486
1487 case Bytecodes::_pop: ppop_any(1); break;
1488 case Bytecodes::_pop2: ppop_any(2); break;
1489
1490 case Bytecodes::_dup: ppdupswap(1, "11"); break;
1491 case Bytecodes::_dup_x1: ppdupswap(2, "121"); break;
1492 case Bytecodes::_dup_x2: ppdupswap(3, "1321"); break;
1493 case Bytecodes::_dup2: ppdupswap(2, "2121"); break;
1494 case Bytecodes::_dup2_x1: ppdupswap(3, "21321"); break;
1495 case Bytecodes::_dup2_x2: ppdupswap(4, "214321"); break;
1496 case Bytecodes::_swap: ppdupswap(2, "12"); break;
1497
1498 case Bytecodes::_iadd:
1499 case Bytecodes::_fadd:
1500 case Bytecodes::_isub:
1501 case Bytecodes::_fsub:
1502 case Bytecodes::_imul:
1503 case Bytecodes::_fmul:
1504 case Bytecodes::_idiv:
1505 case Bytecodes::_fdiv:
1607 case Bytecodes::_newarray:
1608 case Bytecodes::_anewarray: pp_new_ref(vCTS, itr->bci()); break;
1609 case Bytecodes::_checkcast: do_checkcast(); break;
1610 case Bytecodes::_arraylength:
1611 case Bytecodes::_instanceof: pp(rCTS, vCTS); break;
1612 case Bytecodes::_monitorenter: do_monitorenter(itr->bci()); break;
1613 case Bytecodes::_monitorexit: do_monitorexit(itr->bci()); break;
1614
1615 case Bytecodes::_athrow: // handled by do_exception_edge() BUT ...
1616 // vlh(apple): do_exception_edge() does not get
1617 // called if method has no exception handlers
1618 if ((!_has_exceptions) && (_monitor_top > 0)) {
1619 _monitor_safe = false;
1620 }
1621 break;
1622
1623 case Bytecodes::_areturn: do_return_monitor_check();
1624 ppop1(refCTS);
1625 break;
1626
1627 case Bytecodes::_ifnull:
1628 case Bytecodes::_ifnonnull: ppop1(refCTS); break;
1629 case Bytecodes::_multianewarray: do_multianewarray(*(itr->bcp()+3), itr->bci()); break;
1630
1631 case Bytecodes::_wide: fatal("Iterator should skip this bytecode"); break;
1632 case Bytecodes::_ret: break;
1633
1634 // Java opcodes
1635 case Bytecodes::_lookupswitch: ppop1(valCTS); break;
1636
1637 default:
1638 tty->print("unexpected opcode: %d\n", itr->code());
1639 ShouldNotReachHere();
1640 break;
1641 }
1642 }
1643
1644 void GenerateOopMap::check_type(CellTypeState expected, CellTypeState actual) {
1645 if (!expected.equal_kind(actual)) {
1646 verify_error("wrong type on stack (found: %c expected: %c)", actual.to_char(), expected.to_char());
1647 }
1648 }
1649
1650 void GenerateOopMap::ppstore(CellTypeState *in, int loc_no) {
1651 while(!(*in).is_bottom()) {
1652 CellTypeState expected =*in++;
1653 CellTypeState actual = pop();
1654 check_type(expected, actual);
1655 assert(loc_no >= 0, "sanity check");
1656 set_var(loc_no++, actual);
1657 }
1658 }
1659
1660 void GenerateOopMap::ppload(CellTypeState *out, int loc_no) {
1661 while(!(*out).is_bottom()) {
1662 CellTypeState out1 = *out++;
1663 CellTypeState vcts = get_var(loc_no);
1664 assert(out1.can_be_reference() || out1.can_be_value(),
1665 "can only load refs. and values.");
1666 if (out1.is_reference()) {
1667 assert(loc_no>=0, "sanity check");
1668 if (!vcts.is_reference()) {
1669 // We were asked to push a reference, but the type of the
1670 // variable can be something else
1671 _conflict = true;
1672 if (vcts.can_be_uninit()) {
1673 // It is a ref-uninit conflict (at least). If there are other
1674 // problems, we'll get them in the next round
1675 add_to_ref_init_set(loc_no);
1676 vcts = out1;
1677 } else {
1678 // It wasn't a ref-uninit conflict. So must be a
1679 // ref-val or ref-pc conflict. Split the variable.
1680 record_refval_conflict(loc_no);
1681 vcts = out1;
1682 }
1683 push(out1); // recover...
1684 } else {
1713 while (push_ch != '\0') {
1714 int idx = push_ch - '1';
1715 assert(idx >= 0 && idx < poplen, "wrong arguments");
1716 push(actual[idx]);
1717 push_ch = *out++;
1718 }
1719 }
1720
1721 void GenerateOopMap::ppop1(CellTypeState out) {
1722 CellTypeState actual = pop();
1723 check_type(out, actual);
1724 }
1725
1726 void GenerateOopMap::ppop(CellTypeState *out) {
1727 while (!(*out).is_bottom()) {
1728 ppop1(*out++);
1729 }
1730 }
1731
1732 void GenerateOopMap::ppush1(CellTypeState in) {
1733 assert(in.is_reference() || in.is_value(), "sanity check");
1734 push(in);
1735 }
1736
1737 void GenerateOopMap::ppush(CellTypeState *in) {
1738 while (!(*in).is_bottom()) {
1739 ppush1(*in++);
1740 }
1741 }
1742
1743 void GenerateOopMap::pp(CellTypeState *in, CellTypeState *out) {
1744 ppop(in);
1745 ppush(out);
1746 }
1747
1748 void GenerateOopMap::pp_new_ref(CellTypeState *in, int bci) {
1749 ppop(in);
1750 ppush1(CellTypeState::make_line_ref(bci));
1751 }
1752
1753 void GenerateOopMap::ppop_any(int poplen) {
1754 if (_stack_top >= poplen) {
1755 _stack_top -= poplen;
1756 } else {
1757 verify_error("stack underflow");
1758 }
1759 }
1760
1761 // Replace all occurences of the state 'match' with the state 'replace'
1762 // in our current state vector.
1763 void GenerateOopMap::replace_all_CTS_matches(CellTypeState match,
1764 CellTypeState replace) {
1765 int i;
1766 int len = _max_locals + _stack_top;
1767 bool change = false;
1768
1769 for (i = len - 1; i >= 0; i--) {
1770 if (match.equal(_state[i])) {
1771 _state[i] = replace;
1772 }
1901
1902 void GenerateOopMap::do_multianewarray(int dims, int bci) {
1903 assert(dims >= 1, "sanity check");
1904 for(int i = dims -1; i >=0; i--) {
1905 ppop1(valCTS);
1906 }
1907 ppush1(CellTypeState::make_line_ref(bci));
1908 }
1909
1910 void GenerateOopMap::do_astore(int idx) {
1911 CellTypeState r_or_p = pop();
1912 if (!r_or_p.is_address() && !r_or_p.is_reference()) {
1913 // We actually expected ref or pc, but we only report that we expected a ref. It does not
1914 // really matter (at least for now)
1915 verify_error("wrong type on stack (found: %c, expected: {pr})", r_or_p.to_char());
1916 return;
1917 }
1918 set_var(idx, r_or_p);
1919 }
1920
1921 // Copies bottom/zero terminated CTS string from "src" into "dst".
1922 // Does NOT terminate with a bottom. Returns the number of cells copied.
1923 int GenerateOopMap::copy_cts(CellTypeState *dst, CellTypeState *src) {
1924 int idx = 0;
1925 while (!src[idx].is_bottom()) {
1926 dst[idx] = src[idx];
1927 idx++;
1928 }
1929 return idx;
1930 }
1931
1932 void GenerateOopMap::do_field(int is_get, int is_static, int idx, int bci) {
1933 // Dig up signature for field in constant pool
1934 ConstantPool* cp = method()->constants();
1935 int nameAndTypeIdx = cp->name_and_type_ref_index_at(idx);
1936 int signatureIdx = cp->signature_ref_index_at(nameAndTypeIdx);
1937 Symbol* signature = cp->symbol_at(signatureIdx);
1938
1939 // Parse signature (espcially simple for fields)
1940 assert(signature->utf8_length() > 0, "field signatures cannot have zero length");
1941 // The signature is UFT8 encoded, but the first char is always ASCII for signatures.
1942 char sigch = (char)*(signature->base());
1943 CellTypeState temp[4];
1944 CellTypeState *eff = sigchar_to_effect(sigch, bci, temp);
1945
1946 CellTypeState in[4];
1947 CellTypeState *out;
1948 int i = 0;
1949
1950 if (is_get) {
1951 out = eff;
1952 } else {
1953 out = epsilonCTS;
1954 i = copy_cts(in, eff);
1955 }
1956 if (!is_static) {
1957 in[i++] = CellTypeState::ref;
1958 }
1959 in[i] = CellTypeState::bottom;
1960 assert(i<=3, "sanity check");
1961 pp(in, out);
1962 }
1963
1964 void GenerateOopMap::do_method(int is_static, int idx, int bci) {
1965 // Dig up signature for field in constant pool
1966 ConstantPool* cp = _method->constants();
1967 Symbol* signature = cp->signature_ref_at(idx);
1968
1969 // Parse method signature
1970 CellTypeState out[4];
1971 CellTypeState in[MAXARGSIZE+1]; // Includes result
1972 ComputeCallStack cse(signature);
1973
1974 // Compute return type
1975 int res_length= cse.compute_for_returntype(out);
1976
1977 // Temporary hack.
1981
1982 assert(res_length<=4, "max value should be vv");
1983
1984 // Compute arguments
1985 int arg_length = cse.compute_for_parameters(is_static != 0, in);
1986 assert(arg_length<=MAXARGSIZE, "too many locals");
1987
1988 // Pop arguments
1989 for (int i = arg_length - 1; i >= 0; i--) ppop1(in[i]);// Do args in reverse order.
1990
1991 // Report results
1992 if (_report_result_for_send == true) {
1993 fill_stackmap_for_opcodes(_itr_send, vars(), stack(), _stack_top);
1994 _report_result_for_send = false;
1995 }
1996
1997 // Push return address
1998 ppush(out);
1999 }
2000
2001 void GenerateOopMap::do_withfield(int idx, int bci) {
2002 // Dig up signature for field in constant pool
2003 ConstantPool* cp = method()->constants();
2004 int nameAndTypeIdx = cp->name_and_type_ref_index_at(idx);
2005 int signatureIdx = cp->signature_ref_index_at(nameAndTypeIdx);
2006 Symbol* signature = cp->symbol_at(signatureIdx);
2007
2008 // Parse signature (especially simple for fields)
2009 assert(signature->utf8_length() > 0,
2010 "field signatures cannot have zero length");
2011 // The signature is UFT8 encoded, but the first char is always ASCII for signatures.
2012 char sigch = (char) *(signature->base());
2013 CellTypeState temp[4];
2014 CellTypeState *eff = sigchar_to_effect(sigch, bci, temp);
2015
2016 CellTypeState in[4];
2017 int i = copy_cts(in, eff);
2018 in[i++] = CellTypeState::ref;
2019 in[i] = CellTypeState::bottom;
2020 assert(i <= 3, "sanity check");
2021
2022 CellTypeState out[2];
2023 out[0] = CellTypeState::ref;
2024 out[1] = CellTypeState::bottom;
2025
2026 pp(in, out);
2027 }
2028
2029 // This is used to parse the signature for fields, since they are very simple...
2030 CellTypeState *GenerateOopMap::sigchar_to_effect(char sigch, int bci, CellTypeState *out) {
2031 // Object and array
2032 if (sigch=='L' || sigch=='[') {
2033 out[0] = CellTypeState::make_line_ref(bci);
2034 out[1] = CellTypeState::bottom;
2035 return out;
2036 }
2037 if (sigch == 'J' || sigch == 'D' ) return vvCTS; // Long and Double
2038 if (sigch == 'V' ) return epsilonCTS; // Void
2039 return vCTS; // Otherwise
2040 }
2041
2042 long GenerateOopMap::_total_byte_count = 0;
2043 elapsedTimer GenerateOopMap::_total_oopmap_time;
2044
2045 // This function assumes "bcs" is at a "ret" instruction and that the vars
2046 // state is valid for that instruction. Furthermore, the ret instruction
2047 // must be the last instruction in "bb" (we store information about the
2048 // "ret" in "bb").
2049 void GenerateOopMap::ret_jump_targets_do(BytecodeStream *bcs, jmpFct_t jmpFct, int varNo, int *data) {
2050 CellTypeState ra = vars()[varNo];
2051 if (!ra.is_good_address()) {
2052 verify_error("ret returns from two jsr subroutines?");
2053 return;
2054 }
2055 int target = ra.get_info();
2056
|