sharedRuntime.hpp revision 5776:de6a9e811145
1139826Simp/* 253541Sshin * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 353541Sshin * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 453541Sshin * 553541Sshin * This code is free software; you can redistribute it and/or modify it 653541Sshin * under the terms of the GNU General Public License version 2 only, as 753541Sshin * published by the Free Software Foundation. 853541Sshin * 953541Sshin * This code is distributed in the hope that it will be useful, but WITHOUT 1053541Sshin * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1153541Sshin * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1253541Sshin * version 2 for more details (a copy is included in the LICENSE file that 1353541Sshin * accompanied this code). 1453541Sshin * 1553541Sshin * You should have received a copy of the GNU General Public License version 1653541Sshin * 2 along with this work; if not, write to the Free Software Foundation, 1753541Sshin * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1853541Sshin * 1953541Sshin * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2053541Sshin * or visit www.oracle.com if you need additional information or have any 2153541Sshin * questions. 2253541Sshin * 2353541Sshin */ 2453541Sshin 2553541Sshin#ifndef SHARE_VM_RUNTIME_SHAREDRUNTIME_HPP 2653541Sshin#define SHARE_VM_RUNTIME_SHAREDRUNTIME_HPP 2753541Sshin 28174510Sobrien#include "interpreter/bytecodeHistogram.hpp" 29174510Sobrien#include "interpreter/bytecodeTracer.hpp" 3053541Sshin#include "interpreter/linkResolver.hpp" 3153541Sshin#include "memory/allocation.hpp" 32174510Sobrien#include "memory/resourceArea.hpp" 33174510Sobrien#include "runtime/threadLocalStorage.hpp" 34174510Sobrien#include "utilities/hashtable.hpp" 3562587Sitojun#include "utilities/macros.hpp" 3662587Sitojun 3762587Sitojunclass AdapterHandlerEntry; 3853541Sshinclass AdapterHandlerTable; 3953541Sshinclass AdapterFingerPrint; 4053541Sshinclass vframeStream; 4153541Sshin 4253541Sshin// Runtime is the base class for various runtime interfaces 4353541Sshin// (InterpreterRuntime, CompilerRuntime, etc.). It provides 4453541Sshin// shared functionality such as exception forwarding (C++ to 4578064Sume// Java exceptions), locking/unlocking mechanisms, statistical 46185751Simp// information, etc. 4753541Sshin 48185747Skmacyclass SharedRuntime: AllStatic { 4953541Sshin friend class VMStructs; 5078064Sume 5153541Sshin private: 5253541Sshin static methodHandle resolve_sub_helper(JavaThread *thread, 5353541Sshin bool is_virtual, 5453541Sshin bool is_optimized, TRAPS); 5553541Sshin 5653541Sshin // Shared stub locations 57185571Sbz 5853541Sshin static RuntimeStub* _wrong_method_blob; 5953541Sshin static RuntimeStub* _wrong_method_abstract_blob; 60186119Sqingli static RuntimeStub* _ic_miss_blob; 6153541Sshin static RuntimeStub* _resolve_opt_virtual_call_blob; 6278064Sume static RuntimeStub* _resolve_virtual_call_blob; 6362587Sitojun static RuntimeStub* _resolve_static_call_blob; 6453541Sshin 6553541Sshin static DeoptimizationBlob* _deopt_blob; 6662587Sitojun 6762587Sitojun static SafepointBlob* _polling_page_vectors_safepoint_handler_blob; 6853541Sshin static SafepointBlob* _polling_page_safepoint_handler_blob; 69175162Sobrien static SafepointBlob* _polling_page_return_handler_blob; 70175162Sobrien 71241916Sdelphij#ifdef COMPILER2 72241916Sdelphij static UncommonTrapBlob* _uncommon_trap_blob; 73241916Sdelphij#endif // COMPILER2 74241916Sdelphij 75241916Sdelphij#ifndef PRODUCT 76175162Sobrien // Counters 77175162Sobrien static int _nof_megamorphic_calls; // total # of megamorphic calls (through vtable) 7862587Sitojun#endif // !PRODUCT 79175162Sobrien 80175162Sobrien private: 81175162Sobrien enum { POLL_AT_RETURN, POLL_AT_LOOP, POLL_AT_VECTOR_LOOP }; 8253541Sshin static SafepointBlob* generate_handler_blob(address call_ptr, int poll_type); 83175162Sobrien static RuntimeStub* generate_resolve_blob(address destination, const char* name); 84241916Sdelphij 85241916Sdelphij public: 8653541Sshin static void generate_stubs(void); 87229547Sbz 88229547Sbz // max bytes for each dtrace string parameter 89229547Sbz enum { max_dtrace_string_size = 256 }; 90175162Sobrien 9153541Sshin // The following arithmetic routines are used on platforms that do 92195699Srwatson // not have machine instructions to implement their functionality. 93195727Srwatson // Do not remove these. 9453541Sshin 95215701Sdim // long arithmetics 96207369Sbz static jlong lmul(jlong y, jlong x); 97195727Srwatson static jlong ldiv(jlong y, jlong x); 9862587Sitojun static jlong lrem(jlong y, jlong x); 99207369Sbz 100207369Sbz // float and double remainder 101195699Srwatson static jfloat frem(jfloat x, jfloat y); 102207369Sbz static jdouble drem(jdouble x, jdouble y); 103207369Sbz 10478064Sume#ifdef __SOFTFP__ 105207369Sbz static jfloat fadd(jfloat x, jfloat y); 106207369Sbz static jfloat fsub(jfloat x, jfloat y); 107151539Ssuz static jfloat fmul(jfloat x, jfloat y); 108151539Ssuz static jfloat fdiv(jfloat x, jfloat y); 109151539Ssuz 110151539Ssuz static jdouble dadd(jdouble x, jdouble y); 111151539Ssuz static jdouble dsub(jdouble x, jdouble y); 112151539Ssuz static jdouble dmul(jdouble x, jdouble y); 113151539Ssuz static jdouble ddiv(jdouble x, jdouble y); 11478064Sume#endif // __SOFTFP__ 11553541Sshin 11653541Sshin // float conversion (needs to set appropriate rounding mode) 11753541Sshin static jint f2i (jfloat x); 11853541Sshin static jlong f2l (jfloat x); 11953541Sshin static jint d2i (jdouble x); 12053541Sshin static jlong d2l (jdouble x); 12153541Sshin static jfloat d2f (jdouble x); 122171259Sdelphij static jfloat l2f (jlong x); 12353541Sshin static jdouble l2d (jlong x); 12453541Sshin 12553541Sshin#ifdef __SOFTFP__ 12662587Sitojun static jfloat i2f (jint x); 12753541Sshin static jdouble i2d (jint x); 12853541Sshin static jdouble f2d (jfloat x); 12953541Sshin#endif // __SOFTFP__ 13053541Sshin 131165118Sbz // double trigonometrics and transcendentals 13253541Sshin static jdouble dsin(jdouble x); 133222728Shrs static jdouble dcos(jdouble x); 134222728Shrs static jdouble dtan(jdouble x); 135222728Shrs static jdouble dlog(jdouble x); 136222728Shrs static jdouble dlog10(jdouble x); 137222728Shrs static jdouble dexp(jdouble x); 13862587Sitojun static jdouble dpow(jdouble x, jdouble y); 13953541Sshin 14053541Sshin#if defined(__SOFTFP__) || defined(E500V2) 14153541Sshin static double dabs(double f); 14278064Sume#endif 14378064Sume 144165118Sbz#if defined(__SOFTFP__) || defined(PPC) 145165118Sbz static double dsqrt(double f); 14678064Sume#endif 14753541Sshin 14853541Sshin#ifdef __SOFTFP__ 14953541Sshin // C++ compiler generates soft float instructions as well as passing 15053541Sshin // float and double in registers. 15153541Sshin static int fcmpl(float x, float y); 15253541Sshin static int fcmpg(float x, float y); 15353541Sshin static int dcmpl(double x, double y); 15462587Sitojun static int dcmpg(double x, double y); 15562587Sitojun 15662587Sitojun static int unordered_fcmplt(float x, float y); 15762587Sitojun static int unordered_dcmplt(double x, double y); 15862587Sitojun static int unordered_fcmple(float x, float y); 15962587Sitojun static int unordered_dcmple(double x, double y); 16062587Sitojun static int unordered_fcmpge(float x, float y); 16162587Sitojun static int unordered_dcmpge(double x, double y); 162190964Srwatson static int unordered_fcmpgt(float x, float y); 16353541Sshin static int unordered_dcmpgt(double x, double y); 16462587Sitojun 16562587Sitojun static float fneg(float f); 16653541Sshin static double dneg(double f); 16753541Sshin#endif 16853541Sshin 16953541Sshin // exception handling across interpreter/compiler boundaries 17078064Sume static address raw_exception_handler_for_return_address(JavaThread* thread, address return_address); 17178064Sume static address exception_handler_for_return_address(JavaThread* thread, address return_address); 17278064Sume 17362587Sitojun#if INCLUDE_ALL_GCS 17453541Sshin // G1 write barriers 17553541Sshin static void g1_wb_pre(oopDesc* orig, JavaThread *thread); 17653541Sshin static void g1_wb_post(void* card_addr, JavaThread* thread); 17753541Sshin#endif // INCLUDE_ALL_GCS 17853541Sshin 17953541Sshin // exception handling and implicit exceptions 18053541Sshin static address compute_compiled_exc_handler(nmethod* nm, address ret_pc, Handle& exception, 18153541Sshin bool force_unwind, bool top_frame_only); 18278064Sume enum ImplicitExceptionKind { 18353541Sshin IMPLICIT_NULL, 18453541Sshin IMPLICIT_DIVIDE_BY_ZERO, 185165118Sbz STACK_OVERFLOW 186120941Sume }; 18778064Sume static void throw_AbstractMethodError(JavaThread* thread); 18853541Sshin static void throw_IncompatibleClassChangeError(JavaThread* thread); 18953541Sshin static void throw_ArithmeticException(JavaThread* thread); 19053541Sshin static void throw_NullPointerException(JavaThread* thread); 19162587Sitojun static void throw_NullPointerException_at_call(JavaThread* thread); 19262587Sitojun static void throw_StackOverflowError(JavaThread* thread); 19362587Sitojun static address continuation_for_implicit_exception(JavaThread* thread, 19478064Sume address faulting_pc, 19578064Sume ImplicitExceptionKind exception_kind); 19678064Sume 197190964Srwatson // Shared stub locations 19878064Sume static address get_poll_stub(address pc); 19953541Sshin 20053541Sshin static address get_ic_miss_stub() { 20153541Sshin assert(_ic_miss_blob!= NULL, "oops"); 20253541Sshin return _ic_miss_blob->entry_point(); 20353541Sshin } 20453541Sshin 20553541Sshin static address get_handle_wrong_method_stub() { 20653541Sshin assert(_wrong_method_blob!= NULL, "oops"); 20753541Sshin return _wrong_method_blob->entry_point(); 20853541Sshin } 209171259Sdelphij 21053541Sshin static address get_handle_wrong_method_abstract_stub() { 21153541Sshin assert(_wrong_method_abstract_blob!= NULL, "oops"); 212121161Sume return _wrong_method_abstract_blob->entry_point(); 21353541Sshin } 21462587Sitojun 21553541Sshin#ifdef COMPILER2 216151539Ssuz static void generate_uncommon_trap_blob(void); 21753541Sshin static UncommonTrapBlob* uncommon_trap_blob() { return _uncommon_trap_blob; } 21853541Sshin#endif // COMPILER2 219165118Sbz 22053541Sshin static address get_resolve_opt_virtual_call_stub(){ 221118498Sume assert(_resolve_opt_virtual_call_blob != NULL, "oops"); 222222728Shrs return _resolve_opt_virtual_call_blob->entry_point(); 223222728Shrs } 224118498Sume static address get_resolve_virtual_call_stub() { 225222728Shrs assert(_resolve_virtual_call_blob != NULL, "oops"); 22662587Sitojun return _resolve_virtual_call_blob->entry_point(); 22753541Sshin } 22853541Sshin static address get_resolve_static_call_stub() { 22978064Sume assert(_resolve_static_call_blob != NULL, "oops"); 23078064Sume return _resolve_static_call_blob->entry_point(); 231165118Sbz } 232165118Sbz 23378064Sume static SafepointBlob* polling_page_return_handler_blob() { return _polling_page_return_handler_blob; } 23453541Sshin static SafepointBlob* polling_page_safepoint_handler_blob() { return _polling_page_safepoint_handler_blob; } 23553541Sshin static SafepointBlob* polling_page_vectors_safepoint_handler_blob() { return _polling_page_vectors_safepoint_handler_blob; } 23653541Sshin 23778064Sume // Counters 23853541Sshin#ifndef PRODUCT 239165118Sbz static address nof_megamorphic_calls_addr() { return (address)&_nof_megamorphic_calls; } 24078064Sume#endif // PRODUCT 24162587Sitojun 24262587Sitojun // Helper routine for full-speed JVMTI exception throwing support 24362587Sitojun static void throw_and_post_jvmti_exception(JavaThread *thread, Handle h_exception); 24462587Sitojun static void throw_and_post_jvmti_exception(JavaThread *thread, Symbol* name, const char *message = NULL); 24562587Sitojun 24662587Sitojun // RedefineClasses() tracing support for obsolete method entry 24762587Sitojun static int rc_trace_method_entry(JavaThread* thread, Method* m); 24862587Sitojun 249190964Srwatson // To be used as the entry point for unresolved native methods. 25053541Sshin static address native_method_throw_unsatisfied_link_error_entry(); 25153541Sshin static address native_method_throw_unsupported_operation_exception_entry(); 25262587Sitojun 25353541Sshin // bytecode tracing is only used by the TraceBytecodes 25453541Sshin static intptr_t trace_bytecode(JavaThread* thread, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2) PRODUCT_RETURN0; 25553541Sshin 25653541Sshin // Used to back off a spin lock that is under heavy contention 25778064Sume static void yield_all(JavaThread* thread, int attempts = 0); 25878064Sume 25978064Sume static oop retrieve_receiver( Symbol* sig, frame caller ); 26062587Sitojun 26153541Sshin static void register_finalizer(JavaThread* thread, oopDesc* obj); 26253541Sshin 26353541Sshin // dtrace notifications 26453541Sshin static int dtrace_object_alloc(oopDesc* o); 26553541Sshin static int dtrace_object_alloc_base(Thread* thread, oopDesc* o); 26653541Sshin static int dtrace_method_entry(JavaThread* thread, Method* m); 267151539Ssuz static int dtrace_method_exit(JavaThread* thread, Method* m); 268151539Ssuz 269151539Ssuz // Utility method for retrieving the Java thread id, returns 0 if the 270151539Ssuz // thread is not a well formed Java thread. 271151539Ssuz static jlong get_java_tid(Thread* thread); 27253541Sshin 27353541Sshin 274222728Shrs // used by native wrappers to reenable yellow if overflow happened in native code 275225521Shrs static void reguard_yellow_pages(); 276225521Shrs 277225521Shrs /** 278222728Shrs * Fill in the "X cannot be cast to a Y" message for ClassCastException 279225521Shrs * 280222728Shrs * @param thr the current thread 281225521Shrs * @param name the name of the class of the object attempted to be cast 282225521Shrs * @return the dynamically allocated exception message (must be freed 283222728Shrs * by the caller using a resource mark) 284222728Shrs * 285253970Shrs * BCP must refer to the current 'checkcast' opcode for the frame 28653541Sshin * on top of the stack. 28753541Sshin * The caller (or one of it's callers) must use a ResourceMark 28853541Sshin * in order to correctly free the result. 28990868Smike */ 29053541Sshin static char* generate_class_cast_message(JavaThread* thr, const char* name); 29153541Sshin 29253541Sshin /** 29353541Sshin * Fill in the "X cannot be cast to a Y" message for ClassCastException 294181803Sbz * 29553541Sshin * @param name the name of the class of the object attempted to be cast 29653541Sshin * @param klass the name of the target klass attempt 29753541Sshin * @param gripe the specific kind of problem being reported 29853541Sshin * @return the dynamically allocated exception message (must be freed 299281232Sdelphij * by the caller using a resource mark) 300281232Sdelphij * 301281232Sdelphij * This version does not require access the frame, so it can be called 302281232Sdelphij * from interpreted code 303281232Sdelphij * The caller (or one of it's callers) must use a ResourceMark 304281232Sdelphij * in order to correctly free the result. 305281232Sdelphij */ 306281232Sdelphij static char* generate_class_cast_message(const char* name, const char* klass, 307281232Sdelphij const char* gripe = " cannot be cast to "); 308281232Sdelphij 30953541Sshin // Resolves a call site- may patch in the destination of the call into the 31053541Sshin // compiled code. 31153541Sshin static methodHandle resolve_helper(JavaThread *thread, 31253541Sshin bool is_virtual, 31353541Sshin bool is_optimized, TRAPS); 31453541Sshin 31553541Sshin private: 31653541Sshin // deopt blob 31778064Sume static void generate_deopt_blob(void); 318151539Ssuz 31953541Sshin public: 32053541Sshin static DeoptimizationBlob* deopt_blob(void) { return _deopt_blob; } 32153541Sshin 32253541Sshin // Resets a call-site in compiled code so it will get resolved again. 32353541Sshin static methodHandle reresolve_call_site(JavaThread *thread, TRAPS); 32453541Sshin 32553541Sshin // In the code prolog, if the klass comparison fails, the inline cache 32653541Sshin // misses and the call site is patched to megamorphic 32753541Sshin static methodHandle handle_ic_miss_helper(JavaThread* thread, TRAPS); 32853541Sshin 32978064Sume // Find the method that called us. 33078064Sume static methodHandle find_callee_method(JavaThread* thread, TRAPS); 33178064Sume 33278064Sume 33353541Sshin private: 33453541Sshin static Handle find_callee_info(JavaThread* thread, 33553541Sshin Bytecodes::Code& bc, 33653541Sshin CallInfo& callinfo, TRAPS); 33778064Sume static Handle find_callee_info_helper(JavaThread* thread, 33878064Sume vframeStream& vfst, 33978064Sume Bytecodes::Code& bc, 34078064Sume CallInfo& callinfo, TRAPS); 34153541Sshin 34253541Sshin static address clean_virtual_call_entry(); 34353541Sshin static address clean_opt_virtual_call_entry(); 34453541Sshin static address clean_static_call_entry(); 34553541Sshin 34678064Sume public: 34778064Sume 34878064Sume // Read the array of BasicTypes from a Java signature, and compute where 349165118Sbz // compiled Java code would like to put the results. Values in reg_lo and 350165118Sbz // reg_hi refer to 4-byte quantities. Values less than SharedInfo::stack0 are 35153541Sshin // registers, those above refer to 4-byte stack slots. All stack slots are 35253541Sshin // based off of the window top. SharedInfo::stack0 refers to the first usable 35353541Sshin // slot in the bottom of the frame. SharedInfo::stack0+1 refers to the memory word 35453541Sshin // 4-bytes higher. So for sparc because the register window save area is at 35553541Sshin // the bottom of the frame the first 16 words will be skipped and SharedInfo::stack0 35653541Sshin // will be just above it. ( 35753541Sshin // return value is the maximum number of VMReg stack slots the convention will use. 35853541Sshin static int java_calling_convention(const BasicType* sig_bt, VMRegPair* regs, int total_args_passed, int is_outgoing); 35953541Sshin 36053541Sshin static void check_member_name_argument_is_last_argument(methodHandle method, 361120941Sume const BasicType* sig_bt, 36253541Sshin const VMRegPair* regs) NOT_DEBUG_RETURN; 363120941Sume 36453541Sshin // Ditto except for calling C 36553541Sshin static int c_calling_convention(const BasicType *sig_bt, VMRegPair *regs, int total_args_passed); 366120941Sume 367151539Ssuz // Generate I2C and C2I adapters. These adapters are simple argument marshalling 36853541Sshin // blobs. Unlike adapters in the tiger and earlier releases the code in these 36953541Sshin // blobs does not create a new frame and are therefore virtually invisible 37053541Sshin // to the stack walking code. In general these blobs extend the callers stack 37153541Sshin // as needed for the conversion of argument locations. 37253541Sshin 37353541Sshin // When calling a c2i blob the code will always call the interpreter even if 37453541Sshin // by the time we reach the blob there is compiled code available. This allows 375121283Sume // the blob to pass the incoming stack pointer (the sender sp) in a known 376121283Sume // location for the interpreter to record. This is used by the frame code 37753541Sshin // to correct the sender code to match up with the stack pointer when the 378121283Sume // thread left the compiled code. In addition it allows the interpreter 379120941Sume // to remove the space the c2i adapter allocated to do it argument conversion. 38053541Sshin 38153541Sshin // Although a c2i blob will always run interpreted even if compiled code is 38278064Sume // present if we see that compiled code is present the compiled call site 383121283Sume // will be patched/re-resolved so that later calls will run compiled. 384165118Sbz 38553541Sshin // Aditionally a c2i blob need to have a unverified entry because it can be reached 38653541Sshin // in situations where the call site is an inlined cache site and may go megamorphic. 38753541Sshin 38853541Sshin // A i2c adapter is simpler than the c2i adapter. This is because it is assumed 389121283Sume // that the interpreter before it does any call dispatch will record the current 390121283Sume // stack pointer in the interpreter frame. On return it will restore the stack 391121283Sume // pointer as needed. This means the i2c adapter code doesn't need any special 392121283Sume // handshaking path with compiled code to keep the stack walking correct. 39353541Sshin 394121283Sume static AdapterHandlerEntry* generate_i2c2i_adapters(MacroAssembler *_masm, 395121283Sume int total_args_passed, 396121283Sume int max_arg, 39753541Sshin const BasicType *sig_bt, 398121283Sume const VMRegPair *regs, 399121283Sume AdapterFingerPrint* fingerprint); 400121283Sume 401165118Sbz // OSR support 40253541Sshin 40353541Sshin // OSR_migration_begin will extract the jvm state from an interpreter 40453541Sshin // frame (locals, monitors) and store the data in a piece of C heap 40553541Sshin // storage. This then allows the interpreter frame to be removed from the 406120941Sume // stack and the OSR nmethod to be called. That method is called with a 40753541Sshin // pointer to the C heap storage. This pointer is the return value from 40895023Ssuz // OSR_migration_begin. 40953541Sshin 41053541Sshin static intptr_t* OSR_migration_begin( JavaThread *thread); 41153541Sshin 41253541Sshin // OSR_migration_end is a trivial routine. It is called after the compiled 413120941Sume // method has extracted the jvm state from the C heap that OSR_migration_begin 41453541Sshin // created. It's entire job is to simply free this storage. 41553541Sshin static void OSR_migration_end ( intptr_t* buf); 41653541Sshin 41753541Sshin // Convert a sig into a calling convention register layout 41853541Sshin // and find interesting things about it. 41953541Sshin static VMRegPair* find_callee_arguments(Symbol* sig, bool has_receiver, bool has_appendix, int *arg_size); 42078064Sume static VMReg name_for_receiver(); 42153541Sshin 422165118Sbz // "Top of Stack" slots that may be unused by the calling convention but must 423120941Sume // otherwise be preserved. 42478064Sume // On Intel these are not necessary and the value can be zero. 42553541Sshin // On Sparc this describes the words reserved for storing a register window 42653541Sshin // when an interrupt occurs. 427120941Sume static uint out_preserve_stack_slots(); 428120941Sume 42962587Sitojun // Is vector's size (in bytes) bigger than a size saved by default? 43062587Sitojun // For example, on x86 16 bytes XMM registers are saved by default. 43162587Sitojun static bool is_wide_vector(int size); 43262587Sitojun 43362587Sitojun // Save and restore a native result 43462587Sitojun static void save_native_result(MacroAssembler *_masm, BasicType ret_type, int frame_slots ); 43562587Sitojun static void restore_native_result(MacroAssembler *_masm, BasicType ret_type, int frame_slots ); 43653541Sshin 43762587Sitojun // Generate a native wrapper for a given method. The method takes arguments 43878064Sume // in the Java compiled code convention, marshals them to the native 43962587Sitojun // convention (handlizes oops, etc), transitions to native, makes the call, 44078064Sume // returns to java state (possibly blocking), unhandlizes any result and 44178064Sume // returns. 44278064Sume // 443190964Srwatson // The wrapper may contain special-case code if the given method 44478064Sume // is a JNI critical method, or a compiled method handle adapter, 44553541Sshin // such as _invokeBasic, _linkToVirtual, etc. 44653541Sshin static nmethod* generate_native_wrapper(MacroAssembler* masm, 44753541Sshin methodHandle method, 44853541Sshin int compile_id, 44953541Sshin BasicType* sig_bt, 45062587Sitojun VMRegPair* regs, 45162587Sitojun BasicType ret_type ); 45262587Sitojun 453171259Sdelphij // Block before entering a JNI critical method 45462587Sitojun static void block_for_jni_critical(JavaThread* thread); 45562587Sitojun 456191337Srwatson#ifdef HAVE_DTRACE_H 457194760Srwatson // Generate a dtrace wrapper for a given method. The method takes arguments 45862587Sitojun // in the Java compiled code convention, marshals them to the native 45962587Sitojun // convention (handlizes oops, etc), transitions to native, makes the call, 46062587Sitojun // returns to java state (possibly blocking), unhandlizes any result and 46162587Sitojun // returns. 46262587Sitojun static nmethod *generate_dtrace_nmethod(MacroAssembler* masm, 463191337Srwatson methodHandle method); 464191337Srwatson 465229621Sjhb // dtrace support to convert a Java string to utf8 466194760Srwatson static void get_utf(oopDesc* src, address dst); 467194760Srwatson#endif // def HAVE_DTRACE_H 468194760Srwatson 469229621Sjhb // A compiled caller has just called the interpreter, but compiled code 470151539Ssuz // exists. Patch the caller so he no longer calls into the interpreter. 471194760Srwatson static void fixup_callers_callsite(Method* moop, address ret_pc); 472194760Srwatson 47362587Sitojun // Slow-path Locking and Unlocking 474231852Sbz static void complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* thread); 475194760Srwatson static void complete_monitor_unlocking_C(oopDesc* obj, BasicLock* lock); 476194760Srwatson 47762587Sitojun // Resolving of calls 47862587Sitojun static address resolve_static_call_C (JavaThread *thread); 479229547Sbz static address resolve_virtual_call_C (JavaThread *thread); 480171259Sdelphij static address resolve_opt_virtual_call_C(JavaThread *thread); 48153541Sshin 48253541Sshin // arraycopy, the non-leaf version. (See StubRoutines for all the leaf calls.) 48362587Sitojun static void slow_arraycopy_C(oopDesc* src, jint src_pos, 484151539Ssuz oopDesc* dest, jint dest_pos, 48553541Sshin jint length, JavaThread* thread); 486128397Sluigi 487128397Sluigi // handle ic miss with caller being compiled code 488128397Sluigi // wrong method handling (inline cache misses, zombie methods) 48953541Sshin static address handle_wrong_method(JavaThread* thread); 490120941Sume static address handle_wrong_method_abstract(JavaThread* thread); 491120941Sume static address handle_wrong_method_ic_miss(JavaThread* thread); 492151539Ssuz 49353541Sshin#ifndef PRODUCT 49453541Sshin 495231852Sbz // Collect and print inline cache miss statistics 496120941Sume private: 497231852Sbz enum { maxICmiss_count = 100 }; 49862587Sitojun static int _ICmiss_index; // length of IC miss histogram 49978064Sume static int _ICmiss_count[maxICmiss_count]; // miss counts 500186119Sqingli static address _ICmiss_at[maxICmiss_count]; // miss addresses 50162587Sitojun static void trace_ic_miss(address at); 502151539Ssuz 503151539Ssuz public: 50453541Sshin static int _monitor_enter_ctr; // monitor enter slow 50553541Sshin static int _monitor_exit_ctr; // monitor exit slow 50653541Sshin static int _throw_null_ctr; // throwing a null-pointer exception 50753541Sshin static int _ic_miss_ctr; // total # of IC misses 508171259Sdelphij static int _wrong_method_ctr; 50953541Sshin static int _resolve_static_ctr; 51053541Sshin static int _resolve_virtual_ctr; 51153541Sshin static int _resolve_opt_virtual_ctr; 512228966Sjhb static int _implicit_null_throws; 51353541Sshin static int _implicit_div0_throws; 514120856Sume 51562587Sitojun static int _jbyte_array_copy_ctr; // Slow-path byte array copy 51653541Sshin static int _jshort_array_copy_ctr; // Slow-path short array copy 517120856Sume static int _jint_array_copy_ctr; // Slow-path int array copy 51853541Sshin static int _jlong_array_copy_ctr; // Slow-path long array copy 51953541Sshin static int _oop_array_copy_ctr; // Slow-path oop array copy 520151539Ssuz static int _checkcast_array_copy_ctr; // Slow-path oop array copy, with cast 521151539Ssuz static int _unsafe_array_copy_ctr; // Slow-path includes alignment checks 522151539Ssuz static int _generic_array_copy_ctr; // Slow-path includes type decoding 523151539Ssuz static int _slow_array_copy_ctr; // Slow-path failed out to a method call 524151539Ssuz 525151539Ssuz static int _new_instance_ctr; // 'new' object requires GC 526171259Sdelphij static int _new_array_ctr; // 'new' array requires GC 52753541Sshin static int _multi1_ctr, _multi2_ctr, _multi3_ctr, _multi4_ctr, _multi5_ctr; 52853541Sshin static int _find_handler_ctr; // find exception handler 52962587Sitojun static int _rethrow_ctr; // rethrow exception 53053541Sshin static int _mon_enter_stub_ctr; // monitor enter stub 531128397Sluigi static int _mon_exit_stub_ctr; // monitor exit stub 532128397Sluigi static int _mon_enter_ctr; // monitor enter slow 533128397Sluigi static int _mon_exit_ctr; // monitor exit slow 53453541Sshin static int _partial_subtype_ctr; // SubRoutines::partial_subtype_check 535120941Sume 536120941Sume // Statistics code 537151539Ssuz // stats for "normal" compiled calls (non-interface) 53853541Sshin static int _nof_normal_calls; // total # of calls 53953541Sshin static int _nof_optimized_calls; // total # of statically-bound calls 540231852Sbz static int _nof_inlined_calls; // total # of inlined normal calls 541120941Sume static int _nof_static_calls; // total # of calls to static methods or super methods (invokespecial) 542231852Sbz static int _nof_inlined_static_calls; // total # of inlined static calls 54362587Sitojun // stats for compiled interface calls 54478064Sume static int _nof_interface_calls; // total # of compiled calls 545108269Sru static int _nof_optimized_interface_calls; // total # of statically-bound interface calls 54662587Sitojun static int _nof_inlined_interface_calls; // total # of inlined interface calls 54753541Sshin static int _nof_megamorphic_interface_calls;// total # of megamorphic interface calls 548151539Ssuz // stats for runtime exceptions 54953541Sshin static int _nof_removable_exceptions; // total # of exceptions that could be replaced by branches due to inlining 55053541Sshin 551151539Ssuz public: // for compiler 552151539Ssuz static address nof_normal_calls_addr() { return (address)&_nof_normal_calls; } 553151539Ssuz static address nof_optimized_calls_addr() { return (address)&_nof_optimized_calls; } 55453541Sshin static address nof_inlined_calls_addr() { return (address)&_nof_inlined_calls; } 555171259Sdelphij static address nof_static_calls_addr() { return (address)&_nof_static_calls; } 556151539Ssuz static address nof_inlined_static_calls_addr() { return (address)&_nof_inlined_static_calls; } 557151539Ssuz static address nof_interface_calls_addr() { return (address)&_nof_interface_calls; } 558151539Ssuz static address nof_optimized_interface_calls_addr() { return (address)&_nof_optimized_interface_calls; } 559228966Sjhb static address nof_inlined_interface_calls_addr() { return (address)&_nof_inlined_interface_calls; } 560151539Ssuz static address nof_megamorphic_interface_calls_addr() { return (address)&_nof_megamorphic_interface_calls; } 561151539Ssuz static void print_call_statistics(int comp_total); 562151539Ssuz static void print_statistics(); 563151539Ssuz static void print_ic_miss_histogram(); 564151539Ssuz 565151539Ssuz#endif // PRODUCT 566151539Ssuz}; 567151539Ssuz 568151539Ssuz 569171259Sdelphij// --------------------------------------------------------------------------- 57053541Sshin// Implementation of AdapterHandlerLibrary 57153541Sshin// 57253541Sshin// This library manages argument marshaling adapters and native wrappers. 57353541Sshin// There are 2 flavors of adapters: I2C and C2I. 57453541Sshin// 57553541Sshin// The I2C flavor takes a stock interpreted call setup, marshals the 57653541Sshin// arguments for a Java-compiled call, and jumps to Rmethod-> code()-> 57753541Sshin// code_begin(). It is broken to call it without an nmethod assigned. 578222728Shrs// The usual behavior is to lift any register arguments up out of the 57953541Sshin// stack and possibly re-pack the extra arguments to be contigious. 58053541Sshin// I2C adapters will save what the interpreter's stack pointer will be 581151539Ssuz// after arguments are popped, then adjust the interpreter's frame 582151539Ssuz// size to force alignment and possibly to repack the arguments. 583151539Ssuz// After re-packing, it jumps to the compiled code start. There are 584151539Ssuz// no safepoints in this adapter code and a GC cannot happen while 585181803Sbz// marshaling is in progress. 58653541Sshin// 58753541Sshin// The C2I flavor takes a stock compiled call setup plus the target method in 58853541Sshin// Rmethod, marshals the arguments for an interpreted call and jumps to 58953541Sshin// Rmethod->_i2i_entry. On entry, the interpreted frame has not yet been 590228966Sjhb// setup. Compiled frames are fixed-size and the args are likely not in the 59153541Sshin// right place. Hence all the args will likely be copied into the 59253541Sshin// interpreter's frame, forcing that frame to grow. The compiled frame's 59353541Sshin// outgoing stack args will be dead after the copy. 59453541Sshin// 59553541Sshin// Native wrappers, like adapters, marshal arguments. Unlike adapters they 59653541Sshin// also perform an offical frame push & pop. They have a call to the native 59753541Sshin// routine in their middles and end in a return (instead of ending in a jump). 59862587Sitojun// The native wrappers are stored in real nmethods instead of the BufferBlobs 59962587Sitojun// used by the adapters. The code generation happens here because it's very 60062587Sitojun// similar to what the adapters have to do. 60153541Sshin 60253541Sshinclass AdapterHandlerEntry : public BasicHashtableEntry<mtCode> { 60362587Sitojun friend class AdapterHandlerTable; 60462587Sitojun 60553541Sshin private: 60653541Sshin AdapterFingerPrint* _fingerprint; 60753541Sshin address _i2c_entry; 60862587Sitojun address _c2i_entry; 609151539Ssuz address _c2i_unverified_entry; 610151539Ssuz 611151539Ssuz#ifdef ASSERT 612151539Ssuz // Captures code and signature used to generate this adapter when 613151539Ssuz // verifing adapter equivalence. 61462587Sitojun unsigned char* _saved_code; 61562587Sitojun int _saved_code_length; 616151539Ssuz#endif 61762587Sitojun 61862587Sitojun void init(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry, address c2i_unverified_entry) { 619151539Ssuz _fingerprint = fingerprint; 620151539Ssuz _i2c_entry = i2c_entry; 621151539Ssuz _c2i_entry = c2i_entry; 622151539Ssuz _c2i_unverified_entry = c2i_unverified_entry; 623151539Ssuz#ifdef ASSERT 624151539Ssuz _saved_code = NULL; 625151539Ssuz _saved_code_length = 0; 626151539Ssuz#endif 627151539Ssuz } 62862587Sitojun 62962587Sitojun void deallocate(); 630171259Sdelphij 63162587Sitojun // should never be used 632151539Ssuz AdapterHandlerEntry(); 633186119Sqingli 63462587Sitojun public: 63562587Sitojun address get_i2c_entry() const { return _i2c_entry; } 636151539Ssuz address get_c2i_entry() const { return _c2i_entry; } 637151539Ssuz address get_c2i_unverified_entry() const { return _c2i_unverified_entry; } 638151539Ssuz address base_address(); 639241686Sandre void relocate(address new_base); 640151539Ssuz 641151539Ssuz AdapterFingerPrint* fingerprint() const { return _fingerprint; } 642151539Ssuz 64362587Sitojun AdapterHandlerEntry* next() { 644151539Ssuz return (AdapterHandlerEntry*)BasicHashtableEntry<mtCode>::next(); 645151539Ssuz } 64662587Sitojun 647228966Sjhb#ifdef ASSERT 648243148Sae // Used to verify that code generated for shared adapters is equivalent 649151539Ssuz void save_code (unsigned char* code, int length); 650186119Sqingli bool compare_code(unsigned char* code, int length); 65162587Sitojun#endif 652151539Ssuz 65362587Sitojun //virtual void print_on(outputStream* st) const; DO NOT USE 654243148Sae void print_adapter_on(outputStream* st) const; 655188113Sbz}; 656186148Skmacy 657188113Sbzclass AdapterHandlerLibrary: public AllStatic { 658188113Sbz private: 65962587Sitojun static BufferBlob* _buffer; // the temporary code buffer in CodeCache 660151539Ssuz static AdapterHandlerTable* _adapters; 661151539Ssuz static AdapterHandlerEntry* _abstract_method_handler; 662151539Ssuz static BufferBlob* buffer_blob(); 663151539Ssuz static void initialize(); 664151539Ssuz 665151539Ssuz public: 66662587Sitojun 66762587Sitojun static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint, 668151539Ssuz address i2c_entry, address c2i_entry, address c2i_unverified_entry); 669151539Ssuz static nmethod* create_native_wrapper(methodHandle method, int compile_id); 670151539Ssuz static AdapterHandlerEntry* get_adapter(methodHandle method); 671151539Ssuz 672151539Ssuz#ifdef HAVE_DTRACE_H 673151539Ssuz static nmethod* create_dtrace_nmethod (methodHandle method); 674151539Ssuz#endif // HAVE_DTRACE_H 675151539Ssuz 676151539Ssuz static void print_handler(CodeBlob* b) { print_handler_on(tty, b); } 677151539Ssuz static void print_handler_on(outputStream* st, CodeBlob* b); 678181803Sbz static bool contains(CodeBlob* b); 679151539Ssuz#ifndef PRODUCT 680151539Ssuz static void print_statistics(); 681186119Sqingli#endif /* PRODUCT */ 682243148Sae 683186119Sqingli}; 684186119Sqingli 685186119Sqingli#endif // SHARE_VM_RUNTIME_SHAREDRUNTIME_HPP 686186119Sqingli