< 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 "classfile/compactHashtable.hpp"
  29 #include "code/codeBlob.hpp"
  30 #include "code/vmreg.hpp"
  31 #include "interpreter/linkResolver.hpp"
  32 #include "memory/allStatic.hpp"
  33 #include "memory/metaspaceClosure.hpp"
  34 #include "memory/resourceArea.hpp"
  35 #include "runtime/safepointVerifiers.hpp"

  36 #include "runtime/stubInfo.hpp"
  37 #include "utilities/macros.hpp"
  38 
  39 class AdapterHandlerEntry;
  40 class AdapterFingerPrint;
  41 class vframeStream;

  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 class SharedRuntime: AllStatic {
  50  private:
  51   // Declare shared stub fields
  52 #define SHARED_STUB_FIELD_DECLARE(name, type) \
  53   static type*       BLOB_FIELD_NAME(name);
  54   SHARED_STUBS_DO(SHARED_STUB_FIELD_DECLARE)
  55 #undef SHARED_STUB_FIELD_DECLARE
  56 
  57 #ifdef ASSERT
  58   static bool is_resolve_id(StubId id) {
  59     return (id == StubId::shared_wrong_method_id ||
  60             id == StubId::shared_wrong_method_abstract_id ||
  61             id == StubId::shared_ic_miss_id ||

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


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








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

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





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

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

 560   static address resolve_static_call_C     (JavaThread* current);
 561   static address resolve_virtual_call_C    (JavaThread* current);
 562   static address resolve_opt_virtual_call_C(JavaThread* current);
 563 



 564   // arraycopy, the non-leaf version.  (See StubRoutines for all the leaf calls.)
 565   static void slow_arraycopy_C(oopDesc* src,  jint src_pos,
 566                                oopDesc* dest, jint dest_pos,
 567                                jint length, JavaThread* thread);
 568 
 569   // handle ic miss with caller being compiled code
 570   // wrong method handling (inline cache misses)
 571   static address handle_wrong_method(JavaThread* current);
 572   static address handle_wrong_method_abstract(JavaThread* current);
 573   static address handle_wrong_method_ic_miss(JavaThread* current);


 574 
 575   static address handle_unsafe_access(JavaThread* thread, address next_pc);
 576 

 577 #ifndef PRODUCT
 578 
 579   // Collect and print inline cache miss statistics
 580  private:
 581   enum { maxICmiss_count = 100 };
 582   static int     _ICmiss_index;                  // length of IC miss histogram
 583   static int     _ICmiss_count[maxICmiss_count]; // miss counts
 584   static address _ICmiss_at[maxICmiss_count];    // miss addresses
 585   static void trace_ic_miss(address at);
 586 
 587  public:
 588   static uint _ic_miss_ctr;                      // total # of IC misses
 589   static uint _wrong_method_ctr;
 590   static uint _resolve_static_ctr;
 591   static uint _resolve_virtual_ctr;
 592   static uint _resolve_opt_virtual_ctr;
 593   static uint _implicit_null_throws;
 594   static uint _implicit_div0_throws;
 595 
 596   static uint _jbyte_array_copy_ctr;       // Slow-path byte array copy

 695 //
 696 // The C2I flavor takes a stock compiled call setup plus the target method in
 697 // Rmethod, marshals the arguments for an interpreted call and jumps to
 698 // Rmethod->_i2i_entry.  On entry, the interpreted frame has not yet been
 699 // setup.  Compiled frames are fixed-size and the args are likely not in the
 700 // right place.  Hence all the args will likely be copied into the
 701 // interpreter's frame, forcing that frame to grow.  The compiled frame's
 702 // outgoing stack args will be dead after the copy.
 703 //
 704 // Native wrappers, like adapters, marshal arguments.  Unlike adapters they
 705 // also perform an official frame push & pop.  They have a call to the native
 706 // routine in their middles and end in a return (instead of ending in a jump).
 707 // The native wrappers are stored in real nmethods instead of the BufferBlobs
 708 // used by the adapters.  The code generation happens here because it's very
 709 // similar to what the adapters have to do.
 710 
 711 class AdapterHandlerEntry : public MetaspaceObj {
 712   friend class AdapterHandlerLibrary;
 713 
 714  public:
 715   static const int ENTRIES_COUNT = 4;
 716 
 717  private:
 718   AdapterFingerPrint* _fingerprint;
 719   AdapterBlob* _adapter_blob;
 720   uint _id;
 721   bool _linked;
 722 
 723   static const char *_entry_names[];
 724 



 725 #ifdef ASSERT
 726   // Captures code and signature used to generate this adapter when
 727   // verifying adapter equivalence.
 728   unsigned char* _saved_code;
 729   int            _saved_code_length;
 730 #endif
 731 
 732   AdapterHandlerEntry(int id, AdapterFingerPrint* fingerprint) :
 733     _fingerprint(fingerprint),
 734     _adapter_blob(nullptr),
 735     _id(id),
 736     _linked(false)

 737 #ifdef ASSERT
 738     , _saved_code(nullptr),
 739     _saved_code_length(0)
 740 #endif
 741   { }
 742 
 743   ~AdapterHandlerEntry();
 744 
 745   // Allocate on CHeap instead of metaspace (see JDK-8331086).
 746   // Dummy argument is used to avoid C++ warning about using
 747   // deleted opearator MetaspaceObj::delete().
 748   void* operator new(size_t size, size_t dummy) throw() {
 749     assert(size == BytesPerWord * heap_word_size(sizeof(AdapterHandlerEntry)), "should match");
 750     void* p = AllocateHeap(size, mtCode);
 751     memset(p, 0, size);
 752     return p;
 753   }
 754 
 755  public:
 756   static AdapterHandlerEntry* allocate(uint id, AdapterFingerPrint* fingerprint) {

 767   }
 768 
 769   address get_i2c_entry() const {
 770 #ifndef ZERO
 771     assert(_adapter_blob != nullptr, "must be");
 772     return _adapter_blob->i2c_entry();
 773 #else
 774     return nullptr;
 775 #endif // ZERO
 776   }
 777 
 778   address get_c2i_entry() const {
 779 #ifndef ZERO
 780     assert(_adapter_blob != nullptr, "must be");
 781     return _adapter_blob->c2i_entry();
 782 #else
 783     return nullptr;
 784 #endif // ZERO
 785   }
 786 


















 787   address get_c2i_unverified_entry() const {
 788 #ifndef ZERO
 789     assert(_adapter_blob != nullptr, "must be");
 790     return _adapter_blob->c2i_unverified_entry();
 791 #else
 792     return nullptr;
 793 #endif // ZERO
 794   }
 795 









 796   address get_c2i_no_clinit_check_entry()  const {
 797 #ifndef ZERO
 798     assert(_adapter_blob != nullptr, "must be");
 799     return _adapter_blob->c2i_no_clinit_check_entry();
 800 #else
 801     return nullptr;
 802 #endif // ZERO
 803   }
 804 
 805   AdapterBlob* adapter_blob() const { return _adapter_blob; }
 806   bool is_linked() const { return _linked; }
 807 




 808   uint id() const { return _id; }
 809   AdapterFingerPrint* fingerprint() const { return _fingerprint; }
 810 
 811 #ifdef ASSERT
 812   // Used to verify that code generated for shared adapters is equivalent
 813   void save_code   (unsigned char* code, int length);
 814   bool compare_code(AdapterHandlerEntry* other);
 815 #endif
 816 
 817   //virtual void print_on(outputStream* st) const;  DO NOT USE
 818   void print_adapter_on(outputStream* st) const;
 819 
 820   void metaspace_pointers_do(MetaspaceClosure* it);
 821   int size() const {return (int)heap_word_size(sizeof(AdapterHandlerEntry)); }
 822   MetaspaceObj::Type type() const { return AdapterHandlerEntryType; }
 823 
 824   void remove_unshareable_info() NOT_CDS_RETURN;
 825   void link() NOT_CDS_RETURN;
 826 };
 827 
 828 #if INCLUDE_CDS
 829 class ArchivedAdapterTable;
 830 #endif // INCLUDE_CDS
 831 


 832 class AdapterHandlerLibrary: public AllStatic {
 833   friend class SharedRuntime;
 834  private:
 835   static volatile uint _id_counter; // counter for generating unique adapter ids, range = [1,UINT_MAX]
 836   static BufferBlob* _buffer; // the temporary code buffer in CodeCache
 837   static AdapterHandlerEntry* _no_arg_handler;
 838   static AdapterHandlerEntry* _int_arg_handler;
 839   static AdapterHandlerEntry* _obj_arg_handler;
 840   static AdapterHandlerEntry* _obj_int_arg_handler;
 841   static AdapterHandlerEntry* _obj_obj_arg_handler;
 842 #if INCLUDE_CDS
 843   static ArchivedAdapterTable _aot_adapter_handler_table;
 844 #endif // INCLUDE_CDS
 845 
 846   static BufferBlob* buffer_blob();
 847   static void initialize();
 848   static AdapterHandlerEntry* get_simple_adapter(const methodHandle& method);
 849   static void lookup_aot_cache(AdapterHandlerEntry* handler);
 850   static AdapterHandlerEntry* create_adapter(int total_args_passed,
 851                                              BasicType* sig_bt,
 852                                              bool is_transient = false);
 853   static void lookup_simple_adapters() NOT_CDS_RETURN;
 854 #ifndef PRODUCT
 855   static void print_adapter_handler_info(outputStream* st, AdapterHandlerEntry* handler);
 856 #endif // PRODUCT
 857  public:
 858 
 859   static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint);
 860   static void create_native_wrapper(const methodHandle& method);
 861   static AdapterHandlerEntry* get_adapter(const methodHandle& method);
 862   static AdapterHandlerEntry* lookup(int total_args_passed, BasicType* sig_bt);
 863   static bool generate_adapter_code(AdapterHandlerEntry* handler,
 864                                     int total_args_passed,
 865                                     BasicType* sig_bt,
 866                                     bool is_transient);
 867 
 868 #ifdef ASSERT
 869   static void verify_adapter_sharing(int total_args_passed, BasicType* sig_bt, AdapterHandlerEntry* cached);
 870 #endif // ASSERT
 871 
 872   static void print_handler(const CodeBlob* b) { print_handler_on(tty, b); }
 873   static void print_handler_on(outputStream* st, const CodeBlob* b);
 874   static bool contains(const CodeBlob* b);
 875   static const char* name(AdapterHandlerEntry* handler);
 876   static uint32_t id(AdapterHandlerEntry* handler);
 877 #ifndef PRODUCT
 878   static void print_statistics();
 879 #endif // PRODUCT
 880 
 881   static void link_aot_adapter_handler(AdapterHandlerEntry* handler) NOT_CDS_RETURN;
 882   static void dump_aot_adapter_table() NOT_CDS_RETURN;
 883   static void serialize_shared_table_header(SerializeClosure* soc) NOT_CDS_RETURN;
 884   static void link_aot_adapters() NOT_CDS_RETURN;
 885   static void address_to_offset(address entry_address[AdapterBlob::ENTRY_COUNT], int entry_offset[AdapterBlob::ENTRY_COUNT]);
 886 };
 887 




























































 888 #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 "classfile/compactHashtable.hpp"
  30 #include "code/codeBlob.hpp"
  31 #include "code/vmreg.hpp"
  32 #include "interpreter/linkResolver.hpp"
  33 #include "memory/allStatic.hpp"
  34 #include "memory/metaspaceClosure.hpp"
  35 #include "memory/resourceArea.hpp"
  36 #include "runtime/safepointVerifiers.hpp"
  37 #include "runtime/signature.hpp"
  38 #include "runtime/stubInfo.hpp"
  39 #include "utilities/macros.hpp"
  40 
  41 class AdapterHandlerEntry;
  42 class AdapterFingerPrint;
  43 class vframeStream;
  44 class SigEntry;
  45 
  46 // Runtime is the base class for various runtime interfaces
  47 // (InterpreterRuntime, CompilerRuntime, etc.). It provides
  48 // shared functionality such as exception forwarding (C++ to
  49 // Java exceptions), locking/unlocking mechanisms, statistical
  50 // information, etc.
  51 
  52 class SharedRuntime: AllStatic {
  53  private:
  54   // Declare shared stub fields
  55 #define SHARED_STUB_FIELD_DECLARE(name, type) \
  56   static type*       BLOB_FIELD_NAME(name);
  57   SHARED_STUBS_DO(SHARED_STUB_FIELD_DECLARE)
  58 #undef SHARED_STUB_FIELD_DECLARE
  59 
  60 #ifdef ASSERT
  61   static bool is_resolve_id(StubId id) {
  62     return (id == StubId::shared_wrong_method_id ||
  63             id == StubId::shared_wrong_method_abstract_id ||
  64             id == StubId::shared_ic_miss_id ||

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

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

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

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

 719 //
 720 // The C2I flavor takes a stock compiled call setup plus the target method in
 721 // Rmethod, marshals the arguments for an interpreted call and jumps to
 722 // Rmethod->_i2i_entry.  On entry, the interpreted frame has not yet been
 723 // setup.  Compiled frames are fixed-size and the args are likely not in the
 724 // right place.  Hence all the args will likely be copied into the
 725 // interpreter's frame, forcing that frame to grow.  The compiled frame's
 726 // outgoing stack args will be dead after the copy.
 727 //
 728 // Native wrappers, like adapters, marshal arguments.  Unlike adapters they
 729 // also perform an official frame push & pop.  They have a call to the native
 730 // routine in their middles and end in a return (instead of ending in a jump).
 731 // The native wrappers are stored in real nmethods instead of the BufferBlobs
 732 // used by the adapters.  The code generation happens here because it's very
 733 // similar to what the adapters have to do.
 734 
 735 class AdapterHandlerEntry : public MetaspaceObj {
 736   friend class AdapterHandlerLibrary;
 737 
 738  public:
 739   static const int ENTRIES_COUNT = 7;
 740 
 741  private:
 742   AdapterFingerPrint* _fingerprint;
 743   AdapterBlob* _adapter_blob;
 744   uint _id;
 745   bool _linked;
 746 
 747   static const char *_entry_names[];
 748 
 749   // Support for scalarized inline type calling convention
 750   const GrowableArray<SigEntry>* _sig_cc;
 751 
 752 #ifdef ASSERT
 753   // Captures code and signature used to generate this adapter when
 754   // verifying adapter equivalence.
 755   unsigned char* _saved_code;
 756   int            _saved_code_length;
 757 #endif
 758 
 759   AdapterHandlerEntry(int id, AdapterFingerPrint* fingerprint) :
 760     _fingerprint(fingerprint),
 761     _adapter_blob(nullptr),
 762     _id(id),
 763     _linked(false),
 764     _sig_cc(nullptr)
 765 #ifdef ASSERT
 766     , _saved_code(nullptr),
 767     _saved_code_length(0)
 768 #endif
 769   { }
 770 
 771   ~AdapterHandlerEntry();
 772 
 773   // Allocate on CHeap instead of metaspace (see JDK-8331086).
 774   // Dummy argument is used to avoid C++ warning about using
 775   // deleted opearator MetaspaceObj::delete().
 776   void* operator new(size_t size, size_t dummy) throw() {
 777     assert(size == BytesPerWord * heap_word_size(sizeof(AdapterHandlerEntry)), "should match");
 778     void* p = AllocateHeap(size, mtCode);
 779     memset(p, 0, size);
 780     return p;
 781   }
 782 
 783  public:
 784   static AdapterHandlerEntry* allocate(uint id, AdapterFingerPrint* fingerprint) {

 795   }
 796 
 797   address get_i2c_entry() const {
 798 #ifndef ZERO
 799     assert(_adapter_blob != nullptr, "must be");
 800     return _adapter_blob->i2c_entry();
 801 #else
 802     return nullptr;
 803 #endif // ZERO
 804   }
 805 
 806   address get_c2i_entry() const {
 807 #ifndef ZERO
 808     assert(_adapter_blob != nullptr, "must be");
 809     return _adapter_blob->c2i_entry();
 810 #else
 811     return nullptr;
 812 #endif // ZERO
 813   }
 814 
 815   address get_c2i_inline_entry() const {
 816 #ifndef ZERO
 817     assert(_adapter_blob != nullptr, "must be");
 818     return _adapter_blob->c2i_inline_entry();
 819 #else
 820     return nullptr;
 821 #endif // ZERO
 822   }
 823 
 824   address get_c2i_inline_ro_entry() const {
 825 #ifndef ZERO
 826     assert(_adapter_blob != nullptr, "must be");
 827     return _adapter_blob->c2i_inline_ro_entry();
 828 #else
 829     return nullptr;
 830 #endif // ZERO
 831   }
 832 
 833   address get_c2i_unverified_entry() const {
 834 #ifndef ZERO
 835     assert(_adapter_blob != nullptr, "must be");
 836     return _adapter_blob->c2i_unverified_entry();
 837 #else
 838     return nullptr;
 839 #endif // ZERO
 840   }
 841 
 842   address get_c2i_unverified_inline_entry() const {
 843 #ifndef ZERO
 844     assert(_adapter_blob != nullptr, "must be");
 845     return _adapter_blob->c2i_unverified_inline_entry();
 846 #else
 847     return nullptr;
 848 #endif // ZERO
 849   }
 850 
 851   address get_c2i_no_clinit_check_entry()  const {
 852 #ifndef ZERO
 853     assert(_adapter_blob != nullptr, "must be");
 854     return _adapter_blob->c2i_no_clinit_check_entry();
 855 #else
 856     return nullptr;
 857 #endif // ZERO
 858   }
 859 
 860   AdapterBlob* adapter_blob() const { return _adapter_blob; }
 861   bool is_linked() const { return _linked; }
 862 
 863   // Support for scalarized inline type calling convention
 864   void set_sig_cc(const GrowableArray<SigEntry>* sig)  { _sig_cc = sig; }
 865   const GrowableArray<SigEntry>* get_sig_cc()    const { return _sig_cc; }
 866 
 867   uint id() const { return _id; }
 868   AdapterFingerPrint* fingerprint() const { return _fingerprint; }
 869 
 870 #ifdef ASSERT
 871   // Used to verify that code generated for shared adapters is equivalent
 872   void save_code   (unsigned char* code, int length);
 873   bool compare_code(AdapterHandlerEntry* other);
 874 #endif
 875 
 876   //virtual void print_on(outputStream* st) const;  DO NOT USE
 877   void print_adapter_on(outputStream* st) const;
 878 
 879   void metaspace_pointers_do(MetaspaceClosure* it);
 880   int size() const {return (int)heap_word_size(sizeof(AdapterHandlerEntry)); }
 881   MetaspaceObj::Type type() const { return AdapterHandlerEntryType; }
 882 
 883   void remove_unshareable_info() NOT_CDS_RETURN;
 884   void link() NOT_CDS_RETURN;
 885 };
 886 
 887 #if INCLUDE_CDS
 888 class ArchivedAdapterTable;
 889 #endif // INCLUDE_CDS
 890 
 891 class CompiledEntrySignature;
 892 
 893 class AdapterHandlerLibrary: public AllStatic {
 894   friend class SharedRuntime;
 895  private:
 896   static volatile uint _id_counter; // counter for generating unique adapter ids, range = [1,UINT_MAX]
 897   static BufferBlob* _buffer; // the temporary code buffer in CodeCache
 898   static AdapterHandlerEntry* _no_arg_handler;
 899   static AdapterHandlerEntry* _int_arg_handler;
 900   static AdapterHandlerEntry* _obj_arg_handler;
 901   static AdapterHandlerEntry* _obj_int_arg_handler;
 902   static AdapterHandlerEntry* _obj_obj_arg_handler;
 903 #if INCLUDE_CDS
 904   static ArchivedAdapterTable _aot_adapter_handler_table;
 905 #endif // INCLUDE_CDS
 906 
 907   static BufferBlob* buffer_blob();
 908   static void initialize();
 909   static AdapterHandlerEntry* get_simple_adapter(const methodHandle& method);
 910   static void lookup_aot_cache(AdapterHandlerEntry* handler);
 911   static AdapterHandlerEntry* create_adapter(CompiledEntrySignature& ces,
 912                                              bool allocate_code_blob,
 913                                              bool is_transient = false);
 914   static void lookup_simple_adapters() NOT_CDS_RETURN;
 915 #ifndef PRODUCT
 916   static void print_adapter_handler_info(outputStream* st, AdapterHandlerEntry* handler);
 917 #endif // PRODUCT
 918  public:
 919 
 920   static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint);
 921   static void create_native_wrapper(const methodHandle& method);
 922   static AdapterHandlerEntry* get_adapter(const methodHandle& method);
 923   static AdapterHandlerEntry* lookup(const GrowableArray<SigEntry>* sig, bool has_ro_adapter = false);
 924   static bool generate_adapter_code(AdapterHandlerEntry* handler,
 925                                     CompiledEntrySignature& ces,
 926                                     bool allocate_code_blob,
 927                                     bool is_transient);
 928 
 929 #ifdef ASSERT
 930   static void verify_adapter_sharing(CompiledEntrySignature& ces, AdapterHandlerEntry* cached_entry);
 931 #endif // ASSERT
 932 
 933   static void print_handler(const CodeBlob* b) { print_handler_on(tty, b); }
 934   static void print_handler_on(outputStream* st, const CodeBlob* b);
 935   static bool contains(const CodeBlob* b);
 936   static const char* name(AdapterHandlerEntry* handler);
 937   static uint32_t id(AdapterHandlerEntry* handler);
 938 #ifndef PRODUCT
 939   static void print_statistics();
 940 #endif // PRODUCT
 941 
 942   static void link_aot_adapter_handler(AdapterHandlerEntry* handler) NOT_CDS_RETURN;
 943   static void dump_aot_adapter_table() NOT_CDS_RETURN;
 944   static void serialize_shared_table_header(SerializeClosure* soc) NOT_CDS_RETURN;
 945   static void link_aot_adapters() NOT_CDS_RETURN;
 946   static void address_to_offset(address entry_address[AdapterBlob::ENTRY_COUNT], int entry_offset[AdapterBlob::ENTRY_COUNT]);
 947 };
 948 
 949 // Utility class for computing the calling convention of the 3 types
 950 // of compiled method entries:
 951 //     Method::_from_compiled_entry               - sig_cc
 952 //     Method::_from_compiled_inline_ro_entry     - sig_cc_ro
 953 //     Method::_from_compiled_inline_entry        - sig
 954 class CompiledEntrySignature : public StackObj {
 955   Method* _method;
 956   int  _num_inline_args;
 957   bool _has_inline_recv;
 958   GrowableArray<SigEntry>* _sig;
 959   GrowableArray<SigEntry>* _sig_cc;
 960   GrowableArray<SigEntry>* _sig_cc_ro;
 961   VMRegPair* _regs;
 962   VMRegPair* _regs_cc;
 963   VMRegPair* _regs_cc_ro;
 964 
 965   int _args_on_stack;
 966   int _args_on_stack_cc;
 967   int _args_on_stack_cc_ro;
 968 
 969   bool _c1_needs_stack_repair;
 970   bool _c2_needs_stack_repair;
 971 
 972   GrowableArray<Method*>* _supers;
 973 
 974 public:
 975   Method* method()                     const { return _method; }
 976 
 977   // Used by Method::_from_compiled_inline_entry
 978   GrowableArray<SigEntry>* sig()       const { return _sig; }
 979 
 980   // Used by Method::_from_compiled_entry
 981   GrowableArray<SigEntry>* sig_cc()    const { return _sig_cc; }
 982 
 983   // Used by Method::_from_compiled_inline_ro_entry
 984   GrowableArray<SigEntry>* sig_cc_ro() const { return _sig_cc_ro; }
 985 
 986   VMRegPair* regs()                    const { return _regs; }
 987   VMRegPair* regs_cc()                 const { return _regs_cc; }
 988   VMRegPair* regs_cc_ro()              const { return _regs_cc_ro; }
 989 
 990   int args_on_stack()                  const { return _args_on_stack; }
 991   int args_on_stack_cc()               const { return _args_on_stack_cc; }
 992   int args_on_stack_cc_ro()            const { return _args_on_stack_cc_ro; }
 993 
 994   int  num_inline_args()               const { return _num_inline_args; }
 995   bool has_inline_recv()               const { return _has_inline_recv; }
 996 
 997   bool has_scalarized_args()           const { return _sig != _sig_cc; }
 998   bool c1_needs_stack_repair()         const { return _c1_needs_stack_repair; }
 999   bool c2_needs_stack_repair()         const { return _c2_needs_stack_repair; }
1000   CodeOffsets::Entries c1_inline_ro_entry_type() const;
1001 
1002   GrowableArray<Method*>* get_supers();
1003 
1004   CompiledEntrySignature(Method* method = nullptr);
1005   void compute_calling_conventions(bool init = true);
1006   void initialize_from_fingerprint(AdapterFingerPrint* fingerprint);
1007 };
1008 
1009 #endif // SHARE_RUNTIME_SHAREDRUNTIME_HPP
< prev index next >