1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/runtime/sharedRuntime.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,703 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_RUNTIME_SHAREDRUNTIME_HPP 1.29 +#define SHARE_VM_RUNTIME_SHAREDRUNTIME_HPP 1.30 + 1.31 +#include "interpreter/bytecodeHistogram.hpp" 1.32 +#include "interpreter/bytecodeTracer.hpp" 1.33 +#include "interpreter/linkResolver.hpp" 1.34 +#include "memory/allocation.hpp" 1.35 +#include "memory/resourceArea.hpp" 1.36 +#include "runtime/threadLocalStorage.hpp" 1.37 +#include "utilities/hashtable.hpp" 1.38 +#include "utilities/macros.hpp" 1.39 + 1.40 +class AdapterHandlerEntry; 1.41 +class AdapterHandlerTable; 1.42 +class AdapterFingerPrint; 1.43 +class vframeStream; 1.44 + 1.45 +// Runtime is the base class for various runtime interfaces 1.46 +// (InterpreterRuntime, CompilerRuntime, etc.). It provides 1.47 +// shared functionality such as exception forwarding (C++ to 1.48 +// Java exceptions), locking/unlocking mechanisms, statistical 1.49 +// information, etc. 1.50 + 1.51 +class SharedRuntime: AllStatic { 1.52 + friend class VMStructs; 1.53 + 1.54 + private: 1.55 + static methodHandle resolve_sub_helper(JavaThread *thread, 1.56 + bool is_virtual, 1.57 + bool is_optimized, TRAPS); 1.58 + 1.59 + // Shared stub locations 1.60 + 1.61 + static RuntimeStub* _wrong_method_blob; 1.62 + static RuntimeStub* _wrong_method_abstract_blob; 1.63 + static RuntimeStub* _ic_miss_blob; 1.64 + static RuntimeStub* _resolve_opt_virtual_call_blob; 1.65 + static RuntimeStub* _resolve_virtual_call_blob; 1.66 + static RuntimeStub* _resolve_static_call_blob; 1.67 + 1.68 + static DeoptimizationBlob* _deopt_blob; 1.69 + 1.70 + static SafepointBlob* _polling_page_vectors_safepoint_handler_blob; 1.71 + static SafepointBlob* _polling_page_safepoint_handler_blob; 1.72 + static SafepointBlob* _polling_page_return_handler_blob; 1.73 + 1.74 +#ifdef COMPILER2 1.75 + static UncommonTrapBlob* _uncommon_trap_blob; 1.76 +#endif // COMPILER2 1.77 + 1.78 +#ifndef PRODUCT 1.79 + // Counters 1.80 + static int _nof_megamorphic_calls; // total # of megamorphic calls (through vtable) 1.81 +#endif // !PRODUCT 1.82 + 1.83 + private: 1.84 + enum { POLL_AT_RETURN, POLL_AT_LOOP, POLL_AT_VECTOR_LOOP }; 1.85 + static SafepointBlob* generate_handler_blob(address call_ptr, int poll_type); 1.86 + static RuntimeStub* generate_resolve_blob(address destination, const char* name); 1.87 + 1.88 + public: 1.89 + static void generate_stubs(void); 1.90 + 1.91 + // max bytes for each dtrace string parameter 1.92 + enum { max_dtrace_string_size = 256 }; 1.93 + 1.94 + // The following arithmetic routines are used on platforms that do 1.95 + // not have machine instructions to implement their functionality. 1.96 + // Do not remove these. 1.97 + 1.98 + // long arithmetics 1.99 + static jlong lmul(jlong y, jlong x); 1.100 + static jlong ldiv(jlong y, jlong x); 1.101 + static jlong lrem(jlong y, jlong x); 1.102 + 1.103 + // float and double remainder 1.104 + static jfloat frem(jfloat x, jfloat y); 1.105 + static jdouble drem(jdouble x, jdouble y); 1.106 + 1.107 +#ifdef __SOFTFP__ 1.108 + static jfloat fadd(jfloat x, jfloat y); 1.109 + static jfloat fsub(jfloat x, jfloat y); 1.110 + static jfloat fmul(jfloat x, jfloat y); 1.111 + static jfloat fdiv(jfloat x, jfloat y); 1.112 + 1.113 + static jdouble dadd(jdouble x, jdouble y); 1.114 + static jdouble dsub(jdouble x, jdouble y); 1.115 + static jdouble dmul(jdouble x, jdouble y); 1.116 + static jdouble ddiv(jdouble x, jdouble y); 1.117 +#endif // __SOFTFP__ 1.118 + 1.119 + // float conversion (needs to set appropriate rounding mode) 1.120 + static jint f2i (jfloat x); 1.121 + static jlong f2l (jfloat x); 1.122 + static jint d2i (jdouble x); 1.123 + static jlong d2l (jdouble x); 1.124 + static jfloat d2f (jdouble x); 1.125 + static jfloat l2f (jlong x); 1.126 + static jdouble l2d (jlong x); 1.127 + 1.128 +#ifdef __SOFTFP__ 1.129 + static jfloat i2f (jint x); 1.130 + static jdouble i2d (jint x); 1.131 + static jdouble f2d (jfloat x); 1.132 +#endif // __SOFTFP__ 1.133 + 1.134 + // double trigonometrics and transcendentals 1.135 + static jdouble dsin(jdouble x); 1.136 + static jdouble dcos(jdouble x); 1.137 + static jdouble dtan(jdouble x); 1.138 + static jdouble dlog(jdouble x); 1.139 + static jdouble dlog10(jdouble x); 1.140 + static jdouble dexp(jdouble x); 1.141 + static jdouble dpow(jdouble x, jdouble y); 1.142 + 1.143 +#if defined(__SOFTFP__) || defined(E500V2) 1.144 + static double dabs(double f); 1.145 +#endif 1.146 + 1.147 +#if defined(__SOFTFP__) || defined(PPC32) 1.148 + static double dsqrt(double f); 1.149 +#endif 1.150 + 1.151 +#ifdef __SOFTFP__ 1.152 + // C++ compiler generates soft float instructions as well as passing 1.153 + // float and double in registers. 1.154 + static int fcmpl(float x, float y); 1.155 + static int fcmpg(float x, float y); 1.156 + static int dcmpl(double x, double y); 1.157 + static int dcmpg(double x, double y); 1.158 + 1.159 + static int unordered_fcmplt(float x, float y); 1.160 + static int unordered_dcmplt(double x, double y); 1.161 + static int unordered_fcmple(float x, float y); 1.162 + static int unordered_dcmple(double x, double y); 1.163 + static int unordered_fcmpge(float x, float y); 1.164 + static int unordered_dcmpge(double x, double y); 1.165 + static int unordered_fcmpgt(float x, float y); 1.166 + static int unordered_dcmpgt(double x, double y); 1.167 + 1.168 + static float fneg(float f); 1.169 + static double dneg(double f); 1.170 +#endif 1.171 + 1.172 + // exception handling across interpreter/compiler boundaries 1.173 + static address raw_exception_handler_for_return_address(JavaThread* thread, address return_address); 1.174 + static address exception_handler_for_return_address(JavaThread* thread, address return_address); 1.175 + 1.176 +#if INCLUDE_ALL_GCS 1.177 + // G1 write barriers 1.178 + static void g1_wb_pre(oopDesc* orig, JavaThread *thread); 1.179 + static void g1_wb_post(void* card_addr, JavaThread* thread); 1.180 +#endif // INCLUDE_ALL_GCS 1.181 + 1.182 + // exception handling and implicit exceptions 1.183 + static address compute_compiled_exc_handler(nmethod* nm, address ret_pc, Handle& exception, 1.184 + bool force_unwind, bool top_frame_only); 1.185 + enum ImplicitExceptionKind { 1.186 + IMPLICIT_NULL, 1.187 + IMPLICIT_DIVIDE_BY_ZERO, 1.188 + STACK_OVERFLOW 1.189 + }; 1.190 + static void throw_AbstractMethodError(JavaThread* thread); 1.191 + static void throw_IncompatibleClassChangeError(JavaThread* thread); 1.192 + static void throw_ArithmeticException(JavaThread* thread); 1.193 + static void throw_NullPointerException(JavaThread* thread); 1.194 + static void throw_NullPointerException_at_call(JavaThread* thread); 1.195 + static void throw_StackOverflowError(JavaThread* thread); 1.196 + static address continuation_for_implicit_exception(JavaThread* thread, 1.197 + address faulting_pc, 1.198 + ImplicitExceptionKind exception_kind); 1.199 + 1.200 + // Shared stub locations 1.201 + static address get_poll_stub(address pc); 1.202 + 1.203 + static address get_ic_miss_stub() { 1.204 + assert(_ic_miss_blob!= NULL, "oops"); 1.205 + return _ic_miss_blob->entry_point(); 1.206 + } 1.207 + 1.208 + static address get_handle_wrong_method_stub() { 1.209 + assert(_wrong_method_blob!= NULL, "oops"); 1.210 + return _wrong_method_blob->entry_point(); 1.211 + } 1.212 + 1.213 + static address get_handle_wrong_method_abstract_stub() { 1.214 + assert(_wrong_method_abstract_blob!= NULL, "oops"); 1.215 + return _wrong_method_abstract_blob->entry_point(); 1.216 + } 1.217 + 1.218 +#ifdef COMPILER2 1.219 + static void generate_uncommon_trap_blob(void); 1.220 + static UncommonTrapBlob* uncommon_trap_blob() { return _uncommon_trap_blob; } 1.221 +#endif // COMPILER2 1.222 + 1.223 + static address get_resolve_opt_virtual_call_stub(){ 1.224 + assert(_resolve_opt_virtual_call_blob != NULL, "oops"); 1.225 + return _resolve_opt_virtual_call_blob->entry_point(); 1.226 + } 1.227 + static address get_resolve_virtual_call_stub() { 1.228 + assert(_resolve_virtual_call_blob != NULL, "oops"); 1.229 + return _resolve_virtual_call_blob->entry_point(); 1.230 + } 1.231 + static address get_resolve_static_call_stub() { 1.232 + assert(_resolve_static_call_blob != NULL, "oops"); 1.233 + return _resolve_static_call_blob->entry_point(); 1.234 + } 1.235 + 1.236 + static SafepointBlob* polling_page_return_handler_blob() { return _polling_page_return_handler_blob; } 1.237 + static SafepointBlob* polling_page_safepoint_handler_blob() { return _polling_page_safepoint_handler_blob; } 1.238 + static SafepointBlob* polling_page_vectors_safepoint_handler_blob() { return _polling_page_vectors_safepoint_handler_blob; } 1.239 + 1.240 + // Counters 1.241 +#ifndef PRODUCT 1.242 + static address nof_megamorphic_calls_addr() { return (address)&_nof_megamorphic_calls; } 1.243 +#endif // PRODUCT 1.244 + 1.245 + // Helper routine for full-speed JVMTI exception throwing support 1.246 + static void throw_and_post_jvmti_exception(JavaThread *thread, Handle h_exception); 1.247 + static void throw_and_post_jvmti_exception(JavaThread *thread, Symbol* name, const char *message = NULL); 1.248 + 1.249 + // RedefineClasses() tracing support for obsolete method entry 1.250 + static int rc_trace_method_entry(JavaThread* thread, Method* m); 1.251 + 1.252 + // To be used as the entry point for unresolved native methods. 1.253 + static address native_method_throw_unsatisfied_link_error_entry(); 1.254 + static address native_method_throw_unsupported_operation_exception_entry(); 1.255 + 1.256 + // bytecode tracing is only used by the TraceBytecodes 1.257 + static intptr_t trace_bytecode(JavaThread* thread, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2) PRODUCT_RETURN0; 1.258 + 1.259 + // Used to back off a spin lock that is under heavy contention 1.260 + static void yield_all(JavaThread* thread, int attempts = 0); 1.261 + 1.262 + static oop retrieve_receiver( Symbol* sig, frame caller ); 1.263 + 1.264 + static void register_finalizer(JavaThread* thread, oopDesc* obj); 1.265 + 1.266 + // dtrace notifications 1.267 + static int dtrace_object_alloc(oopDesc* o, int size); 1.268 + static int dtrace_object_alloc_base(Thread* thread, oopDesc* o, int size); 1.269 + static int dtrace_method_entry(JavaThread* thread, Method* m); 1.270 + static int dtrace_method_exit(JavaThread* thread, Method* m); 1.271 + 1.272 + // Utility method for retrieving the Java thread id, returns 0 if the 1.273 + // thread is not a well formed Java thread. 1.274 + static jlong get_java_tid(Thread* thread); 1.275 + 1.276 + 1.277 + // used by native wrappers to reenable yellow if overflow happened in native code 1.278 + static void reguard_yellow_pages(); 1.279 + 1.280 + /** 1.281 + * Fill in the "X cannot be cast to a Y" message for ClassCastException 1.282 + * 1.283 + * @param thr the current thread 1.284 + * @param name the name of the class of the object attempted to be cast 1.285 + * @return the dynamically allocated exception message (must be freed 1.286 + * by the caller using a resource mark) 1.287 + * 1.288 + * BCP must refer to the current 'checkcast' opcode for the frame 1.289 + * on top of the stack. 1.290 + * The caller (or one of it's callers) must use a ResourceMark 1.291 + * in order to correctly free the result. 1.292 + */ 1.293 + static char* generate_class_cast_message(JavaThread* thr, const char* name); 1.294 + 1.295 + /** 1.296 + * Fill in the "X cannot be cast to a Y" message for ClassCastException 1.297 + * 1.298 + * @param name the name of the class of the object attempted to be cast 1.299 + * @param klass the name of the target klass attempt 1.300 + * @param gripe the specific kind of problem being reported 1.301 + * @return the dynamically allocated exception message (must be freed 1.302 + * by the caller using a resource mark) 1.303 + * 1.304 + * This version does not require access the frame, so it can be called 1.305 + * from interpreted code 1.306 + * The caller (or one of it's callers) must use a ResourceMark 1.307 + * in order to correctly free the result. 1.308 + */ 1.309 + static char* generate_class_cast_message(const char* name, const char* klass, 1.310 + const char* gripe = " cannot be cast to "); 1.311 + 1.312 + // Resolves a call site- may patch in the destination of the call into the 1.313 + // compiled code. 1.314 + static methodHandle resolve_helper(JavaThread *thread, 1.315 + bool is_virtual, 1.316 + bool is_optimized, TRAPS); 1.317 + 1.318 + private: 1.319 + // deopt blob 1.320 + static void generate_deopt_blob(void); 1.321 + 1.322 + public: 1.323 + static DeoptimizationBlob* deopt_blob(void) { return _deopt_blob; } 1.324 + 1.325 + // Resets a call-site in compiled code so it will get resolved again. 1.326 + static methodHandle reresolve_call_site(JavaThread *thread, TRAPS); 1.327 + 1.328 + // In the code prolog, if the klass comparison fails, the inline cache 1.329 + // misses and the call site is patched to megamorphic 1.330 + static methodHandle handle_ic_miss_helper(JavaThread* thread, TRAPS); 1.331 + 1.332 + // Find the method that called us. 1.333 + static methodHandle find_callee_method(JavaThread* thread, TRAPS); 1.334 + 1.335 + 1.336 + private: 1.337 + static Handle find_callee_info(JavaThread* thread, 1.338 + Bytecodes::Code& bc, 1.339 + CallInfo& callinfo, TRAPS); 1.340 + static Handle find_callee_info_helper(JavaThread* thread, 1.341 + vframeStream& vfst, 1.342 + Bytecodes::Code& bc, 1.343 + CallInfo& callinfo, TRAPS); 1.344 + 1.345 + static address clean_virtual_call_entry(); 1.346 + static address clean_opt_virtual_call_entry(); 1.347 + static address clean_static_call_entry(); 1.348 + 1.349 + public: 1.350 + 1.351 + // Read the array of BasicTypes from a Java signature, and compute where 1.352 + // compiled Java code would like to put the results. Values in reg_lo and 1.353 + // reg_hi refer to 4-byte quantities. Values less than SharedInfo::stack0 are 1.354 + // registers, those above refer to 4-byte stack slots. All stack slots are 1.355 + // based off of the window top. SharedInfo::stack0 refers to the first usable 1.356 + // slot in the bottom of the frame. SharedInfo::stack0+1 refers to the memory word 1.357 + // 4-bytes higher. So for sparc because the register window save area is at 1.358 + // the bottom of the frame the first 16 words will be skipped and SharedInfo::stack0 1.359 + // will be just above it. ( 1.360 + // return value is the maximum number of VMReg stack slots the convention will use. 1.361 + static int java_calling_convention(const BasicType* sig_bt, VMRegPair* regs, int total_args_passed, int is_outgoing); 1.362 + 1.363 + static void check_member_name_argument_is_last_argument(methodHandle method, 1.364 + const BasicType* sig_bt, 1.365 + const VMRegPair* regs) NOT_DEBUG_RETURN; 1.366 + 1.367 + // Ditto except for calling C 1.368 + // 1.369 + // C argument in register AND stack slot. 1.370 + // Some architectures require that an argument must be passed in a register 1.371 + // AND in a stack slot. These architectures provide a second VMRegPair array 1.372 + // to be filled by the c_calling_convention method. On other architectures, 1.373 + // NULL is being passed as the second VMRegPair array, so arguments are either 1.374 + // passed in a register OR in a stack slot. 1.375 + static int c_calling_convention(const BasicType *sig_bt, VMRegPair *regs, VMRegPair *regs2, 1.376 + int total_args_passed); 1.377 + 1.378 + // Compute the new number of arguments in the signature if 32 bit ints 1.379 + // must be converted to longs. Needed if CCallingConventionRequiresIntsAsLongs 1.380 + // is true. 1.381 + static int convert_ints_to_longints_argcnt(int in_args_count, BasicType* in_sig_bt); 1.382 + // Adapt a method's signature if it contains 32 bit integers that must 1.383 + // be converted to longs. Needed if CCallingConventionRequiresIntsAsLongs 1.384 + // is true. 1.385 + static void convert_ints_to_longints(int i2l_argcnt, int& in_args_count, 1.386 + BasicType*& in_sig_bt, VMRegPair*& in_regs); 1.387 + 1.388 + // Generate I2C and C2I adapters. These adapters are simple argument marshalling 1.389 + // blobs. Unlike adapters in the tiger and earlier releases the code in these 1.390 + // blobs does not create a new frame and are therefore virtually invisible 1.391 + // to the stack walking code. In general these blobs extend the callers stack 1.392 + // as needed for the conversion of argument locations. 1.393 + 1.394 + // When calling a c2i blob the code will always call the interpreter even if 1.395 + // by the time we reach the blob there is compiled code available. This allows 1.396 + // the blob to pass the incoming stack pointer (the sender sp) in a known 1.397 + // location for the interpreter to record. This is used by the frame code 1.398 + // to correct the sender code to match up with the stack pointer when the 1.399 + // thread left the compiled code. In addition it allows the interpreter 1.400 + // to remove the space the c2i adapter allocated to do its argument conversion. 1.401 + 1.402 + // Although a c2i blob will always run interpreted even if compiled code is 1.403 + // present if we see that compiled code is present the compiled call site 1.404 + // will be patched/re-resolved so that later calls will run compiled. 1.405 + 1.406 + // Aditionally a c2i blob need to have a unverified entry because it can be reached 1.407 + // in situations where the call site is an inlined cache site and may go megamorphic. 1.408 + 1.409 + // A i2c adapter is simpler than the c2i adapter. This is because it is assumed 1.410 + // that the interpreter before it does any call dispatch will record the current 1.411 + // stack pointer in the interpreter frame. On return it will restore the stack 1.412 + // pointer as needed. This means the i2c adapter code doesn't need any special 1.413 + // handshaking path with compiled code to keep the stack walking correct. 1.414 + 1.415 + static AdapterHandlerEntry* generate_i2c2i_adapters(MacroAssembler *_masm, 1.416 + int total_args_passed, 1.417 + int max_arg, 1.418 + const BasicType *sig_bt, 1.419 + const VMRegPair *regs, 1.420 + AdapterFingerPrint* fingerprint); 1.421 + 1.422 + // OSR support 1.423 + 1.424 + // OSR_migration_begin will extract the jvm state from an interpreter 1.425 + // frame (locals, monitors) and store the data in a piece of C heap 1.426 + // storage. This then allows the interpreter frame to be removed from the 1.427 + // stack and the OSR nmethod to be called. That method is called with a 1.428 + // pointer to the C heap storage. This pointer is the return value from 1.429 + // OSR_migration_begin. 1.430 + 1.431 + static intptr_t* OSR_migration_begin( JavaThread *thread); 1.432 + 1.433 + // OSR_migration_end is a trivial routine. It is called after the compiled 1.434 + // method has extracted the jvm state from the C heap that OSR_migration_begin 1.435 + // created. It's entire job is to simply free this storage. 1.436 + static void OSR_migration_end ( intptr_t* buf); 1.437 + 1.438 + // Convert a sig into a calling convention register layout 1.439 + // and find interesting things about it. 1.440 + static VMRegPair* find_callee_arguments(Symbol* sig, bool has_receiver, bool has_appendix, int *arg_size); 1.441 + static VMReg name_for_receiver(); 1.442 + 1.443 + // "Top of Stack" slots that may be unused by the calling convention but must 1.444 + // otherwise be preserved. 1.445 + // On Intel these are not necessary and the value can be zero. 1.446 + // On Sparc this describes the words reserved for storing a register window 1.447 + // when an interrupt occurs. 1.448 + static uint out_preserve_stack_slots(); 1.449 + 1.450 + // Is vector's size (in bytes) bigger than a size saved by default? 1.451 + // For example, on x86 16 bytes XMM registers are saved by default. 1.452 + static bool is_wide_vector(int size); 1.453 + 1.454 + // Save and restore a native result 1.455 + static void save_native_result(MacroAssembler *_masm, BasicType ret_type, int frame_slots ); 1.456 + static void restore_native_result(MacroAssembler *_masm, BasicType ret_type, int frame_slots ); 1.457 + 1.458 + // Generate a native wrapper for a given method. The method takes arguments 1.459 + // in the Java compiled code convention, marshals them to the native 1.460 + // convention (handlizes oops, etc), transitions to native, makes the call, 1.461 + // returns to java state (possibly blocking), unhandlizes any result and 1.462 + // returns. 1.463 + // 1.464 + // The wrapper may contain special-case code if the given method 1.465 + // is a JNI critical method, or a compiled method handle adapter, 1.466 + // such as _invokeBasic, _linkToVirtual, etc. 1.467 + static nmethod* generate_native_wrapper(MacroAssembler* masm, 1.468 + methodHandle method, 1.469 + int compile_id, 1.470 + BasicType* sig_bt, 1.471 + VMRegPair* regs, 1.472 + BasicType ret_type ); 1.473 + 1.474 + // Block before entering a JNI critical method 1.475 + static void block_for_jni_critical(JavaThread* thread); 1.476 + 1.477 +#ifdef HAVE_DTRACE_H 1.478 + // Generate a dtrace wrapper for a given method. The method takes arguments 1.479 + // in the Java compiled code convention, marshals them to the native 1.480 + // convention (handlizes oops, etc), transitions to native, makes the call, 1.481 + // returns to java state (possibly blocking), unhandlizes any result and 1.482 + // returns. 1.483 + static nmethod *generate_dtrace_nmethod(MacroAssembler* masm, 1.484 + methodHandle method); 1.485 + 1.486 + // dtrace support to convert a Java string to utf8 1.487 + static void get_utf(oopDesc* src, address dst); 1.488 +#endif // def HAVE_DTRACE_H 1.489 + 1.490 + // A compiled caller has just called the interpreter, but compiled code 1.491 + // exists. Patch the caller so he no longer calls into the interpreter. 1.492 + static void fixup_callers_callsite(Method* moop, address ret_pc); 1.493 + 1.494 + // Slow-path Locking and Unlocking 1.495 + static void complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* thread); 1.496 + static void complete_monitor_unlocking_C(oopDesc* obj, BasicLock* lock); 1.497 + 1.498 + // Resolving of calls 1.499 + static address resolve_static_call_C (JavaThread *thread); 1.500 + static address resolve_virtual_call_C (JavaThread *thread); 1.501 + static address resolve_opt_virtual_call_C(JavaThread *thread); 1.502 + 1.503 + // arraycopy, the non-leaf version. (See StubRoutines for all the leaf calls.) 1.504 + static void slow_arraycopy_C(oopDesc* src, jint src_pos, 1.505 + oopDesc* dest, jint dest_pos, 1.506 + jint length, JavaThread* thread); 1.507 + 1.508 + // handle ic miss with caller being compiled code 1.509 + // wrong method handling (inline cache misses, zombie methods) 1.510 + static address handle_wrong_method(JavaThread* thread); 1.511 + static address handle_wrong_method_abstract(JavaThread* thread); 1.512 + static address handle_wrong_method_ic_miss(JavaThread* thread); 1.513 + 1.514 +#ifndef PRODUCT 1.515 + 1.516 + // Collect and print inline cache miss statistics 1.517 + private: 1.518 + enum { maxICmiss_count = 100 }; 1.519 + static int _ICmiss_index; // length of IC miss histogram 1.520 + static int _ICmiss_count[maxICmiss_count]; // miss counts 1.521 + static address _ICmiss_at[maxICmiss_count]; // miss addresses 1.522 + static void trace_ic_miss(address at); 1.523 + 1.524 + public: 1.525 + static int _monitor_enter_ctr; // monitor enter slow 1.526 + static int _monitor_exit_ctr; // monitor exit slow 1.527 + static int _throw_null_ctr; // throwing a null-pointer exception 1.528 + static int _ic_miss_ctr; // total # of IC misses 1.529 + static int _wrong_method_ctr; 1.530 + static int _resolve_static_ctr; 1.531 + static int _resolve_virtual_ctr; 1.532 + static int _resolve_opt_virtual_ctr; 1.533 + static int _implicit_null_throws; 1.534 + static int _implicit_div0_throws; 1.535 + 1.536 + static int _jbyte_array_copy_ctr; // Slow-path byte array copy 1.537 + static int _jshort_array_copy_ctr; // Slow-path short array copy 1.538 + static int _jint_array_copy_ctr; // Slow-path int array copy 1.539 + static int _jlong_array_copy_ctr; // Slow-path long array copy 1.540 + static int _oop_array_copy_ctr; // Slow-path oop array copy 1.541 + static int _checkcast_array_copy_ctr; // Slow-path oop array copy, with cast 1.542 + static int _unsafe_array_copy_ctr; // Slow-path includes alignment checks 1.543 + static int _generic_array_copy_ctr; // Slow-path includes type decoding 1.544 + static int _slow_array_copy_ctr; // Slow-path failed out to a method call 1.545 + 1.546 + static int _new_instance_ctr; // 'new' object requires GC 1.547 + static int _new_array_ctr; // 'new' array requires GC 1.548 + static int _multi1_ctr, _multi2_ctr, _multi3_ctr, _multi4_ctr, _multi5_ctr; 1.549 + static int _find_handler_ctr; // find exception handler 1.550 + static int _rethrow_ctr; // rethrow exception 1.551 + static int _mon_enter_stub_ctr; // monitor enter stub 1.552 + static int _mon_exit_stub_ctr; // monitor exit stub 1.553 + static int _mon_enter_ctr; // monitor enter slow 1.554 + static int _mon_exit_ctr; // monitor exit slow 1.555 + static int _partial_subtype_ctr; // SubRoutines::partial_subtype_check 1.556 + 1.557 + // Statistics code 1.558 + // stats for "normal" compiled calls (non-interface) 1.559 + static int _nof_normal_calls; // total # of calls 1.560 + static int _nof_optimized_calls; // total # of statically-bound calls 1.561 + static int _nof_inlined_calls; // total # of inlined normal calls 1.562 + static int _nof_static_calls; // total # of calls to static methods or super methods (invokespecial) 1.563 + static int _nof_inlined_static_calls; // total # of inlined static calls 1.564 + // stats for compiled interface calls 1.565 + static int _nof_interface_calls; // total # of compiled calls 1.566 + static int _nof_optimized_interface_calls; // total # of statically-bound interface calls 1.567 + static int _nof_inlined_interface_calls; // total # of inlined interface calls 1.568 + static int _nof_megamorphic_interface_calls;// total # of megamorphic interface calls 1.569 + // stats for runtime exceptions 1.570 + static int _nof_removable_exceptions; // total # of exceptions that could be replaced by branches due to inlining 1.571 + 1.572 + public: // for compiler 1.573 + static address nof_normal_calls_addr() { return (address)&_nof_normal_calls; } 1.574 + static address nof_optimized_calls_addr() { return (address)&_nof_optimized_calls; } 1.575 + static address nof_inlined_calls_addr() { return (address)&_nof_inlined_calls; } 1.576 + static address nof_static_calls_addr() { return (address)&_nof_static_calls; } 1.577 + static address nof_inlined_static_calls_addr() { return (address)&_nof_inlined_static_calls; } 1.578 + static address nof_interface_calls_addr() { return (address)&_nof_interface_calls; } 1.579 + static address nof_optimized_interface_calls_addr() { return (address)&_nof_optimized_interface_calls; } 1.580 + static address nof_inlined_interface_calls_addr() { return (address)&_nof_inlined_interface_calls; } 1.581 + static address nof_megamorphic_interface_calls_addr() { return (address)&_nof_megamorphic_interface_calls; } 1.582 + static void print_call_statistics(int comp_total); 1.583 + static void print_statistics(); 1.584 + static void print_ic_miss_histogram(); 1.585 + 1.586 +#endif // PRODUCT 1.587 +}; 1.588 + 1.589 + 1.590 +// --------------------------------------------------------------------------- 1.591 +// Implementation of AdapterHandlerLibrary 1.592 +// 1.593 +// This library manages argument marshaling adapters and native wrappers. 1.594 +// There are 2 flavors of adapters: I2C and C2I. 1.595 +// 1.596 +// The I2C flavor takes a stock interpreted call setup, marshals the 1.597 +// arguments for a Java-compiled call, and jumps to Rmethod-> code()-> 1.598 +// code_begin(). It is broken to call it without an nmethod assigned. 1.599 +// The usual behavior is to lift any register arguments up out of the 1.600 +// stack and possibly re-pack the extra arguments to be contigious. 1.601 +// I2C adapters will save what the interpreter's stack pointer will be 1.602 +// after arguments are popped, then adjust the interpreter's frame 1.603 +// size to force alignment and possibly to repack the arguments. 1.604 +// After re-packing, it jumps to the compiled code start. There are 1.605 +// no safepoints in this adapter code and a GC cannot happen while 1.606 +// marshaling is in progress. 1.607 +// 1.608 +// The C2I flavor takes a stock compiled call setup plus the target method in 1.609 +// Rmethod, marshals the arguments for an interpreted call and jumps to 1.610 +// Rmethod->_i2i_entry. On entry, the interpreted frame has not yet been 1.611 +// setup. Compiled frames are fixed-size and the args are likely not in the 1.612 +// right place. Hence all the args will likely be copied into the 1.613 +// interpreter's frame, forcing that frame to grow. The compiled frame's 1.614 +// outgoing stack args will be dead after the copy. 1.615 +// 1.616 +// Native wrappers, like adapters, marshal arguments. Unlike adapters they 1.617 +// also perform an offical frame push & pop. They have a call to the native 1.618 +// routine in their middles and end in a return (instead of ending in a jump). 1.619 +// The native wrappers are stored in real nmethods instead of the BufferBlobs 1.620 +// used by the adapters. The code generation happens here because it's very 1.621 +// similar to what the adapters have to do. 1.622 + 1.623 +class AdapterHandlerEntry : public BasicHashtableEntry<mtCode> { 1.624 + friend class AdapterHandlerTable; 1.625 + 1.626 + private: 1.627 + AdapterFingerPrint* _fingerprint; 1.628 + address _i2c_entry; 1.629 + address _c2i_entry; 1.630 + address _c2i_unverified_entry; 1.631 + 1.632 +#ifdef ASSERT 1.633 + // Captures code and signature used to generate this adapter when 1.634 + // verifing adapter equivalence. 1.635 + unsigned char* _saved_code; 1.636 + int _saved_code_length; 1.637 +#endif 1.638 + 1.639 + void init(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry, address c2i_unverified_entry) { 1.640 + _fingerprint = fingerprint; 1.641 + _i2c_entry = i2c_entry; 1.642 + _c2i_entry = c2i_entry; 1.643 + _c2i_unverified_entry = c2i_unverified_entry; 1.644 +#ifdef ASSERT 1.645 + _saved_code = NULL; 1.646 + _saved_code_length = 0; 1.647 +#endif 1.648 + } 1.649 + 1.650 + void deallocate(); 1.651 + 1.652 + // should never be used 1.653 + AdapterHandlerEntry(); 1.654 + 1.655 + public: 1.656 + address get_i2c_entry() const { return _i2c_entry; } 1.657 + address get_c2i_entry() const { return _c2i_entry; } 1.658 + address get_c2i_unverified_entry() const { return _c2i_unverified_entry; } 1.659 + address base_address(); 1.660 + void relocate(address new_base); 1.661 + 1.662 + AdapterFingerPrint* fingerprint() const { return _fingerprint; } 1.663 + 1.664 + AdapterHandlerEntry* next() { 1.665 + return (AdapterHandlerEntry*)BasicHashtableEntry<mtCode>::next(); 1.666 + } 1.667 + 1.668 +#ifdef ASSERT 1.669 + // Used to verify that code generated for shared adapters is equivalent 1.670 + void save_code (unsigned char* code, int length); 1.671 + bool compare_code(unsigned char* code, int length); 1.672 +#endif 1.673 + 1.674 + //virtual void print_on(outputStream* st) const; DO NOT USE 1.675 + void print_adapter_on(outputStream* st) const; 1.676 +}; 1.677 + 1.678 +class AdapterHandlerLibrary: public AllStatic { 1.679 + private: 1.680 + static BufferBlob* _buffer; // the temporary code buffer in CodeCache 1.681 + static AdapterHandlerTable* _adapters; 1.682 + static AdapterHandlerEntry* _abstract_method_handler; 1.683 + static BufferBlob* buffer_blob(); 1.684 + static void initialize(); 1.685 + 1.686 + public: 1.687 + 1.688 + static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint, 1.689 + address i2c_entry, address c2i_entry, address c2i_unverified_entry); 1.690 + static void create_native_wrapper(methodHandle method); 1.691 + static AdapterHandlerEntry* get_adapter(methodHandle method); 1.692 + 1.693 +#ifdef HAVE_DTRACE_H 1.694 + static nmethod* create_dtrace_nmethod (methodHandle method); 1.695 +#endif // HAVE_DTRACE_H 1.696 + 1.697 + static void print_handler(CodeBlob* b) { print_handler_on(tty, b); } 1.698 + static void print_handler_on(outputStream* st, CodeBlob* b); 1.699 + static bool contains(CodeBlob* b); 1.700 +#ifndef PRODUCT 1.701 + static void print_statistics(); 1.702 +#endif /* PRODUCT */ 1.703 + 1.704 +}; 1.705 + 1.706 +#endif // SHARE_VM_RUNTIME_SHAREDRUNTIME_HPP