84 int size = Method::size(access_flags.is_native());
85 return new (loader_data, size, MetaspaceObj::MethodType, THREAD) Method(cm, access_flags);
86 }
87
88 Method::Method(ConstMethod* xconst, AccessFlags access_flags) {
89 NoSafepointVerifier no_safepoint;
90 set_constMethod(xconst);
91 set_access_flags(access_flags);
92 set_intrinsic_id(vmIntrinsics::_none);
93 set_force_inline(false);
94 set_hidden(false);
95 set_dont_inline(false);
96 set_has_injected_profile(false);
97 set_method_data(NULL);
98 clear_method_counters();
99 set_vtable_index(Method::garbage_vtable_index);
100
101 // Fix and bury in Method*
102 set_interpreter_entry(NULL); // sets i2i entry and from_int
103 set_adapter_entry(NULL);
104 clear_code(false /* don't need a lock */); // from_c/from_i get set to c2i/i2i
105
106 if (access_flags.is_native()) {
107 clear_native_function();
108 set_signature_handler(NULL);
109 }
110
111 NOT_PRODUCT(set_compiled_invocation_count(0);)
112 }
113
114 // Release Method*. The nmethod will be gone when we get here because
115 // we've walked the code cache.
116 void Method::deallocate_contents(ClassLoaderData* loader_data) {
117 MetadataFactory::free_metadata(loader_data, constMethod());
118 set_constMethod(NULL);
119 MetadataFactory::free_metadata(loader_data, method_data());
120 set_method_data(NULL);
121 MetadataFactory::free_metadata(loader_data, method_counters());
122 clear_method_counters();
123 // The nmethod will be gone when we get here.
124 if (code() != NULL) _code = NULL;
787 CompiledMethod* nm = code(); // Put it into local variable to guard against concurrent updates
788 if (nm != NULL) {
789 nm->make_not_entrant();
790 }
791 }
792
793
794 bool Method::has_native_function() const {
795 if (is_method_handle_intrinsic())
796 return false; // special-cased in SharedRuntime::generate_native_wrapper
797 address func = native_function();
798 return (func != NULL && func != SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
799 }
800
801
802 void Method::clear_native_function() {
803 // Note: is_method_handle_intrinsic() is allowed here.
804 set_native_function(
805 SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
806 !native_bind_event_is_interesting);
807 clear_code();
808 }
809
810 address Method::critical_native_function() {
811 methodHandle mh(this);
812 return NativeLookup::lookup_critical_entry(mh);
813 }
814
815
816 void Method::set_signature_handler(address handler) {
817 address* signature_handler = signature_handler_addr();
818 *signature_handler = handler;
819 }
820
821
822 void Method::print_made_not_compilable(int comp_level, bool is_osr, bool report, const char* reason) {
823 if (PrintCompilation && report) {
824 ttyLocker ttyl;
825 tty->print("made not %scompilable on ", is_osr ? "OSR " : "");
826 if (comp_level == CompLevel_all) {
827 tty->print("all levels ");
910 return is_not_c2_osr_compilable();
911 return false;
912 }
913
914 void Method::set_not_osr_compilable(int comp_level, bool report, const char* reason) {
915 print_made_not_compilable(comp_level, /*is_osr*/ true, report, reason);
916 if (comp_level == CompLevel_all) {
917 set_not_c1_osr_compilable();
918 set_not_c2_osr_compilable();
919 } else {
920 if (is_c1_compile(comp_level))
921 set_not_c1_osr_compilable();
922 if (is_c2_compile(comp_level))
923 set_not_c2_osr_compilable();
924 }
925 CompilationPolicy::policy()->disable_compilation(this);
926 assert(!CompilationPolicy::can_be_osr_compiled(this, comp_level), "sanity check");
927 }
928
929 // Revert to using the interpreter and clear out the nmethod
930 void Method::clear_code(bool acquire_lock /* = true */) {
931 MutexLockerEx pl(acquire_lock ? Patching_lock : NULL, Mutex::_no_safepoint_check_flag);
932 // this may be NULL if c2i adapters have not been made yet
933 // Only should happen at allocate time.
934 if (adapter() == NULL) {
935 _from_compiled_entry = NULL;
936 } else {
937 _from_compiled_entry = adapter()->get_c2i_entry();
938 }
939 OrderAccess::storestore();
940 _from_interpreted_entry = _i2i_entry;
941 OrderAccess::storestore();
942 _code = NULL;
943 }
944
945 #if INCLUDE_CDS
946 // Called by class data sharing to remove any entry points (which are not shared)
947 void Method::unlink_method() {
948 _code = NULL;
949
950 assert(DumpSharedSpaces, "dump time only");
951 // Set the values to what they should be at run time. Note that
952 // this Method can no longer be executed during dump time.
953 _i2i_entry = Interpreter::entry_for_cds_method(this);
954 _from_interpreted_entry = _i2i_entry;
955
956 if (is_native()) {
957 *native_function_addr() = NULL;
958 set_signature_handler(NULL);
959 }
960 NOT_PRODUCT(set_compiled_invocation_count(0);)
961
962 CDSAdapterHandlerEntry* cds_adapter = (CDSAdapterHandlerEntry*)adapter();
|
84 int size = Method::size(access_flags.is_native());
85 return new (loader_data, size, MetaspaceObj::MethodType, THREAD) Method(cm, access_flags);
86 }
87
88 Method::Method(ConstMethod* xconst, AccessFlags access_flags) {
89 NoSafepointVerifier no_safepoint;
90 set_constMethod(xconst);
91 set_access_flags(access_flags);
92 set_intrinsic_id(vmIntrinsics::_none);
93 set_force_inline(false);
94 set_hidden(false);
95 set_dont_inline(false);
96 set_has_injected_profile(false);
97 set_method_data(NULL);
98 clear_method_counters();
99 set_vtable_index(Method::garbage_vtable_index);
100
101 // Fix and bury in Method*
102 set_interpreter_entry(NULL); // sets i2i entry and from_int
103 set_adapter_entry(NULL);
104 Method::unlink_code(this);
105
106 if (access_flags.is_native()) {
107 clear_native_function();
108 set_signature_handler(NULL);
109 }
110
111 NOT_PRODUCT(set_compiled_invocation_count(0);)
112 }
113
114 // Release Method*. The nmethod will be gone when we get here because
115 // we've walked the code cache.
116 void Method::deallocate_contents(ClassLoaderData* loader_data) {
117 MetadataFactory::free_metadata(loader_data, constMethod());
118 set_constMethod(NULL);
119 MetadataFactory::free_metadata(loader_data, method_data());
120 set_method_data(NULL);
121 MetadataFactory::free_metadata(loader_data, method_counters());
122 clear_method_counters();
123 // The nmethod will be gone when we get here.
124 if (code() != NULL) _code = NULL;
787 CompiledMethod* nm = code(); // Put it into local variable to guard against concurrent updates
788 if (nm != NULL) {
789 nm->make_not_entrant();
790 }
791 }
792
793
794 bool Method::has_native_function() const {
795 if (is_method_handle_intrinsic())
796 return false; // special-cased in SharedRuntime::generate_native_wrapper
797 address func = native_function();
798 return (func != NULL && func != SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
799 }
800
801
802 void Method::clear_native_function() {
803 // Note: is_method_handle_intrinsic() is allowed here.
804 set_native_function(
805 SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
806 !native_bind_event_is_interesting);
807 Method::unlink_code(this);
808 }
809
810 address Method::critical_native_function() {
811 methodHandle mh(this);
812 return NativeLookup::lookup_critical_entry(mh);
813 }
814
815
816 void Method::set_signature_handler(address handler) {
817 address* signature_handler = signature_handler_addr();
818 *signature_handler = handler;
819 }
820
821
822 void Method::print_made_not_compilable(int comp_level, bool is_osr, bool report, const char* reason) {
823 if (PrintCompilation && report) {
824 ttyLocker ttyl;
825 tty->print("made not %scompilable on ", is_osr ? "OSR " : "");
826 if (comp_level == CompLevel_all) {
827 tty->print("all levels ");
910 return is_not_c2_osr_compilable();
911 return false;
912 }
913
914 void Method::set_not_osr_compilable(int comp_level, bool report, const char* reason) {
915 print_made_not_compilable(comp_level, /*is_osr*/ true, report, reason);
916 if (comp_level == CompLevel_all) {
917 set_not_c1_osr_compilable();
918 set_not_c2_osr_compilable();
919 } else {
920 if (is_c1_compile(comp_level))
921 set_not_c1_osr_compilable();
922 if (is_c2_compile(comp_level))
923 set_not_c2_osr_compilable();
924 }
925 CompilationPolicy::policy()->disable_compilation(this);
926 assert(!CompilationPolicy::can_be_osr_compiled(this, comp_level), "sanity check");
927 }
928
929 // Revert to using the interpreter and clear out the nmethod
930 void Method::locked_unlink_code() {
931 // this may be NULL if c2i adapters have not been made yet
932 // Only should happen at allocate time.
933 if (adapter() == NULL) {
934 _from_compiled_entry = NULL;
935 } else {
936 _from_compiled_entry = adapter()->get_c2i_entry();
937 }
938 OrderAccess::storestore();
939 _from_interpreted_entry = _i2i_entry;
940 OrderAccess::storestore();
941 _code = NULL;
942 }
943
944 void Method::unlink_code(Method *method, CompiledMethod *compare) {
945 if (method != NULL) {
946 MutexLockerEx ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
947 if (method->code() != compare && method->from_compiled_entry() != compare->verified_entry_point()) {
948 return;
949 }
950 method->locked_unlink_code();
951 }
952 }
953
954 void Method::unlink_code(Method *method) {
955 if (method != NULL) {
956 MutexLockerEx ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
957 method->locked_unlink_code();
958 }
959 }
960
961 #if INCLUDE_CDS
962 // Called by class data sharing to remove any entry points (which are not shared)
963 void Method::unlink_method() {
964 _code = NULL;
965
966 assert(DumpSharedSpaces, "dump time only");
967 // Set the values to what they should be at run time. Note that
968 // this Method can no longer be executed during dump time.
969 _i2i_entry = Interpreter::entry_for_cds_method(this);
970 _from_interpreted_entry = _i2i_entry;
971
972 if (is_native()) {
973 *native_function_addr() = NULL;
974 set_signature_handler(NULL);
975 }
976 NOT_PRODUCT(set_compiled_invocation_count(0);)
977
978 CDSAdapterHandlerEntry* cds_adapter = (CDSAdapterHandlerEntry*)adapter();
|