/* * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
class AdapterHandlerEntry; class AdapterFingerPrint; class vframeStream;
// Runtime is the base class for various runtime interfaces // (InterpreterRuntime, CompilerRuntime, etc.). It provides // shared functionality such as exception forwarding (C++ to // Java exceptions), locking/unlocking mechanisms, statistical // information, etc.
class SharedRuntime: AllStatic { friendclass VMStructs;
// max bytes for each dtrace string parameter enum { max_dtrace_string_size = 256 };
// The following arithmetic routines are used on platforms that do // not have machine instructions to implement their functionality. // Do not remove these.
// long arithmetics static jlong lmul(jlong y, jlong x); static jlong ldiv(jlong y, jlong x); static jlong lrem(jlong y, jlong x);
// Utility method for retrieving the Java thread id, returns 0 if the // thread is not a well formed Java thread. static jlong get_java_tid(JavaThread* thread);
// used by native wrappers to re-enable yellow if overflow happened in native code staticvoid reguard_yellow_pages();
// Fill in the "X cannot be cast to a Y" message for ClassCastException // // @param thr the current thread // @param caster_klass the class of the object we are casting // @return the dynamically allocated exception message (must be freed // by the caller using a resource mark) // // BCP must refer to the current 'checkcast' opcode for the frame // on top of the stack. // The caller (or one of its callers) must use a ResourceMark // in order to correctly free the result. // staticchar* generate_class_cast_message(JavaThread* thr, Klass* caster_klass);
// Fill in the "X cannot be cast to a Y" message for ClassCastException // // @param caster_klass the class of the object we are casting // @param target_klass the target klass attempt // @return the dynamically allocated exception message (must be freed // by the caller using a resource mark) // // This version does not require access the frame, so it can be called // from interpreted code // The caller (or one of it's callers) must use a ResourceMark // in order to correctly free the result. // staticchar* generate_class_cast_message(Klass* caster_klass, Klass* target_klass, Symbol* target_klass_name = NULL);
// Resolves a call site- may patch in the destination of the call into the // compiled code. static methodHandle resolve_helper(bool is_virtual, bool is_optimized, TRAPS);
// Resets a call-site in compiled code so it will get resolved again. static methodHandle reresolve_call_site(TRAPS);
// In the code prolog, if the klass comparison fails, the inline cache // misses and the call site is patched to megamorphic static methodHandle handle_ic_miss_helper(TRAPS);
// Find the method that called us. static methodHandle find_callee_method(TRAPS);
#ifdefined(X86) && defined(COMPILER1) // For Object.hashCode, System.identityHashCode try to pull hashCode from object header if available. staticvoid inline_check_hashcode_from_object_header(MacroAssembler* masm, const methodHandle& method, Register obj_reg, Register result); #endif// X86 && COMPILER1
public:
// Read the array of BasicTypes from a Java signature, and compute where // compiled Java code would like to put the results. Values in reg_lo and // reg_hi refer to 4-byte quantities. Values less than SharedInfo::stack0 are // registers, those above refer to 4-byte stack slots. All stack slots are // based off of the window top. SharedInfo::stack0 refers to the first usable // slot in the bottom of the frame. SharedInfo::stack0+1 refers to the memory word // 4-bytes higher. // return value is the maximum number of VMReg stack slots the convention will use. staticint java_calling_convention(const BasicType* sig_bt, VMRegPair* regs, int total_args_passed);
// Ditto except for calling C // // C argument in register AND stack slot. // Some architectures require that an argument must be passed in a register // AND in a stack slot. These architectures provide a second VMRegPair array // to be filled by the c_calling_convention method. On other architectures, // NULL is being passed as the second VMRegPair array, so arguments are either // passed in a register OR in a stack slot. staticint c_calling_convention(const BasicType *sig_bt, VMRegPair *regs, VMRegPair *regs2, int total_args_passed);
// Generate I2C and C2I adapters. These adapters are simple argument marshalling // blobs. Unlike adapters in the tiger and earlier releases the code in these // blobs does not create a new frame and are therefore virtually invisible // to the stack walking code. In general these blobs extend the callers stack // as needed for the conversion of argument locations.
// When calling a c2i blob the code will always call the interpreter even if // by the time we reach the blob there is compiled code available. This allows // the blob to pass the incoming stack pointer (the sender sp) in a known // location for the interpreter to record. This is used by the frame code // to correct the sender code to match up with the stack pointer when the // thread left the compiled code. In addition it allows the interpreter // to remove the space the c2i adapter allocated to do its argument conversion.
// Although a c2i blob will always run interpreted even if compiled code is // present if we see that compiled code is present the compiled call site // will be patched/re-resolved so that later calls will run compiled.
// Additionally a c2i blob need to have a unverified entry because it can be reached // in situations where the call site is an inlined cache site and may go megamorphic.
// A i2c adapter is simpler than the c2i adapter. This is because it is assumed // that the interpreter before it does any call dispatch will record the current // stack pointer in the interpreter frame. On return it will restore the stack // pointer as needed. This means the i2c adapter code doesn't need any special // handshaking path with compiled code to keep the stack walking correct.
static AdapterHandlerEntry* generate_i2c2i_adapters(MacroAssembler *_masm, int total_args_passed, int max_arg, const BasicType *sig_bt, const VMRegPair *regs,
AdapterFingerPrint* fingerprint);
staticvoid gen_i2c_adapter(MacroAssembler *_masm, int total_args_passed, int comp_args_on_stack, const BasicType *sig_bt, const VMRegPair *regs);
// OSR support
// OSR_migration_begin will extract the jvm state from an interpreter // frame (locals, monitors) and store the data in a piece of C heap // storage. This then allows the interpreter frame to be removed from the // stack and the OSR nmethod to be called. That method is called with a // pointer to the C heap storage. This pointer is the return value from // OSR_migration_begin.
// OSR_migration_end is a trivial routine. It is called after the compiled // method has extracted the jvm state from the C heap that OSR_migration_begin // created. It's entire job is to simply free this storage. staticvoid OSR_migration_end(intptr_t* buf);
// Convert a sig into a calling convention register layout // and find interesting things about it. static VMRegPair* find_callee_arguments(Symbol* sig, bool has_receiver, bool has_appendix, int *arg_size); static VMReg name_for_receiver();
// "Top of Stack" slots that may be unused by the calling convention but must // otherwise be preserved. // On Intel these are not necessary and the value can be zero. // On Sparc this describes the words reserved for storing a register window // when an interrupt occurs. static uint out_preserve_stack_slots();
// Stack slots that may be unused by the calling convention but must // otherwise be preserved. On Intel this includes the return address. // On PowerPC it includes the 4 words holding the old TOC & LR glue. static uint in_preserve_stack_slots();
// Is vector's size (in bytes) bigger than a size saved by default? // For example, on x86 16 bytes XMM registers are saved by default. staticbool is_wide_vector(int size);
// Save and restore a native result staticvoid save_native_result(MacroAssembler *_masm, BasicType ret_type, int frame_slots); staticvoid restore_native_result(MacroAssembler *_masm, BasicType ret_type, int frame_slots);
// Generate a native wrapper for a given method. The method takes arguments // in the Java compiled code convention, marshals them to the native // convention (handlizes oops, etc), transitions to native, makes the call, // returns to java state (possibly blocking), unhandlizes any result and // returns. // // The wrapper may contain special-case code if the given method // is a compiled method handle adapter, such as _invokeBasic, _linkToVirtual, etc. static nmethod* generate_native_wrapper(MacroAssembler* masm, const methodHandle& method, int compile_id,
BasicType* sig_bt,
VMRegPair* regs,
BasicType ret_type);
// A compiled caller has just called the interpreter, but compiled code // exists. Patch the caller so he no longer calls into the interpreter. staticvoid fixup_callers_callsite(Method* moop, address ret_pc); staticbool should_fixup_call_destination(address destination, address entry_point, address caller_pc, Method* moop, CodeBlob* cb);
// arraycopy, the non-leaf version. (See StubRoutines for all the leaf calls.) staticvoid slow_arraycopy_C(oopDesc* src, jint src_pos,
oopDesc* dest, jint dest_pos,
jint length, JavaThread* thread);
// handle ic miss with caller being compiled code // wrong method handling (inline cache misses) static address handle_wrong_method(JavaThread* current); static address handle_wrong_method_abstract(JavaThread* current); static address handle_wrong_method_ic_miss(JavaThread* current);
// Statistics code // stats for "normal" compiled calls (non-interface) static int64_t _nof_normal_calls; // total # of calls static int64_t _nof_inlined_calls; // total # of inlined normal calls static int64_t _nof_static_calls; // total # of calls to static methods or super methods (invokespecial) static int64_t _nof_inlined_static_calls; // total # of inlined static calls // stats for compiled interface calls static int64_t _nof_interface_calls; // total # of compiled calls static int64_t _nof_inlined_interface_calls; // total # of inlined interface calls
// --------------------------------------------------------------------------- // Implementation of AdapterHandlerLibrary // // This library manages argument marshaling adapters and native wrappers. // There are 2 flavors of adapters: I2C and C2I. // // The I2C flavor takes a stock interpreted call setup, marshals the // arguments for a Java-compiled call, and jumps to Rmethod-> code()-> // code_begin(). It is broken to call it without an nmethod assigned. // The usual behavior is to lift any register arguments up out of the // stack and possibly re-pack the extra arguments to be contiguous. // I2C adapters will save what the interpreter's stack pointer will be // after arguments are popped, then adjust the interpreter's frame // size to force alignment and possibly to repack the arguments. // After re-packing, it jumps to the compiled code start. There are // no safepoints in this adapter code and a GC cannot happen while // marshaling is in progress. // // The C2I flavor takes a stock compiled call setup plus the target method in // Rmethod, marshals the arguments for an interpreted call and jumps to // Rmethod->_i2i_entry. On entry, the interpreted frame has not yet been // setup. Compiled frames are fixed-size and the args are likely not in the // right place. Hence all the args will likely be copied into the // interpreter's frame, forcing that frame to grow. The compiled frame's // outgoing stack args will be dead after the copy. // // Native wrappers, like adapters, marshal arguments. Unlike adapters they // also perform an official frame push & pop. They have a call to the native // routine in their middles and end in a return (instead of ending in a jump). // The native wrappers are stored in real nmethods instead of the BufferBlobs // used by the adapters. The code generation happens here because it's very // similar to what the adapters have to do.
class AdapterHandlerEntry : public CHeapObj<mtCode> { friendclass AdapterHandlerLibrary;
#ifdef ASSERT // Captures code and signature used to generate this adapter when // verifying adapter equivalence. unsignedchar* _saved_code; int _saved_code_length; #endif
#ifdef ASSERT // Used to verify that code generated for shared adapters is equivalent void save_code (unsignedchar* code, int length); bool compare_code(AdapterHandlerEntry* other); #endif
//virtual void print_on(outputStream* st) const; DO NOT USE void print_adapter_on(outputStream* st) const;
};
class AdapterHandlerLibrary: public AllStatic { friendclass SharedRuntime; private: static BufferBlob* _buffer; // the temporary code buffer in CodeCache static AdapterHandlerEntry* _abstract_method_handler; static AdapterHandlerEntry* _no_arg_handler; static AdapterHandlerEntry* _int_arg_handler; static AdapterHandlerEntry* _obj_arg_handler; static AdapterHandlerEntry* _obj_int_arg_handler; static AdapterHandlerEntry* _obj_obj_arg_handler;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.