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)
54 NUM_STUBIDS
55 };
56 #undef SHARED_STUB_ID_ENUM_DECLARE
57
58 class SharedRuntime: AllStatic {
59 private:
60 // Declare shared stub fields
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 #ifndef PRODUCT
572
573 // Collect and print inline cache miss statistics
574 private:
575 enum { maxICmiss_count = 100 };
576 static int _ICmiss_index; // length of IC miss histogram
577 static int _ICmiss_count[maxICmiss_count]; // miss counts
578 static address _ICmiss_at[maxICmiss_count]; // miss addresses
579 static void trace_ic_miss(address at);
580
581 public:
582 static uint _ic_miss_ctr; // total # of IC misses
583 static uint _wrong_method_ctr;
584 static uint _resolve_static_ctr;
585 static uint _resolve_virtual_ctr;
586 static uint _resolve_opt_virtual_ctr;
587 static uint _implicit_null_throws;
588 static uint _implicit_div0_throws;
589
590 static uint _jbyte_array_copy_ctr; // Slow-path byte array copy
591 static uint _jshort_array_copy_ctr; // Slow-path short array copy
592 static uint _jint_array_copy_ctr; // Slow-path int array copy
593 static uint _jlong_array_copy_ctr; // Slow-path long array copy
594 static uint _oop_array_copy_ctr; // Slow-path oop array copy
595 static uint _checkcast_array_copy_ctr; // Slow-path oop array copy, with cast
596 static uint _unsafe_array_copy_ctr; // Slow-path includes alignment checks
597 static uint _generic_array_copy_ctr; // Slow-path includes type decoding
598 static uint _slow_array_copy_ctr; // Slow-path failed out to a method call
599
600 static uint _unsafe_set_memory_ctr; // Slow-path includes alignment checks
601
602 static uint _new_instance_ctr; // 'new' object requires GC
603 static uint _new_array_ctr; // 'new' array requires GC
604 static uint _multi2_ctr, _multi3_ctr, _multi4_ctr, _multi5_ctr;
605 static uint _find_handler_ctr; // find exception handler
606 static uint _rethrow_ctr; // rethrow exception
610 static uint _mon_exit_ctr; // monitor exit slow
611 static uint _partial_subtype_ctr; // SubRoutines::partial_subtype_check
612
613 // Statistics code
614 // stats for "normal" compiled calls (non-interface)
615 static int64_t _nof_normal_calls; // total # of calls
616 static int64_t _nof_inlined_calls; // total # of inlined normal calls
617 static int64_t _nof_static_calls; // total # of calls to static methods or super methods (invokespecial)
618 static int64_t _nof_inlined_static_calls; // total # of inlined static calls
619 // stats for compiled interface calls
620 static int64_t _nof_interface_calls; // total # of compiled calls
621 static int64_t _nof_inlined_interface_calls; // total # of inlined interface calls
622
623 public: // for compiler
624 static address nof_normal_calls_addr() { return (address)&_nof_normal_calls; }
625 static address nof_inlined_calls_addr() { return (address)&_nof_inlined_calls; }
626 static address nof_static_calls_addr() { return (address)&_nof_static_calls; }
627 static address nof_inlined_static_calls_addr() { return (address)&_nof_inlined_static_calls; }
628 static address nof_interface_calls_addr() { return (address)&_nof_interface_calls; }
629 static address nof_inlined_interface_calls_addr() { return (address)&_nof_inlined_interface_calls; }
630 static void print_call_statistics(uint64_t comp_total);
631 static void print_ic_miss_histogram();
632
633 #endif // PRODUCT
634
635 static void print_statistics() PRODUCT_RETURN;
636 };
637
638
639 // ---------------------------------------------------------------------------
640 // Implementation of AdapterHandlerLibrary
641 //
642 // This library manages argument marshaling adapters and native wrappers.
643 // There are 2 flavors of adapters: I2C and C2I.
644 //
645 // The I2C flavor takes a stock interpreted call setup, marshals the
646 // arguments for a Java-compiled call, and jumps to Rmethod-> code()->
647 // code_begin(). It is broken to call it without an nmethod assigned.
648 // The usual behavior is to lift any register arguments up out of the
649 // stack and possibly re-pack the extra arguments to be contiguous.
650 // I2C adapters will save what the interpreter's stack pointer will be
651 // after arguments are popped, then adjust the interpreter's frame
652 // size to force alignment and possibly to repack the arguments.
802 static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint);
803 static void create_native_wrapper(const methodHandle& method);
804 static AdapterHandlerEntry* get_adapter(const methodHandle& method);
805 static AdapterHandlerEntry* lookup(int total_args_passed, BasicType* sig_bt);
806 static bool generate_adapter_code(AdapterBlob*& adapter_blob,
807 AdapterHandlerEntry* handler,
808 int total_args_passed,
809 BasicType* sig_bt,
810 bool is_transient);
811
812 #ifdef ASSERT
813 static void verify_adapter_sharing(int total_args_passed, BasicType* sig_bt, AdapterHandlerEntry* cached);
814 #endif // ASSERT
815
816 static void print_handler(const CodeBlob* b) { print_handler_on(tty, b); }
817 static void print_handler_on(outputStream* st, const CodeBlob* b);
818 static bool contains(const CodeBlob* b);
819 static const char* name(AdapterFingerPrint* fingerprint);
820 static uint32_t id(AdapterFingerPrint* fingerprint);
821 #ifndef PRODUCT
822 static void print_statistics();
823 #endif // PRODUCT
824
825 static bool is_abstract_method_adapter(AdapterHandlerEntry* adapter);
826
827 static AdapterBlob* link_aot_adapter_handler(AdapterHandlerEntry* handler) NOT_CDS_RETURN_(nullptr);
828 static void dump_aot_adapter_table() NOT_CDS_RETURN;
829 static void serialize_shared_table_header(SerializeClosure* soc) NOT_CDS_RETURN;
830 static void link_aot_adapters() NOT_CDS_RETURN;
831 };
832
833 #endif // SHARE_RUNTIME_SHAREDRUNTIME_HPP
|
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 class MetaspaceClosure;
42
43 // Runtime is the base class for various runtime interfaces
44 // (InterpreterRuntime, CompilerRuntime, etc.). It provides
45 // shared functionality such as exception forwarding (C++ to
46 // Java exceptions), locking/unlocking mechanisms, statistical
47 // information, etc.
48
49 // define SharedStubId enum tags: wrong_method_id, etc
50
51 #define SHARED_STUB_ID_ENUM_DECLARE(name, type) STUB_ID_NAME(name),
52 enum class SharedStubId :int {
53 NO_STUBID = -1,
54 SHARED_STUBS_DO(SHARED_STUB_ID_ENUM_DECLARE)
55 NUM_STUBIDS
56 };
57 #undef SHARED_STUB_ID_ENUM_DECLARE
58
59 class SharedRuntime: AllStatic {
60 private:
61 // Declare shared stub fields
552
553 // Resolving of calls
554 static address get_resolved_entry (JavaThread* current, methodHandle callee_method);
555 static address resolve_static_call_C (JavaThread* current);
556 static address resolve_virtual_call_C (JavaThread* current);
557 static address resolve_opt_virtual_call_C(JavaThread* current);
558
559 // arraycopy, the non-leaf version. (See StubRoutines for all the leaf calls.)
560 static void slow_arraycopy_C(oopDesc* src, jint src_pos,
561 oopDesc* dest, jint dest_pos,
562 jint length, JavaThread* thread);
563
564 // handle ic miss with caller being compiled code
565 // wrong method handling (inline cache misses)
566 static address handle_wrong_method(JavaThread* current);
567 static address handle_wrong_method_abstract(JavaThread* current);
568 static address handle_wrong_method_ic_miss(JavaThread* current);
569
570 static address handle_unsafe_access(JavaThread* thread, address next_pc);
571
572 private:
573 static PerfTickCounters* _perf_resolve_opt_virtual_total_time;
574 static PerfTickCounters* _perf_resolve_virtual_total_time;
575 static PerfTickCounters* _perf_resolve_static_total_time;
576 static PerfTickCounters* _perf_handle_wrong_method_total_time;
577 static PerfTickCounters* _perf_ic_miss_total_time;
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
585 static void print_counters_on(outputStream* st);
586
587 #ifndef PRODUCT
588
589 // Collect and print inline cache miss statistics
590 private:
591 enum { maxICmiss_count = 100 };
592 static int _ICmiss_index; // length of IC miss histogram
593 static int _ICmiss_count[maxICmiss_count]; // miss counts
594 static address _ICmiss_at[maxICmiss_count]; // miss addresses
595 static void trace_ic_miss(address at);
596
597 public:
598 static uint _implicit_null_throws;
599 static uint _implicit_div0_throws;
600
601 static uint _jbyte_array_copy_ctr; // Slow-path byte array copy
602 static uint _jshort_array_copy_ctr; // Slow-path short array copy
603 static uint _jint_array_copy_ctr; // Slow-path int array copy
604 static uint _jlong_array_copy_ctr; // Slow-path long array copy
605 static uint _oop_array_copy_ctr; // Slow-path oop array copy
606 static uint _checkcast_array_copy_ctr; // Slow-path oop array copy, with cast
607 static uint _unsafe_array_copy_ctr; // Slow-path includes alignment checks
608 static uint _generic_array_copy_ctr; // Slow-path includes type decoding
609 static uint _slow_array_copy_ctr; // Slow-path failed out to a method call
610
611 static uint _unsafe_set_memory_ctr; // Slow-path includes alignment checks
612
613 static uint _new_instance_ctr; // 'new' object requires GC
614 static uint _new_array_ctr; // 'new' array requires GC
615 static uint _multi2_ctr, _multi3_ctr, _multi4_ctr, _multi5_ctr;
616 static uint _find_handler_ctr; // find exception handler
617 static uint _rethrow_ctr; // rethrow exception
621 static uint _mon_exit_ctr; // monitor exit slow
622 static uint _partial_subtype_ctr; // SubRoutines::partial_subtype_check
623
624 // Statistics code
625 // stats for "normal" compiled calls (non-interface)
626 static int64_t _nof_normal_calls; // total # of calls
627 static int64_t _nof_inlined_calls; // total # of inlined normal calls
628 static int64_t _nof_static_calls; // total # of calls to static methods or super methods (invokespecial)
629 static int64_t _nof_inlined_static_calls; // total # of inlined static calls
630 // stats for compiled interface calls
631 static int64_t _nof_interface_calls; // total # of compiled calls
632 static int64_t _nof_inlined_interface_calls; // total # of inlined interface calls
633
634 public: // for compiler
635 static address nof_normal_calls_addr() { return (address)&_nof_normal_calls; }
636 static address nof_inlined_calls_addr() { return (address)&_nof_inlined_calls; }
637 static address nof_static_calls_addr() { return (address)&_nof_static_calls; }
638 static address nof_inlined_static_calls_addr() { return (address)&_nof_inlined_static_calls; }
639 static address nof_interface_calls_addr() { return (address)&_nof_interface_calls; }
640 static address nof_inlined_interface_calls_addr() { return (address)&_nof_inlined_interface_calls; }
641
642 static void print_call_statistics_on(outputStream* st);
643 static void print_ic_miss_histogram_on(outputStream* st);
644 #endif // PRODUCT
645
646 static void print_statistics() PRODUCT_RETURN;
647 };
648
649
650 // ---------------------------------------------------------------------------
651 // Implementation of AdapterHandlerLibrary
652 //
653 // This library manages argument marshaling adapters and native wrappers.
654 // There are 2 flavors of adapters: I2C and C2I.
655 //
656 // The I2C flavor takes a stock interpreted call setup, marshals the
657 // arguments for a Java-compiled call, and jumps to Rmethod-> code()->
658 // code_begin(). It is broken to call it without an nmethod assigned.
659 // The usual behavior is to lift any register arguments up out of the
660 // stack and possibly re-pack the extra arguments to be contiguous.
661 // I2C adapters will save what the interpreter's stack pointer will be
662 // after arguments are popped, then adjust the interpreter's frame
663 // size to force alignment and possibly to repack the arguments.
813 static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint);
814 static void create_native_wrapper(const methodHandle& method);
815 static AdapterHandlerEntry* get_adapter(const methodHandle& method);
816 static AdapterHandlerEntry* lookup(int total_args_passed, BasicType* sig_bt);
817 static bool generate_adapter_code(AdapterBlob*& adapter_blob,
818 AdapterHandlerEntry* handler,
819 int total_args_passed,
820 BasicType* sig_bt,
821 bool is_transient);
822
823 #ifdef ASSERT
824 static void verify_adapter_sharing(int total_args_passed, BasicType* sig_bt, AdapterHandlerEntry* cached);
825 #endif // ASSERT
826
827 static void print_handler(const CodeBlob* b) { print_handler_on(tty, b); }
828 static void print_handler_on(outputStream* st, const CodeBlob* b);
829 static bool contains(const CodeBlob* b);
830 static const char* name(AdapterFingerPrint* fingerprint);
831 static uint32_t id(AdapterFingerPrint* fingerprint);
832 #ifndef PRODUCT
833 static void print_statistics_on(outputStream* st);
834 #endif // PRODUCT
835
836 static bool is_abstract_method_adapter(AdapterHandlerEntry* adapter);
837
838 static AdapterBlob* link_aot_adapter_handler(AdapterHandlerEntry* handler) NOT_CDS_RETURN_(nullptr);
839 static void dump_aot_adapter_table() NOT_CDS_RETURN;
840 static void serialize_shared_table_header(SerializeClosure* soc) NOT_CDS_RETURN;
841 static void link_aot_adapters() NOT_CDS_RETURN;
842 };
843
844 #endif // SHARE_RUNTIME_SHAREDRUNTIME_HPP
|