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)
97 // Counters
98 static int64_t _nof_megamorphic_calls; // total # of megamorphic calls (through vtable)
99 #endif // !PRODUCT
100
101 private:
102 static SafepointBlob* generate_handler_blob(SharedStubId id, address call_ptr);
103 static RuntimeStub* generate_resolve_blob(SharedStubId id, address destination);
104 static RuntimeStub* generate_throw_exception(SharedStubId id, address runtime_entry);
105 public:
106 static void generate_initial_stubs(void);
107 static void generate_stubs(void);
108 #if INCLUDE_JFR
109 static void generate_jfr_stubs(void);
110 // For c2: c_rarg0 is junk, call to runtime to write a checkpoint.
111 // It returns a jobject handle to the event writer.
112 // The handle is dereferenced and the return value is the event writer oop.
113 static RuntimeStub* generate_jfr_write_checkpoint();
114 // For c2: call to runtime to return a buffer lease.
115 static RuntimeStub* generate_jfr_return_lease();
116 #endif
117
118 static const char *stub_name(SharedStubId id) {
119 assert(id > SharedStubId::NO_STUBID && id < SharedStubId::NUM_STUBIDS, "stub id out of range");
120 return _stub_names[(int)id];
121 }
122
123 // max bytes for each dtrace string parameter
124 enum { max_dtrace_string_size = 256 };
125
126 // The following arithmetic routines are used on platforms that do
127 // not have machine instructions to implement their functionality.
128 // Do not remove these.
129
130 // long arithmetics
131 static jlong lmul(jlong y, jlong x);
132 static jlong ldiv(jlong y, jlong x);
133 static jlong lrem(jlong y, jlong x);
134
135 // float and double remainder
136 static jfloat frem(jfloat x, jfloat y);
447 // by the time we reach the blob there is compiled code available. This allows
448 // the blob to pass the incoming stack pointer (the sender sp) in a known
449 // location for the interpreter to record. This is used by the frame code
450 // to correct the sender code to match up with the stack pointer when the
451 // thread left the compiled code. In addition it allows the interpreter
452 // to remove the space the c2i adapter allocated to do its argument conversion.
453
454 // Although a c2i blob will always run interpreted even if compiled code is
455 // present if we see that compiled code is present the compiled call site
456 // will be patched/re-resolved so that later calls will run compiled.
457
458 // Additionally a c2i blob need to have a unverified entry because it can be reached
459 // in situations where the call site is an inlined cache site and may go megamorphic.
460
461 // A i2c adapter is simpler than the c2i adapter. This is because it is assumed
462 // that the interpreter before it does any call dispatch will record the current
463 // stack pointer in the interpreter frame. On return it will restore the stack
464 // pointer as needed. This means the i2c adapter code doesn't need any special
465 // handshaking path with compiled code to keep the stack walking correct.
466
467 static AdapterHandlerEntry* generate_i2c2i_adapters(MacroAssembler *_masm,
468 int total_args_passed,
469 int max_arg,
470 const BasicType *sig_bt,
471 const VMRegPair *regs,
472 AdapterFingerPrint* fingerprint);
473
474 static void gen_i2c_adapter(MacroAssembler *_masm,
475 int total_args_passed,
476 int comp_args_on_stack,
477 const BasicType *sig_bt,
478 const VMRegPair *regs);
479
480 // OSR support
481
482 // OSR_migration_begin will extract the jvm state from an interpreter
483 // frame (locals, monitors) and store the data in a piece of C heap
484 // storage. This then allows the interpreter frame to be removed from the
485 // stack and the OSR nmethod to be called. That method is called with a
486 // pointer to the C heap storage. This pointer is the return value from
487 // OSR_migration_begin.
488
489 static intptr_t* OSR_migration_begin(JavaThread *thread);
490
491 // OSR_migration_end is a trivial routine. It is called after the compiled
492 // method has extracted the jvm state from the C heap that OSR_migration_begin
548
549 // Resolving of calls
550 static address get_resolved_entry (JavaThread* current, methodHandle callee_method);
551 static address resolve_static_call_C (JavaThread* current);
552 static address resolve_virtual_call_C (JavaThread* current);
553 static address resolve_opt_virtual_call_C(JavaThread* current);
554
555 // arraycopy, the non-leaf version. (See StubRoutines for all the leaf calls.)
556 static void slow_arraycopy_C(oopDesc* src, jint src_pos,
557 oopDesc* dest, jint dest_pos,
558 jint length, JavaThread* thread);
559
560 // handle ic miss with caller being compiled code
561 // wrong method handling (inline cache misses)
562 static address handle_wrong_method(JavaThread* current);
563 static address handle_wrong_method_abstract(JavaThread* current);
564 static address handle_wrong_method_ic_miss(JavaThread* current);
565
566 static address handle_unsafe_access(JavaThread* thread, address next_pc);
567
568 #ifndef PRODUCT
569
570 // Collect and print inline cache miss statistics
571 private:
572 enum { maxICmiss_count = 100 };
573 static int _ICmiss_index; // length of IC miss histogram
574 static int _ICmiss_count[maxICmiss_count]; // miss counts
575 static address _ICmiss_at[maxICmiss_count]; // miss addresses
576 static void trace_ic_miss(address at);
577
578 public:
579 static uint _ic_miss_ctr; // total # of IC misses
580 static uint _wrong_method_ctr;
581 static uint _resolve_static_ctr;
582 static uint _resolve_virtual_ctr;
583 static uint _resolve_opt_virtual_ctr;
584 static uint _implicit_null_throws;
585 static uint _implicit_div0_throws;
586
587 static uint _jbyte_array_copy_ctr; // Slow-path byte array copy
588 static uint _jshort_array_copy_ctr; // Slow-path short array copy
589 static uint _jint_array_copy_ctr; // Slow-path int array copy
590 static uint _jlong_array_copy_ctr; // Slow-path long array copy
591 static uint _oop_array_copy_ctr; // Slow-path oop array copy
592 static uint _checkcast_array_copy_ctr; // Slow-path oop array copy, with cast
593 static uint _unsafe_array_copy_ctr; // Slow-path includes alignment checks
594 static uint _generic_array_copy_ctr; // Slow-path includes type decoding
595 static uint _slow_array_copy_ctr; // Slow-path failed out to a method call
596
597 static uint _unsafe_set_memory_ctr; // Slow-path includes alignment checks
598
599 static uint _new_instance_ctr; // 'new' object requires GC
600 static uint _new_array_ctr; // 'new' array requires GC
601 static uint _multi2_ctr, _multi3_ctr, _multi4_ctr, _multi5_ctr;
602 static uint _find_handler_ctr; // find exception handler
603 static uint _rethrow_ctr; // rethrow exception
607 static uint _mon_exit_ctr; // monitor exit slow
608 static uint _partial_subtype_ctr; // SubRoutines::partial_subtype_check
609
610 // Statistics code
611 // stats for "normal" compiled calls (non-interface)
612 static int64_t _nof_normal_calls; // total # of calls
613 static int64_t _nof_inlined_calls; // total # of inlined normal calls
614 static int64_t _nof_static_calls; // total # of calls to static methods or super methods (invokespecial)
615 static int64_t _nof_inlined_static_calls; // total # of inlined static calls
616 // stats for compiled interface calls
617 static int64_t _nof_interface_calls; // total # of compiled calls
618 static int64_t _nof_inlined_interface_calls; // total # of inlined interface calls
619
620 public: // for compiler
621 static address nof_normal_calls_addr() { return (address)&_nof_normal_calls; }
622 static address nof_inlined_calls_addr() { return (address)&_nof_inlined_calls; }
623 static address nof_static_calls_addr() { return (address)&_nof_static_calls; }
624 static address nof_inlined_static_calls_addr() { return (address)&_nof_inlined_static_calls; }
625 static address nof_interface_calls_addr() { return (address)&_nof_interface_calls; }
626 static address nof_inlined_interface_calls_addr() { return (address)&_nof_inlined_interface_calls; }
627 static void print_call_statistics(uint64_t comp_total);
628 static void print_ic_miss_histogram();
629
630 #endif // PRODUCT
631
632 static void print_statistics() PRODUCT_RETURN;
633 };
634
635
636 // ---------------------------------------------------------------------------
637 // Implementation of AdapterHandlerLibrary
638 //
639 // This library manages argument marshaling adapters and native wrappers.
640 // There are 2 flavors of adapters: I2C and C2I.
641 //
642 // The I2C flavor takes a stock interpreted call setup, marshals the
643 // arguments for a Java-compiled call, and jumps to Rmethod-> code()->
644 // code_begin(). It is broken to call it without an nmethod assigned.
645 // The usual behavior is to lift any register arguments up out of the
646 // stack and possibly re-pack the extra arguments to be contiguous.
647 // I2C adapters will save what the interpreter's stack pointer will be
648 // after arguments are popped, then adjust the interpreter's frame
649 // size to force alignment and possibly to repack the arguments.
650 // After re-packing, it jumps to the compiled code start. There are
651 // no safepoints in this adapter code and a GC cannot happen while
652 // marshaling is in progress.
653 //
654 // The C2I flavor takes a stock compiled call setup plus the target method in
655 // Rmethod, marshals the arguments for an interpreted call and jumps to
656 // Rmethod->_i2i_entry. On entry, the interpreted frame has not yet been
657 // setup. Compiled frames are fixed-size and the args are likely not in the
658 // right place. Hence all the args will likely be copied into the
659 // interpreter's frame, forcing that frame to grow. The compiled frame's
660 // outgoing stack args will be dead after the copy.
661 //
662 // Native wrappers, like adapters, marshal arguments. Unlike adapters they
663 // also perform an official frame push & pop. They have a call to the native
664 // routine in their middles and end in a return (instead of ending in a jump).
665 // The native wrappers are stored in real nmethods instead of the BufferBlobs
666 // used by the adapters. The code generation happens here because it's very
667 // similar to what the adapters have to do.
668
669 class AdapterHandlerEntry : public CHeapObj<mtCode> {
670 friend class AdapterHandlerLibrary;
671
672 private:
673 AdapterFingerPrint* _fingerprint;
674 address _i2c_entry;
675 address _c2i_entry;
676 address _c2i_unverified_entry;
677 address _c2i_no_clinit_check_entry;
678
679 #ifdef ASSERT
680 // Captures code and signature used to generate this adapter when
681 // verifying adapter equivalence.
682 unsigned char* _saved_code;
683 int _saved_code_length;
684 #endif
685
686 AdapterHandlerEntry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry,
687 address c2i_unverified_entry,
688 address c2i_no_clinit_check_entry) :
689 _fingerprint(fingerprint),
690 _i2c_entry(i2c_entry),
691 _c2i_entry(c2i_entry),
692 _c2i_unverified_entry(c2i_unverified_entry),
693 _c2i_no_clinit_check_entry(c2i_no_clinit_check_entry)
694 #ifdef ASSERT
695 , _saved_code_length(0)
696 #endif
697 { }
698
699 ~AdapterHandlerEntry();
700
701 public:
702 address get_i2c_entry() const { return _i2c_entry; }
703 address get_c2i_entry() const { return _c2i_entry; }
704 address get_c2i_unverified_entry() const { return _c2i_unverified_entry; }
705 address get_c2i_no_clinit_check_entry() const { return _c2i_no_clinit_check_entry; }
706
707 address base_address();
708 void relocate(address new_base);
709
710 AdapterFingerPrint* fingerprint() const { return _fingerprint; }
711
712 #ifdef ASSERT
713 // Used to verify that code generated for shared adapters is equivalent
714 void save_code (unsigned char* code, int length);
715 bool compare_code(AdapterHandlerEntry* other);
716 #endif
717
718 //virtual void print_on(outputStream* st) const; DO NOT USE
719 void print_adapter_on(outputStream* st) const;
720 };
721
722 class AdapterHandlerLibrary: public AllStatic {
723 friend class SharedRuntime;
724 private:
725 static BufferBlob* _buffer; // the temporary code buffer in CodeCache
726 static AdapterHandlerEntry* _abstract_method_handler;
727 static AdapterHandlerEntry* _no_arg_handler;
728 static AdapterHandlerEntry* _int_arg_handler;
729 static AdapterHandlerEntry* _obj_arg_handler;
730 static AdapterHandlerEntry* _obj_int_arg_handler;
731 static AdapterHandlerEntry* _obj_obj_arg_handler;
732
733 static BufferBlob* buffer_blob();
734 static void initialize();
735 static AdapterHandlerEntry* create_adapter(AdapterBlob*& new_adapter,
736 int total_args_passed,
737 BasicType* sig_bt,
738 bool allocate_code_blob);
739 static AdapterHandlerEntry* get_simple_adapter(const methodHandle& method);
740 public:
741
742 static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint,
743 address i2c_entry,
744 address c2i_entry,
745 address c2i_unverified_entry,
746 address c2i_no_clinit_check_entry = nullptr);
747 static void create_native_wrapper(const methodHandle& method);
748 static AdapterHandlerEntry* get_adapter(const methodHandle& method);
749
750 static void print_handler(const CodeBlob* b) { print_handler_on(tty, b); }
751 static void print_handler_on(outputStream* st, const CodeBlob* b);
752 static bool contains(const CodeBlob* b);
753 #ifndef PRODUCT
754 static void print_statistics();
755 #endif // PRODUCT
756
757 };
758
759 #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 "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/stubDeclarations.hpp"
36 #include "utilities/macros.hpp"
37
38 class AdapterHandlerEntry;
39 class AdapterFingerPrint;
40 class vframeStream;
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 // define SharedStubId enum tags: wrong_method_id, etc
49
50 #define SHARED_STUB_ID_ENUM_DECLARE(name, type) STUB_ID_NAME(name),
51 enum class SharedStubId :int {
52 NO_STUBID = -1,
53 SHARED_STUBS_DO(SHARED_STUB_ID_ENUM_DECLARE)
99 // Counters
100 static int64_t _nof_megamorphic_calls; // total # of megamorphic calls (through vtable)
101 #endif // !PRODUCT
102
103 private:
104 static SafepointBlob* generate_handler_blob(SharedStubId id, address call_ptr);
105 static RuntimeStub* generate_resolve_blob(SharedStubId id, address destination);
106 static RuntimeStub* generate_throw_exception(SharedStubId id, address runtime_entry);
107 public:
108 static void generate_initial_stubs(void);
109 static void generate_stubs(void);
110 #if INCLUDE_JFR
111 static void generate_jfr_stubs(void);
112 // For c2: c_rarg0 is junk, call to runtime to write a checkpoint.
113 // It returns a jobject handle to the event writer.
114 // The handle is dereferenced and the return value is the event writer oop.
115 static RuntimeStub* generate_jfr_write_checkpoint();
116 // For c2: call to runtime to return a buffer lease.
117 static RuntimeStub* generate_jfr_return_lease();
118 #endif
119 static void init_adapter_library();
120
121 static const char *stub_name(SharedStubId id) {
122 assert(id > SharedStubId::NO_STUBID && id < SharedStubId::NUM_STUBIDS, "stub id out of range");
123 return _stub_names[(int)id];
124 }
125
126 // max bytes for each dtrace string parameter
127 enum { max_dtrace_string_size = 256 };
128
129 // The following arithmetic routines are used on platforms that do
130 // not have machine instructions to implement their functionality.
131 // Do not remove these.
132
133 // long arithmetics
134 static jlong lmul(jlong y, jlong x);
135 static jlong ldiv(jlong y, jlong x);
136 static jlong lrem(jlong y, jlong x);
137
138 // float and double remainder
139 static jfloat frem(jfloat x, jfloat y);
450 // by the time we reach the blob there is compiled code available. This allows
451 // the blob to pass the incoming stack pointer (the sender sp) in a known
452 // location for the interpreter to record. This is used by the frame code
453 // to correct the sender code to match up with the stack pointer when the
454 // thread left the compiled code. In addition it allows the interpreter
455 // to remove the space the c2i adapter allocated to do its argument conversion.
456
457 // Although a c2i blob will always run interpreted even if compiled code is
458 // present if we see that compiled code is present the compiled call site
459 // will be patched/re-resolved so that later calls will run compiled.
460
461 // Additionally a c2i blob need to have a unverified entry because it can be reached
462 // in situations where the call site is an inlined cache site and may go megamorphic.
463
464 // A i2c adapter is simpler than the c2i adapter. This is because it is assumed
465 // that the interpreter before it does any call dispatch will record the current
466 // stack pointer in the interpreter frame. On return it will restore the stack
467 // pointer as needed. This means the i2c adapter code doesn't need any special
468 // handshaking path with compiled code to keep the stack walking correct.
469
470 static void generate_i2c2i_adapters(MacroAssembler *_masm,
471 int total_args_passed,
472 int max_arg,
473 const BasicType *sig_bt,
474 const VMRegPair *regs,
475 AdapterHandlerEntry* handler);
476
477 static void gen_i2c_adapter(MacroAssembler *_masm,
478 int total_args_passed,
479 int comp_args_on_stack,
480 const BasicType *sig_bt,
481 const VMRegPair *regs);
482
483 // OSR support
484
485 // OSR_migration_begin will extract the jvm state from an interpreter
486 // frame (locals, monitors) and store the data in a piece of C heap
487 // storage. This then allows the interpreter frame to be removed from the
488 // stack and the OSR nmethod to be called. That method is called with a
489 // pointer to the C heap storage. This pointer is the return value from
490 // OSR_migration_begin.
491
492 static intptr_t* OSR_migration_begin(JavaThread *thread);
493
494 // OSR_migration_end is a trivial routine. It is called after the compiled
495 // method has extracted the jvm state from the C heap that OSR_migration_begin
551
552 // Resolving of calls
553 static address get_resolved_entry (JavaThread* current, methodHandle callee_method);
554 static address resolve_static_call_C (JavaThread* current);
555 static address resolve_virtual_call_C (JavaThread* current);
556 static address resolve_opt_virtual_call_C(JavaThread* current);
557
558 // arraycopy, the non-leaf version. (See StubRoutines for all the leaf calls.)
559 static void slow_arraycopy_C(oopDesc* src, jint src_pos,
560 oopDesc* dest, jint dest_pos,
561 jint length, JavaThread* thread);
562
563 // handle ic miss with caller being compiled code
564 // wrong method handling (inline cache misses)
565 static address handle_wrong_method(JavaThread* current);
566 static address handle_wrong_method_abstract(JavaThread* current);
567 static address handle_wrong_method_ic_miss(JavaThread* current);
568
569 static address handle_unsafe_access(JavaThread* thread, address next_pc);
570
571 private:
572 static PerfTickCounters* _perf_resolve_opt_virtual_total_time;
573 static PerfTickCounters* _perf_resolve_virtual_total_time;
574 static PerfTickCounters* _perf_resolve_static_total_time;
575 static PerfTickCounters* _perf_handle_wrong_method_total_time;
576 static PerfTickCounters* _perf_ic_miss_total_time;
577 public:
578 static uint _ic_miss_ctr; // total # of IC misses
579 static uint _wrong_method_ctr;
580 static uint _resolve_static_ctr;
581 static uint _resolve_virtual_ctr;
582 static uint _resolve_opt_virtual_ctr;
583
584 static void print_counters_on(outputStream* st);
585
586 #ifndef PRODUCT
587
588 // Collect and print inline cache miss statistics
589 private:
590 enum { maxICmiss_count = 100 };
591 static int _ICmiss_index; // length of IC miss histogram
592 static int _ICmiss_count[maxICmiss_count]; // miss counts
593 static address _ICmiss_at[maxICmiss_count]; // miss addresses
594 static void trace_ic_miss(address at);
595
596 public:
597 static uint _implicit_null_throws;
598 static uint _implicit_div0_throws;
599
600 static uint _jbyte_array_copy_ctr; // Slow-path byte array copy
601 static uint _jshort_array_copy_ctr; // Slow-path short array copy
602 static uint _jint_array_copy_ctr; // Slow-path int array copy
603 static uint _jlong_array_copy_ctr; // Slow-path long array copy
604 static uint _oop_array_copy_ctr; // Slow-path oop array copy
605 static uint _checkcast_array_copy_ctr; // Slow-path oop array copy, with cast
606 static uint _unsafe_array_copy_ctr; // Slow-path includes alignment checks
607 static uint _generic_array_copy_ctr; // Slow-path includes type decoding
608 static uint _slow_array_copy_ctr; // Slow-path failed out to a method call
609
610 static uint _unsafe_set_memory_ctr; // Slow-path includes alignment checks
611
612 static uint _new_instance_ctr; // 'new' object requires GC
613 static uint _new_array_ctr; // 'new' array requires GC
614 static uint _multi2_ctr, _multi3_ctr, _multi4_ctr, _multi5_ctr;
615 static uint _find_handler_ctr; // find exception handler
616 static uint _rethrow_ctr; // rethrow exception
620 static uint _mon_exit_ctr; // monitor exit slow
621 static uint _partial_subtype_ctr; // SubRoutines::partial_subtype_check
622
623 // Statistics code
624 // stats for "normal" compiled calls (non-interface)
625 static int64_t _nof_normal_calls; // total # of calls
626 static int64_t _nof_inlined_calls; // total # of inlined normal calls
627 static int64_t _nof_static_calls; // total # of calls to static methods or super methods (invokespecial)
628 static int64_t _nof_inlined_static_calls; // total # of inlined static calls
629 // stats for compiled interface calls
630 static int64_t _nof_interface_calls; // total # of compiled calls
631 static int64_t _nof_inlined_interface_calls; // total # of inlined interface calls
632
633 public: // for compiler
634 static address nof_normal_calls_addr() { return (address)&_nof_normal_calls; }
635 static address nof_inlined_calls_addr() { return (address)&_nof_inlined_calls; }
636 static address nof_static_calls_addr() { return (address)&_nof_static_calls; }
637 static address nof_inlined_static_calls_addr() { return (address)&_nof_inlined_static_calls; }
638 static address nof_interface_calls_addr() { return (address)&_nof_interface_calls; }
639 static address nof_inlined_interface_calls_addr() { return (address)&_nof_inlined_interface_calls; }
640
641 static void print_call_statistics_on(outputStream* st);
642 static void print_ic_miss_histogram_on(outputStream* st);
643 #endif // PRODUCT
644
645 static void print_statistics() PRODUCT_RETURN;
646 };
647
648
649 // ---------------------------------------------------------------------------
650 // Implementation of AdapterHandlerLibrary
651 //
652 // This library manages argument marshaling adapters and native wrappers.
653 // There are 2 flavors of adapters: I2C and C2I.
654 //
655 // The I2C flavor takes a stock interpreted call setup, marshals the
656 // arguments for a Java-compiled call, and jumps to Rmethod-> code()->
657 // code_begin(). It is broken to call it without an nmethod assigned.
658 // The usual behavior is to lift any register arguments up out of the
659 // stack and possibly re-pack the extra arguments to be contiguous.
660 // I2C adapters will save what the interpreter's stack pointer will be
661 // after arguments are popped, then adjust the interpreter's frame
662 // size to force alignment and possibly to repack the arguments.
663 // After re-packing, it jumps to the compiled code start. There are
664 // no safepoints in this adapter code and a GC cannot happen while
665 // marshaling is in progress.
666 //
667 // The C2I flavor takes a stock compiled call setup plus the target method in
668 // Rmethod, marshals the arguments for an interpreted call and jumps to
669 // Rmethod->_i2i_entry. On entry, the interpreted frame has not yet been
670 // setup. Compiled frames are fixed-size and the args are likely not in the
671 // right place. Hence all the args will likely be copied into the
672 // interpreter's frame, forcing that frame to grow. The compiled frame's
673 // outgoing stack args will be dead after the copy.
674 //
675 // Native wrappers, like adapters, marshal arguments. Unlike adapters they
676 // also perform an official frame push & pop. They have a call to the native
677 // routine in their middles and end in a return (instead of ending in a jump).
678 // The native wrappers are stored in real nmethods instead of the BufferBlobs
679 // used by the adapters. The code generation happens here because it's very
680 // similar to what the adapters have to do.
681
682 class AdapterHandlerEntry : public MetaspaceObj {
683 friend class AdapterHandlerLibrary;
684
685 private:
686 AdapterFingerPrint* _fingerprint;
687 address _i2c_entry;
688 address _c2i_entry;
689 address _c2i_unverified_entry;
690 address _c2i_no_clinit_check_entry;
691 bool _linked;
692
693 #ifdef ASSERT
694 // Captures code and signature used to generate this adapter when
695 // verifying adapter equivalence.
696 unsigned char* _saved_code;
697 int _saved_code_length;
698 #endif
699
700 AdapterHandlerEntry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry,
701 address c2i_unverified_entry,
702 address c2i_no_clinit_check_entry) :
703 _fingerprint(fingerprint),
704 _i2c_entry(i2c_entry),
705 _c2i_entry(c2i_entry),
706 _c2i_unverified_entry(c2i_unverified_entry),
707 _c2i_no_clinit_check_entry(c2i_no_clinit_check_entry),
708 _linked(false)
709 #ifdef ASSERT
710 , _saved_code_length(0)
711 #endif
712 { }
713
714 ~AdapterHandlerEntry();
715
716 public:
717 static AdapterHandlerEntry* allocate(AdapterFingerPrint* fingerprint,
718 address i2c_entry,
719 address c2i_entry,
720 address c2i_unverified_entry,
721 address c2i_no_clinit_check_entry)
722 {
723 return new (mtCode) AdapterHandlerEntry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry, c2i_no_clinit_check_entry);
724 }
725
726 static void deallocate(AdapterHandlerEntry *handler) {
727 handler->~AdapterHandlerEntry();
728 }
729
730 void set_entry_points(address i2c_entry, address c2i_entry, address c2i_unverified_entry, address c2i_no_clinit_check_entry, bool linked = true) {
731 _i2c_entry = i2c_entry;
732 _c2i_entry = c2i_entry;
733 _c2i_unverified_entry = c2i_unverified_entry;
734 _c2i_no_clinit_check_entry = c2i_no_clinit_check_entry;
735 _linked = linked;
736 }
737
738 address get_i2c_entry() const { return _i2c_entry; }
739 address get_c2i_entry() const { return _c2i_entry; }
740 address get_c2i_unverified_entry() const { return _c2i_unverified_entry; }
741 address get_c2i_no_clinit_check_entry() const { return _c2i_no_clinit_check_entry; }
742
743 bool is_linked() const { return _linked; }
744 address base_address();
745 void relocate(address new_base);
746
747 AdapterFingerPrint* fingerprint() const { return _fingerprint; }
748
749 #ifdef ASSERT
750 // Used to verify that code generated for shared adapters is equivalent
751 void save_code (unsigned char* code, int length);
752 bool compare_code(AdapterHandlerEntry* other);
753 #endif
754
755 //virtual void print_on(outputStream* st) const; DO NOT USE
756 void print_adapter_on(outputStream* st) const;
757
758 void metaspace_pointers_do(MetaspaceClosure* it);
759 int size() const {return (int)heap_word_size(sizeof(AdapterHandlerEntry)); }
760 MetaspaceObj::Type type() const { return AdapterHandlerEntryType; }
761
762 void remove_unshareable_info() NOT_CDS_RETURN;
763 void restore_unshareable_info(TRAPS) NOT_CDS_RETURN;
764 };
765
766 #if INCLUDE_CDS
767 class ArchivedAdapterTable;
768 #endif // INCLUDE_CDS
769
770 class AdapterHandlerLibrary: public AllStatic {
771 friend class SharedRuntime;
772 private:
773 static BufferBlob* _buffer; // the temporary code buffer in CodeCache
774 static AdapterHandlerEntry* _abstract_method_handler;
775 static AdapterHandlerEntry* _no_arg_handler;
776 static AdapterHandlerEntry* _int_arg_handler;
777 static AdapterHandlerEntry* _obj_arg_handler;
778 static AdapterHandlerEntry* _obj_int_arg_handler;
779 static AdapterHandlerEntry* _obj_obj_arg_handler;
780 #if INCLUDE_CDS
781 static ArchivedAdapterTable _archived_adapter_handler_table;
782 #endif // INCLUDE_CDS
783 static BufferBlob* buffer_blob();
784 static void initialize();
785 static AdapterHandlerEntry* create_simple_adapter(AdapterBlob*& new_adapter,
786 int total_args_passed,
787 BasicType* sig_bt);
788 static AdapterHandlerEntry* get_simple_adapter(const methodHandle& method);
789 static bool lookup_aot_cache(AdapterHandlerEntry* handler, CodeBuffer* buffer);
790 static AdapterHandlerEntry* create_adapter(AdapterBlob*& new_adapter,
791 AdapterFingerPrint* fingerprint,
792 int total_args_passed,
793 BasicType* sig_bt,
794 bool is_transient);
795 #ifndef PRODUCT
796 static void print_adapter_handler_info(AdapterHandlerEntry* handler, AdapterBlob* adapter_blob);
797 #endif // PRODUCT
798 public:
799
800 static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint,
801 address i2c_entry = nullptr,
802 address c2i_entry = nullptr,
803 address c2i_unverified_entry = nullptr,
804 address c2i_no_clinit_check_entry = nullptr);
805 static void create_native_wrapper(const methodHandle& method);
806 static AdapterHandlerEntry* get_adapter(const methodHandle& method);
807 static AdapterHandlerEntry* lookup(AdapterFingerPrint* fp);
808 static bool generate_adapter_code(AdapterBlob*& adapter_blob,
809 AdapterHandlerEntry* handler,
810 int total_args_passed,
811 BasicType* sig_bt,
812 bool is_transient);
813
814 static void print_handler(const CodeBlob* b) { print_handler_on(tty, b); }
815 static void print_handler_on(outputStream* st, const CodeBlob* b);
816 static bool contains(const CodeBlob* b);
817 static const char* name(AdapterFingerPrint* fingerprint);
818 static uint32_t id(AdapterFingerPrint* fingerprint);
819 #ifndef PRODUCT
820 static void print_statistics_on(outputStream* st);
821 #endif // PRODUCT
822
823 static bool is_abstract_method_adapter(AdapterHandlerEntry* adapter);
824
825 static bool link_adapter_handler(AdapterHandlerEntry* handler, AdapterBlob*& adapter_blob) NOT_CDS_RETURN_(false);
826 static void archive_adapter_table() NOT_CDS_RETURN;
827 static void serialize_shared_table_header(SerializeClosure* soc) NOT_CDS_RETURN;
828 };
829
830 #endif // SHARE_RUNTIME_SHAREDRUNTIME_HPP
|