< 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 "utilities/macros.hpp"
 34 
 35 class AdapterHandlerEntry;
 36 class AdapterFingerPrint;
 37 class vframeStream;

 38 
 39 // Runtime is the base class for various runtime interfaces
 40 // (InterpreterRuntime, CompilerRuntime, etc.). It provides
 41 // shared functionality such as exception forwarding (C++ to
 42 // Java exceptions), locking/unlocking mechanisms, statistical
 43 // information, etc.
 44 
 45 class SharedRuntime: AllStatic {
 46   friend class VMStructs;
 47 
 48  private:
 49   static methodHandle resolve_sub_helper(bool is_virtual, bool is_optimized, TRAPS);
 50 
 51   // Shared stub locations
 52 
 53   static RuntimeStub*        _wrong_method_blob;
 54   static RuntimeStub*        _wrong_method_abstract_blob;
 55   static RuntimeStub*        _ic_miss_blob;
 56   static RuntimeStub*        _resolve_opt_virtual_call_blob;
 57   static RuntimeStub*        _resolve_virtual_call_blob;
 58   static RuntimeStub*        _resolve_static_call_blob;
 59   static address             _resolve_static_call_entry;
 60 
 61   static DeoptimizationBlob* _deopt_blob;
 62 
 63   static SafepointBlob*      _polling_page_vectors_safepoint_handler_blob;
 64   static SafepointBlob*      _polling_page_safepoint_handler_blob;
 65   static SafepointBlob*      _polling_page_return_handler_blob;
 66 
 67 #ifdef COMPILER2
 68   static UncommonTrapBlob*   _uncommon_trap_blob;
 69 #endif // COMPILER2
 70 
 71   static nmethod*            _cont_doYield_stub;
 72 
 73 #ifndef PRODUCT
 74   // Counters
 75   static int64_t _nof_megamorphic_calls;         // total # of megamorphic calls (through vtable)
 76 #endif // !PRODUCT
 77 
 78  private:
 79   enum { POLL_AT_RETURN,  POLL_AT_LOOP, POLL_AT_VECTOR_LOOP };
 80   static SafepointBlob* generate_handler_blob(address call_ptr, int poll_type);
 81   static RuntimeStub*   generate_resolve_blob(address destination, const char* name);
 82 
 83  public:
 84   static void generate_stubs(void);
 85 
 86   // max bytes for each dtrace string parameter
 87   enum { max_dtrace_string_size = 256 };
 88 
 89   // The following arithmetic routines are used on platforms that do
 90   // not have machine instructions to implement their functionality.
 91   // Do not remove these.
 92 
 93   // long arithmetics
 94   static jlong   lmul(jlong y, jlong x);
 95   static jlong   ldiv(jlong y, jlong x);
 96   static jlong   lrem(jlong y, jlong x);
 97 
 98   // float and double remainder
 99   static jfloat  frem(jfloat  x, jfloat  y);
100   static jdouble drem(jdouble x, jdouble y);
101 
102 

303   // on top of the stack.
304   // The caller (or one of its callers) must use a ResourceMark
305   // in order to correctly free the result.
306   //
307   static char* generate_class_cast_message(JavaThread* thr, Klass* caster_klass);
308 
309   // Fill in the "X cannot be cast to a Y" message for ClassCastException
310   //
311   // @param caster_klass the class of the object we are casting
312   // @param target_klass the target klass attempt
313   // @return the dynamically allocated exception message (must be freed
314   // by the caller using a resource mark)
315   //
316   // This version does not require access the frame, so it can be called
317   // from interpreted code
318   // The caller (or one of it's callers) must use a ResourceMark
319   // in order to correctly free the result.
320   //
321   static char* generate_class_cast_message(Klass* caster_klass, Klass* target_klass, Symbol* target_klass_name = nullptr);
322 


323   // Resolves a call site- may patch in the destination of the call into the
324   // compiled code.
325   static methodHandle resolve_helper(bool is_virtual, bool is_optimized, TRAPS);
326 
327  private:
328   // deopt blob
329   static void generate_deopt_blob(void);
330 
331   static bool handle_ic_miss_helper_internal(Handle receiver, CompiledMethod* caller_nm, const frame& caller_frame,
332                                              methodHandle callee_method, Bytecodes::Code bc, CallInfo& call_info,
333                                              bool& needs_ic_stub_refill, TRAPS);
334 
335  public:
336   static DeoptimizationBlob* deopt_blob(void)      { return _deopt_blob; }
337 
338   // Resets a call-site in compiled code so it will get resolved again.
339   static methodHandle reresolve_call_site(TRAPS);
340 
341   // In the code prolog, if the klass comparison fails, the inline cache
342   // misses and the call site is patched to megamorphic
343   static methodHandle handle_ic_miss_helper(TRAPS);
344 
345   // Find the method that called us.
346   static methodHandle find_callee_method(TRAPS);
347 
348   static void monitor_enter_helper(oopDesc* obj, BasicLock* lock, JavaThread* thread);
349 
350   static void monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThread* current);
351 













352  private:
353   static Handle find_callee_info(Bytecodes::Code& bc, CallInfo& callinfo, TRAPS);
354   static Handle find_callee_info_helper(vframeStream& vfst, Bytecodes::Code& bc, CallInfo& callinfo, TRAPS);
355 
356   static Method* extract_attached_method(vframeStream& vfst);
357 
358 #if defined(X86) && defined(COMPILER1)
359   // For Object.hashCode, System.identityHashCode try to pull hashCode from object header if available.
360   static void inline_check_hashcode_from_object_header(MacroAssembler* masm, const methodHandle& method, Register obj_reg, Register result);
361 #endif // X86 && COMPILER1
362 
363  public:
364 
365   // Read the array of BasicTypes from a Java signature, and compute where
366   // compiled Java code would like to put the results.  Values in reg_lo and
367   // reg_hi refer to 4-byte quantities.  Values less than SharedInfo::stack0 are
368   // registers, those above refer to 4-byte stack slots.  All stack slots are
369   // based off of the window top.  SharedInfo::stack0 refers to the first usable
370   // slot in the bottom of the frame. SharedInfo::stack0+1 refers to the memory word
371   // 4-bytes higher.
372   // return value is the maximum number of VMReg stack slots the convention will use.
373   static int java_calling_convention(const BasicType* sig_bt, VMRegPair* regs, int total_args_passed);








374 
375   static void check_member_name_argument_is_last_argument(const methodHandle& method,
376                                                           const BasicType* sig_bt,
377                                                           const VMRegPair* regs) NOT_DEBUG_RETURN;
378 
379   // Ditto except for calling C
380   //
381   // C argument in register AND stack slot.
382   // Some architectures require that an argument must be passed in a register
383   // AND in a stack slot. These architectures provide a second VMRegPair array
384   // to be filled by the c_calling_convention method. On other architectures,
385   // null is being passed as the second VMRegPair array, so arguments are either
386   // passed in a register OR in a stack slot.
387   static int c_calling_convention(const BasicType *sig_bt, VMRegPair *regs, int total_args_passed);
388 
389   static int vector_calling_convention(VMRegPair *regs,
390                                        uint num_bits,
391                                        uint total_args_passed);
392 
393   // Generate I2C and C2I adapters. These adapters are simple argument marshalling

400   // by the time we reach the blob there is compiled code available. This allows
401   // the blob to pass the incoming stack pointer (the sender sp) in a known
402   // location for the interpreter to record. This is used by the frame code
403   // to correct the sender code to match up with the stack pointer when the
404   // thread left the compiled code. In addition it allows the interpreter
405   // to remove the space the c2i adapter allocated to do its argument conversion.
406 
407   // Although a c2i blob will always run interpreted even if compiled code is
408   // present if we see that compiled code is present the compiled call site
409   // will be patched/re-resolved so that later calls will run compiled.
410 
411   // Additionally a c2i blob need to have a unverified entry because it can be reached
412   // in situations where the call site is an inlined cache site and may go megamorphic.
413 
414   // A i2c adapter is simpler than the c2i adapter. This is because it is assumed
415   // that the interpreter before it does any call dispatch will record the current
416   // stack pointer in the interpreter frame. On return it will restore the stack
417   // pointer as needed. This means the i2c adapter code doesn't need any special
418   // handshaking path with compiled code to keep the stack walking correct.
419 
420   static AdapterHandlerEntry* generate_i2c2i_adapters(MacroAssembler *_masm,
421                                                       int total_args_passed,
422                                                       int max_arg,
423                                                       const BasicType *sig_bt,
424                                                       const VMRegPair *regs,
425                                                       AdapterFingerPrint* fingerprint);





426 
427   static void gen_i2c_adapter(MacroAssembler *_masm,
428                               int total_args_passed,
429                               int comp_args_on_stack,
430                               const BasicType *sig_bt,
431                               const VMRegPair *regs);
432 
433   // OSR support
434 
435   // OSR_migration_begin will extract the jvm state from an interpreter
436   // frame (locals, monitors) and store the data in a piece of C heap
437   // storage. This then allows the interpreter frame to be removed from the
438   // stack and the OSR nmethod to be called. That method is called with a
439   // pointer to the C heap storage. This pointer is the return value from
440   // OSR_migration_begin.
441 
442   static intptr_t* OSR_migration_begin(JavaThread *thread);
443 
444   // OSR_migration_end is a trivial routine. It is called after the compiled
445   // method has extracted the jvm state from the C heap that OSR_migration_begin
446   // created. It's entire job is to simply free this storage.
447   static void OSR_migration_end(intptr_t* buf);
448 
449   // Convert a sig into a calling convention register layout
450   // and find interesting things about it.

483                                           const methodHandle& method,
484                                           int compile_id,
485                                           BasicType* sig_bt,
486                                           VMRegPair* regs,
487                                           BasicType ret_type);
488 
489   // A compiled caller has just called the interpreter, but compiled code
490   // exists.  Patch the caller so he no longer calls into the interpreter.
491   static void fixup_callers_callsite(Method* moop, address ret_pc);
492   static bool should_fixup_call_destination(address destination, address entry_point, address caller_pc, Method* moop, CodeBlob* cb);
493 
494   // Slow-path Locking and Unlocking
495   static void complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current);
496   static void complete_monitor_unlocking_C(oopDesc* obj, BasicLock* lock, JavaThread* current);
497 
498   // Resolving of calls
499   static address resolve_static_call_C     (JavaThread* current);
500   static address resolve_virtual_call_C    (JavaThread* current);
501   static address resolve_opt_virtual_call_C(JavaThread* current);
502 



503   // arraycopy, the non-leaf version.  (See StubRoutines for all the leaf calls.)
504   static void slow_arraycopy_C(oopDesc* src,  jint src_pos,
505                                oopDesc* dest, jint dest_pos,
506                                jint length, JavaThread* thread);
507 
508   // handle ic miss with caller being compiled code
509   // wrong method handling (inline cache misses)
510   static address handle_wrong_method(JavaThread* current);
511   static address handle_wrong_method_abstract(JavaThread* current);
512   static address handle_wrong_method_ic_miss(JavaThread* current);


513 
514   static address handle_unsafe_access(JavaThread* thread, address next_pc);
515 

516 #ifndef PRODUCT
517 
518   // Collect and print inline cache miss statistics
519  private:
520   enum { maxICmiss_count = 100 };
521   static int     _ICmiss_index;                  // length of IC miss histogram
522   static int     _ICmiss_count[maxICmiss_count]; // miss counts
523   static address _ICmiss_at[maxICmiss_count];    // miss addresses
524   static void trace_ic_miss(address at);
525 
526  public:
527   static uint _ic_miss_ctr;                      // total # of IC misses
528   static uint _wrong_method_ctr;
529   static uint _resolve_static_ctr;
530   static uint _resolve_virtual_ctr;
531   static uint _resolve_opt_virtual_ctr;
532   static uint _implicit_null_throws;
533   static uint _implicit_div0_throws;
534 
535   static uint _jbyte_array_copy_ctr;       // Slow-path byte array copy

602 // Rmethod->_i2i_entry.  On entry, the interpreted frame has not yet been
603 // setup.  Compiled frames are fixed-size and the args are likely not in the
604 // right place.  Hence all the args will likely be copied into the
605 // interpreter's frame, forcing that frame to grow.  The compiled frame's
606 // outgoing stack args will be dead after the copy.
607 //
608 // Native wrappers, like adapters, marshal arguments.  Unlike adapters they
609 // also perform an official frame push & pop.  They have a call to the native
610 // routine in their middles and end in a return (instead of ending in a jump).
611 // The native wrappers are stored in real nmethods instead of the BufferBlobs
612 // used by the adapters.  The code generation happens here because it's very
613 // similar to what the adapters have to do.
614 
615 class AdapterHandlerEntry : public CHeapObj<mtCode> {
616   friend class AdapterHandlerLibrary;
617 
618  private:
619   AdapterFingerPrint* _fingerprint;
620   address _i2c_entry;
621   address _c2i_entry;


622   address _c2i_unverified_entry;

623   address _c2i_no_clinit_check_entry;
624 



625 #ifdef ASSERT
626   // Captures code and signature used to generate this adapter when
627   // verifying adapter equivalence.
628   unsigned char* _saved_code;
629   int            _saved_code_length;
630 #endif
631 
632   AdapterHandlerEntry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry,
633                       address c2i_unverified_entry,

634                       address c2i_no_clinit_check_entry) :
635     _fingerprint(fingerprint),
636     _i2c_entry(i2c_entry),
637     _c2i_entry(c2i_entry),


638     _c2i_unverified_entry(c2i_unverified_entry),
639     _c2i_no_clinit_check_entry(c2i_no_clinit_check_entry)


640 #ifdef ASSERT
641     , _saved_code_length(0)
642 #endif
643   { }
644 
645   ~AdapterHandlerEntry();
646 
647  public:
648   address get_i2c_entry()                  const { return _i2c_entry; }
649   address get_c2i_entry()                  const { return _c2i_entry; }
650   address get_c2i_unverified_entry()       const { return _c2i_unverified_entry; }
651   address get_c2i_no_clinit_check_entry()  const { return _c2i_no_clinit_check_entry; }



652 
653   address base_address();
654   void relocate(address new_base);
655 




656   AdapterFingerPrint* fingerprint() const { return _fingerprint; }
657 
658 #ifdef ASSERT
659   // Used to verify that code generated for shared adapters is equivalent
660   void save_code   (unsigned char* code, int length);
661   bool compare_code(AdapterHandlerEntry* other);
662 #endif
663 
664   //virtual void print_on(outputStream* st) const;  DO NOT USE
665   void print_adapter_on(outputStream* st) const;
666 };
667 


668 class AdapterHandlerLibrary: public AllStatic {
669   friend class SharedRuntime;
670  private:
671   static BufferBlob* _buffer; // the temporary code buffer in CodeCache
672   static AdapterHandlerEntry* _abstract_method_handler;
673   static AdapterHandlerEntry* _no_arg_handler;
674   static AdapterHandlerEntry* _int_arg_handler;
675   static AdapterHandlerEntry* _obj_arg_handler;
676   static AdapterHandlerEntry* _obj_int_arg_handler;
677   static AdapterHandlerEntry* _obj_obj_arg_handler;
678 
679   static BufferBlob* buffer_blob();
680   static void initialize();
681   static AdapterHandlerEntry* create_adapter(AdapterBlob*& new_adapter,
682                                              int total_args_passed,
683                                              BasicType* sig_bt,
684                                              bool allocate_code_blob);
685   static AdapterHandlerEntry* get_simple_adapter(const methodHandle& method);
686  public:
687 
688   static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint,
689                                         address i2c_entry,
690                                         address c2i_entry,
691                                         address c2i_unverified_entry,
692                                         address c2i_no_clinit_check_entry = nullptr);
693   static void create_native_wrapper(const methodHandle& method);
694   static AdapterHandlerEntry* get_adapter(const methodHandle& method);
695 
696   static void print_handler(const CodeBlob* b) { print_handler_on(tty, b); }
697   static void print_handler_on(outputStream* st, const CodeBlob* b);
698   static bool contains(const CodeBlob* b);
699 #ifndef PRODUCT
700   static void print_statistics();
701 #endif // PRODUCT
702 
703 };
704 



























































705 #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 "utilities/macros.hpp"
 36 
 37 class AdapterHandlerEntry;
 38 class AdapterFingerPrint;
 39 class vframeStream;
 40 class SigEntry;
 41 
 42 // Runtime is the base class for various runtime interfaces
 43 // (InterpreterRuntime, CompilerRuntime, etc.). It provides
 44 // shared functionality such as exception forwarding (C++ to
 45 // Java exceptions), locking/unlocking mechanisms, statistical
 46 // information, etc.
 47 
 48 class SharedRuntime: AllStatic {
 49   friend class VMStructs;
 50 
 51  private:


 52   // Shared stub locations
 53 
 54   static RuntimeStub*        _wrong_method_blob;
 55   static RuntimeStub*        _wrong_method_abstract_blob;
 56   static RuntimeStub*        _ic_miss_blob;
 57   static RuntimeStub*        _resolve_opt_virtual_call_blob;
 58   static RuntimeStub*        _resolve_virtual_call_blob;
 59   static RuntimeStub*        _resolve_static_call_blob;

 60 
 61   static DeoptimizationBlob* _deopt_blob;
 62 
 63   static SafepointBlob*      _polling_page_vectors_safepoint_handler_blob;
 64   static SafepointBlob*      _polling_page_safepoint_handler_blob;
 65   static SafepointBlob*      _polling_page_return_handler_blob;
 66 
 67 #ifdef COMPILER2
 68   static UncommonTrapBlob*   _uncommon_trap_blob;
 69 #endif // COMPILER2
 70 
 71   static nmethod*            _cont_doYield_stub;
 72 
 73 #ifndef PRODUCT
 74   // Counters
 75   static int64_t _nof_megamorphic_calls;         // total # of megamorphic calls (through vtable)
 76 #endif // !PRODUCT
 77 
 78  private:
 79   enum { POLL_AT_RETURN,  POLL_AT_LOOP, POLL_AT_VECTOR_LOOP };
 80   static SafepointBlob* generate_handler_blob(address call_ptr, int poll_type);
 81   static RuntimeStub*   generate_resolve_blob(address destination, const char* name);

 82  public:
 83   static void generate_stubs(void);
 84 
 85   // max bytes for each dtrace string parameter
 86   enum { max_dtrace_string_size = 256 };
 87 
 88   // The following arithmetic routines are used on platforms that do
 89   // not have machine instructions to implement their functionality.
 90   // Do not remove these.
 91 
 92   // long arithmetics
 93   static jlong   lmul(jlong y, jlong x);
 94   static jlong   ldiv(jlong y, jlong x);
 95   static jlong   lrem(jlong y, jlong x);
 96 
 97   // float and double remainder
 98   static jfloat  frem(jfloat  x, jfloat  y);
 99   static jdouble drem(jdouble x, jdouble y);
100 
101 

302   // on top of the stack.
303   // The caller (or one of its callers) must use a ResourceMark
304   // in order to correctly free the result.
305   //
306   static char* generate_class_cast_message(JavaThread* thr, Klass* caster_klass);
307 
308   // Fill in the "X cannot be cast to a Y" message for ClassCastException
309   //
310   // @param caster_klass the class of the object we are casting
311   // @param target_klass the target klass attempt
312   // @return the dynamically allocated exception message (must be freed
313   // by the caller using a resource mark)
314   //
315   // This version does not require access the frame, so it can be called
316   // from interpreted code
317   // The caller (or one of it's callers) must use a ResourceMark
318   // in order to correctly free the result.
319   //
320   static char* generate_class_cast_message(Klass* caster_klass, Klass* target_klass, Symbol* target_klass_name = nullptr);
321 
322   static char* generate_identity_exception_message(JavaThread* thr, Klass* klass);
323 
324   // Resolves a call site- may patch in the destination of the call into the
325   // compiled code.
326   static methodHandle resolve_helper(bool is_virtual, bool is_optimized, bool& caller_is_c1, TRAPS);
327 
328  private:
329   // deopt blob
330   static void generate_deopt_blob(void);
331 
332   static bool handle_ic_miss_helper_internal(Handle receiver, CompiledMethod* caller_nm, const frame& caller_frame,
333                                              methodHandle callee_method, Bytecodes::Code bc, CallInfo& call_info,
334                                              bool& needs_ic_stub_refill, bool& is_optimized, bool caller_is_c1, TRAPS);
335 
336  public:
337   static DeoptimizationBlob* deopt_blob(void)      { return _deopt_blob; }
338 
339   // Resets a call-site in compiled code so it will get resolved again.
340   static methodHandle reresolve_call_site(bool& is_static_call, bool& is_optimized, bool& caller_is_c1, TRAPS);
341 
342   // In the code prolog, if the klass comparison fails, the inline cache
343   // misses and the call site is patched to megamorphic
344   static methodHandle handle_ic_miss_helper(bool& is_optimized, bool& caller_is_c1, TRAPS);
345 
346   // Find the method that called us.
347   static methodHandle find_callee_method(bool is_optimized, bool& caller_is_c1, TRAPS);
348 
349   static void monitor_enter_helper(oopDesc* obj, BasicLock* lock, JavaThread* thread);
350 
351   static void monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThread* current);
352 
353   static address entry_for_handle_wrong_method(methodHandle callee_method, bool is_static_call, bool is_optimized, bool caller_is_c1) {
354     assert(callee_method->verified_code_entry() != nullptr, "Jump to zero!");
355     assert(callee_method->verified_inline_code_entry() != nullptr, "Jump to zero!");
356     assert(callee_method->verified_inline_ro_code_entry() != nullptr, "Jump to zero!");
357     if (caller_is_c1) {
358       return callee_method->verified_inline_code_entry();
359     } else if (is_static_call || is_optimized) {
360       return callee_method->verified_code_entry();
361     } else {
362       return callee_method->verified_inline_ro_code_entry();
363     }
364   }
365 
366  private:
367   static Handle find_callee_info(Bytecodes::Code& bc, CallInfo& callinfo, TRAPS);
368   static Handle find_callee_info_helper(vframeStream& vfst, Bytecodes::Code& bc, CallInfo& callinfo, TRAPS);
369 
370   static Method* extract_attached_method(vframeStream& vfst);
371 
372 #if defined(X86) && defined(COMPILER1)
373   // For Object.hashCode, System.identityHashCode try to pull hashCode from object header if available.
374   static void inline_check_hashcode_from_object_header(MacroAssembler* masm, const methodHandle& method, Register obj_reg, Register result);
375 #endif // X86 && COMPILER1
376 
377  public:
378 
379   // Read the array of BasicTypes from a Java signature, and compute where
380   // compiled Java code would like to put the results.  Values in reg_lo and
381   // reg_hi refer to 4-byte quantities.  Values less than SharedInfo::stack0 are
382   // registers, those above refer to 4-byte stack slots.  All stack slots are
383   // based off of the window top.  SharedInfo::stack0 refers to the first usable
384   // slot in the bottom of the frame. SharedInfo::stack0+1 refers to the memory word
385   // 4-bytes higher.
386   // return value is the maximum number of VMReg stack slots the convention will use.
387   static int java_calling_convention(const BasicType* sig_bt, VMRegPair* regs, int total_args_passed);
388   static int java_calling_convention(const GrowableArray<SigEntry>* sig, VMRegPair* regs) {
389     BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sig->length());
390     int total_args_passed = SigEntry::fill_sig_bt(sig, sig_bt);
391     return java_calling_convention(sig_bt, regs, total_args_passed);
392   }
393   static int java_return_convention(const BasicType* sig_bt, VMRegPair* regs, int total_args_passed);
394   static const uint java_return_convention_max_int;
395   static const uint java_return_convention_max_float;
396 
397   static void check_member_name_argument_is_last_argument(const methodHandle& method,
398                                                           const BasicType* sig_bt,
399                                                           const VMRegPair* regs) NOT_DEBUG_RETURN;
400 
401   // Ditto except for calling C
402   //
403   // C argument in register AND stack slot.
404   // Some architectures require that an argument must be passed in a register
405   // AND in a stack slot. These architectures provide a second VMRegPair array
406   // to be filled by the c_calling_convention method. On other architectures,
407   // null is being passed as the second VMRegPair array, so arguments are either
408   // passed in a register OR in a stack slot.
409   static int c_calling_convention(const BasicType *sig_bt, VMRegPair *regs, int total_args_passed);
410 
411   static int vector_calling_convention(VMRegPair *regs,
412                                        uint num_bits,
413                                        uint total_args_passed);
414 
415   // Generate I2C and C2I adapters. These adapters are simple argument marshalling

422   // by the time we reach the blob there is compiled code available. This allows
423   // the blob to pass the incoming stack pointer (the sender sp) in a known
424   // location for the interpreter to record. This is used by the frame code
425   // to correct the sender code to match up with the stack pointer when the
426   // thread left the compiled code. In addition it allows the interpreter
427   // to remove the space the c2i adapter allocated to do its argument conversion.
428 
429   // Although a c2i blob will always run interpreted even if compiled code is
430   // present if we see that compiled code is present the compiled call site
431   // will be patched/re-resolved so that later calls will run compiled.
432 
433   // Additionally a c2i blob need to have a unverified entry because it can be reached
434   // in situations where the call site is an inlined cache site and may go megamorphic.
435 
436   // A i2c adapter is simpler than the c2i adapter. This is because it is assumed
437   // that the interpreter before it does any call dispatch will record the current
438   // stack pointer in the interpreter frame. On return it will restore the stack
439   // pointer as needed. This means the i2c adapter code doesn't need any special
440   // handshaking path with compiled code to keep the stack walking correct.
441 
442   static AdapterHandlerEntry* generate_i2c2i_adapters(MacroAssembler *masm,
443                                                       int comp_args_on_stack,
444                                                       const GrowableArray<SigEntry>* sig,
445                                                       const VMRegPair* regs,
446                                                       const GrowableArray<SigEntry>* sig_cc,
447                                                       const VMRegPair* regs_cc,
448                                                       const GrowableArray<SigEntry>* sig_cc_ro,
449                                                       const VMRegPair* regs_cc_ro,
450                                                       AdapterFingerPrint* fingerprint,
451                                                       AdapterBlob*& new_adapter,
452                                                       bool allocate_code_blob);
453 
454   static void gen_i2c_adapter(MacroAssembler *_masm,

455                               int comp_args_on_stack,
456                               const GrowableArray<SigEntry>* sig,
457                               const VMRegPair *regs);
458 
459   // OSR support
460 
461   // OSR_migration_begin will extract the jvm state from an interpreter
462   // frame (locals, monitors) and store the data in a piece of C heap
463   // storage. This then allows the interpreter frame to be removed from the
464   // stack and the OSR nmethod to be called. That method is called with a
465   // pointer to the C heap storage. This pointer is the return value from
466   // OSR_migration_begin.
467 
468   static intptr_t* OSR_migration_begin(JavaThread *thread);
469 
470   // OSR_migration_end is a trivial routine. It is called after the compiled
471   // method has extracted the jvm state from the C heap that OSR_migration_begin
472   // created. It's entire job is to simply free this storage.
473   static void OSR_migration_end(intptr_t* buf);
474 
475   // Convert a sig into a calling convention register layout
476   // and find interesting things about it.

509                                           const methodHandle& method,
510                                           int compile_id,
511                                           BasicType* sig_bt,
512                                           VMRegPair* regs,
513                                           BasicType ret_type);
514 
515   // A compiled caller has just called the interpreter, but compiled code
516   // exists.  Patch the caller so he no longer calls into the interpreter.
517   static void fixup_callers_callsite(Method* moop, address ret_pc);
518   static bool should_fixup_call_destination(address destination, address entry_point, address caller_pc, Method* moop, CodeBlob* cb);
519 
520   // Slow-path Locking and Unlocking
521   static void complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current);
522   static void complete_monitor_unlocking_C(oopDesc* obj, BasicLock* lock, JavaThread* current);
523 
524   // Resolving of calls
525   static address resolve_static_call_C     (JavaThread* current);
526   static address resolve_virtual_call_C    (JavaThread* current);
527   static address resolve_opt_virtual_call_C(JavaThread* current);
528 
529   static void load_inline_type_fields_in_regs(JavaThread* current, oopDesc* res);
530   static void store_inline_type_fields_to_buf(JavaThread* current, intptr_t res);
531 
532   // arraycopy, the non-leaf version.  (See StubRoutines for all the leaf calls.)
533   static void slow_arraycopy_C(oopDesc* src,  jint src_pos,
534                                oopDesc* dest, jint dest_pos,
535                                jint length, JavaThread* thread);
536 
537   // handle ic miss with caller being compiled code
538   // wrong method handling (inline cache misses)
539   static address handle_wrong_method(JavaThread* current);
540   static address handle_wrong_method_abstract(JavaThread* current);
541   static address handle_wrong_method_ic_miss(JavaThread* current);
542   static void allocate_inline_types(JavaThread* current, Method* callee, bool allocate_receiver);
543   static oop allocate_inline_types_impl(JavaThread* current, methodHandle callee, bool allocate_receiver, TRAPS);
544 
545   static address handle_unsafe_access(JavaThread* thread, address next_pc);
546 
547   static BufferedInlineTypeBlob* generate_buffered_inline_type_adapter(const InlineKlass* vk);
548 #ifndef PRODUCT
549 
550   // Collect and print inline cache miss statistics
551  private:
552   enum { maxICmiss_count = 100 };
553   static int     _ICmiss_index;                  // length of IC miss histogram
554   static int     _ICmiss_count[maxICmiss_count]; // miss counts
555   static address _ICmiss_at[maxICmiss_count];    // miss addresses
556   static void trace_ic_miss(address at);
557 
558  public:
559   static uint _ic_miss_ctr;                      // total # of IC misses
560   static uint _wrong_method_ctr;
561   static uint _resolve_static_ctr;
562   static uint _resolve_virtual_ctr;
563   static uint _resolve_opt_virtual_ctr;
564   static uint _implicit_null_throws;
565   static uint _implicit_div0_throws;
566 
567   static uint _jbyte_array_copy_ctr;       // Slow-path byte array copy

634 // Rmethod->_i2i_entry.  On entry, the interpreted frame has not yet been
635 // setup.  Compiled frames are fixed-size and the args are likely not in the
636 // right place.  Hence all the args will likely be copied into the
637 // interpreter's frame, forcing that frame to grow.  The compiled frame's
638 // outgoing stack args will be dead after the copy.
639 //
640 // Native wrappers, like adapters, marshal arguments.  Unlike adapters they
641 // also perform an official frame push & pop.  They have a call to the native
642 // routine in their middles and end in a return (instead of ending in a jump).
643 // The native wrappers are stored in real nmethods instead of the BufferBlobs
644 // used by the adapters.  The code generation happens here because it's very
645 // similar to what the adapters have to do.
646 
647 class AdapterHandlerEntry : public CHeapObj<mtCode> {
648   friend class AdapterHandlerLibrary;
649 
650  private:
651   AdapterFingerPrint* _fingerprint;
652   address _i2c_entry;
653   address _c2i_entry;
654   address _c2i_inline_entry;
655   address _c2i_inline_ro_entry;
656   address _c2i_unverified_entry;
657   address _c2i_unverified_inline_entry;
658   address _c2i_no_clinit_check_entry;
659 
660   // Support for scalarized inline type calling convention
661   const GrowableArray<SigEntry>* _sig_cc;
662 
663 #ifdef ASSERT
664   // Captures code and signature used to generate this adapter when
665   // verifying adapter equivalence.
666   unsigned char* _saved_code;
667   int            _saved_code_length;
668 #endif
669 
670   AdapterHandlerEntry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry,
671                       address c2i_inline_entry, address c2i_inline_ro_entry,
672                       address c2i_unverified_entry, address c2i_unverified_inline_entry,
673                       address c2i_no_clinit_check_entry) :
674     _fingerprint(fingerprint),
675     _i2c_entry(i2c_entry),
676     _c2i_entry(c2i_entry),
677     _c2i_inline_entry(c2i_inline_entry),
678     _c2i_inline_ro_entry(c2i_inline_ro_entry),
679     _c2i_unverified_entry(c2i_unverified_entry),
680     _c2i_unverified_inline_entry(c2i_unverified_inline_entry),
681     _c2i_no_clinit_check_entry(c2i_no_clinit_check_entry),
682     _sig_cc(nullptr)
683 #ifdef ASSERT
684     , _saved_code_length(0)
685 #endif
686   { }
687 
688   ~AdapterHandlerEntry();
689 
690  public:
691   address get_i2c_entry()                   const { return _i2c_entry; }
692   address get_c2i_entry()                   const { return _c2i_entry; }
693   address get_c2i_inline_entry()            const { return _c2i_inline_entry; }
694   address get_c2i_inline_ro_entry()         const { return _c2i_inline_ro_entry; }
695   address get_c2i_unverified_entry()        const { return _c2i_unverified_entry; }
696   address get_c2i_unverified_inline_entry() const { return _c2i_unverified_inline_entry; }
697   address get_c2i_no_clinit_check_entry()   const { return _c2i_no_clinit_check_entry; }
698 
699   address base_address();
700   void relocate(address new_base);
701 
702   // Support for scalarized inline type calling convention
703   void set_sig_cc(const GrowableArray<SigEntry>* sig)  { _sig_cc = sig; }
704   const GrowableArray<SigEntry>* get_sig_cc()    const { return _sig_cc; }
705 
706   AdapterFingerPrint* fingerprint() const { return _fingerprint; }
707 
708 #ifdef ASSERT
709   // Used to verify that code generated for shared adapters is equivalent
710   void save_code   (unsigned char* code, int length);
711   bool compare_code(AdapterHandlerEntry* other);
712 #endif
713 
714   //virtual void print_on(outputStream* st) const;  DO NOT USE
715   void print_adapter_on(outputStream* st) const;
716 };
717 
718 class CompiledEntrySignature;
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                                              CompiledEntrySignature& ces,

735                                              bool allocate_code_blob);
736   static AdapterHandlerEntry* get_simple_adapter(const methodHandle& method);
737  public:
738 
739   static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint,
740                                         address i2c_entry, address c2i_entry, address c2i_inline_entry, address c2i_inline_ro_entry,
741                                         address c2i_unverified_entry, address c2i_unverified_inline_entry, address c2i_no_clinit_check_entry = nullptr);


742   static void create_native_wrapper(const methodHandle& method);
743   static AdapterHandlerEntry* get_adapter(const methodHandle& method);
744 
745   static void print_handler(const CodeBlob* b) { print_handler_on(tty, b); }
746   static void print_handler_on(outputStream* st, const CodeBlob* b);
747   static bool contains(const CodeBlob* b);
748 #ifndef PRODUCT
749   static void print_statistics();
750 #endif // PRODUCT
751 
752 };
753 
754 // Utility class for computing the calling convention of the 3 types
755 // of compiled method entries:
756 //     Method::_from_compiled_entry               - sig_cc
757 //     Method::_from_compiled_inline_ro_entry     - sig_cc_ro
758 //     Method::_from_compiled_inline_entry        - sig
759 class CompiledEntrySignature : public StackObj {
760   Method* _method;
761   int  _num_inline_args;
762   bool _has_inline_recv;
763   GrowableArray<SigEntry>* _sig;
764   GrowableArray<SigEntry>* _sig_cc;
765   GrowableArray<SigEntry>* _sig_cc_ro;
766   VMRegPair* _regs;
767   VMRegPair* _regs_cc;
768   VMRegPair* _regs_cc_ro;
769 
770   int _args_on_stack;
771   int _args_on_stack_cc;
772   int _args_on_stack_cc_ro;
773 
774   bool _c1_needs_stack_repair;
775   bool _c2_needs_stack_repair;
776 
777   GrowableArray<Method*>* _supers;
778 
779 public:
780   Method* method()                     const { return _method; }
781 
782   // Used by Method::_from_compiled_inline_entry
783   GrowableArray<SigEntry>* sig()       const { return _sig; }
784 
785   // Used by Method::_from_compiled_entry
786   GrowableArray<SigEntry>* sig_cc()    const { return _sig_cc; }
787 
788   // Used by Method::_from_compiled_inline_ro_entry
789   GrowableArray<SigEntry>* sig_cc_ro() const { return _sig_cc_ro; }
790 
791   VMRegPair* regs()                    const { return _regs; }
792   VMRegPair* regs_cc()                 const { return _regs_cc; }
793   VMRegPair* regs_cc_ro()              const { return _regs_cc_ro; }
794 
795   int args_on_stack()                  const { return _args_on_stack; }
796   int args_on_stack_cc()               const { return _args_on_stack_cc; }
797   int args_on_stack_cc_ro()            const { return _args_on_stack_cc_ro; }
798 
799   int  num_inline_args()               const { return _num_inline_args; }
800   bool has_inline_recv()               const { return _has_inline_recv; }
801 
802   bool has_scalarized_args()           const { return _sig != _sig_cc; }
803   bool c1_needs_stack_repair()         const { return _c1_needs_stack_repair; }
804   bool c2_needs_stack_repair()         const { return _c2_needs_stack_repair; }
805   CodeOffsets::Entries c1_inline_ro_entry_type() const;
806 
807   GrowableArray<Method*>* get_supers();
808 
809   CompiledEntrySignature(Method* method = nullptr);
810   void compute_calling_conventions(bool init = true);
811 };
812 
813 #endif // SHARE_RUNTIME_SHAREDRUNTIME_HPP
< prev index next >