src/share/vm/opto/output.cpp

Print this page




 432       }
 433       blk_size += nj->size(_regalloc);
 434       // Remember end of call offset
 435       if (nj->is_MachCall() && !nj->is_MachCallLeaf()) {
 436         last_call_adr = blk_starts[i]+blk_size;
 437       }
 438       // Remember end of avoid_back_to_back offset
 439       if (nj->is_Mach() && nj->as_Mach()->avoid_back_to_back()) {
 440         last_avoid_back_to_back_adr = blk_starts[i]+blk_size;
 441       }
 442     }
 443 
 444     // When the next block starts a loop, we may insert pad NOP
 445     // instructions.  Since we cannot know our future alignment,
 446     // assume the worst.
 447     if (i< nblocks-1) {
 448       Block *nb = _cfg->_blocks[i+1];
 449       int max_loop_pad = nb->code_alignment()-relocInfo::addr_unit();
 450       if (max_loop_pad > 0) {
 451         assert(is_power_of_2(max_loop_pad+relocInfo::addr_unit()), "");











 452         blk_size += max_loop_pad;
 453       }
 454     }
 455 
 456     // Save block size; update total method size
 457     blk_starts[i+1] = blk_starts[i]+blk_size;
 458   }
 459 
 460   // Step two, replace eligible long jumps.
 461   bool progress = true;
 462   uint last_may_be_short_branch_adr = max_uint;
 463   while (has_short_branch_candidate && progress) {
 464     progress = false;
 465     has_short_branch_candidate = false;
 466     int adjust_block_start = 0;
 467     for (uint i = 0; i < nblocks; i++) {
 468       Block *b = _cfg->_blocks[i];
 469       int idx = jmp_nidx[i];
 470       MachNode* mach = (idx == -1) ? NULL: b->_nodes[idx]->as_Mach();
 471       if (mach != NULL && mach->may_be_short_branch()) {


1176 
1177   // !!!!! This preserves old handling of oopmaps for now
1178   debug_info()->set_oopmaps(_oop_map_set);
1179 
1180   uint nblocks  = _cfg->_num_blocks;
1181   // Count and start of implicit null check instructions
1182   uint inct_cnt = 0;
1183   uint *inct_starts = NEW_RESOURCE_ARRAY(uint, nblocks+1);
1184 
1185   // Count and start of calls
1186   uint *call_returns = NEW_RESOURCE_ARRAY(uint, nblocks+1);
1187 
1188   uint  return_offset = 0;
1189   int nop_size = (new (this) MachNopNode())->size(_regalloc);
1190 
1191   int previous_offset = 0;
1192   int current_offset  = 0;
1193   int last_call_offset = -1;
1194   int last_avoid_back_to_back_offset = -1;
1195 #ifdef ASSERT
1196   int block_alignment_padding = 0;
1197 
1198   uint* jmp_target = NEW_RESOURCE_ARRAY(uint,nblocks);
1199   uint* jmp_offset = NEW_RESOURCE_ARRAY(uint,nblocks);
1200   uint* jmp_size   = NEW_RESOURCE_ARRAY(uint,nblocks);
1201   uint* jmp_rule   = NEW_RESOURCE_ARRAY(uint,nblocks);
1202 #endif
1203 
1204   // Create an array of unused labels, one for each basic block, if printing is enabled
1205 #ifndef PRODUCT
1206   int *node_offsets      = NULL;
1207   uint node_offset_limit = unique();
1208 
1209   if (print_assembly())
1210     node_offsets         = NEW_RESOURCE_ARRAY(int, node_offset_limit);
1211 #endif
1212 
1213   NonSafepointEmitter non_safepoints(this);  // emit non-safepoints lazily
1214 
1215   // Emit the constant table.
1216   if (has_mach_constant_base_node()) {
1217     constant_table().emit(*cb);
1218   }
1219 
1220   // Create an array of labels, one for each basic block
1221   Label *blk_labels = NEW_RESOURCE_ARRAY(Label, nblocks+1);
1222   for (uint i=0; i <= nblocks; i++) {
1223     blk_labels[i].init();
1224   }
1225 
1226   // ------------------
1227   // Now fill in the code buffer
1228   Node *delay_slot = NULL;
1229 
1230   for (uint i=0; i < nblocks; i++) {
1231     guarantee(blk_starts[i] >= (uint)cb->insts_size(),"should not increase size");
1232 
1233     Block *b = _cfg->_blocks[i];
1234 
1235     Node *head = b->head();
1236 
1237     // If this block needs to start aligned (i.e, can be reached other
1238     // than by falling-thru from the previous block), then force the
1239     // start of a new bundle.
1240     if (Pipeline::requires_bundling() && starts_bundle(head))
1241       cb->flush_bundle(true);
1242 
1243 #ifdef ASSERT
1244     if (!b->is_connector()) {
1245       stringStream st;
1246       b->dump_head(&_cfg->_bbs, &st);
1247       MacroAssembler(cb).block_comment(st.as_string());
1248     }
1249     jmp_target[i] = 0;
1250     jmp_offset[i] = 0;
1251     jmp_size[i]   = 0;
1252     jmp_rule[i]   = 0;
1253 
1254     // Maximum alignment padding for loop block was used
1255     // during first round of branches shortening, as result
1256     // padding for nodes (sfpt after call) was not added.
1257     // Take this into account for block's size change check
1258     // and allow increase block's size by the difference
1259     // of maximum and actual alignment paddings.
1260     int orig_blk_size = blk_starts[i+1] - blk_starts[i] + block_alignment_padding;
1261 #endif
1262     int blk_offset = current_offset;
1263 
1264     // Define the label at the beginning of the basic block
1265     MacroAssembler(cb).bind(blk_labels[b->_pre_order]);
1266 
1267     uint last_inst = b->_nodes.size();
1268 
1269     // Emit block normally, except for last instruction.
1270     // Emit means "dump code bits into code buffer".
1271     for (uint j = 0; j<last_inst; j++) {
1272 
1273       // Get the node
1274       Node* n = b->_nodes[j];
1275 
1276       // See if delay slots are supported
1277       if (valid_bundle_info(n) &&
1278           node_bundling(n)->used_in_unconditional_delay()) {
1279         assert(delay_slot == NULL, "no use of delay slot node");
1280         assert(n->size(_regalloc) == Pipeline::instr_unit_size(), "delay slot instruction wrong size");


1540 #           endif
1541             delay_slot = NULL;
1542             continue;
1543           }
1544 
1545           int adjusted_offset = current_offset - Pipeline::instr_unit_size();
1546           non_safepoints.observe_safepoint(mach->as_MachSafePoint()->jvms(),
1547                                            adjusted_offset);
1548           // Generate an OopMap entry
1549           Process_OopMap_Node(mach, adjusted_offset);
1550         }
1551 
1552         // Insert the delay slot instruction
1553         delay_slot->emit(*cb, _regalloc);
1554 
1555         // Don't reuse it
1556         delay_slot = NULL;
1557       }
1558 
1559     } // End for all instructions in block
1560     assert((uint)blk_offset <= blk_starts[i], "shouldn't increase distance");
1561     blk_starts[i] = blk_offset;
1562 
1563     // If the next block is the top of a loop, pad this block out to align
1564     // the loop top a little. Helps prevent pipe stalls at loop back branches.
1565     if (i < nblocks-1) {
1566       Block *nb = _cfg->_blocks[i+1];
1567       int padding = nb->alignment_padding(current_offset);
1568       if( padding > 0 ) {
1569         MachNode *nop = new (this) MachNopNode(padding / nop_size);
1570         b->_nodes.insert( b->_nodes.size(), nop );
1571         _cfg->_bbs.map( nop->_idx, b );
1572         nop->emit(*cb, _regalloc);
1573         current_offset = cb->insts_size();
1574       }
1575 #ifdef ASSERT
1576       int max_loop_pad = nb->code_alignment()-relocInfo::addr_unit();
1577       block_alignment_padding = (max_loop_pad - padding);
1578       assert(block_alignment_padding >= 0, "sanity");
1579 #endif
1580     }
1581     // Verify that the distance for generated before forward
1582     // short branches is still valid.
1583     assert(orig_blk_size >= (current_offset - blk_offset), "shouldn't increase block size");
1584 


1585   } // End of for all blocks
1586   blk_starts[nblocks] = current_offset;
1587 
1588   non_safepoints.flush_at_end();
1589 
1590   // Offset too large?
1591   if (failing())  return;
1592 
1593   // Define a pseudo-label at the end of the code
1594   MacroAssembler(cb).bind( blk_labels[nblocks] );
1595 
1596   // Compute the size of the first block
1597   _first_block_size = blk_labels[1].loc_pos() - blk_labels[0].loc_pos();
1598 
1599   assert(cb->insts_size() < 500000, "method is unreasonably large");
1600 
1601 #ifdef ASSERT
1602   for (uint i = 0; i < nblocks; i++) { // For all blocks
1603     if (jmp_target[i] != 0) {
1604       int br_size = jmp_size[i];




 432       }
 433       blk_size += nj->size(_regalloc);
 434       // Remember end of call offset
 435       if (nj->is_MachCall() && !nj->is_MachCallLeaf()) {
 436         last_call_adr = blk_starts[i]+blk_size;
 437       }
 438       // Remember end of avoid_back_to_back offset
 439       if (nj->is_Mach() && nj->as_Mach()->avoid_back_to_back()) {
 440         last_avoid_back_to_back_adr = blk_starts[i]+blk_size;
 441       }
 442     }
 443 
 444     // When the next block starts a loop, we may insert pad NOP
 445     // instructions.  Since we cannot know our future alignment,
 446     // assume the worst.
 447     if (i< nblocks-1) {
 448       Block *nb = _cfg->_blocks[i+1];
 449       int max_loop_pad = nb->code_alignment()-relocInfo::addr_unit();
 450       if (max_loop_pad > 0) {
 451         assert(is_power_of_2(max_loop_pad+relocInfo::addr_unit()), "");
 452         // Adjust last_call_adr and/or last_avoid_back_to_back_adr.
 453         // If either is the last instruction in this block, bump by
 454         // max_loop_pad in lock-step with blk_size, so sizing
 455         // calculations in subsequent blocks still can conservatively
 456         // detect that it may the last instruction in this block.
 457         if (last_call_adr == blk_starts[i]+blk_size) {
 458           last_call_adr += max_loop_pad;
 459         }
 460         if (last_avoid_back_to_back_adr == blk_starts[i]+blk_size) {
 461           last_avoid_back_to_back_adr += max_loop_pad;
 462         }
 463         blk_size += max_loop_pad;
 464       }
 465     }
 466 
 467     // Save block size; update total method size
 468     blk_starts[i+1] = blk_starts[i]+blk_size;
 469   }
 470 
 471   // Step two, replace eligible long jumps.
 472   bool progress = true;
 473   uint last_may_be_short_branch_adr = max_uint;
 474   while (has_short_branch_candidate && progress) {
 475     progress = false;
 476     has_short_branch_candidate = false;
 477     int adjust_block_start = 0;
 478     for (uint i = 0; i < nblocks; i++) {
 479       Block *b = _cfg->_blocks[i];
 480       int idx = jmp_nidx[i];
 481       MachNode* mach = (idx == -1) ? NULL: b->_nodes[idx]->as_Mach();
 482       if (mach != NULL && mach->may_be_short_branch()) {


1187 
1188   // !!!!! This preserves old handling of oopmaps for now
1189   debug_info()->set_oopmaps(_oop_map_set);
1190 
1191   uint nblocks  = _cfg->_num_blocks;
1192   // Count and start of implicit null check instructions
1193   uint inct_cnt = 0;
1194   uint *inct_starts = NEW_RESOURCE_ARRAY(uint, nblocks+1);
1195 
1196   // Count and start of calls
1197   uint *call_returns = NEW_RESOURCE_ARRAY(uint, nblocks+1);
1198 
1199   uint  return_offset = 0;
1200   int nop_size = (new (this) MachNopNode())->size(_regalloc);
1201 
1202   int previous_offset = 0;
1203   int current_offset  = 0;
1204   int last_call_offset = -1;
1205   int last_avoid_back_to_back_offset = -1;
1206 #ifdef ASSERT


1207   uint* jmp_target = NEW_RESOURCE_ARRAY(uint,nblocks);
1208   uint* jmp_offset = NEW_RESOURCE_ARRAY(uint,nblocks);
1209   uint* jmp_size   = NEW_RESOURCE_ARRAY(uint,nblocks);
1210   uint* jmp_rule   = NEW_RESOURCE_ARRAY(uint,nblocks);
1211 #endif
1212 
1213   // Create an array of unused labels, one for each basic block, if printing is enabled
1214 #ifndef PRODUCT
1215   int *node_offsets      = NULL;
1216   uint node_offset_limit = unique();
1217 
1218   if (print_assembly())
1219     node_offsets         = NEW_RESOURCE_ARRAY(int, node_offset_limit);
1220 #endif
1221 
1222   NonSafepointEmitter non_safepoints(this);  // emit non-safepoints lazily
1223 
1224   // Emit the constant table.
1225   if (has_mach_constant_base_node()) {
1226     constant_table().emit(*cb);
1227   }
1228 
1229   // Create an array of labels, one for each basic block
1230   Label *blk_labels = NEW_RESOURCE_ARRAY(Label, nblocks+1);
1231   for (uint i=0; i <= nblocks; i++) {
1232     blk_labels[i].init();
1233   }
1234 
1235   // ------------------
1236   // Now fill in the code buffer
1237   Node *delay_slot = NULL;
1238 
1239   for (uint i=0; i < nblocks; i++) {


1240     Block *b = _cfg->_blocks[i];
1241 
1242     Node *head = b->head();
1243 
1244     // If this block needs to start aligned (i.e, can be reached other
1245     // than by falling-thru from the previous block), then force the
1246     // start of a new bundle.
1247     if (Pipeline::requires_bundling() && starts_bundle(head))
1248       cb->flush_bundle(true);
1249 
1250 #ifdef ASSERT
1251     if (!b->is_connector()) {
1252       stringStream st;
1253       b->dump_head(&_cfg->_bbs, &st);
1254       MacroAssembler(cb).block_comment(st.as_string());
1255     }
1256     jmp_target[i] = 0;
1257     jmp_offset[i] = 0;
1258     jmp_size[i]   = 0;
1259     jmp_rule[i]   = 0;








1260 #endif
1261     int blk_offset = current_offset;
1262 
1263     // Define the label at the beginning of the basic block
1264     MacroAssembler(cb).bind(blk_labels[b->_pre_order]);
1265 
1266     uint last_inst = b->_nodes.size();
1267 
1268     // Emit block normally, except for last instruction.
1269     // Emit means "dump code bits into code buffer".
1270     for (uint j = 0; j<last_inst; j++) {
1271 
1272       // Get the node
1273       Node* n = b->_nodes[j];
1274 
1275       // See if delay slots are supported
1276       if (valid_bundle_info(n) &&
1277           node_bundling(n)->used_in_unconditional_delay()) {
1278         assert(delay_slot == NULL, "no use of delay slot node");
1279         assert(n->size(_regalloc) == Pipeline::instr_unit_size(), "delay slot instruction wrong size");


1539 #           endif
1540             delay_slot = NULL;
1541             continue;
1542           }
1543 
1544           int adjusted_offset = current_offset - Pipeline::instr_unit_size();
1545           non_safepoints.observe_safepoint(mach->as_MachSafePoint()->jvms(),
1546                                            adjusted_offset);
1547           // Generate an OopMap entry
1548           Process_OopMap_Node(mach, adjusted_offset);
1549         }
1550 
1551         // Insert the delay slot instruction
1552         delay_slot->emit(*cb, _regalloc);
1553 
1554         // Don't reuse it
1555         delay_slot = NULL;
1556       }
1557 
1558     } // End for all instructions in block


1559 
1560     // If the next block is the top of a loop, pad this block out to align
1561     // the loop top a little. Helps prevent pipe stalls at loop back branches.
1562     if (i < nblocks-1) {
1563       Block *nb = _cfg->_blocks[i+1];
1564       int padding = nb->alignment_padding(current_offset);
1565       if( padding > 0 ) {
1566         MachNode *nop = new (this) MachNopNode(padding / nop_size);
1567         b->_nodes.insert( b->_nodes.size(), nop );
1568         _cfg->_bbs.map( nop->_idx, b );
1569         nop->emit(*cb, _regalloc);
1570         current_offset = cb->insts_size();
1571       }





1572     }
1573     // Verify that the distance for generated before forward
1574     // short branches is still valid.
1575     guarantee((int)(blk_starts[i+1] - blk_starts[i]) >= (current_offset - blk_offset), "shouldn't increase block size");
1576 
1577     // Save new block start offset
1578     blk_starts[i] = blk_offset;
1579   } // End of for all blocks
1580   blk_starts[nblocks] = current_offset;
1581 
1582   non_safepoints.flush_at_end();
1583 
1584   // Offset too large?
1585   if (failing())  return;
1586 
1587   // Define a pseudo-label at the end of the code
1588   MacroAssembler(cb).bind( blk_labels[nblocks] );
1589 
1590   // Compute the size of the first block
1591   _first_block_size = blk_labels[1].loc_pos() - blk_labels[0].loc_pos();
1592 
1593   assert(cb->insts_size() < 500000, "method is unreasonably large");
1594 
1595 #ifdef ASSERT
1596   for (uint i = 0; i < nblocks; i++) { // For all blocks
1597     if (jmp_target[i] != 0) {
1598       int br_size = jmp_size[i];