1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/runtime/sharedRuntime.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,536 @@ 1.4 +/* 1.5 + * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +class AdapterHandlerEntry; 1.29 +class vframeStream; 1.30 + 1.31 +// Runtime is the base class for various runtime interfaces 1.32 +// (InterpreterRuntime, CompilerRuntime, etc.). It provides 1.33 +// shared functionality such as exception forwarding (C++ to 1.34 +// Java exceptions), locking/unlocking mechanisms, statistical 1.35 +// information, etc. 1.36 + 1.37 +class SharedRuntime: AllStatic { 1.38 + private: 1.39 + static methodHandle resolve_sub_helper(JavaThread *thread, 1.40 + bool is_virtual, 1.41 + bool is_optimized, TRAPS); 1.42 + 1.43 + // Shared stub locations 1.44 + 1.45 + static RuntimeStub* _wrong_method_blob; 1.46 + static RuntimeStub* _ic_miss_blob; 1.47 + static RuntimeStub* _resolve_opt_virtual_call_blob; 1.48 + static RuntimeStub* _resolve_virtual_call_blob; 1.49 + static RuntimeStub* _resolve_static_call_blob; 1.50 + 1.51 + static SafepointBlob* _polling_page_safepoint_handler_blob; 1.52 + static SafepointBlob* _polling_page_return_handler_blob; 1.53 +#ifdef COMPILER2 1.54 + static ExceptionBlob* _exception_blob; 1.55 + static UncommonTrapBlob* _uncommon_trap_blob; 1.56 +#endif // COMPILER2 1.57 + 1.58 +#ifndef PRODUCT 1.59 + 1.60 + // Counters 1.61 + static int _nof_megamorphic_calls; // total # of megamorphic calls (through vtable) 1.62 + 1.63 +#endif // !PRODUCT 1.64 + public: 1.65 + // The following arithmetic routines are used on platforms that do 1.66 + // not have machine instructions to implement their functionality. 1.67 + // Do not remove these. 1.68 + 1.69 + // long arithmetics 1.70 + static jlong lmul(jlong y, jlong x); 1.71 + static jlong ldiv(jlong y, jlong x); 1.72 + static jlong lrem(jlong y, jlong x); 1.73 + 1.74 + // float and double remainder 1.75 + static jfloat frem(jfloat x, jfloat y); 1.76 + static jdouble drem(jdouble x, jdouble y); 1.77 + 1.78 + // float conversion (needs to set appropriate rounding mode) 1.79 + static jint f2i (jfloat x); 1.80 + static jlong f2l (jfloat x); 1.81 + static jint d2i (jdouble x); 1.82 + static jlong d2l (jdouble x); 1.83 + static jfloat d2f (jdouble x); 1.84 + static jfloat l2f (jlong x); 1.85 + static jdouble l2d (jlong x); 1.86 + 1.87 + // double trigonometrics and transcendentals 1.88 + static jdouble dsin(jdouble x); 1.89 + static jdouble dcos(jdouble x); 1.90 + static jdouble dtan(jdouble x); 1.91 + static jdouble dlog(jdouble x); 1.92 + static jdouble dlog10(jdouble x); 1.93 + static jdouble dexp(jdouble x); 1.94 + static jdouble dpow(jdouble x, jdouble y); 1.95 + 1.96 + 1.97 + // exception handling across interpreter/compiler boundaries 1.98 + static address raw_exception_handler_for_return_address(address return_address); 1.99 + static address exception_handler_for_return_address(address return_address); 1.100 + 1.101 + // exception handling and implicit exceptions 1.102 + static address compute_compiled_exc_handler(nmethod* nm, address ret_pc, Handle& exception, 1.103 + bool force_unwind, bool top_frame_only); 1.104 + enum ImplicitExceptionKind { 1.105 + IMPLICIT_NULL, 1.106 + IMPLICIT_DIVIDE_BY_ZERO, 1.107 + STACK_OVERFLOW 1.108 + }; 1.109 + static void throw_AbstractMethodError(JavaThread* thread); 1.110 + static void throw_ArithmeticException(JavaThread* thread); 1.111 + static void throw_NullPointerException(JavaThread* thread); 1.112 + static void throw_NullPointerException_at_call(JavaThread* thread); 1.113 + static void throw_StackOverflowError(JavaThread* thread); 1.114 + static address continuation_for_implicit_exception(JavaThread* thread, 1.115 + address faulting_pc, 1.116 + ImplicitExceptionKind exception_kind); 1.117 + 1.118 + // Shared stub locations 1.119 + static address get_poll_stub(address pc); 1.120 + 1.121 + static address get_ic_miss_stub() { 1.122 + assert(_ic_miss_blob!= NULL, "oops"); 1.123 + return _ic_miss_blob->instructions_begin(); 1.124 + } 1.125 + 1.126 + static address get_handle_wrong_method_stub() { 1.127 + assert(_wrong_method_blob!= NULL, "oops"); 1.128 + return _wrong_method_blob->instructions_begin(); 1.129 + } 1.130 + 1.131 +#ifdef COMPILER2 1.132 + static void generate_uncommon_trap_blob(void); 1.133 + static UncommonTrapBlob* uncommon_trap_blob() { return _uncommon_trap_blob; } 1.134 +#endif // COMPILER2 1.135 + 1.136 + static address get_resolve_opt_virtual_call_stub(){ 1.137 + assert(_resolve_opt_virtual_call_blob != NULL, "oops"); 1.138 + return _resolve_opt_virtual_call_blob->instructions_begin(); 1.139 + } 1.140 + static address get_resolve_virtual_call_stub() { 1.141 + assert(_resolve_virtual_call_blob != NULL, "oops"); 1.142 + return _resolve_virtual_call_blob->instructions_begin(); 1.143 + } 1.144 + static address get_resolve_static_call_stub() { 1.145 + assert(_resolve_static_call_blob != NULL, "oops"); 1.146 + return _resolve_static_call_blob->instructions_begin(); 1.147 + } 1.148 + 1.149 + static SafepointBlob* polling_page_return_handler_blob() { return _polling_page_return_handler_blob; } 1.150 + static SafepointBlob* polling_page_safepoint_handler_blob() { return _polling_page_safepoint_handler_blob; } 1.151 + 1.152 + // Counters 1.153 +#ifndef PRODUCT 1.154 + static address nof_megamorphic_calls_addr() { return (address)&_nof_megamorphic_calls; } 1.155 +#endif // PRODUCT 1.156 + 1.157 + // Helper routine for full-speed JVMTI exception throwing support 1.158 + static void throw_and_post_jvmti_exception(JavaThread *thread, Handle h_exception); 1.159 + static void throw_and_post_jvmti_exception(JavaThread *thread, symbolOop name, const char *message = NULL); 1.160 + 1.161 + // To be used as the entry point for unresolved native methods. 1.162 + static address native_method_throw_unsatisfied_link_error_entry(); 1.163 + 1.164 + // bytecode tracing is only used by the TraceBytecodes 1.165 + static intptr_t trace_bytecode(JavaThread* thread, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2) PRODUCT_RETURN0; 1.166 + 1.167 + // Used to back off a spin lock that is under heavy contention 1.168 + static void yield_all(JavaThread* thread, int attempts = 0); 1.169 + 1.170 + static oop retrieve_receiver( symbolHandle sig, frame caller ); 1.171 + 1.172 + static void verify_caller_frame(frame caller_frame, methodHandle callee_method) PRODUCT_RETURN; 1.173 + static methodHandle find_callee_method_inside_interpreter(frame caller_frame, methodHandle caller_method, int bci) PRODUCT_RETURN_(return methodHandle();); 1.174 + 1.175 + static void register_finalizer(JavaThread* thread, oopDesc* obj); 1.176 + 1.177 + // dtrace notifications 1.178 + static int dtrace_object_alloc(oopDesc* o); 1.179 + static int dtrace_object_alloc_base(Thread* thread, oopDesc* o); 1.180 + static int dtrace_method_entry(JavaThread* thread, methodOopDesc* m); 1.181 + static int dtrace_method_exit(JavaThread* thread, methodOopDesc* m); 1.182 + 1.183 + // Utility method for retrieving the Java thread id, returns 0 if the 1.184 + // thread is not a well formed Java thread. 1.185 + static jlong get_java_tid(Thread* thread); 1.186 + 1.187 + 1.188 + // used by native wrappers to reenable yellow if overflow happened in native code 1.189 + static void reguard_yellow_pages(); 1.190 + 1.191 + /** 1.192 + * Fill in the "X cannot be cast to a Y" message for ClassCastException 1.193 + * 1.194 + * @param thr the current thread 1.195 + * @param name the name of the class of the object attempted to be cast 1.196 + * @return the dynamically allocated exception message (must be freed 1.197 + * by the caller using a resource mark) 1.198 + * 1.199 + * BCP must refer to the current 'checkcast' opcode for the frame 1.200 + * on top of the stack. 1.201 + * The caller (or one of it's callers) must use a ResourceMark 1.202 + * in order to correctly free the result. 1.203 + */ 1.204 + static char* generate_class_cast_message(JavaThread* thr, const char* name); 1.205 + 1.206 + /** 1.207 + * Fill in the "X cannot be cast to a Y" message for ClassCastException 1.208 + * 1.209 + * @param name the name of the class of the object attempted to be cast 1.210 + * @param klass the name of the target klass attempt 1.211 + * @return the dynamically allocated exception message (must be freed 1.212 + * by the caller using a resource mark) 1.213 + * 1.214 + * This version does not require access the frame, so it can be called 1.215 + * from interpreted code 1.216 + * The caller (or one of it's callers) must use a ResourceMark 1.217 + * in order to correctly free the result. 1.218 + */ 1.219 + static char* generate_class_cast_message(const char* name, const char* klass); 1.220 + 1.221 + // Resolves a call site- may patch in the destination of the call into the 1.222 + // compiled code. 1.223 + static methodHandle resolve_helper(JavaThread *thread, 1.224 + bool is_virtual, 1.225 + bool is_optimized, TRAPS); 1.226 + 1.227 + static void generate_stubs(void); 1.228 + 1.229 + private: 1.230 + // deopt blob 1.231 + static void generate_deopt_blob(void); 1.232 + static DeoptimizationBlob* _deopt_blob; 1.233 + 1.234 + public: 1.235 + static DeoptimizationBlob* deopt_blob(void) { return _deopt_blob; } 1.236 + 1.237 + // Resets a call-site in compiled code so it will get resolved again. 1.238 + static methodHandle reresolve_call_site(JavaThread *thread, TRAPS); 1.239 + 1.240 + // In the code prolog, if the klass comparison fails, the inline cache 1.241 + // misses and the call site is patched to megamorphic 1.242 + static methodHandle handle_ic_miss_helper(JavaThread* thread, TRAPS); 1.243 + 1.244 + // Find the method that called us. 1.245 + static methodHandle find_callee_method(JavaThread* thread, TRAPS); 1.246 + 1.247 + 1.248 + private: 1.249 + static Handle find_callee_info(JavaThread* thread, 1.250 + Bytecodes::Code& bc, 1.251 + CallInfo& callinfo, TRAPS); 1.252 + static Handle find_callee_info_helper(JavaThread* thread, 1.253 + vframeStream& vfst, 1.254 + Bytecodes::Code& bc, 1.255 + CallInfo& callinfo, TRAPS); 1.256 + 1.257 + static address clean_virtual_call_entry(); 1.258 + static address clean_opt_virtual_call_entry(); 1.259 + static address clean_static_call_entry(); 1.260 + 1.261 + public: 1.262 + 1.263 + 1.264 + static void create_native_wrapper (JavaThread* thread, methodOop method); 1.265 + 1.266 + // Read the array of BasicTypes from a Java signature, and compute where 1.267 + // compiled Java code would like to put the results. Values in reg_lo and 1.268 + // reg_hi refer to 4-byte quantities. Values less than SharedInfo::stack0 are 1.269 + // registers, those above refer to 4-byte stack slots. All stack slots are 1.270 + // based off of the window top. SharedInfo::stack0 refers to the first usable 1.271 + // slot in the bottom of the frame. SharedInfo::stack0+1 refers to the memory word 1.272 + // 4-bytes higher. So for sparc because the register window save area is at 1.273 + // the bottom of the frame the first 16 words will be skipped and SharedInfo::stack0 1.274 + // will be just above it. ( 1.275 + // return value is the maximum number of VMReg stack slots the convention will use. 1.276 + static int java_calling_convention(const BasicType *sig_bt, VMRegPair *regs, int total_args_passed, int is_outgoing); 1.277 + 1.278 + // Ditto except for calling C 1.279 + static int c_calling_convention(const BasicType *sig_bt, VMRegPair *regs, int total_args_passed); 1.280 + 1.281 + // Generate I2C and C2I adapters. These adapters are simple argument marshalling 1.282 + // blobs. Unlike adapters in the tiger and earlier releases the code in these 1.283 + // blobs does not create a new frame and are therefore virtually invisible 1.284 + // to the stack walking code. In general these blobs extend the callers stack 1.285 + // as needed for the conversion of argument locations. 1.286 + 1.287 + // When calling a c2i blob the code will always call the interpreter even if 1.288 + // by the time we reach the blob there is compiled code available. This allows 1.289 + // the blob to pass the incoming stack pointer (the sender sp) in a known 1.290 + // location for the interpreter to record. This is used by the frame code 1.291 + // to correct the sender code to match up with the stack pointer when the 1.292 + // thread left the compiled code. In addition it allows the interpreter 1.293 + // to remove the space the c2i adapter allocated to do it argument conversion. 1.294 + 1.295 + // Although a c2i blob will always run interpreted even if compiled code is 1.296 + // present if we see that compiled code is present the compiled call site 1.297 + // will be patched/re-resolved so that later calls will run compiled. 1.298 + 1.299 + // Aditionally a c2i blob need to have a unverified entry because it can be reached 1.300 + // in situations where the call site is an inlined cache site and may go megamorphic. 1.301 + 1.302 + // A i2c adapter is simpler than the c2i adapter. This is because it is assumed 1.303 + // that the interpreter before it does any call dispatch will record the current 1.304 + // stack pointer in the interpreter frame. On return it will restore the stack 1.305 + // pointer as needed. This means the i2c adapter code doesn't need any special 1.306 + // handshaking path with compiled code to keep the stack walking correct. 1.307 + 1.308 + static AdapterHandlerEntry* generate_i2c2i_adapters(MacroAssembler *_masm, 1.309 + int total_args_passed, 1.310 + int max_arg, 1.311 + const BasicType *sig_bt, 1.312 + const VMRegPair *regs); 1.313 + 1.314 + // OSR support 1.315 + 1.316 + // OSR_migration_begin will extract the jvm state from an interpreter 1.317 + // frame (locals, monitors) and store the data in a piece of C heap 1.318 + // storage. This then allows the interpreter frame to be removed from the 1.319 + // stack and the OSR nmethod to be called. That method is called with a 1.320 + // pointer to the C heap storage. This pointer is the return value from 1.321 + // OSR_migration_begin. 1.322 + 1.323 + static intptr_t* OSR_migration_begin( JavaThread *thread); 1.324 + 1.325 + // OSR_migration_end is a trivial routine. It is called after the compiled 1.326 + // method has extracted the jvm state from the C heap that OSR_migration_begin 1.327 + // created. It's entire job is to simply free this storage. 1.328 + static void OSR_migration_end ( intptr_t* buf); 1.329 + 1.330 + // Convert a sig into a calling convention register layout 1.331 + // and find interesting things about it. 1.332 + static VMRegPair* find_callee_arguments(symbolOop sig, bool is_static, int *arg_size); 1.333 + static VMReg name_for_receiver(); 1.334 + 1.335 + // "Top of Stack" slots that may be unused by the calling convention but must 1.336 + // otherwise be preserved. 1.337 + // On Intel these are not necessary and the value can be zero. 1.338 + // On Sparc this describes the words reserved for storing a register window 1.339 + // when an interrupt occurs. 1.340 + static uint out_preserve_stack_slots(); 1.341 + 1.342 + // Save and restore a native result 1.343 + static void save_native_result(MacroAssembler *_masm, BasicType ret_type, int frame_slots ); 1.344 + static void restore_native_result(MacroAssembler *_masm, BasicType ret_type, int frame_slots ); 1.345 + 1.346 + // Generate a native wrapper for a given method. The method takes arguments 1.347 + // in the Java compiled code convention, marshals them to the native 1.348 + // convention (handlizes oops, etc), transitions to native, makes the call, 1.349 + // returns to java state (possibly blocking), unhandlizes any result and 1.350 + // returns. 1.351 + static nmethod *generate_native_wrapper(MacroAssembler* masm, 1.352 + methodHandle method, 1.353 + int total_args_passed, 1.354 + int max_arg, 1.355 + BasicType *sig_bt, 1.356 + VMRegPair *regs, 1.357 + BasicType ret_type ); 1.358 + 1.359 + // A compiled caller has just called the interpreter, but compiled code 1.360 + // exists. Patch the caller so he no longer calls into the interpreter. 1.361 + static void fixup_callers_callsite(methodOopDesc* moop, address ret_pc); 1.362 + 1.363 + // Slow-path Locking and Unlocking 1.364 + static void complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* thread); 1.365 + static void complete_monitor_unlocking_C(oopDesc* obj, BasicLock* lock); 1.366 + 1.367 + // Resolving of calls 1.368 + static address resolve_static_call_C (JavaThread *thread); 1.369 + static address resolve_virtual_call_C (JavaThread *thread); 1.370 + static address resolve_opt_virtual_call_C(JavaThread *thread); 1.371 + 1.372 + // arraycopy, the non-leaf version. (See StubRoutines for all the leaf calls.) 1.373 + static void slow_arraycopy_C(oopDesc* src, jint src_pos, 1.374 + oopDesc* dest, jint dest_pos, 1.375 + jint length, JavaThread* thread); 1.376 + 1.377 + // handle ic miss with caller being compiled code 1.378 + // wrong method handling (inline cache misses, zombie methods) 1.379 + static address handle_wrong_method(JavaThread* thread); 1.380 + static address handle_wrong_method_ic_miss(JavaThread* thread); 1.381 + 1.382 +#ifndef PRODUCT 1.383 + 1.384 + // Collect and print inline cache miss statistics 1.385 + private: 1.386 + enum { maxICmiss_count = 100 }; 1.387 + static int _ICmiss_index; // length of IC miss histogram 1.388 + static int _ICmiss_count[maxICmiss_count]; // miss counts 1.389 + static address _ICmiss_at[maxICmiss_count]; // miss addresses 1.390 + static void trace_ic_miss(address at); 1.391 + 1.392 + public: 1.393 + static int _monitor_enter_ctr; // monitor enter slow 1.394 + static int _monitor_exit_ctr; // monitor exit slow 1.395 + static int _throw_null_ctr; // throwing a null-pointer exception 1.396 + static int _ic_miss_ctr; // total # of IC misses 1.397 + static int _wrong_method_ctr; 1.398 + static int _resolve_static_ctr; 1.399 + static int _resolve_virtual_ctr; 1.400 + static int _resolve_opt_virtual_ctr; 1.401 + static int _implicit_null_throws; 1.402 + static int _implicit_div0_throws; 1.403 + 1.404 + static int _jbyte_array_copy_ctr; // Slow-path byte array copy 1.405 + static int _jshort_array_copy_ctr; // Slow-path short array copy 1.406 + static int _jint_array_copy_ctr; // Slow-path int array copy 1.407 + static int _jlong_array_copy_ctr; // Slow-path long array copy 1.408 + static int _oop_array_copy_ctr; // Slow-path oop array copy 1.409 + static int _checkcast_array_copy_ctr; // Slow-path oop array copy, with cast 1.410 + static int _unsafe_array_copy_ctr; // Slow-path includes alignment checks 1.411 + static int _generic_array_copy_ctr; // Slow-path includes type decoding 1.412 + static int _slow_array_copy_ctr; // Slow-path failed out to a method call 1.413 + 1.414 + static int _new_instance_ctr; // 'new' object requires GC 1.415 + static int _new_array_ctr; // 'new' array requires GC 1.416 + static int _multi1_ctr, _multi2_ctr, _multi3_ctr, _multi4_ctr, _multi5_ctr; 1.417 + static int _find_handler_ctr; // find exception handler 1.418 + static int _rethrow_ctr; // rethrow exception 1.419 + static int _mon_enter_stub_ctr; // monitor enter stub 1.420 + static int _mon_exit_stub_ctr; // monitor exit stub 1.421 + static int _mon_enter_ctr; // monitor enter slow 1.422 + static int _mon_exit_ctr; // monitor exit slow 1.423 + static int _partial_subtype_ctr; // SubRoutines::partial_subtype_check 1.424 + 1.425 + // Statistics code 1.426 + // stats for "normal" compiled calls (non-interface) 1.427 + static int _nof_normal_calls; // total # of calls 1.428 + static int _nof_optimized_calls; // total # of statically-bound calls 1.429 + static int _nof_inlined_calls; // total # of inlined normal calls 1.430 + static int _nof_static_calls; // total # of calls to static methods or super methods (invokespecial) 1.431 + static int _nof_inlined_static_calls; // total # of inlined static calls 1.432 + // stats for compiled interface calls 1.433 + static int _nof_interface_calls; // total # of compiled calls 1.434 + static int _nof_optimized_interface_calls; // total # of statically-bound interface calls 1.435 + static int _nof_inlined_interface_calls; // total # of inlined interface calls 1.436 + static int _nof_megamorphic_interface_calls;// total # of megamorphic interface calls 1.437 + // stats for runtime exceptions 1.438 + static int _nof_removable_exceptions; // total # of exceptions that could be replaced by branches due to inlining 1.439 + 1.440 + public: // for compiler 1.441 + static address nof_normal_calls_addr() { return (address)&_nof_normal_calls; } 1.442 + static address nof_optimized_calls_addr() { return (address)&_nof_optimized_calls; } 1.443 + static address nof_inlined_calls_addr() { return (address)&_nof_inlined_calls; } 1.444 + static address nof_static_calls_addr() { return (address)&_nof_static_calls; } 1.445 + static address nof_inlined_static_calls_addr() { return (address)&_nof_inlined_static_calls; } 1.446 + static address nof_interface_calls_addr() { return (address)&_nof_interface_calls; } 1.447 + static address nof_optimized_interface_calls_addr() { return (address)&_nof_optimized_interface_calls; } 1.448 + static address nof_inlined_interface_calls_addr() { return (address)&_nof_inlined_interface_calls; } 1.449 + static address nof_megamorphic_interface_calls_addr() { return (address)&_nof_megamorphic_interface_calls; } 1.450 + static void print_call_statistics(int comp_total); 1.451 + static void print_statistics(); 1.452 + static void print_ic_miss_histogram(); 1.453 + 1.454 +#endif // PRODUCT 1.455 +}; 1.456 + 1.457 + 1.458 +// --------------------------------------------------------------------------- 1.459 +// Implementation of AdapterHandlerLibrary 1.460 +// 1.461 +// This library manages argument marshaling adapters and native wrappers. 1.462 +// There are 2 flavors of adapters: I2C and C2I. 1.463 +// 1.464 +// The I2C flavor takes a stock interpreted call setup, marshals the arguments 1.465 +// for a Java-compiled call, and jumps to Rmethod-> code()-> 1.466 +// instructions_begin(). It is broken to call it without an nmethod assigned. 1.467 +// The usual behavior is to lift any register arguments up out of the stack 1.468 +// and possibly re-pack the extra arguments to be contigious. I2C adapters 1.469 +// will save what the interpreter's stack pointer will be after arguments are 1.470 +// popped, then adjust the interpreter's frame size to force alignment and 1.471 +// possibly to repack the arguments. After re-packing, it jumps to the 1.472 +// compiled code start. There are no safepoints in this adapter code and a GC 1.473 +// cannot happen while marshaling is in progress. 1.474 +// 1.475 +// The C2I flavor takes a stock compiled call setup plus the target method in 1.476 +// Rmethod, marshals the arguments for an interpreted call and jumps to 1.477 +// Rmethod->_i2i_entry. On entry, the interpreted frame has not yet been 1.478 +// setup. Compiled frames are fixed-size and the args are likely not in the 1.479 +// right place. Hence all the args will likely be copied into the 1.480 +// interpreter's frame, forcing that frame to grow. The compiled frame's 1.481 +// outgoing stack args will be dead after the copy. 1.482 +// 1.483 +// Native wrappers, like adapters, marshal arguments. Unlike adapters they 1.484 +// also perform an offical frame push & pop. They have a call to the native 1.485 +// routine in their middles and end in a return (instead of ending in a jump). 1.486 +// The native wrappers are stored in real nmethods instead of the BufferBlobs 1.487 +// used by the adapters. The code generation happens here because it's very 1.488 +// similar to what the adapters have to do. 1.489 + 1.490 +class AdapterHandlerEntry : public CHeapObj { 1.491 + private: 1.492 + address _i2c_entry; 1.493 + address _c2i_entry; 1.494 + address _c2i_unverified_entry; 1.495 + 1.496 + public: 1.497 + AdapterHandlerEntry(address i2c_entry, address c2i_entry, address c2i_unverified_entry): 1.498 + _i2c_entry(i2c_entry), 1.499 + _c2i_entry(c2i_entry), 1.500 + _c2i_unverified_entry(c2i_unverified_entry) { 1.501 + } 1.502 + // The name we give all buffer blobs 1.503 + static const char* name; 1.504 + 1.505 + address get_i2c_entry() { return _i2c_entry; } 1.506 + address get_c2i_entry() { return _c2i_entry; } 1.507 + address get_c2i_unverified_entry() { return _c2i_unverified_entry; } 1.508 + void relocate(address new_base); 1.509 +#ifndef PRODUCT 1.510 + void print(); 1.511 +#endif /* PRODUCT */ 1.512 +}; 1.513 + 1.514 + 1.515 +class AdapterHandlerLibrary: public AllStatic { 1.516 + private: 1.517 + enum { 1.518 + AbstractMethodHandler = 1 // special handler for abstract methods 1.519 + }; 1.520 + static GrowableArray<uint64_t>* _fingerprints; // the fingerprint collection 1.521 + static GrowableArray<AdapterHandlerEntry*> * _handlers; // the corresponding handlers 1.522 + static u_char _buffer[]; // the temporary code buffer 1.523 + static void initialize(); 1.524 + static AdapterHandlerEntry* get_entry( int index ) { return _handlers->at(index); } 1.525 + static int get_create_adapter_index(methodHandle method); 1.526 + static address get_i2c_entry( int index ) { return get_entry(index)->get_i2c_entry(); } 1.527 + static address get_c2i_entry( int index ) { return get_entry(index)->get_c2i_entry(); } 1.528 + static address get_c2i_unverified_entry( int index ) { return get_entry(index)->get_c2i_unverified_entry(); } 1.529 + 1.530 + public: 1.531 + static nmethod* create_native_wrapper(methodHandle method); 1.532 + static AdapterHandlerEntry* get_adapter(methodHandle method) { return get_entry(get_create_adapter_index(method)); } 1.533 + 1.534 +#ifndef PRODUCT 1.535 + static void print_handler(CodeBlob* b); 1.536 + static bool contains(CodeBlob* b); 1.537 +#endif /* PRODUCT */ 1.538 + 1.539 +};