25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
26 #include "classfile/javaClasses.inline.hpp" |
26 #include "classfile/javaClasses.inline.hpp" |
27 #include "classfile/systemDictionary.hpp" |
27 #include "classfile/systemDictionary.hpp" |
28 #include "classfile/vmSymbols.hpp" |
28 #include "classfile/vmSymbols.hpp" |
29 #include "code/codeCache.hpp" |
29 #include "code/codeCache.hpp" |
|
30 #include "code/codeCacheExtensions.hpp" |
30 #include "compiler/compileBroker.hpp" |
31 #include "compiler/compileBroker.hpp" |
31 #include "compiler/disassembler.hpp" |
32 #include "compiler/disassembler.hpp" |
32 #include "gc/shared/collectedHeap.hpp" |
33 #include "gc/shared/collectedHeap.hpp" |
33 #include "interpreter/interpreter.hpp" |
34 #include "interpreter/interpreter.hpp" |
34 #include "interpreter/interpreterRuntime.hpp" |
35 #include "interpreter/interpreterRuntime.hpp" |
1176 memcpy(handler, buffer->insts_begin(), insts_size); |
1177 memcpy(handler, buffer->insts_begin(), insts_size); |
1177 pd_set_handler(handler); |
1178 pd_set_handler(handler); |
1178 ICache::invalidate_range(handler, insts_size); |
1179 ICache::invalidate_range(handler, insts_size); |
1179 _handler = handler + insts_size; |
1180 _handler = handler + insts_size; |
1180 } |
1181 } |
|
1182 CodeCacheExtensions::handle_generated_handler(handler, buffer->name(), _handler); |
1181 return handler; |
1183 return handler; |
1182 } |
1184 } |
1183 |
1185 |
1184 void SignatureHandlerLibrary::add(methodHandle method) { |
1186 void SignatureHandlerLibrary::add(methodHandle method) { |
1185 if (method->signature_handler() == NULL) { |
1187 if (method->signature_handler() == NULL) { |
1186 // use slow signature handler if we can't do better |
1188 // use slow signature handler if we can't do better |
1187 int handler_index = -1; |
1189 int handler_index = -1; |
1188 // check if we can use customized (fast) signature handler |
1190 // check if we can use customized (fast) signature handler |
1189 if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) { |
1191 if (UseFastSignatureHandlers && CodeCacheExtensions::support_fast_signature_handlers() && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) { |
1190 // use customized signature handler |
1192 // use customized signature handler |
1191 MutexLocker mu(SignatureHandlerLibrary_lock); |
1193 MutexLocker mu(SignatureHandlerLibrary_lock); |
1192 // make sure data structure is initialized |
1194 // make sure data structure is initialized |
1193 initialize(); |
1195 initialize(); |
1194 // lookup method signature's fingerprint |
1196 // lookup method signature's fingerprint |
1201 ResourceMark rm; |
1203 ResourceMark rm; |
1202 ptrdiff_t align_offset = (address) |
1204 ptrdiff_t align_offset = (address) |
1203 round_to((intptr_t)_buffer, CodeEntryAlignment) - (address)_buffer; |
1205 round_to((intptr_t)_buffer, CodeEntryAlignment) - (address)_buffer; |
1204 CodeBuffer buffer((address)(_buffer + align_offset), |
1206 CodeBuffer buffer((address)(_buffer + align_offset), |
1205 SignatureHandlerLibrary::buffer_size - align_offset); |
1207 SignatureHandlerLibrary::buffer_size - align_offset); |
|
1208 if (!CodeCacheExtensions::support_dynamic_code()) { |
|
1209 // we need a name for the signature (for lookups or saving) |
|
1210 const int SYMBOL_SIZE = 50; |
|
1211 char *symbolName = NEW_RESOURCE_ARRAY(char, SYMBOL_SIZE); |
|
1212 // support for named signatures |
|
1213 jio_snprintf(symbolName, SYMBOL_SIZE, |
|
1214 "native_" UINT64_FORMAT, fingerprint); |
|
1215 buffer.set_name(symbolName); |
|
1216 } |
1206 InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint); |
1217 InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint); |
1207 // copy into code heap |
1218 // copy into code heap |
1208 address handler = set_handler(&buffer); |
1219 address handler = set_handler(&buffer); |
1209 if (handler == NULL) { |
1220 if (handler == NULL) { |
1210 // use slow signature handler |
1221 // use slow signature handler (without memorizing it in the fingerprints) |
1211 } else { |
1222 } else { |
1212 // debugging suppport |
1223 // debugging suppport |
1213 if (PrintSignatureHandlers) { |
1224 if (PrintSignatureHandlers && (handler != Interpreter::slow_signature_handler())) { |
1214 tty->cr(); |
1225 tty->cr(); |
1215 tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)", |
1226 tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)", |
1216 _handlers->length(), |
1227 _handlers->length(), |
1217 (method->is_static() ? "static" : "receiver"), |
1228 (method->is_static() ? "static" : "receiver"), |
1218 method->name_and_sig_as_C_string(), |
1229 method->name_and_sig_as_C_string(), |
1219 fingerprint, |
1230 fingerprint, |
1220 buffer.insts_size()); |
1231 buffer.insts_size()); |
1221 Disassembler::decode(handler, handler + buffer.insts_size()); |
1232 if (buffer.insts_size() > 0) { |
|
1233 // buffer may be empty for pregenerated handlers |
|
1234 Disassembler::decode(handler, handler + buffer.insts_size()); |
|
1235 } |
1222 #ifndef PRODUCT |
1236 #ifndef PRODUCT |
1223 address rh_begin = Interpreter::result_handler(method()->result_type()); |
1237 address rh_begin = Interpreter::result_handler(method()->result_type()); |
1224 if (CodeCache::contains(rh_begin)) { |
1238 if (CodeCache::contains(rh_begin)) { |
1225 // else it might be special platform dependent values |
1239 // else it might be special platform dependent values |
1226 tty->print_cr(" --- associated result handler ---"); |
1240 tty->print_cr(" --- associated result handler ---"); |
1275 assert(method->signature_handler() == Interpreter::slow_signature_handler() || |
1289 assert(method->signature_handler() == Interpreter::slow_signature_handler() || |
1276 handler_index == fingerprint_index, "sanity check"); |
1290 handler_index == fingerprint_index, "sanity check"); |
1277 #endif // ASSERT |
1291 #endif // ASSERT |
1278 } |
1292 } |
1279 |
1293 |
|
1294 void SignatureHandlerLibrary::add(uint64_t fingerprint, address handler) { |
|
1295 int handler_index = -1; |
|
1296 // use customized signature handler |
|
1297 MutexLocker mu(SignatureHandlerLibrary_lock); |
|
1298 // make sure data structure is initialized |
|
1299 initialize(); |
|
1300 fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint); |
|
1301 handler_index = _fingerprints->find(fingerprint); |
|
1302 // create handler if necessary |
|
1303 if (handler_index < 0) { |
|
1304 if (PrintSignatureHandlers && (handler != Interpreter::slow_signature_handler())) { |
|
1305 tty->cr(); |
|
1306 tty->print_cr("argument handler #%d at "PTR_FORMAT" for fingerprint " UINT64_FORMAT, |
|
1307 _handlers->length(), |
|
1308 handler, |
|
1309 fingerprint); |
|
1310 } |
|
1311 _fingerprints->append(fingerprint); |
|
1312 _handlers->append(handler); |
|
1313 } else { |
|
1314 if (PrintSignatureHandlers) { |
|
1315 tty->cr(); |
|
1316 tty->print_cr("duplicate argument handler #%d for fingerprint " UINT64_FORMAT "(old: "PTR_FORMAT", new : "PTR_FORMAT")", |
|
1317 _handlers->length(), |
|
1318 fingerprint, |
|
1319 _handlers->at(handler_index), |
|
1320 handler); |
|
1321 } |
|
1322 } |
|
1323 } |
|
1324 |
1280 |
1325 |
1281 BufferBlob* SignatureHandlerLibrary::_handler_blob = NULL; |
1326 BufferBlob* SignatureHandlerLibrary::_handler_blob = NULL; |
1282 address SignatureHandlerLibrary::_handler = NULL; |
1327 address SignatureHandlerLibrary::_handler = NULL; |
1283 GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = NULL; |
1328 GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = NULL; |
1284 GrowableArray<address>* SignatureHandlerLibrary::_handlers = NULL; |
1329 GrowableArray<address>* SignatureHandlerLibrary::_handlers = NULL; |