Mercurial > hg > graal-compiler
comparison src/cpu/ppc/vm/ppc.ad @ 17809:a433eb716ce1
8037821: Account for trampoline stubs when estimating code buffer sizes
Summary: Take into account space needed for "trampoline code" used by calls on PPC64.
Reviewed-by: kvn
Contributed-by: lutz.schmidt@sap.com
author | goetz |
---|---|
date | Tue, 25 Mar 2014 12:54:21 -0700 |
parents | 71a71b0bc844 |
children | 3a55cf1e3c9f |
comparison
equal
deleted
inserted
replaced
17808:d623bc507723 | 17809:a433eb716ce1 |
---|---|
889 | 889 |
890 //----------SOURCE BLOCK------------------------------------------------------- | 890 //----------SOURCE BLOCK------------------------------------------------------- |
891 // This is a block of C++ code which provides values, functions, and | 891 // This is a block of C++ code which provides values, functions, and |
892 // definitions necessary in the rest of the architecture description. | 892 // definitions necessary in the rest of the architecture description. |
893 source_hpp %{ | 893 source_hpp %{ |
894 // Header information of the source block. | |
895 // Method declarations/definitions which are used outside | |
896 // the ad-scope can conveniently be defined here. | |
897 // | |
898 // To keep related declarations/definitions/uses close together, | |
899 // we switch between source %{ }% and source_hpp %{ }% freely as needed. | |
900 | |
894 // Returns true if Node n is followed by a MemBar node that | 901 // Returns true if Node n is followed by a MemBar node that |
895 // will do an acquire. If so, this node must not do the acquire | 902 // will do an acquire. If so, this node must not do the acquire |
896 // operation. | 903 // operation. |
897 bool followed_by_acquire(const Node *n); | 904 bool followed_by_acquire(const Node *n); |
898 %} | 905 %} |
1112 cbuf.set_insts_end(cbuf.insts_end() + BytesPerInstWord); | 1119 cbuf.set_insts_end(cbuf.insts_end() + BytesPerInstWord); |
1113 } | 1120 } |
1114 | 1121 |
1115 //============================================================================= | 1122 //============================================================================= |
1116 | 1123 |
1124 %} // interrupt source | |
1125 | |
1126 source_hpp %{ // Header information of the source block. | |
1127 | |
1128 //-------------------------------------------------------------- | |
1129 //---< Used for optimization in Compile::Shorten_branches >--- | |
1130 //-------------------------------------------------------------- | |
1131 | |
1132 const uint trampoline_stub_size = 6 * BytesPerInstWord; | |
1133 | |
1134 class CallStubImpl { | |
1135 | |
1136 public: | |
1137 | |
1138 static void emit_trampoline_stub(MacroAssembler &_masm, int destination_toc_offset, int insts_call_instruction_offset); | |
1139 | |
1140 // Size of call trampoline stub. | |
1141 // This doesn't need to be accurate to the byte, but it | |
1142 // must be larger than or equal to the real size of the stub. | |
1143 static uint size_call_trampoline() { | |
1144 return trampoline_stub_size; | |
1145 } | |
1146 | |
1147 // number of relocations needed by a call trampoline stub | |
1148 static uint reloc_call_trampoline() { | |
1149 return 5; | |
1150 } | |
1151 | |
1152 }; | |
1153 | |
1154 %} // end source_hpp | |
1155 | |
1156 source %{ | |
1157 | |
1117 // Emit a trampoline stub for a call to a target which is too far away. | 1158 // Emit a trampoline stub for a call to a target which is too far away. |
1118 // | 1159 // |
1119 // code sequences: | 1160 // code sequences: |
1120 // | 1161 // |
1121 // call-site: | 1162 // call-site: |
1123 // | 1164 // |
1124 // Related trampoline stub for this call-site in the stub section: | 1165 // Related trampoline stub for this call-site in the stub section: |
1125 // load the call target from the constant pool | 1166 // load the call target from the constant pool |
1126 // branch via CTR (LR/link still points to the call-site above) | 1167 // branch via CTR (LR/link still points to the call-site above) |
1127 | 1168 |
1128 const uint trampoline_stub_size = 6 * BytesPerInstWord; | 1169 void CallStubImpl::emit_trampoline_stub(MacroAssembler &_masm, int destination_toc_offset, int insts_call_instruction_offset) { |
1129 | |
1130 void emit_trampoline_stub(MacroAssembler &_masm, int destination_toc_offset, int insts_call_instruction_offset) { | |
1131 // Start the stub. | 1170 // Start the stub. |
1132 address stub = __ start_a_stub(Compile::MAX_stubs_size/2); | 1171 address stub = __ start_a_stub(Compile::MAX_stubs_size/2); |
1133 if (stub == NULL) { | 1172 if (stub == NULL) { |
1134 Compile::current()->env()->record_out_of_memory_failure(); | 1173 Compile::current()->env()->record_out_of_memory_failure(); |
1135 return; | 1174 return; |
1166 assert((uint)(__ offset() - stub_start_offset) <= trampoline_stub_size, "should be good size"); | 1205 assert((uint)(__ offset() - stub_start_offset) <= trampoline_stub_size, "should be good size"); |
1167 assert(is_NativeCallTrampolineStub_at(stub_start_addr), "doesn't look like a trampoline"); | 1206 assert(is_NativeCallTrampolineStub_at(stub_start_addr), "doesn't look like a trampoline"); |
1168 | 1207 |
1169 // End the stub. | 1208 // End the stub. |
1170 __ end_a_stub(); | 1209 __ end_a_stub(); |
1171 } | |
1172 | |
1173 // Size of trampoline stub, this doesn't need to be accurate but it must | |
1174 // be larger or equal to the real size of the stub. | |
1175 // Used for optimization in Compile::Shorten_branches. | |
1176 uint size_call_trampoline() { | |
1177 return trampoline_stub_size; | |
1178 } | |
1179 | |
1180 // Number of relocation entries needed by trampoline stub. | |
1181 // Used for optimization in Compile::Shorten_branches. | |
1182 uint reloc_call_trampoline() { | |
1183 return 5; | |
1184 } | 1210 } |
1185 | 1211 |
1186 //============================================================================= | 1212 //============================================================================= |
1187 | 1213 |
1188 // Emit an inline branch-and-link call and a related trampoline stub. | 1214 // Emit an inline branch-and-link call and a related trampoline stub. |
1219 // Put the entry point as a constant into the constant pool. | 1245 // Put the entry point as a constant into the constant pool. |
1220 const address entry_point_toc_addr = __ address_constant(entry_point, RelocationHolder::none); | 1246 const address entry_point_toc_addr = __ address_constant(entry_point, RelocationHolder::none); |
1221 const int entry_point_toc_offset = __ offset_to_method_toc(entry_point_toc_addr); | 1247 const int entry_point_toc_offset = __ offset_to_method_toc(entry_point_toc_addr); |
1222 | 1248 |
1223 // Emit the trampoline stub which will be related to the branch-and-link below. | 1249 // Emit the trampoline stub which will be related to the branch-and-link below. |
1224 emit_trampoline_stub(_masm, entry_point_toc_offset, offsets.insts_call_instruction_offset); | 1250 CallStubImpl::emit_trampoline_stub(_masm, entry_point_toc_offset, offsets.insts_call_instruction_offset); |
1225 __ relocate(rtype); | 1251 __ relocate(rtype); |
1226 } | 1252 } |
1227 | 1253 |
1228 // Note: At this point we do not have the address of the trampoline | 1254 // Note: At this point we do not have the address of the trampoline |
1229 // stub, and the entry point might be too far away for bl, so __ pc() | 1255 // stub, and the entry point might be too far away for bl, so __ pc() |
2021 return MachNode::size(ra_); | 2047 return MachNode::size(ra_); |
2022 } | 2048 } |
2023 | 2049 |
2024 //============================================================================= | 2050 //============================================================================= |
2025 | 2051 |
2026 uint size_exception_handler() { | 2052 %} // interrupt source |
2027 // The exception_handler is a b64_patchable. | 2053 |
2028 return MacroAssembler::b64_patchable_size; | 2054 source_hpp %{ // Header information of the source block. |
2029 } | 2055 |
2030 | 2056 class HandlerImpl { |
2031 uint size_deopt_handler() { | 2057 |
2032 // The deopt_handler is a bl64_patchable. | 2058 public: |
2033 return MacroAssembler::bl64_patchable_size; | 2059 |
2034 } | 2060 static int emit_exception_handler(CodeBuffer &cbuf); |
2035 | 2061 static int emit_deopt_handler(CodeBuffer& cbuf); |
2036 int emit_exception_handler(CodeBuffer &cbuf) { | 2062 |
2063 static uint size_exception_handler() { | |
2064 // The exception_handler is a b64_patchable. | |
2065 return MacroAssembler::b64_patchable_size; | |
2066 } | |
2067 | |
2068 static uint size_deopt_handler() { | |
2069 // The deopt_handler is a bl64_patchable. | |
2070 return MacroAssembler::bl64_patchable_size; | |
2071 } | |
2072 | |
2073 }; | |
2074 | |
2075 %} // end source_hpp | |
2076 | |
2077 source %{ | |
2078 | |
2079 int HandlerImpl::emit_exception_handler(CodeBuffer &cbuf) { | |
2037 MacroAssembler _masm(&cbuf); | 2080 MacroAssembler _masm(&cbuf); |
2038 | 2081 |
2039 address base = __ start_a_stub(size_exception_handler()); | 2082 address base = __ start_a_stub(size_exception_handler()); |
2040 if (base == NULL) return 0; // CodeBuffer::expand failed | 2083 if (base == NULL) return 0; // CodeBuffer::expand failed |
2041 | 2084 |
2048 return offset; | 2091 return offset; |
2049 } | 2092 } |
2050 | 2093 |
2051 // The deopt_handler is like the exception handler, but it calls to | 2094 // The deopt_handler is like the exception handler, but it calls to |
2052 // the deoptimization blob instead of jumping to the exception blob. | 2095 // the deoptimization blob instead of jumping to the exception blob. |
2053 int emit_deopt_handler(CodeBuffer& cbuf) { | 2096 int HandlerImpl::emit_deopt_handler(CodeBuffer& cbuf) { |
2054 MacroAssembler _masm(&cbuf); | 2097 MacroAssembler _masm(&cbuf); |
2055 | 2098 |
2056 address base = __ start_a_stub(size_deopt_handler()); | 2099 address base = __ start_a_stub(size_deopt_handler()); |
2057 if (base == NULL) return 0; // CodeBuffer::expand failed | 2100 if (base == NULL) return 0; // CodeBuffer::expand failed |
2058 | 2101 |
3448 // Put the entry point as a constant into the constant pool. | 3491 // Put the entry point as a constant into the constant pool. |
3449 const address entry_point_toc_addr = __ address_constant(entry_point, RelocationHolder::none); | 3492 const address entry_point_toc_addr = __ address_constant(entry_point, RelocationHolder::none); |
3450 const int entry_point_toc_offset = __ offset_to_method_toc(entry_point_toc_addr); | 3493 const int entry_point_toc_offset = __ offset_to_method_toc(entry_point_toc_addr); |
3451 | 3494 |
3452 // Emit the trampoline stub which will be related to the branch-and-link below. | 3495 // Emit the trampoline stub which will be related to the branch-and-link below. |
3453 emit_trampoline_stub(_masm, entry_point_toc_offset, start_offset); | 3496 CallStubImpl::emit_trampoline_stub(_masm, entry_point_toc_offset, start_offset); |
3454 __ relocate(_optimized_virtual ? | 3497 __ relocate(_optimized_virtual ? |
3455 relocInfo::opt_virtual_call_type : relocInfo::static_call_type); | 3498 relocInfo::opt_virtual_call_type : relocInfo::static_call_type); |
3456 } | 3499 } |
3457 | 3500 |
3458 // The real call. | 3501 // The real call. |
3491 // Put the entry point as a constant into the constant pool. | 3534 // Put the entry point as a constant into the constant pool. |
3492 const address entry_point_toc_addr = __ address_constant(entry_point, RelocationHolder::none); | 3535 const address entry_point_toc_addr = __ address_constant(entry_point, RelocationHolder::none); |
3493 const int entry_point_toc_offset = __ offset_to_method_toc(entry_point_toc_addr); | 3536 const int entry_point_toc_offset = __ offset_to_method_toc(entry_point_toc_addr); |
3494 | 3537 |
3495 // Emit the trampoline stub which will be related to the branch-and-link below. | 3538 // Emit the trampoline stub which will be related to the branch-and-link below. |
3496 emit_trampoline_stub(_masm, entry_point_toc_offset, start_offset); | 3539 CallStubImpl::emit_trampoline_stub(_masm, entry_point_toc_offset, start_offset); |
3497 assert(_optimized_virtual, "methodHandle call should be a virtual call"); | 3540 assert(_optimized_virtual, "methodHandle call should be a virtual call"); |
3498 __ relocate(relocInfo::opt_virtual_call_type); | 3541 __ relocate(relocInfo::opt_virtual_call_type); |
3499 } | 3542 } |
3500 | 3543 |
3501 // The real call. | 3544 // The real call. |
3541 if (!ra_->C->in_scratch_emit_size()) { | 3584 if (!ra_->C->in_scratch_emit_size()) { |
3542 // Create a call trampoline stub for the given method. | 3585 // Create a call trampoline stub for the given method. |
3543 const address entry_point = !($meth$$method) ? 0 : (address)$meth$$method; | 3586 const address entry_point = !($meth$$method) ? 0 : (address)$meth$$method; |
3544 const address entry_point_const = __ address_constant(entry_point, RelocationHolder::none); | 3587 const address entry_point_const = __ address_constant(entry_point, RelocationHolder::none); |
3545 const int entry_point_const_toc_offset = __ offset_to_method_toc(entry_point_const); | 3588 const int entry_point_const_toc_offset = __ offset_to_method_toc(entry_point_const); |
3546 emit_trampoline_stub(_masm, entry_point_const_toc_offset, __ offset()); | 3589 CallStubImpl::emit_trampoline_stub(_masm, entry_point_const_toc_offset, __ offset()); |
3547 | 3590 |
3548 if (ra_->C->env()->failing()) | 3591 if (ra_->C->env()->failing()) |
3549 return; | 3592 return; |
3550 | 3593 |
3551 // Build relocation at call site with ic position as data. | 3594 // Build relocation at call site with ic position as data. |