10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/javaClasses.inline.hpp"
27 #include "classfile/systemDictionary.hpp"
28 #include "classfile/vmSymbols.hpp"
29 #include "code/codeCache.hpp"
30 #include "code/codeCacheExtensions.hpp"
31 #include "compiler/compileBroker.hpp"
32 #include "compiler/disassembler.hpp"
33 #include "gc/shared/collectedHeap.hpp"
34 #include "interpreter/interpreter.hpp"
35 #include "interpreter/interpreterRuntime.hpp"
36 #include "interpreter/linkResolver.hpp"
37 #include "interpreter/templateTable.hpp"
38 #include "logging/log.hpp"
39 #include "memory/oopFactory.hpp"
40 #include "memory/resourceArea.hpp"
41 #include "memory/universe.inline.hpp"
42 #include "oops/constantPool.hpp"
43 #include "oops/instanceKlass.hpp"
44 #include "oops/methodData.hpp"
45 #include "oops/objArrayKlass.hpp"
46 #include "oops/objArrayOop.inline.hpp"
47 #include "oops/oop.inline.hpp"
48 #include "oops/symbol.hpp"
49 #include "prims/jvmtiExport.hpp"
50 #include "prims/nativeLookup.hpp"
1182 SignatureHandlerLibrary::buffer_size);
1183 _buffer = bb->code_begin();
1184
1185 _fingerprints = new(ResourceObj::C_HEAP, mtCode)GrowableArray<uint64_t>(32, true);
1186 _handlers = new(ResourceObj::C_HEAP, mtCode)GrowableArray<address>(32, true);
1187 }
1188
1189 address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) {
1190 address handler = _handler;
1191 int insts_size = buffer->pure_insts_size();
1192 if (handler + insts_size > _handler_blob->code_end()) {
1193 // get a new handler blob
1194 handler = set_handler_blob();
1195 }
1196 if (handler != NULL) {
1197 memcpy(handler, buffer->insts_begin(), insts_size);
1198 pd_set_handler(handler);
1199 ICache::invalidate_range(handler, insts_size);
1200 _handler = handler + insts_size;
1201 }
1202 CodeCacheExtensions::handle_generated_handler(handler, buffer->name(), _handler);
1203 return handler;
1204 }
1205
1206 void SignatureHandlerLibrary::add(const methodHandle& method) {
1207 if (method->signature_handler() == NULL) {
1208 // use slow signature handler if we can't do better
1209 int handler_index = -1;
1210 // check if we can use customized (fast) signature handler
1211 if (UseFastSignatureHandlers && CodeCacheExtensions::support_fast_signature_handlers() && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) {
1212 // use customized signature handler
1213 MutexLocker mu(SignatureHandlerLibrary_lock);
1214 // make sure data structure is initialized
1215 initialize();
1216 // lookup method signature's fingerprint
1217 uint64_t fingerprint = Fingerprinter(method).fingerprint();
1218 // allow CPU dependant code to optimize the fingerprints for the fast handler
1219 fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint);
1220 handler_index = _fingerprints->find(fingerprint);
1221 // create handler if necessary
1222 if (handler_index < 0) {
1223 ResourceMark rm;
1224 ptrdiff_t align_offset = (address)
1225 round_to((intptr_t)_buffer, CodeEntryAlignment) - (address)_buffer;
1226 CodeBuffer buffer((address)(_buffer + align_offset),
1227 SignatureHandlerLibrary::buffer_size - align_offset);
1228 if (!CodeCacheExtensions::support_dynamic_code()) {
1229 // we need a name for the signature (for lookups or saving)
1230 const int SYMBOL_SIZE = 50;
1231 char *symbolName = NEW_RESOURCE_ARRAY(char, SYMBOL_SIZE);
1232 // support for named signatures
1233 jio_snprintf(symbolName, SYMBOL_SIZE,
1234 "native_" UINT64_FORMAT, fingerprint);
1235 buffer.set_name(symbolName);
1236 }
1237 InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint);
1238 // copy into code heap
1239 address handler = set_handler(&buffer);
1240 if (handler == NULL) {
1241 // use slow signature handler (without memorizing it in the fingerprints)
1242 } else {
1243 // debugging suppport
1244 if (PrintSignatureHandlers && (handler != Interpreter::slow_signature_handler())) {
1245 ttyLocker ttyl;
1246 tty->cr();
1247 tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)",
1248 _handlers->length(),
1249 (method->is_static() ? "static" : "receiver"),
1250 method->name_and_sig_as_C_string(),
1251 fingerprint,
1252 buffer.insts_size());
1253 if (buffer.insts_size() > 0) {
1254 // buffer may be empty for pregenerated handlers
1255 Disassembler::decode(handler, handler + buffer.insts_size());
1256 }
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/javaClasses.inline.hpp"
27 #include "classfile/systemDictionary.hpp"
28 #include "classfile/vmSymbols.hpp"
29 #include "code/codeCache.hpp"
30 #include "compiler/compileBroker.hpp"
31 #include "compiler/disassembler.hpp"
32 #include "gc/shared/collectedHeap.hpp"
33 #include "interpreter/interpreter.hpp"
34 #include "interpreter/interpreterRuntime.hpp"
35 #include "interpreter/linkResolver.hpp"
36 #include "interpreter/templateTable.hpp"
37 #include "logging/log.hpp"
38 #include "memory/oopFactory.hpp"
39 #include "memory/resourceArea.hpp"
40 #include "memory/universe.inline.hpp"
41 #include "oops/constantPool.hpp"
42 #include "oops/instanceKlass.hpp"
43 #include "oops/methodData.hpp"
44 #include "oops/objArrayKlass.hpp"
45 #include "oops/objArrayOop.inline.hpp"
46 #include "oops/oop.inline.hpp"
47 #include "oops/symbol.hpp"
48 #include "prims/jvmtiExport.hpp"
49 #include "prims/nativeLookup.hpp"
1181 SignatureHandlerLibrary::buffer_size);
1182 _buffer = bb->code_begin();
1183
1184 _fingerprints = new(ResourceObj::C_HEAP, mtCode)GrowableArray<uint64_t>(32, true);
1185 _handlers = new(ResourceObj::C_HEAP, mtCode)GrowableArray<address>(32, true);
1186 }
1187
1188 address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) {
1189 address handler = _handler;
1190 int insts_size = buffer->pure_insts_size();
1191 if (handler + insts_size > _handler_blob->code_end()) {
1192 // get a new handler blob
1193 handler = set_handler_blob();
1194 }
1195 if (handler != NULL) {
1196 memcpy(handler, buffer->insts_begin(), insts_size);
1197 pd_set_handler(handler);
1198 ICache::invalidate_range(handler, insts_size);
1199 _handler = handler + insts_size;
1200 }
1201 return handler;
1202 }
1203
1204 void SignatureHandlerLibrary::add(const methodHandle& method) {
1205 if (method->signature_handler() == NULL) {
1206 // use slow signature handler if we can't do better
1207 int handler_index = -1;
1208 // check if we can use customized (fast) signature handler
1209 if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) {
1210 // use customized signature handler
1211 MutexLocker mu(SignatureHandlerLibrary_lock);
1212 // make sure data structure is initialized
1213 initialize();
1214 // lookup method signature's fingerprint
1215 uint64_t fingerprint = Fingerprinter(method).fingerprint();
1216 // allow CPU dependant code to optimize the fingerprints for the fast handler
1217 fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint);
1218 handler_index = _fingerprints->find(fingerprint);
1219 // create handler if necessary
1220 if (handler_index < 0) {
1221 ResourceMark rm;
1222 ptrdiff_t align_offset = (address)
1223 round_to((intptr_t)_buffer, CodeEntryAlignment) - (address)_buffer;
1224 CodeBuffer buffer((address)(_buffer + align_offset),
1225 SignatureHandlerLibrary::buffer_size - align_offset);
1226 InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint);
1227 // copy into code heap
1228 address handler = set_handler(&buffer);
1229 if (handler == NULL) {
1230 // use slow signature handler (without memorizing it in the fingerprints)
1231 } else {
1232 // debugging suppport
1233 if (PrintSignatureHandlers && (handler != Interpreter::slow_signature_handler())) {
1234 ttyLocker ttyl;
1235 tty->cr();
1236 tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)",
1237 _handlers->length(),
1238 (method->is_static() ? "static" : "receiver"),
1239 method->name_and_sig_as_C_string(),
1240 fingerprint,
1241 buffer.insts_size());
1242 if (buffer.insts_size() > 0) {
1243 // buffer may be empty for pregenerated handlers
1244 Disassembler::decode(handler, handler + buffer.insts_size());
1245 }
|