< prev index next >

src/hotspot/share/oops/method.cpp

Print this page
rev 56098 : imported patch 8226705-8221734-baseline


  86   int size = Method::size(access_flags.is_native());
  87   return new (loader_data, size, MetaspaceObj::MethodType, THREAD) Method(cm, access_flags);
  88 }
  89 
  90 Method::Method(ConstMethod* xconst, AccessFlags access_flags) {
  91   NoSafepointVerifier no_safepoint;
  92   set_constMethod(xconst);
  93   set_access_flags(access_flags);
  94   set_intrinsic_id(vmIntrinsics::_none);
  95   set_force_inline(false);
  96   set_hidden(false);
  97   set_dont_inline(false);
  98   set_has_injected_profile(false);
  99   set_method_data(NULL);
 100   clear_method_counters();
 101   set_vtable_index(Method::garbage_vtable_index);
 102 
 103   // Fix and bury in Method*
 104   set_interpreter_entry(NULL); // sets i2i entry and from_int
 105   set_adapter_entry(NULL);
 106   clear_code(false /* don't need a lock */); // from_c/from_i get set to c2i/i2i
 107 
 108   if (access_flags.is_native()) {
 109     clear_native_function();
 110     set_signature_handler(NULL);
 111   }
 112 
 113   NOT_PRODUCT(set_compiled_invocation_count(0);)
 114 }
 115 
 116 // Release Method*.  The nmethod will be gone when we get here because
 117 // we've walked the code cache.
 118 void Method::deallocate_contents(ClassLoaderData* loader_data) {
 119   MetadataFactory::free_metadata(loader_data, constMethod());
 120   set_constMethod(NULL);
 121 #if INCLUDE_JVMCI
 122   if (method_data()) {
 123     FailedSpeculation::free_failed_speculations(method_data()->get_failed_speculations_address());
 124   }
 125 #endif
 126   MetadataFactory::free_metadata(loader_data, method_data());


 808   CompiledMethod* nm = code(); // Put it into local variable to guard against concurrent updates
 809   if (nm != NULL) {
 810     nm->make_not_entrant();
 811   }
 812 }
 813 
 814 
 815 bool Method::has_native_function() const {
 816   if (is_method_handle_intrinsic())
 817     return false;  // special-cased in SharedRuntime::generate_native_wrapper
 818   address func = native_function();
 819   return (func != NULL && func != SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
 820 }
 821 
 822 
 823 void Method::clear_native_function() {
 824   // Note: is_method_handle_intrinsic() is allowed here.
 825   set_native_function(
 826     SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
 827     !native_bind_event_is_interesting);
 828   clear_code();
 829 }
 830 
 831 
 832 void Method::set_signature_handler(address handler) {
 833   address* signature_handler =  signature_handler_addr();
 834   *signature_handler = handler;
 835 }
 836 
 837 
 838 void Method::print_made_not_compilable(int comp_level, bool is_osr, bool report, const char* reason) {
 839   assert(reason != NULL, "must provide a reason");
 840   if (PrintCompilation && report) {
 841     ttyLocker ttyl;
 842     tty->print("made not %scompilable on ", is_osr ? "OSR " : "");
 843     if (comp_level == CompLevel_all) {
 844       tty->print("all levels ");
 845     } else {
 846       tty->print("level %d ", comp_level);
 847     }
 848     this->print_short_name(tty);


 924     return is_not_c2_osr_compilable();
 925   return false;
 926 }
 927 
 928 void Method::set_not_osr_compilable(const char* reason, int comp_level, bool report) {
 929   print_made_not_compilable(comp_level, /*is_osr*/ true, report, reason);
 930   if (comp_level == CompLevel_all) {
 931     set_not_c1_osr_compilable();
 932     set_not_c2_osr_compilable();
 933   } else {
 934     if (is_c1_compile(comp_level))
 935       set_not_c1_osr_compilable();
 936     if (is_c2_compile(comp_level))
 937       set_not_c2_osr_compilable();
 938   }
 939   CompilationPolicy::policy()->disable_compilation(this);
 940   assert(!CompilationPolicy::can_be_osr_compiled(this, comp_level), "sanity check");
 941 }
 942 
 943 // Revert to using the interpreter and clear out the nmethod
 944 void Method::clear_code(bool acquire_lock /* = true */) {
 945   MutexLocker pl(acquire_lock ? Patching_lock : NULL, Mutex::_no_safepoint_check_flag);
 946   // this may be NULL if c2i adapters have not been made yet
 947   // Only should happen at allocate time.
 948   if (adapter() == NULL) {
 949     _from_compiled_entry    = NULL;
 950   } else {
 951     _from_compiled_entry    = adapter()->get_c2i_entry();
 952   }
 953   OrderAccess::storestore();
 954   _from_interpreted_entry = _i2i_entry;
 955   OrderAccess::storestore();
 956   _code = NULL;
 957 }
 958 



















 959 #if INCLUDE_CDS
 960 // Called by class data sharing to remove any entry points (which are not shared)
 961 void Method::unlink_method() {
 962   _code = NULL;
 963 
 964   assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "dump time only");
 965   // Set the values to what they should be at run time. Note that
 966   // this Method can no longer be executed during dump time.
 967   _i2i_entry = Interpreter::entry_for_cds_method(this);
 968   _from_interpreted_entry = _i2i_entry;
 969 
 970   if (DynamicDumpSharedSpaces) {
 971     assert(_from_compiled_entry != NULL, "sanity");
 972   } else {
 973     // TODO: Simplify the adapter trampoline allocation for static archiving.
 974     //       Remove the use of CDSAdapterHandlerEntry.
 975     CDSAdapterHandlerEntry* cds_adapter = (CDSAdapterHandlerEntry*)adapter();
 976     constMethod()->set_adapter_trampoline(cds_adapter->get_adapter_trampoline());
 977     _from_compiled_entry = cds_adapter->get_c2i_entry_trampoline();
 978     assert(*((int*)_from_compiled_entry) == 0,


1165 // This function is called after potential safepoints so that nmethod
1166 // or adapter that it points to is still live and valid.
1167 // This function must not hit a safepoint!
1168 address Method::verified_code_entry() {
1169   debug_only(NoSafepointVerifier nsv;)
1170   assert(_from_compiled_entry != NULL, "must be set");
1171   return _from_compiled_entry;
1172 }
1173 
1174 // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all
1175 // (could be racing a deopt).
1176 // Not inline to avoid circular ref.
1177 bool Method::check_code() const {
1178   // cached in a register or local.  There's a race on the value of the field.
1179   CompiledMethod *code = OrderAccess::load_acquire(&_code);
1180   return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
1181 }
1182 
1183 // Install compiled code.  Instantly it can execute.
1184 void Method::set_code(const methodHandle& mh, CompiledMethod *code) {
1185   MutexLocker pl(Patching_lock, Mutex::_no_safepoint_check_flag);
1186   assert( code, "use clear_code to remove code" );
1187   assert( mh->check_code(), "" );
1188 
1189   guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
1190 
1191   // These writes must happen in this order, because the interpreter will
1192   // directly jump to from_interpreted_entry which jumps to an i2c adapter
1193   // which jumps to _from_compiled_entry.
1194   mh->_code = code;             // Assign before allowing compiled code to exec
1195 
1196   int comp_level = code->comp_level();
1197   // In theory there could be a race here. In practice it is unlikely
1198   // and not worth worrying about.
1199   if (comp_level > mh->highest_comp_level()) {
1200     mh->set_highest_comp_level(comp_level);
1201   }
1202 
1203   OrderAccess::storestore();
1204   mh->_from_compiled_entry = code->verified_entry_point();
1205   OrderAccess::storestore();




  86   int size = Method::size(access_flags.is_native());
  87   return new (loader_data, size, MetaspaceObj::MethodType, THREAD) Method(cm, access_flags);
  88 }
  89 
  90 Method::Method(ConstMethod* xconst, AccessFlags access_flags) {
  91   NoSafepointVerifier no_safepoint;
  92   set_constMethod(xconst);
  93   set_access_flags(access_flags);
  94   set_intrinsic_id(vmIntrinsics::_none);
  95   set_force_inline(false);
  96   set_hidden(false);
  97   set_dont_inline(false);
  98   set_has_injected_profile(false);
  99   set_method_data(NULL);
 100   clear_method_counters();
 101   set_vtable_index(Method::garbage_vtable_index);
 102 
 103   // Fix and bury in Method*
 104   set_interpreter_entry(NULL); // sets i2i entry and from_int
 105   set_adapter_entry(NULL);
 106   Method::clear_code(); // from_c/from_i get set to c2i/i2i
 107 
 108   if (access_flags.is_native()) {
 109     clear_native_function();
 110     set_signature_handler(NULL);
 111   }
 112 
 113   NOT_PRODUCT(set_compiled_invocation_count(0);)
 114 }
 115 
 116 // Release Method*.  The nmethod will be gone when we get here because
 117 // we've walked the code cache.
 118 void Method::deallocate_contents(ClassLoaderData* loader_data) {
 119   MetadataFactory::free_metadata(loader_data, constMethod());
 120   set_constMethod(NULL);
 121 #if INCLUDE_JVMCI
 122   if (method_data()) {
 123     FailedSpeculation::free_failed_speculations(method_data()->get_failed_speculations_address());
 124   }
 125 #endif
 126   MetadataFactory::free_metadata(loader_data, method_data());


 808   CompiledMethod* nm = code(); // Put it into local variable to guard against concurrent updates
 809   if (nm != NULL) {
 810     nm->make_not_entrant();
 811   }
 812 }
 813 
 814 
 815 bool Method::has_native_function() const {
 816   if (is_method_handle_intrinsic())
 817     return false;  // special-cased in SharedRuntime::generate_native_wrapper
 818   address func = native_function();
 819   return (func != NULL && func != SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
 820 }
 821 
 822 
 823 void Method::clear_native_function() {
 824   // Note: is_method_handle_intrinsic() is allowed here.
 825   set_native_function(
 826     SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
 827     !native_bind_event_is_interesting);
 828   this->unlink_code();
 829 }
 830 
 831 
 832 void Method::set_signature_handler(address handler) {
 833   address* signature_handler =  signature_handler_addr();
 834   *signature_handler = handler;
 835 }
 836 
 837 
 838 void Method::print_made_not_compilable(int comp_level, bool is_osr, bool report, const char* reason) {
 839   assert(reason != NULL, "must provide a reason");
 840   if (PrintCompilation && report) {
 841     ttyLocker ttyl;
 842     tty->print("made not %scompilable on ", is_osr ? "OSR " : "");
 843     if (comp_level == CompLevel_all) {
 844       tty->print("all levels ");
 845     } else {
 846       tty->print("level %d ", comp_level);
 847     }
 848     this->print_short_name(tty);


 924     return is_not_c2_osr_compilable();
 925   return false;
 926 }
 927 
 928 void Method::set_not_osr_compilable(const char* reason, int comp_level, bool report) {
 929   print_made_not_compilable(comp_level, /*is_osr*/ true, report, reason);
 930   if (comp_level == CompLevel_all) {
 931     set_not_c1_osr_compilable();
 932     set_not_c2_osr_compilable();
 933   } else {
 934     if (is_c1_compile(comp_level))
 935       set_not_c1_osr_compilable();
 936     if (is_c2_compile(comp_level))
 937       set_not_c2_osr_compilable();
 938   }
 939   CompilationPolicy::policy()->disable_compilation(this);
 940   assert(!CompilationPolicy::can_be_osr_compiled(this, comp_level), "sanity check");
 941 }
 942 
 943 // Revert to using the interpreter and clear out the nmethod
 944 void Method::clear_code() {

 945   // this may be NULL if c2i adapters have not been made yet
 946   // Only should happen at allocate time.
 947   if (adapter() == NULL) {
 948     _from_compiled_entry    = NULL;
 949   } else {
 950     _from_compiled_entry    = adapter()->get_c2i_entry();
 951   }
 952   OrderAccess::storestore();
 953   _from_interpreted_entry = _i2i_entry;
 954   OrderAccess::storestore();
 955   _code = NULL;
 956 }
 957 
 958 void Method::unlink_code(CompiledMethod *compare) {
 959   MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
 960   // We need to check if either the _code or _from_compiled_code_entry_point
 961   // refer to this nmethod because there is a race in setting these two fields
 962   // in Method* as seen in bugid 4947125.
 963   // If the vep() points to the zombie nmethod, the memory for the nmethod
 964   // could be flushed and the compiler and vtable stubs could still call
 965   // through it.
 966   if (code() == compare ||
 967       from_compiled_entry() == compare->verified_entry_point()) {
 968     clear_code();
 969   }
 970 }
 971 
 972 void Method::unlink_code() {
 973   MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
 974   clear_code();
 975 }
 976 
 977 #if INCLUDE_CDS
 978 // Called by class data sharing to remove any entry points (which are not shared)
 979 void Method::unlink_method() {
 980   _code = NULL;
 981 
 982   assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "dump time only");
 983   // Set the values to what they should be at run time. Note that
 984   // this Method can no longer be executed during dump time.
 985   _i2i_entry = Interpreter::entry_for_cds_method(this);
 986   _from_interpreted_entry = _i2i_entry;
 987 
 988   if (DynamicDumpSharedSpaces) {
 989     assert(_from_compiled_entry != NULL, "sanity");
 990   } else {
 991     // TODO: Simplify the adapter trampoline allocation for static archiving.
 992     //       Remove the use of CDSAdapterHandlerEntry.
 993     CDSAdapterHandlerEntry* cds_adapter = (CDSAdapterHandlerEntry*)adapter();
 994     constMethod()->set_adapter_trampoline(cds_adapter->get_adapter_trampoline());
 995     _from_compiled_entry = cds_adapter->get_c2i_entry_trampoline();
 996     assert(*((int*)_from_compiled_entry) == 0,


1183 // This function is called after potential safepoints so that nmethod
1184 // or adapter that it points to is still live and valid.
1185 // This function must not hit a safepoint!
1186 address Method::verified_code_entry() {
1187   debug_only(NoSafepointVerifier nsv;)
1188   assert(_from_compiled_entry != NULL, "must be set");
1189   return _from_compiled_entry;
1190 }
1191 
1192 // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all
1193 // (could be racing a deopt).
1194 // Not inline to avoid circular ref.
1195 bool Method::check_code() const {
1196   // cached in a register or local.  There's a race on the value of the field.
1197   CompiledMethod *code = OrderAccess::load_acquire(&_code);
1198   return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
1199 }
1200 
1201 // Install compiled code.  Instantly it can execute.
1202 void Method::set_code(const methodHandle& mh, CompiledMethod *code) {
1203   MutexLocker pl(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1204   assert( code, "use clear_code to remove code" );
1205   assert( mh->check_code(), "" );
1206 
1207   guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
1208 
1209   // These writes must happen in this order, because the interpreter will
1210   // directly jump to from_interpreted_entry which jumps to an i2c adapter
1211   // which jumps to _from_compiled_entry.
1212   mh->_code = code;             // Assign before allowing compiled code to exec
1213 
1214   int comp_level = code->comp_level();
1215   // In theory there could be a race here. In practice it is unlikely
1216   // and not worth worrying about.
1217   if (comp_level > mh->highest_comp_level()) {
1218     mh->set_highest_comp_level(comp_level);
1219   }
1220 
1221   OrderAccess::storestore();
1222   mh->_from_compiled_entry = code->verified_entry_point();
1223   OrderAccess::storestore();


< prev index next >