< prev index next >

src/hotspot/share/code/compiledMethod.cpp

Print this page
rev 54099 : 8219586: CodeHeap State Analytics processes dead nmethods
Reviewed-by: thartmann, eosterlund


  33 #include "memory/resourceArea.hpp"
  34 #include "oops/methodData.hpp"
  35 #include "oops/method.inline.hpp"
  36 #include "prims/methodHandles.hpp"
  37 #include "runtime/handles.inline.hpp"
  38 #include "runtime/mutexLocker.hpp"
  39 
  40 CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, const CodeBlobLayout& layout, int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps, bool caller_must_gc_arguments)
  41   : CodeBlob(name, type, layout, frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments),
  42   _method(method), _mark_for_deoptimization_status(not_marked) {
  43   init_defaults();
  44 }
  45 
  46 CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, int size, int header_size, CodeBuffer* cb, int frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments)
  47   : CodeBlob(name, type, CodeBlobLayout((address) this, size, header_size, cb), cb, frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments),
  48   _method(method), _mark_for_deoptimization_status(not_marked) {
  49   init_defaults();
  50 }
  51 
  52 void CompiledMethod::init_defaults() {







  53   _has_unsafe_access          = 0;
  54   _has_method_handle_invokes  = 0;
  55   _lazy_critical_native       = 0;
  56   _has_wide_vectors           = 0;
  57   _unloading_clock            = 0;
  58 }
  59 
  60 bool CompiledMethod::is_method_handle_return(address return_pc) {
  61   if (!has_method_handle_invokes())  return false;
  62   PcDesc* pd = pc_desc_at(return_pc);
  63   if (pd == NULL)
  64     return false;
  65   return pd->is_method_handle_invoke();
  66 }
  67 
  68 // Returns a string version of the method state.
  69 const char* CompiledMethod::state() const {
  70   int state = get_state();
  71   switch (state) {
  72   case not_installed:


 604     switch (iter.type()) {
 605 
 606     case relocInfo::virtual_call_type:
 607       clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), this, true);
 608       break;
 609 
 610     case relocInfo::opt_virtual_call_type:
 611       clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), this, true);
 612       break;
 613 
 614     case relocInfo::static_call_type:
 615       clean_if_nmethod_is_unloaded(compiledStaticCall_at(iter.reloc()), this, true);
 616       break;
 617 
 618     default:
 619       break;
 620     }
 621   }
 622 }
 623 
 624 // Iterating over all nmethods, e.g. with the help of CodeCache::nmethods_do(fun) was found
 625 // to not be inherently safe. There is a chance that fields are seen which are not properly
 626 // initialized. This happens despite the fact that nmethods_do() asserts the CodeCache_lock
 627 // to be held.
 628 // To bundle knowledge about necessary checks in one place, this function was introduced.
 629 // It is not claimed that these checks are sufficient, but they were found to be necessary.
 630 bool CompiledMethod::nmethod_access_is_safe(nmethod* nm) {
 631   Method* method = (nm == NULL) ? NULL : nm->method();  // nm->method() may be uninitialized, i.e. != NULL, but invalid
 632   return (nm != NULL) && (method != NULL) && (method->signature() != NULL) &&
 633          !nm->is_zombie() && !nm->is_not_installed() &&
 634          os::is_readable_pointer(method) &&
 635          os::is_readable_pointer(method->constants()) &&
 636          os::is_readable_pointer(method->signature());
 637 }


  33 #include "memory/resourceArea.hpp"
  34 #include "oops/methodData.hpp"
  35 #include "oops/method.inline.hpp"
  36 #include "prims/methodHandles.hpp"
  37 #include "runtime/handles.inline.hpp"
  38 #include "runtime/mutexLocker.hpp"
  39 
  40 CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, const CodeBlobLayout& layout, int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps, bool caller_must_gc_arguments)
  41   : CodeBlob(name, type, layout, frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments),
  42   _method(method), _mark_for_deoptimization_status(not_marked) {
  43   init_defaults();
  44 }
  45 
  46 CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, int size, int header_size, CodeBuffer* cb, int frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments)
  47   : CodeBlob(name, type, CodeBlobLayout((address) this, size, header_size, cb), cb, frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments),
  48   _method(method), _mark_for_deoptimization_status(not_marked) {
  49   init_defaults();
  50 }
  51 
  52 void CompiledMethod::init_defaults() {
  53   { // avoid uninitialized fields, even for short time periods
  54     _is_far_code                = false;
  55     _scopes_data_begin          = NULL;
  56     _deopt_handler_begin        = NULL;
  57     _deopt_mh_handler_begin     = NULL;
  58     _exception_cache            = NULL;
  59   }
  60   _has_unsafe_access          = 0;
  61   _has_method_handle_invokes  = 0;
  62   _lazy_critical_native       = 0;
  63   _has_wide_vectors           = 0;
  64   _unloading_clock            = 0;
  65 }
  66 
  67 bool CompiledMethod::is_method_handle_return(address return_pc) {
  68   if (!has_method_handle_invokes())  return false;
  69   PcDesc* pd = pc_desc_at(return_pc);
  70   if (pd == NULL)
  71     return false;
  72   return pd->is_method_handle_invoke();
  73 }
  74 
  75 // Returns a string version of the method state.
  76 const char* CompiledMethod::state() const {
  77   int state = get_state();
  78   switch (state) {
  79   case not_installed:


 611     switch (iter.type()) {
 612 
 613     case relocInfo::virtual_call_type:
 614       clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), this, true);
 615       break;
 616 
 617     case relocInfo::opt_virtual_call_type:
 618       clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), this, true);
 619       break;
 620 
 621     case relocInfo::static_call_type:
 622       clean_if_nmethod_is_unloaded(compiledStaticCall_at(iter.reloc()), this, true);
 623       break;
 624 
 625     default:
 626       break;
 627     }
 628   }
 629 }
 630 














< prev index next >