< prev index next >

src/hotspot/share/runtime/sharedRuntime.hpp

Print this page

  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_RUNTIME_SHAREDRUNTIME_HPP
 26 #define SHARE_RUNTIME_SHAREDRUNTIME_HPP
 27 

 28 #include "code/codeBlob.hpp"
 29 #include "code/vmreg.hpp"
 30 #include "interpreter/linkResolver.hpp"
 31 #include "memory/allStatic.hpp"
 32 #include "memory/resourceArea.hpp"

 33 #include "runtime/stubDeclarations.hpp"
 34 #include "utilities/macros.hpp"
 35 
 36 class AdapterHandlerEntry;
 37 class AdapterFingerPrint;
 38 class vframeStream;

 39 
 40 // Runtime is the base class for various runtime interfaces
 41 // (InterpreterRuntime, CompilerRuntime, etc.). It provides
 42 // shared functionality such as exception forwarding (C++ to
 43 // Java exceptions), locking/unlocking mechanisms, statistical
 44 // information, etc.
 45 
 46 // define SharedStubId enum tags: wrong_method_id, etc
 47 
 48 #define SHARED_STUB_ID_ENUM_DECLARE(name, type) STUB_ID_NAME(name),
 49 enum class SharedStubId :int {
 50   NO_STUBID = -1,
 51   SHARED_STUBS_DO(SHARED_STUB_ID_ENUM_DECLARE)
 52   NUM_STUBIDS
 53 };
 54 #undef SHARED_STUB_ID_ENUM_DECLARE
 55 
 56 class SharedRuntime: AllStatic {
 57   friend class VMStructs;
 58 

349   // on top of the stack.
350   // The caller (or one of its callers) must use a ResourceMark
351   // in order to correctly free the result.
352   //
353   static char* generate_class_cast_message(JavaThread* thr, Klass* caster_klass);
354 
355   // Fill in the "X cannot be cast to a Y" message for ClassCastException
356   //
357   // @param caster_klass the class of the object we are casting
358   // @param target_klass the target klass attempt
359   // @return the dynamically allocated exception message (must be freed
360   // by the caller using a resource mark)
361   //
362   // This version does not require access the frame, so it can be called
363   // from interpreted code
364   // The caller (or one of it's callers) must use a ResourceMark
365   // in order to correctly free the result.
366   //
367   static char* generate_class_cast_message(Klass* caster_klass, Klass* target_klass, Symbol* target_klass_name = nullptr);
368 


369   // Resolves a call site- may patch in the destination of the call into the
370   // compiled code.
371   static methodHandle resolve_helper(bool is_virtual, bool is_optimized, TRAPS);
372 
373  private:
374   // deopt blob
375   static void generate_deopt_blob(void);
376 
377   static bool handle_ic_miss_helper_internal(Handle receiver, nmethod* caller_nm, const frame& caller_frame,
378                                              methodHandle callee_method, Bytecodes::Code bc, CallInfo& call_info,
379                                              bool& needs_ic_stub_refill, TRAPS);
380 
381  public:
382   static DeoptimizationBlob* deopt_blob(void)      { return _deopt_blob; }
383 
384   // Resets a call-site in compiled code so it will get resolved again.
385   static methodHandle reresolve_call_site(TRAPS);
386 
387   // In the code prolog, if the klass comparison fails, the inline cache
388   // misses and the call site is patched to megamorphic
389   static methodHandle handle_ic_miss_helper(TRAPS);
390 
391   // Find the method that called us.
392   static methodHandle find_callee_method(TRAPS);
393 
394   static void monitor_enter_helper(oopDesc* obj, BasicLock* lock, JavaThread* thread);
395 
396   static void monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThread* current);
397 
398   // Issue UL warning for unlocked JNI monitor on virtual thread termination
399   static void log_jni_monitor_still_held();
400 
401  private:
402   static Handle find_callee_info(Bytecodes::Code& bc, CallInfo& callinfo, TRAPS);
403   static Handle find_callee_info_helper(vframeStream& vfst, Bytecodes::Code& bc, CallInfo& callinfo, TRAPS);
404 
405   static Method* extract_attached_method(vframeStream& vfst);
406 
407 #if defined(X86) && defined(COMPILER1)
408   // For Object.hashCode, System.identityHashCode try to pull hashCode from object header if available.
409   static void inline_check_hashcode_from_object_header(MacroAssembler* masm, const methodHandle& method, Register obj_reg, Register result);
410 #endif // X86 && COMPILER1
411 
412  public:
413 
414   // Read the array of BasicTypes from a Java signature, and compute where
415   // compiled Java code would like to put the results.  Values in reg_lo and
416   // reg_hi refer to 4-byte quantities.  Values less than SharedInfo::stack0 are
417   // registers, those above refer to 4-byte stack slots.  All stack slots are
418   // based off of the window top.  SharedInfo::stack0 refers to the first usable
419   // slot in the bottom of the frame. SharedInfo::stack0+1 refers to the memory word
420   // 4-bytes higher.
421   // return value is the maximum number of VMReg stack slots the convention will use.
422   static int java_calling_convention(const BasicType* sig_bt, VMRegPair* regs, int total_args_passed);








423 
424   static void check_member_name_argument_is_last_argument(const methodHandle& method,
425                                                           const BasicType* sig_bt,
426                                                           const VMRegPair* regs) NOT_DEBUG_RETURN;
427 
428   // Ditto except for calling C
429   //
430   // C argument in register AND stack slot.
431   // Some architectures require that an argument must be passed in a register
432   // AND in a stack slot. These architectures provide a second VMRegPair array
433   // to be filled by the c_calling_convention method. On other architectures,
434   // null is being passed as the second VMRegPair array, so arguments are either
435   // passed in a register OR in a stack slot.
436   static int c_calling_convention(const BasicType *sig_bt, VMRegPair *regs, int total_args_passed);
437 
438   static int vector_calling_convention(VMRegPair *regs,
439                                        uint num_bits,
440                                        uint total_args_passed);
441 
442   // Generate I2C and C2I adapters. These adapters are simple argument marshalling

449   // by the time we reach the blob there is compiled code available. This allows
450   // the blob to pass the incoming stack pointer (the sender sp) in a known
451   // location for the interpreter to record. This is used by the frame code
452   // to correct the sender code to match up with the stack pointer when the
453   // thread left the compiled code. In addition it allows the interpreter
454   // to remove the space the c2i adapter allocated to do its argument conversion.
455 
456   // Although a c2i blob will always run interpreted even if compiled code is
457   // present if we see that compiled code is present the compiled call site
458   // will be patched/re-resolved so that later calls will run compiled.
459 
460   // Additionally a c2i blob need to have a unverified entry because it can be reached
461   // in situations where the call site is an inlined cache site and may go megamorphic.
462 
463   // A i2c adapter is simpler than the c2i adapter. This is because it is assumed
464   // that the interpreter before it does any call dispatch will record the current
465   // stack pointer in the interpreter frame. On return it will restore the stack
466   // pointer as needed. This means the i2c adapter code doesn't need any special
467   // handshaking path with compiled code to keep the stack walking correct.
468 
469   static AdapterHandlerEntry* generate_i2c2i_adapters(MacroAssembler *_masm,
470                                                       int total_args_passed,
471                                                       int max_arg,
472                                                       const BasicType *sig_bt,
473                                                       const VMRegPair *regs,
474                                                       AdapterFingerPrint* fingerprint);





475 
476   static void gen_i2c_adapter(MacroAssembler *_masm,
477                               int total_args_passed,
478                               int comp_args_on_stack,
479                               const BasicType *sig_bt,
480                               const VMRegPair *regs);
481 
482   // OSR support
483 
484   // OSR_migration_begin will extract the jvm state from an interpreter
485   // frame (locals, monitors) and store the data in a piece of C heap
486   // storage. This then allows the interpreter frame to be removed from the
487   // stack and the OSR nmethod to be called. That method is called with a
488   // pointer to the C heap storage. This pointer is the return value from
489   // OSR_migration_begin.
490 
491   static intptr_t* OSR_migration_begin(JavaThread *thread);
492 
493   // OSR_migration_end is a trivial routine. It is called after the compiled
494   // method has extracted the jvm state from the C heap that OSR_migration_begin
495   // created. It's entire job is to simply free this storage.
496   static void OSR_migration_end(intptr_t* buf);
497 
498   // Convert a sig into a calling convention register layout
499   // and find interesting things about it.

528   //
529   // The wrapper may contain special-case code if the given method
530   // is a compiled method handle adapter, such as _invokeBasic, _linkToVirtual, etc.
531   static nmethod* generate_native_wrapper(MacroAssembler* masm,
532                                           const methodHandle& method,
533                                           int compile_id,
534                                           BasicType* sig_bt,
535                                           VMRegPair* regs,
536                                           BasicType ret_type);
537 
538   // A compiled caller has just called the interpreter, but compiled code
539   // exists.  Patch the caller so he no longer calls into the interpreter.
540   static void fixup_callers_callsite(Method* moop, address ret_pc);
541   static bool should_fixup_call_destination(address destination, address entry_point, address caller_pc, Method* moop, CodeBlob* cb);
542 
543   // Slow-path Locking and Unlocking
544   static void complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current);
545   static void complete_monitor_unlocking_C(oopDesc* obj, BasicLock* lock, JavaThread* current);
546 
547   // Resolving of calls
548   static address get_resolved_entry        (JavaThread* current, methodHandle callee_method);

549   static address resolve_static_call_C     (JavaThread* current);
550   static address resolve_virtual_call_C    (JavaThread* current);
551   static address resolve_opt_virtual_call_C(JavaThread* current);
552 



553   // arraycopy, the non-leaf version.  (See StubRoutines for all the leaf calls.)
554   static void slow_arraycopy_C(oopDesc* src,  jint src_pos,
555                                oopDesc* dest, jint dest_pos,
556                                jint length, JavaThread* thread);
557 
558   // handle ic miss with caller being compiled code
559   // wrong method handling (inline cache misses)
560   static address handle_wrong_method(JavaThread* current);
561   static address handle_wrong_method_abstract(JavaThread* current);
562   static address handle_wrong_method_ic_miss(JavaThread* current);


563 
564   static address handle_unsafe_access(JavaThread* thread, address next_pc);
565 

566 #ifndef PRODUCT
567 
568   // Collect and print inline cache miss statistics
569  private:
570   enum { maxICmiss_count = 100 };
571   static int     _ICmiss_index;                  // length of IC miss histogram
572   static int     _ICmiss_count[maxICmiss_count]; // miss counts
573   static address _ICmiss_at[maxICmiss_count];    // miss addresses
574   static void trace_ic_miss(address at);
575 
576  public:
577   static uint _ic_miss_ctr;                      // total # of IC misses
578   static uint _wrong_method_ctr;
579   static uint _resolve_static_ctr;
580   static uint _resolve_virtual_ctr;
581   static uint _resolve_opt_virtual_ctr;
582   static uint _implicit_null_throws;
583   static uint _implicit_div0_throws;
584 
585   static uint _jbyte_array_copy_ctr;       // Slow-path byte array copy

654 // Rmethod->_i2i_entry.  On entry, the interpreted frame has not yet been
655 // setup.  Compiled frames are fixed-size and the args are likely not in the
656 // right place.  Hence all the args will likely be copied into the
657 // interpreter's frame, forcing that frame to grow.  The compiled frame's
658 // outgoing stack args will be dead after the copy.
659 //
660 // Native wrappers, like adapters, marshal arguments.  Unlike adapters they
661 // also perform an official frame push & pop.  They have a call to the native
662 // routine in their middles and end in a return (instead of ending in a jump).
663 // The native wrappers are stored in real nmethods instead of the BufferBlobs
664 // used by the adapters.  The code generation happens here because it's very
665 // similar to what the adapters have to do.
666 
667 class AdapterHandlerEntry : public CHeapObj<mtCode> {
668   friend class AdapterHandlerLibrary;
669 
670  private:
671   AdapterFingerPrint* _fingerprint;
672   address _i2c_entry;
673   address _c2i_entry;


674   address _c2i_unverified_entry;

675   address _c2i_no_clinit_check_entry;
676 



677 #ifdef ASSERT
678   // Captures code and signature used to generate this adapter when
679   // verifying adapter equivalence.
680   unsigned char* _saved_code;
681   int            _saved_code_length;
682 #endif
683 
684   AdapterHandlerEntry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry,
685                       address c2i_unverified_entry,

686                       address c2i_no_clinit_check_entry) :
687     _fingerprint(fingerprint),
688     _i2c_entry(i2c_entry),
689     _c2i_entry(c2i_entry),


690     _c2i_unverified_entry(c2i_unverified_entry),
691     _c2i_no_clinit_check_entry(c2i_no_clinit_check_entry)


692 #ifdef ASSERT
693     , _saved_code_length(0)
694 #endif
695   { }
696 
697   ~AdapterHandlerEntry();
698 
699  public:
700   address get_i2c_entry()                  const { return _i2c_entry; }
701   address get_c2i_entry()                  const { return _c2i_entry; }
702   address get_c2i_unverified_entry()       const { return _c2i_unverified_entry; }
703   address get_c2i_no_clinit_check_entry()  const { return _c2i_no_clinit_check_entry; }



704 
705   address base_address();
706   void relocate(address new_base);
707 




708   AdapterFingerPrint* fingerprint() const { return _fingerprint; }
709 
710 #ifdef ASSERT
711   // Used to verify that code generated for shared adapters is equivalent
712   void save_code   (unsigned char* code, int length);
713   bool compare_code(AdapterHandlerEntry* other);
714 #endif
715 
716   //virtual void print_on(outputStream* st) const;  DO NOT USE
717   void print_adapter_on(outputStream* st) const;
718 };
719 


720 class AdapterHandlerLibrary: public AllStatic {
721   friend class SharedRuntime;
722  private:
723   static BufferBlob* _buffer; // the temporary code buffer in CodeCache
724   static AdapterHandlerEntry* _abstract_method_handler;
725   static AdapterHandlerEntry* _no_arg_handler;
726   static AdapterHandlerEntry* _int_arg_handler;
727   static AdapterHandlerEntry* _obj_arg_handler;
728   static AdapterHandlerEntry* _obj_int_arg_handler;
729   static AdapterHandlerEntry* _obj_obj_arg_handler;
730 
731   static BufferBlob* buffer_blob();
732   static void initialize();
733   static AdapterHandlerEntry* create_adapter(AdapterBlob*& new_adapter,
734                                              int total_args_passed,
735                                              BasicType* sig_bt,
736                                              bool allocate_code_blob);
737   static AdapterHandlerEntry* get_simple_adapter(const methodHandle& method);
738  public:
739 
740   static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint,
741                                         address i2c_entry,
742                                         address c2i_entry,
743                                         address c2i_unverified_entry,
744                                         address c2i_no_clinit_check_entry = nullptr);
745   static void create_native_wrapper(const methodHandle& method);
746   static AdapterHandlerEntry* get_adapter(const methodHandle& method);
747 
748   static void print_handler(const CodeBlob* b) { print_handler_on(tty, b); }
749   static void print_handler_on(outputStream* st, const CodeBlob* b);
750   static bool contains(const CodeBlob* b);
751 #ifndef PRODUCT
752   static void print_statistics();
753 #endif // PRODUCT
754 
755 };
756 



























































757 #endif // SHARE_RUNTIME_SHAREDRUNTIME_HPP

  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_RUNTIME_SHAREDRUNTIME_HPP
 26 #define SHARE_RUNTIME_SHAREDRUNTIME_HPP
 27 
 28 #include "asm/codeBuffer.hpp"
 29 #include "code/codeBlob.hpp"
 30 #include "code/vmreg.hpp"
 31 #include "interpreter/linkResolver.hpp"
 32 #include "memory/allStatic.hpp"
 33 #include "memory/resourceArea.hpp"
 34 #include "runtime/signature.hpp"
 35 #include "runtime/stubDeclarations.hpp"
 36 #include "utilities/macros.hpp"
 37 
 38 class AdapterHandlerEntry;
 39 class AdapterFingerPrint;
 40 class vframeStream;
 41 class SigEntry;
 42 
 43 // Runtime is the base class for various runtime interfaces
 44 // (InterpreterRuntime, CompilerRuntime, etc.). It provides
 45 // shared functionality such as exception forwarding (C++ to
 46 // Java exceptions), locking/unlocking mechanisms, statistical
 47 // information, etc.
 48 
 49 // define SharedStubId enum tags: wrong_method_id, etc
 50 
 51 #define SHARED_STUB_ID_ENUM_DECLARE(name, type) STUB_ID_NAME(name),
 52 enum class SharedStubId :int {
 53   NO_STUBID = -1,
 54   SHARED_STUBS_DO(SHARED_STUB_ID_ENUM_DECLARE)
 55   NUM_STUBIDS
 56 };
 57 #undef SHARED_STUB_ID_ENUM_DECLARE
 58 
 59 class SharedRuntime: AllStatic {
 60   friend class VMStructs;
 61 

352   // on top of the stack.
353   // The caller (or one of its callers) must use a ResourceMark
354   // in order to correctly free the result.
355   //
356   static char* generate_class_cast_message(JavaThread* thr, Klass* caster_klass);
357 
358   // Fill in the "X cannot be cast to a Y" message for ClassCastException
359   //
360   // @param caster_klass the class of the object we are casting
361   // @param target_klass the target klass attempt
362   // @return the dynamically allocated exception message (must be freed
363   // by the caller using a resource mark)
364   //
365   // This version does not require access the frame, so it can be called
366   // from interpreted code
367   // The caller (or one of it's callers) must use a ResourceMark
368   // in order to correctly free the result.
369   //
370   static char* generate_class_cast_message(Klass* caster_klass, Klass* target_klass, Symbol* target_klass_name = nullptr);
371 
372   static char* generate_identity_exception_message(JavaThread* thr, Klass* klass);
373 
374   // Resolves a call site- may patch in the destination of the call into the
375   // compiled code.
376   static methodHandle resolve_helper(bool is_virtual, bool is_optimized, bool& caller_is_c1, TRAPS);
377 
378  private:
379   // deopt blob
380   static void generate_deopt_blob(void);
381 
382   static bool handle_ic_miss_helper_internal(Handle receiver, nmethod* caller_nm, const frame& caller_frame,
383                                              methodHandle callee_method, Bytecodes::Code bc, CallInfo& call_info,
384                                              bool& needs_ic_stub_refill, bool& is_optimized, bool caller_is_c1, TRAPS);
385 
386  public:
387   static DeoptimizationBlob* deopt_blob(void)      { return _deopt_blob; }
388 
389   // Resets a call-site in compiled code so it will get resolved again.
390   static methodHandle reresolve_call_site(bool& is_static_call, bool& is_optimized, bool& caller_is_c1, TRAPS);
391 
392   // In the code prolog, if the klass comparison fails, the inline cache
393   // misses and the call site is patched to megamorphic
394   static methodHandle handle_ic_miss_helper(bool& is_optimized, bool& caller_is_c1, TRAPS);
395 
396   // Find the method that called us.
397   static methodHandle find_callee_method(bool is_optimized, bool& caller_is_c1, TRAPS);
398 
399   static void monitor_enter_helper(oopDesc* obj, BasicLock* lock, JavaThread* thread);
400 
401   static void monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThread* current);
402 
403   // Issue UL warning for unlocked JNI monitor on virtual thread termination
404   static void log_jni_monitor_still_held();
405 
406  private:
407   static Handle find_callee_info(Bytecodes::Code& bc, CallInfo& callinfo, TRAPS);
408   static Handle find_callee_info_helper(vframeStream& vfst, Bytecodes::Code& bc, CallInfo& callinfo, TRAPS);
409 
410   static Method* extract_attached_method(vframeStream& vfst);
411 
412 #if defined(X86) && defined(COMPILER1)
413   // For Object.hashCode, System.identityHashCode try to pull hashCode from object header if available.
414   static void inline_check_hashcode_from_object_header(MacroAssembler* masm, const methodHandle& method, Register obj_reg, Register result);
415 #endif // X86 && COMPILER1
416 
417  public:
418 
419   // Read the array of BasicTypes from a Java signature, and compute where
420   // compiled Java code would like to put the results.  Values in reg_lo and
421   // reg_hi refer to 4-byte quantities.  Values less than SharedInfo::stack0 are
422   // registers, those above refer to 4-byte stack slots.  All stack slots are
423   // based off of the window top.  SharedInfo::stack0 refers to the first usable
424   // slot in the bottom of the frame. SharedInfo::stack0+1 refers to the memory word
425   // 4-bytes higher.
426   // return value is the maximum number of VMReg stack slots the convention will use.
427   static int java_calling_convention(const BasicType* sig_bt, VMRegPair* regs, int total_args_passed);
428   static int java_calling_convention(const GrowableArray<SigEntry>* sig, VMRegPair* regs) {
429     BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sig->length());
430     int total_args_passed = SigEntry::fill_sig_bt(sig, sig_bt);
431     return java_calling_convention(sig_bt, regs, total_args_passed);
432   }
433   static int java_return_convention(const BasicType* sig_bt, VMRegPair* regs, int total_args_passed);
434   static const uint java_return_convention_max_int;
435   static const uint java_return_convention_max_float;
436 
437   static void check_member_name_argument_is_last_argument(const methodHandle& method,
438                                                           const BasicType* sig_bt,
439                                                           const VMRegPair* regs) NOT_DEBUG_RETURN;
440 
441   // Ditto except for calling C
442   //
443   // C argument in register AND stack slot.
444   // Some architectures require that an argument must be passed in a register
445   // AND in a stack slot. These architectures provide a second VMRegPair array
446   // to be filled by the c_calling_convention method. On other architectures,
447   // null is being passed as the second VMRegPair array, so arguments are either
448   // passed in a register OR in a stack slot.
449   static int c_calling_convention(const BasicType *sig_bt, VMRegPair *regs, int total_args_passed);
450 
451   static int vector_calling_convention(VMRegPair *regs,
452                                        uint num_bits,
453                                        uint total_args_passed);
454 
455   // Generate I2C and C2I adapters. These adapters are simple argument marshalling

462   // by the time we reach the blob there is compiled code available. This allows
463   // the blob to pass the incoming stack pointer (the sender sp) in a known
464   // location for the interpreter to record. This is used by the frame code
465   // to correct the sender code to match up with the stack pointer when the
466   // thread left the compiled code. In addition it allows the interpreter
467   // to remove the space the c2i adapter allocated to do its argument conversion.
468 
469   // Although a c2i blob will always run interpreted even if compiled code is
470   // present if we see that compiled code is present the compiled call site
471   // will be patched/re-resolved so that later calls will run compiled.
472 
473   // Additionally a c2i blob need to have a unverified entry because it can be reached
474   // in situations where the call site is an inlined cache site and may go megamorphic.
475 
476   // A i2c adapter is simpler than the c2i adapter. This is because it is assumed
477   // that the interpreter before it does any call dispatch will record the current
478   // stack pointer in the interpreter frame. On return it will restore the stack
479   // pointer as needed. This means the i2c adapter code doesn't need any special
480   // handshaking path with compiled code to keep the stack walking correct.
481 
482   static AdapterHandlerEntry* generate_i2c2i_adapters(MacroAssembler *masm,
483                                                       int comp_args_on_stack,
484                                                       const GrowableArray<SigEntry>* sig,
485                                                       const VMRegPair* regs,
486                                                       const GrowableArray<SigEntry>* sig_cc,
487                                                       const VMRegPair* regs_cc,
488                                                       const GrowableArray<SigEntry>* sig_cc_ro,
489                                                       const VMRegPair* regs_cc_ro,
490                                                       AdapterFingerPrint* fingerprint,
491                                                       AdapterBlob*& new_adapter,
492                                                       bool allocate_code_blob);
493 
494   static void gen_i2c_adapter(MacroAssembler *_masm,

495                               int comp_args_on_stack,
496                               const GrowableArray<SigEntry>* sig,
497                               const VMRegPair *regs);
498 
499   // OSR support
500 
501   // OSR_migration_begin will extract the jvm state from an interpreter
502   // frame (locals, monitors) and store the data in a piece of C heap
503   // storage. This then allows the interpreter frame to be removed from the
504   // stack and the OSR nmethod to be called. That method is called with a
505   // pointer to the C heap storage. This pointer is the return value from
506   // OSR_migration_begin.
507 
508   static intptr_t* OSR_migration_begin(JavaThread *thread);
509 
510   // OSR_migration_end is a trivial routine. It is called after the compiled
511   // method has extracted the jvm state from the C heap that OSR_migration_begin
512   // created. It's entire job is to simply free this storage.
513   static void OSR_migration_end(intptr_t* buf);
514 
515   // Convert a sig into a calling convention register layout
516   // and find interesting things about it.

545   //
546   // The wrapper may contain special-case code if the given method
547   // is a compiled method handle adapter, such as _invokeBasic, _linkToVirtual, etc.
548   static nmethod* generate_native_wrapper(MacroAssembler* masm,
549                                           const methodHandle& method,
550                                           int compile_id,
551                                           BasicType* sig_bt,
552                                           VMRegPair* regs,
553                                           BasicType ret_type);
554 
555   // A compiled caller has just called the interpreter, but compiled code
556   // exists.  Patch the caller so he no longer calls into the interpreter.
557   static void fixup_callers_callsite(Method* moop, address ret_pc);
558   static bool should_fixup_call_destination(address destination, address entry_point, address caller_pc, Method* moop, CodeBlob* cb);
559 
560   // Slow-path Locking and Unlocking
561   static void complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current);
562   static void complete_monitor_unlocking_C(oopDesc* obj, BasicLock* lock, JavaThread* current);
563 
564   // Resolving of calls
565   static address get_resolved_entry        (JavaThread* current, methodHandle callee_method,
566                                             bool is_static_call, bool is_optimized, bool caller_is_c1);
567   static address resolve_static_call_C     (JavaThread* current);
568   static address resolve_virtual_call_C    (JavaThread* current);
569   static address resolve_opt_virtual_call_C(JavaThread* current);
570 
571   static void load_inline_type_fields_in_regs(JavaThread* current, oopDesc* res);
572   static void store_inline_type_fields_to_buf(JavaThread* current, intptr_t res);
573 
574   // arraycopy, the non-leaf version.  (See StubRoutines for all the leaf calls.)
575   static void slow_arraycopy_C(oopDesc* src,  jint src_pos,
576                                oopDesc* dest, jint dest_pos,
577                                jint length, JavaThread* thread);
578 
579   // handle ic miss with caller being compiled code
580   // wrong method handling (inline cache misses)
581   static address handle_wrong_method(JavaThread* current);
582   static address handle_wrong_method_abstract(JavaThread* current);
583   static address handle_wrong_method_ic_miss(JavaThread* current);
584   static void allocate_inline_types(JavaThread* current, Method* callee, bool allocate_receiver);
585   static oop allocate_inline_types_impl(JavaThread* current, methodHandle callee, bool allocate_receiver, TRAPS);
586 
587   static address handle_unsafe_access(JavaThread* thread, address next_pc);
588 
589   static BufferedInlineTypeBlob* generate_buffered_inline_type_adapter(const InlineKlass* vk);
590 #ifndef PRODUCT
591 
592   // Collect and print inline cache miss statistics
593  private:
594   enum { maxICmiss_count = 100 };
595   static int     _ICmiss_index;                  // length of IC miss histogram
596   static int     _ICmiss_count[maxICmiss_count]; // miss counts
597   static address _ICmiss_at[maxICmiss_count];    // miss addresses
598   static void trace_ic_miss(address at);
599 
600  public:
601   static uint _ic_miss_ctr;                      // total # of IC misses
602   static uint _wrong_method_ctr;
603   static uint _resolve_static_ctr;
604   static uint _resolve_virtual_ctr;
605   static uint _resolve_opt_virtual_ctr;
606   static uint _implicit_null_throws;
607   static uint _implicit_div0_throws;
608 
609   static uint _jbyte_array_copy_ctr;       // Slow-path byte array copy

678 // Rmethod->_i2i_entry.  On entry, the interpreted frame has not yet been
679 // setup.  Compiled frames are fixed-size and the args are likely not in the
680 // right place.  Hence all the args will likely be copied into the
681 // interpreter's frame, forcing that frame to grow.  The compiled frame's
682 // outgoing stack args will be dead after the copy.
683 //
684 // Native wrappers, like adapters, marshal arguments.  Unlike adapters they
685 // also perform an official frame push & pop.  They have a call to the native
686 // routine in their middles and end in a return (instead of ending in a jump).
687 // The native wrappers are stored in real nmethods instead of the BufferBlobs
688 // used by the adapters.  The code generation happens here because it's very
689 // similar to what the adapters have to do.
690 
691 class AdapterHandlerEntry : public CHeapObj<mtCode> {
692   friend class AdapterHandlerLibrary;
693 
694  private:
695   AdapterFingerPrint* _fingerprint;
696   address _i2c_entry;
697   address _c2i_entry;
698   address _c2i_inline_entry;
699   address _c2i_inline_ro_entry;
700   address _c2i_unverified_entry;
701   address _c2i_unverified_inline_entry;
702   address _c2i_no_clinit_check_entry;
703 
704   // Support for scalarized inline type calling convention
705   const GrowableArray<SigEntry>* _sig_cc;
706 
707 #ifdef ASSERT
708   // Captures code and signature used to generate this adapter when
709   // verifying adapter equivalence.
710   unsigned char* _saved_code;
711   int            _saved_code_length;
712 #endif
713 
714   AdapterHandlerEntry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry,
715                       address c2i_inline_entry, address c2i_inline_ro_entry,
716                       address c2i_unverified_entry, address c2i_unverified_inline_entry,
717                       address c2i_no_clinit_check_entry) :
718     _fingerprint(fingerprint),
719     _i2c_entry(i2c_entry),
720     _c2i_entry(c2i_entry),
721     _c2i_inline_entry(c2i_inline_entry),
722     _c2i_inline_ro_entry(c2i_inline_ro_entry),
723     _c2i_unverified_entry(c2i_unverified_entry),
724     _c2i_unverified_inline_entry(c2i_unverified_inline_entry),
725     _c2i_no_clinit_check_entry(c2i_no_clinit_check_entry),
726     _sig_cc(nullptr)
727 #ifdef ASSERT
728     , _saved_code_length(0)
729 #endif
730   { }
731 
732   ~AdapterHandlerEntry();
733 
734  public:
735   address get_i2c_entry()                   const { return _i2c_entry; }
736   address get_c2i_entry()                   const { return _c2i_entry; }
737   address get_c2i_inline_entry()            const { return _c2i_inline_entry; }
738   address get_c2i_inline_ro_entry()         const { return _c2i_inline_ro_entry; }
739   address get_c2i_unverified_entry()        const { return _c2i_unverified_entry; }
740   address get_c2i_unverified_inline_entry() const { return _c2i_unverified_inline_entry; }
741   address get_c2i_no_clinit_check_entry()   const { return _c2i_no_clinit_check_entry; }
742 
743   address base_address();
744   void relocate(address new_base);
745 
746   // Support for scalarized inline type calling convention
747   void set_sig_cc(const GrowableArray<SigEntry>* sig)  { _sig_cc = sig; }
748   const GrowableArray<SigEntry>* get_sig_cc()    const { return _sig_cc; }
749 
750   AdapterFingerPrint* fingerprint() const { return _fingerprint; }
751 
752 #ifdef ASSERT
753   // Used to verify that code generated for shared adapters is equivalent
754   void save_code   (unsigned char* code, int length);
755   bool compare_code(AdapterHandlerEntry* other);
756 #endif
757 
758   //virtual void print_on(outputStream* st) const;  DO NOT USE
759   void print_adapter_on(outputStream* st) const;
760 };
761 
762 class CompiledEntrySignature;
763 
764 class AdapterHandlerLibrary: public AllStatic {
765   friend class SharedRuntime;
766  private:
767   static BufferBlob* _buffer; // the temporary code buffer in CodeCache
768   static AdapterHandlerEntry* _abstract_method_handler;
769   static AdapterHandlerEntry* _no_arg_handler;
770   static AdapterHandlerEntry* _int_arg_handler;
771   static AdapterHandlerEntry* _obj_arg_handler;
772   static AdapterHandlerEntry* _obj_int_arg_handler;
773   static AdapterHandlerEntry* _obj_obj_arg_handler;
774 
775   static BufferBlob* buffer_blob();
776   static void initialize();
777   static AdapterHandlerEntry* create_adapter(AdapterBlob*& new_adapter,
778                                              CompiledEntrySignature& ces,

779                                              bool allocate_code_blob);
780   static AdapterHandlerEntry* get_simple_adapter(const methodHandle& method);
781  public:
782 
783   static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint,
784                                         address i2c_entry, address c2i_entry, address c2i_inline_entry, address c2i_inline_ro_entry,
785                                         address c2i_unverified_entry, address c2i_unverified_inline_entry, address c2i_no_clinit_check_entry = nullptr);


786   static void create_native_wrapper(const methodHandle& method);
787   static AdapterHandlerEntry* get_adapter(const methodHandle& method);
788 
789   static void print_handler(const CodeBlob* b) { print_handler_on(tty, b); }
790   static void print_handler_on(outputStream* st, const CodeBlob* b);
791   static bool contains(const CodeBlob* b);
792 #ifndef PRODUCT
793   static void print_statistics();
794 #endif // PRODUCT
795 
796 };
797 
798 // Utility class for computing the calling convention of the 3 types
799 // of compiled method entries:
800 //     Method::_from_compiled_entry               - sig_cc
801 //     Method::_from_compiled_inline_ro_entry     - sig_cc_ro
802 //     Method::_from_compiled_inline_entry        - sig
803 class CompiledEntrySignature : public StackObj {
804   Method* _method;
805   int  _num_inline_args;
806   bool _has_inline_recv;
807   GrowableArray<SigEntry>* _sig;
808   GrowableArray<SigEntry>* _sig_cc;
809   GrowableArray<SigEntry>* _sig_cc_ro;
810   VMRegPair* _regs;
811   VMRegPair* _regs_cc;
812   VMRegPair* _regs_cc_ro;
813 
814   int _args_on_stack;
815   int _args_on_stack_cc;
816   int _args_on_stack_cc_ro;
817 
818   bool _c1_needs_stack_repair;
819   bool _c2_needs_stack_repair;
820 
821   GrowableArray<Method*>* _supers;
822 
823 public:
824   Method* method()                     const { return _method; }
825 
826   // Used by Method::_from_compiled_inline_entry
827   GrowableArray<SigEntry>* sig()       const { return _sig; }
828 
829   // Used by Method::_from_compiled_entry
830   GrowableArray<SigEntry>* sig_cc()    const { return _sig_cc; }
831 
832   // Used by Method::_from_compiled_inline_ro_entry
833   GrowableArray<SigEntry>* sig_cc_ro() const { return _sig_cc_ro; }
834 
835   VMRegPair* regs()                    const { return _regs; }
836   VMRegPair* regs_cc()                 const { return _regs_cc; }
837   VMRegPair* regs_cc_ro()              const { return _regs_cc_ro; }
838 
839   int args_on_stack()                  const { return _args_on_stack; }
840   int args_on_stack_cc()               const { return _args_on_stack_cc; }
841   int args_on_stack_cc_ro()            const { return _args_on_stack_cc_ro; }
842 
843   int  num_inline_args()               const { return _num_inline_args; }
844   bool has_inline_recv()               const { return _has_inline_recv; }
845 
846   bool has_scalarized_args()           const { return _sig != _sig_cc; }
847   bool c1_needs_stack_repair()         const { return _c1_needs_stack_repair; }
848   bool c2_needs_stack_repair()         const { return _c2_needs_stack_repair; }
849   CodeOffsets::Entries c1_inline_ro_entry_type() const;
850 
851   GrowableArray<Method*>* get_supers();
852 
853   CompiledEntrySignature(Method* method = nullptr);
854   void compute_calling_conventions(bool init = true);
855 };
856 
857 #endif // SHARE_RUNTIME_SHAREDRUNTIME_HPP
< prev index next >