Mercurial > hg > truffle
comparison src/share/vm/opto/output.cpp @ 2008:2f644f85485d
6961690: load oops from constant table on SPARC
Summary: oops should be loaded from the constant table of an nmethod instead of materializing them with a long code sequence.
Reviewed-by: never, kvn
author | twisti |
---|---|
date | Fri, 03 Dec 2010 01:34:31 -0800 |
parents | f95d63e2154a |
children | 51bd2d261853 |
comparison
equal
deleted
inserted
replaced
2007:5ddfcf4b079e | 2008:2f644f85485d |
---|---|
58 //------------------------------Output----------------------------------------- | 58 //------------------------------Output----------------------------------------- |
59 // Convert Nodes to instruction bits and pass off to the VM | 59 // Convert Nodes to instruction bits and pass off to the VM |
60 void Compile::Output() { | 60 void Compile::Output() { |
61 // RootNode goes | 61 // RootNode goes |
62 assert( _cfg->_broot->_nodes.size() == 0, "" ); | 62 assert( _cfg->_broot->_nodes.size() == 0, "" ); |
63 | |
64 // Initialize the space for the BufferBlob used to find and verify | |
65 // instruction size in MachNode::emit_size() | |
66 init_scratch_buffer_blob(); | |
67 if (failing()) return; // Out of memory | |
68 | 63 |
69 // The number of new nodes (mostly MachNop) is proportional to | 64 // The number of new nodes (mostly MachNop) is proportional to |
70 // the number of java calls and inner loops which are aligned. | 65 // the number of java calls and inner loops which are aligned. |
71 if ( C->check_node_count((NodeLimitFudgeFactor + C->java_calls()*3 + | 66 if ( C->check_node_count((NodeLimitFudgeFactor + C->java_calls()*3 + |
72 C->inner_loops()*(OptoLoopAlignment-1)), | 67 C->inner_loops()*(OptoLoopAlignment-1)), |
331 } | 326 } |
332 | 327 |
333 //----------------------Shorten_branches--------------------------------------- | 328 //----------------------Shorten_branches--------------------------------------- |
334 // The architecture description provides short branch variants for some long | 329 // The architecture description provides short branch variants for some long |
335 // branch instructions. Replace eligible long branches with short branches. | 330 // branch instructions. Replace eligible long branches with short branches. |
336 void Compile::Shorten_branches(Label *labels, int& code_size, int& reloc_size, int& stub_size, int& const_size) { | 331 void Compile::Shorten_branches(Label *labels, int& code_size, int& reloc_size, int& stub_size) { |
337 | 332 |
338 // fill in the nop array for bundling computations | 333 // fill in the nop array for bundling computations |
339 MachNode *_nop_list[Bundle::_nop_count]; | 334 MachNode *_nop_list[Bundle::_nop_count]; |
340 Bundle::initialize_nops(_nop_list, this); | 335 Bundle::initialize_nops(_nop_list, this); |
341 | 336 |
351 code_size = 0; // Size in bytes of generated code | 346 code_size = 0; // Size in bytes of generated code |
352 stub_size = 0; // Size in bytes of all stub entries | 347 stub_size = 0; // Size in bytes of all stub entries |
353 // Size in bytes of all relocation entries, including those in local stubs. | 348 // Size in bytes of all relocation entries, including those in local stubs. |
354 // Start with 2-bytes of reloc info for the unvalidated entry point | 349 // Start with 2-bytes of reloc info for the unvalidated entry point |
355 reloc_size = 1; // Number of relocation entries | 350 reloc_size = 1; // Number of relocation entries |
356 const_size = 0; // size of fp constants in words | |
357 | 351 |
358 // Make three passes. The first computes pessimistic blk_starts, | 352 // Make three passes. The first computes pessimistic blk_starts, |
359 // relative jmp_end, reloc_size and const_size information. | 353 // relative jmp_end and reloc_size information. The second performs |
360 // The second performs short branch substitution using the pessimistic | 354 // short branch substitution using the pessimistic sizing. The |
361 // sizing. The third inserts nops where needed. | 355 // third inserts nops where needed. |
362 | 356 |
363 Node *nj; // tmp | 357 Node *nj; // tmp |
364 | 358 |
365 // Step one, perform a pessimistic sizing pass. | 359 // Step one, perform a pessimistic sizing pass. |
366 uint i; | 360 uint i; |
379 // Handle machine instruction nodes | 373 // Handle machine instruction nodes |
380 if( nj->is_Mach() ) { | 374 if( nj->is_Mach() ) { |
381 MachNode *mach = nj->as_Mach(); | 375 MachNode *mach = nj->as_Mach(); |
382 blk_size += (mach->alignment_required() - 1) * relocInfo::addr_unit(); // assume worst case padding | 376 blk_size += (mach->alignment_required() - 1) * relocInfo::addr_unit(); // assume worst case padding |
383 reloc_size += mach->reloc(); | 377 reloc_size += mach->reloc(); |
384 const_size += mach->const_size(); | |
385 if( mach->is_MachCall() ) { | 378 if( mach->is_MachCall() ) { |
386 MachCallNode *mcall = mach->as_MachCall(); | 379 MachCallNode *mcall = mach->as_MachCall(); |
387 // This destination address is NOT PC-relative | 380 // This destination address is NOT PC-relative |
388 | 381 |
389 mcall->method_set((intptr_t)mcall->entry_point()); | 382 mcall->method_set((intptr_t)mcall->entry_point()); |
396 // If call/safepoint are adjacent, account for possible | 389 // If call/safepoint are adjacent, account for possible |
397 // nop to disambiguate the two safepoints. | 390 // nop to disambiguate the two safepoints. |
398 if (min_offset_from_last_call == 0) { | 391 if (min_offset_from_last_call == 0) { |
399 blk_size += nop_size; | 392 blk_size += nop_size; |
400 } | 393 } |
401 } else if (mach->ideal_Opcode() == Op_Jump) { | |
402 const_size += b->_num_succs; // Address table size | |
403 // The size is valid even for 64 bit since it is | |
404 // multiplied by 2*jintSize on this method exit. | |
405 } | 394 } |
406 } | 395 } |
407 min_offset_from_last_call += inst_size; | 396 min_offset_from_last_call += inst_size; |
408 // Remember end of call offset | 397 // Remember end of call offset |
409 if (nj->is_MachCall() && nj->as_MachCall()->is_safepoint_node()) { | 398 if (nj->is_MachCall() && nj->as_MachCall()->is_safepoint_node()) { |
560 // Adjust reloc_size to number of record of relocation info | 549 // Adjust reloc_size to number of record of relocation info |
561 // Min is 2 bytes, max is probably 6 or 8, with a tax up to 25% for | 550 // Min is 2 bytes, max is probably 6 or 8, with a tax up to 25% for |
562 // a relocation index. | 551 // a relocation index. |
563 // The CodeBuffer will expand the locs array if this estimate is too low. | 552 // The CodeBuffer will expand the locs array if this estimate is too low. |
564 reloc_size *= 10 / sizeof(relocInfo); | 553 reloc_size *= 10 / sizeof(relocInfo); |
565 | |
566 // Adjust const_size to number of bytes | |
567 const_size *= 2*jintSize; // both float and double take two words per entry | |
568 | |
569 } | 554 } |
570 | 555 |
571 //------------------------------FillLocArray----------------------------------- | 556 //------------------------------FillLocArray----------------------------------- |
572 // Create a bit of debug info and append it to the array. The mapping is from | 557 // Create a bit of debug info and append it to the array. The mapping is from |
573 // Java local or expression stack to constant, register or stack-slot. For | 558 // Java local or expression stack to constant, register or stack-slot. For |
1100 | 1085 |
1101 for( i=0; i <= _cfg->_num_blocks; i++ ) { | 1086 for( i=0; i <= _cfg->_num_blocks; i++ ) { |
1102 blk_labels[i].init(); | 1087 blk_labels[i].init(); |
1103 } | 1088 } |
1104 | 1089 |
1090 if (has_mach_constant_base_node()) { | |
1091 // Fill the constant table. | |
1092 // Note: This must happen before Shorten_branches. | |
1093 for (i = 0; i < _cfg->_num_blocks; i++) { | |
1094 Block* b = _cfg->_blocks[i]; | |
1095 | |
1096 for (uint j = 0; j < b->_nodes.size(); j++) { | |
1097 Node* n = b->_nodes[j]; | |
1098 | |
1099 // If the node is a MachConstantNode evaluate the constant | |
1100 // value section. | |
1101 if (n->is_MachConstant()) { | |
1102 MachConstantNode* machcon = n->as_MachConstant(); | |
1103 machcon->eval_constant(C); | |
1104 } | |
1105 } | |
1106 } | |
1107 | |
1108 // Calculate the offsets of the constants and the size of the | |
1109 // constant table (including the padding to the next section). | |
1110 constant_table().calculate_offsets_and_size(); | |
1111 const_req = constant_table().size(); | |
1112 } | |
1113 | |
1114 // Initialize the space for the BufferBlob used to find and verify | |
1115 // instruction size in MachNode::emit_size() | |
1116 init_scratch_buffer_blob(const_req); | |
1117 if (failing()) return; // Out of memory | |
1118 | |
1105 // If this machine supports different size branch offsets, then pre-compute | 1119 // If this machine supports different size branch offsets, then pre-compute |
1106 // the length of the blocks | 1120 // the length of the blocks |
1107 if( _matcher->is_short_branch_offset(-1, 0) ) { | 1121 if( _matcher->is_short_branch_offset(-1, 0) ) { |
1108 Shorten_branches(blk_labels, code_req, locs_req, stub_req, const_req); | 1122 Shorten_branches(blk_labels, code_req, locs_req, stub_req); |
1109 labels_not_set = false; | 1123 labels_not_set = false; |
1110 } | 1124 } |
1111 | 1125 |
1112 // nmethod and CodeBuffer count stubs & constants as part of method's code. | 1126 // nmethod and CodeBuffer count stubs & constants as part of method's code. |
1113 int exception_handler_req = size_exception_handler(); | 1127 int exception_handler_req = size_exception_handler(); |
1119 | 1133 |
1120 if (StressCodeBuffers) | 1134 if (StressCodeBuffers) |
1121 code_req = const_req = stub_req = exception_handler_req = deopt_handler_req = 0x10; // force expansion | 1135 code_req = const_req = stub_req = exception_handler_req = deopt_handler_req = 0x10; // force expansion |
1122 | 1136 |
1123 int total_req = | 1137 int total_req = |
1138 const_req + | |
1124 code_req + | 1139 code_req + |
1125 pad_req + | 1140 pad_req + |
1126 stub_req + | 1141 stub_req + |
1127 exception_handler_req + | 1142 exception_handler_req + |
1128 deopt_handler_req + // deopt handler | 1143 deopt_handler_req; // deopt handler |
1129 const_req; | |
1130 | 1144 |
1131 if (has_method_handle_invokes()) | 1145 if (has_method_handle_invokes()) |
1132 total_req += deopt_handler_req; // deopt MH handler | 1146 total_req += deopt_handler_req; // deopt MH handler |
1133 | 1147 |
1134 CodeBuffer* cb = code_buffer(); | 1148 CodeBuffer* cb = code_buffer(); |
1177 if ( print_assembly() ) | 1191 if ( print_assembly() ) |
1178 node_offsets = NEW_RESOURCE_ARRAY(int, node_offset_limit); | 1192 node_offsets = NEW_RESOURCE_ARRAY(int, node_offset_limit); |
1179 #endif | 1193 #endif |
1180 | 1194 |
1181 NonSafepointEmitter non_safepoints(this); // emit non-safepoints lazily | 1195 NonSafepointEmitter non_safepoints(this); // emit non-safepoints lazily |
1196 | |
1197 // Emit the constant table. | |
1198 if (has_mach_constant_base_node()) { | |
1199 constant_table().emit(*cb); | |
1200 } | |
1182 | 1201 |
1183 // ------------------ | 1202 // ------------------ |
1184 // Now fill in the code buffer | 1203 // Now fill in the code buffer |
1185 Node *delay_slot = NULL; | 1204 Node *delay_slot = NULL; |
1186 | 1205 |
1194 // start of a new bundle. | 1213 // start of a new bundle. |
1195 if( Pipeline::requires_bundling() && starts_bundle(head) ) | 1214 if( Pipeline::requires_bundling() && starts_bundle(head) ) |
1196 cb->flush_bundle(true); | 1215 cb->flush_bundle(true); |
1197 | 1216 |
1198 // Define the label at the beginning of the basic block | 1217 // Define the label at the beginning of the basic block |
1199 if( labels_not_set ) | 1218 if (labels_not_set) { |
1200 MacroAssembler(cb).bind( blk_labels[b->_pre_order] ); | 1219 MacroAssembler(cb).bind(blk_labels[b->_pre_order]); |
1201 | 1220 } else { |
1202 else | 1221 assert(blk_labels[b->_pre_order].loc_pos() == cb->insts_size(), |
1203 assert( blk_labels[b->_pre_order].loc_pos() == cb->insts_size(), | 1222 err_msg("label position does not match code offset: %d != %d", |
1204 "label position does not match code offset" ); | 1223 blk_labels[b->_pre_order].loc_pos(), cb->insts_size())); |
1224 } | |
1205 | 1225 |
1206 uint last_inst = b->_nodes.size(); | 1226 uint last_inst = b->_nodes.size(); |
1207 | 1227 |
1208 // Emit block normally, except for last instruction. | 1228 // Emit block normally, except for last instruction. |
1209 // Emit means "dump code bits into code buffer". | 1229 // Emit means "dump code bits into code buffer". |
1716 NOT_PRODUCT( TracePhase t2("isched", &_t_instrSched, TimeCompiler); ) | 1736 NOT_PRODUCT( TracePhase t2("isched", &_t_instrSched, TimeCompiler); ) |
1717 | 1737 |
1718 // Create a data structure for all the scheduling information | 1738 // Create a data structure for all the scheduling information |
1719 Scheduling scheduling(Thread::current()->resource_area(), *this); | 1739 Scheduling scheduling(Thread::current()->resource_area(), *this); |
1720 | 1740 |
1741 // Initialize the space for the BufferBlob used to find and verify | |
1742 // instruction size in MachNode::emit_size() | |
1743 init_scratch_buffer_blob(MAX_const_size); | |
1744 if (failing()) return; // Out of memory | |
1745 | |
1721 // Walk backwards over each basic block, computing the needed alignment | 1746 // Walk backwards over each basic block, computing the needed alignment |
1722 // Walk over all the basic blocks | 1747 // Walk over all the basic blocks |
1723 scheduling.DoScheduling(); | 1748 scheduling.DoScheduling(); |
1749 | |
1750 // Clear the BufferBlob used for scheduling. | |
1751 clear_scratch_buffer_blob(); | |
1724 } | 1752 } |
1725 | 1753 |
1726 //------------------------------ComputeLocalLatenciesForward------------------- | 1754 //------------------------------ComputeLocalLatenciesForward------------------- |
1727 // Compute the latency of all the instructions. This is fairly simple, | 1755 // Compute the latency of all the instructions. This is fairly simple, |
1728 // because we already have a legal ordering. Walk over the instructions | 1756 // because we already have a legal ordering. Walk over the instructions |