< prev index next >

src/hotspot/share/oops/method.cpp

Print this page
rev 54697 : imported patch 8221734-v2-merge
rev 54698 : imported patch 8221734-v2


  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 #if INCLUDE_JVMCI
 120   if (method_data()) {
 121     FailedSpeculation::free_failed_speculations(method_data()->get_failed_speculations_address());
 122   }
 123 #endif
 124   MetadataFactory::free_metadata(loader_data, method_data());


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



 956   }
 957 }
 958 
 959 void Method::unlink_code(Method *method) {
 960   if (method != NULL) {
 961     MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
 962     method->locked_unlink_code();
 963   }
 964 }
 965 
 966 #if INCLUDE_CDS
 967 // Called by class data sharing to remove any entry points (which are not shared)
 968 void Method::unlink_method() {
 969   _code = NULL;
 970 
 971   assert(DumpSharedSpaces, "dump time only");
 972   // Set the values to what they should be at run time. Note that
 973   // this Method can no longer be executed during dump time.
 974   _i2i_entry = Interpreter::entry_for_cds_method(this);
 975   _from_interpreted_entry = _i2i_entry;
 976 
 977   if (is_native()) {
 978     *native_function_addr() = NULL;
 979     set_signature_handler(NULL);
 980   }
 981   NOT_PRODUCT(set_compiled_invocation_count(0);)
 982 


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();




  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::clear_code(); // 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 #if INCLUDE_JVMCI
 120   if (method_data()) {
 121     FailedSpeculation::free_failed_speculations(method_data()->get_failed_speculations_address());
 122   }
 123 #endif
 124   MetadataFactory::free_metadata(loader_data, method_data());


 915     return is_not_c2_osr_compilable();
 916   return false;
 917 }
 918 
 919 void Method::set_not_osr_compilable(int comp_level, bool report, const char* reason) {
 920   print_made_not_compilable(comp_level, /*is_osr*/ true, report, reason);
 921   if (comp_level == CompLevel_all) {
 922     set_not_c1_osr_compilable();
 923     set_not_c2_osr_compilable();
 924   } else {
 925     if (is_c1_compile(comp_level))
 926       set_not_c1_osr_compilable();
 927     if (is_c2_compile(comp_level))
 928       set_not_c2_osr_compilable();
 929   }
 930   CompilationPolicy::policy()->disable_compilation(this);
 931   assert(!CompilationPolicy::can_be_osr_compiled(this, comp_level), "sanity check");
 932 }
 933 
 934 // Revert to using the interpreter and clear out the nmethod
 935 void Method::clear_code() {
 936   // this may be NULL if c2i adapters have not been made yet
 937   // Only should happen at allocate time.
 938   if (adapter() == NULL) {
 939     _from_compiled_entry    = NULL;
 940   } else {
 941     _from_compiled_entry    = adapter()->get_c2i_entry();
 942   }
 943   OrderAccess::storestore();
 944   _from_interpreted_entry = _i2i_entry;
 945   OrderAccess::storestore();
 946   _code = NULL;
 947 }
 948 
 949 void Method::unlink_code(Method *method, CompiledMethod *compare) {
 950   if (method == NULL) {


 951     return;
 952   }
 953   MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
 954   if (method->code() == compare ||
 955       method->from_compiled_entry() == compare->verified_entry_point()) {
 956     method->clear_code();
 957   }
 958 }
 959 
 960 void Method::unlink_code(Method *method) {
 961   if (method != NULL) {
 962     MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
 963     method->clear_code();
 964   }
 965 }
 966 
 967 #if INCLUDE_CDS
 968 // Called by class data sharing to remove any entry points (which are not shared)
 969 void Method::unlink_method() {
 970   _code = NULL;
 971 
 972   assert(DumpSharedSpaces, "dump time only");
 973   // Set the values to what they should be at run time. Note that
 974   // this Method can no longer be executed during dump time.
 975   _i2i_entry = Interpreter::entry_for_cds_method(this);
 976   _from_interpreted_entry = _i2i_entry;
 977 
 978   if (is_native()) {
 979     *native_function_addr() = NULL;
 980     set_signature_handler(NULL);
 981   }
 982   NOT_PRODUCT(set_compiled_invocation_count(0);)
 983 


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


< prev index next >