< prev index next >

src/hotspot/share/code/codeCache.hpp

Print this page




  59 // for details).
  60 //
  61 // Code cache segmentation is controlled by the flag SegmentedCodeCache.
  62 // If turned off, all code types are stored in a single code heap. By default
  63 // code cache segmentation is turned on if TieredCompilation is enabled and
  64 // ReservedCodeCacheSize >= 240 MB.
  65 //
  66 // All methods of the CodeCache accepting a CodeBlobType only apply to
  67 // CodeBlobs of the given type. For example, iteration over the
  68 // CodeBlobs of a specific type can be done by using CodeCache::first_blob(..)
  69 // and CodeCache::next_blob(..) and providing the corresponding CodeBlobType.
  70 //
  71 // IMPORTANT: If you add new CodeHeaps to the code cache or change the
  72 // existing ones, make sure to adapt the dtrace scripts (jhelper.d) for
  73 // Solaris and BSD.
  74 
  75 class ExceptionCache;
  76 class KlassDepChange;
  77 class OopClosure;
  78 class ShenandoahParallelCodeHeapIterator;

  79 
  80 class CodeCache : AllStatic {
  81   friend class VMStructs;
  82   friend class JVMCIVMStructs;
  83   template <class T, class Filter> friend class CodeBlobIterator;
  84   friend class WhiteBox;
  85   friend class CodeCacheLoader;
  86   friend class ShenandoahParallelCodeHeapIterator;
  87  private:
  88   // CodeHeaps of the cache
  89   static GrowableArray<CodeHeap*>* _heaps;
  90   static GrowableArray<CodeHeap*>* _compiled_heaps;
  91   static GrowableArray<CodeHeap*>* _nmethod_heaps;
  92   static GrowableArray<CodeHeap*>* _allocable_heaps;
  93 
  94   static address _low_bound;                            // Lower bound of CodeHeap addresses
  95   static address _high_bound;                           // Upper bound of CodeHeap addresses
  96   static int _number_of_nmethods_with_dependencies;     // Total number of nmethods with dependencies
  97   static uint8_t _unloading_cycle;                      // Global state for recognizing old nmethods that need to be unloaded
  98 


 105   // Creates a new heap with the given name and size, containing CodeBlobs of the given type
 106   static void add_heap(ReservedSpace rs, const char* name, int code_blob_type);
 107   static CodeHeap* get_code_heap_containing(void* p);         // Returns the CodeHeap containing the given pointer, or NULL
 108   static CodeHeap* get_code_heap(const CodeBlob* cb);         // Returns the CodeHeap for the given CodeBlob
 109   static CodeHeap* get_code_heap(int code_blob_type);         // Returns the CodeHeap for the given CodeBlobType
 110   // Returns the name of the VM option to set the size of the corresponding CodeHeap
 111   static const char* get_code_heap_flag_name(int code_blob_type);
 112   static ReservedCodeSpace reserve_heap_memory(size_t size);  // Reserves one continuous chunk of memory for the CodeHeaps
 113 
 114   // Iteration
 115   static CodeBlob* first_blob(CodeHeap* heap);                // Returns the first CodeBlob on the given CodeHeap
 116   static CodeBlob* first_blob(int code_blob_type);            // Returns the first CodeBlob of the given type
 117   static CodeBlob* next_blob(CodeHeap* heap, CodeBlob* cb);   // Returns the next CodeBlob on the given CodeHeap
 118 
 119   static size_t bytes_allocated_in_freelists();
 120   static int    allocated_segments();
 121   static size_t freelists_length();
 122 
 123   // Make private to prevent unsafe calls.  Not all CodeBlob*'s are embedded in a CodeHeap.
 124   static bool contains(CodeBlob *p) { fatal("don't call me!"); return false; }

 125 
 126  public:
 127   // Initialization
 128   static void initialize();
 129   static size_t page_size(bool aligned = true, size_t min_pages = 1); // Returns the page size used by the CodeCache
 130 
 131   static int code_heap_compare(CodeHeap* const &lhs, CodeHeap* const &rhs);
 132 
 133   static void add_heap(CodeHeap* heap);
 134   static const GrowableArray<CodeHeap*>* heaps() { return _heaps; }
 135   static const GrowableArray<CodeHeap*>* compiled_heaps() { return _compiled_heaps; }
 136   static const GrowableArray<CodeHeap*>* nmethod_heaps() { return _nmethod_heaps; }
 137 
 138   // Allocation/administration
 139   static CodeBlob* allocate(int size, int code_blob_type, int orig_code_blob_type = CodeBlobType::All); // allocates a new CodeBlob
 140   static void commit(CodeBlob* cb);                        // called when the allocated CodeBlob has been filled
 141   static int  alignment_unit();                            // guaranteed alignment of all CodeBlobs
 142   static int  alignment_offset();                          // guaranteed offset of first CodeBlob byte within alignment unit (i.e., allocation header)
 143   static void free(CodeBlob* cb);                          // frees a CodeBlob
 144   static void free_unused_tail(CodeBlob* cb, size_t used); // frees the unused tail of a CodeBlob (only used by TemplateInterpreter::initialize())
 145   static bool contains(void *p);                           // returns whether p is included
 146   static bool contains(nmethod* nm);                       // returns whether nm is included
 147   static void blobs_do(void f(CodeBlob* cb));              // iterates over all CodeBlobs
 148   static void blobs_do(CodeBlobClosure* f);                // iterates over all CodeBlobs
 149   static void nmethods_do(void f(nmethod* nm));            // iterates over all nmethods
 150   static void metadata_do(MetadataClosure* f);             // iterates over metadata in alive nmethods
 151 
 152   // Lookup
 153   static CodeBlob* find_blob(void* start);              // Returns the CodeBlob containing the given address
 154   static CodeBlob* find_blob_unsafe(void* start);       // Same as find_blob but does not fail if looking up a zombie method


 155   static nmethod*  find_nmethod(void* start);           // Returns the nmethod containing the given address
 156   static CompiledMethod* find_compiled(void* start);
 157 
 158   static int       blob_count();                        // Returns the total number of CodeBlobs in the cache
 159   static int       blob_count(int code_blob_type);
 160   static int       adapter_count();                     // Returns the total number of Adapters in the cache
 161   static int       adapter_count(int code_blob_type);
 162   static int       nmethod_count();                     // Returns the total number of nmethods in the cache
 163   static int       nmethod_count(int code_blob_type);
 164 
 165   // GC support
 166   static void verify_oops();
 167   // If any oops are not marked this method unloads (i.e., breaks root links
 168   // to) any unmarked codeBlobs in the cache.  Sets "marked_for_unloading"
 169   // to "true" iff some code got unloaded.
 170   // "unloading_occurred" controls whether metadata should be cleaned because of class unloading.
 171   class UnloadingScope: StackObj {
 172     ClosureIsUnloadingBehaviour _is_unloading_behaviour;
 173     IsUnloadingBehaviour*       _saved_behaviour;
 174 




  59 // for details).
  60 //
  61 // Code cache segmentation is controlled by the flag SegmentedCodeCache.
  62 // If turned off, all code types are stored in a single code heap. By default
  63 // code cache segmentation is turned on if TieredCompilation is enabled and
  64 // ReservedCodeCacheSize >= 240 MB.
  65 //
  66 // All methods of the CodeCache accepting a CodeBlobType only apply to
  67 // CodeBlobs of the given type. For example, iteration over the
  68 // CodeBlobs of a specific type can be done by using CodeCache::first_blob(..)
  69 // and CodeCache::next_blob(..) and providing the corresponding CodeBlobType.
  70 //
  71 // IMPORTANT: If you add new CodeHeaps to the code cache or change the
  72 // existing ones, make sure to adapt the dtrace scripts (jhelper.d) for
  73 // Solaris and BSD.
  74 
  75 class ExceptionCache;
  76 class KlassDepChange;
  77 class OopClosure;
  78 class ShenandoahParallelCodeHeapIterator;
  79 class NativePostCallNop;
  80 
  81 class CodeCache : AllStatic {
  82   friend class VMStructs;
  83   friend class JVMCIVMStructs;
  84   template <class T, class Filter> friend class CodeBlobIterator;
  85   friend class WhiteBox;
  86   friend class CodeCacheLoader;
  87   friend class ShenandoahParallelCodeHeapIterator;
  88  private:
  89   // CodeHeaps of the cache
  90   static GrowableArray<CodeHeap*>* _heaps;
  91   static GrowableArray<CodeHeap*>* _compiled_heaps;
  92   static GrowableArray<CodeHeap*>* _nmethod_heaps;
  93   static GrowableArray<CodeHeap*>* _allocable_heaps;
  94 
  95   static address _low_bound;                            // Lower bound of CodeHeap addresses
  96   static address _high_bound;                           // Upper bound of CodeHeap addresses
  97   static int _number_of_nmethods_with_dependencies;     // Total number of nmethods with dependencies
  98   static uint8_t _unloading_cycle;                      // Global state for recognizing old nmethods that need to be unloaded
  99 


 106   // Creates a new heap with the given name and size, containing CodeBlobs of the given type
 107   static void add_heap(ReservedSpace rs, const char* name, int code_blob_type);
 108   static CodeHeap* get_code_heap_containing(void* p);         // Returns the CodeHeap containing the given pointer, or NULL
 109   static CodeHeap* get_code_heap(const CodeBlob* cb);         // Returns the CodeHeap for the given CodeBlob
 110   static CodeHeap* get_code_heap(int code_blob_type);         // Returns the CodeHeap for the given CodeBlobType
 111   // Returns the name of the VM option to set the size of the corresponding CodeHeap
 112   static const char* get_code_heap_flag_name(int code_blob_type);
 113   static ReservedCodeSpace reserve_heap_memory(size_t size);  // Reserves one continuous chunk of memory for the CodeHeaps
 114 
 115   // Iteration
 116   static CodeBlob* first_blob(CodeHeap* heap);                // Returns the first CodeBlob on the given CodeHeap
 117   static CodeBlob* first_blob(int code_blob_type);            // Returns the first CodeBlob of the given type
 118   static CodeBlob* next_blob(CodeHeap* heap, CodeBlob* cb);   // Returns the next CodeBlob on the given CodeHeap
 119 
 120   static size_t bytes_allocated_in_freelists();
 121   static int    allocated_segments();
 122   static size_t freelists_length();
 123 
 124   // Make private to prevent unsafe calls.  Not all CodeBlob*'s are embedded in a CodeHeap.
 125   static bool contains(CodeBlob *p) { fatal("don't call me!"); return false; }
 126   static CodeBlob* patch_nop(NativePostCallNop* nop, void* pc, int& slot);
 127 
 128  public:
 129   // Initialization
 130   static void initialize();
 131   static size_t page_size(bool aligned = true, size_t min_pages = 1); // Returns the page size used by the CodeCache
 132 
 133   static int code_heap_compare(CodeHeap* const &lhs, CodeHeap* const &rhs);
 134 
 135   static void add_heap(CodeHeap* heap);
 136   static const GrowableArray<CodeHeap*>* heaps() { return _heaps; }
 137   static const GrowableArray<CodeHeap*>* compiled_heaps() { return _compiled_heaps; }
 138   static const GrowableArray<CodeHeap*>* nmethod_heaps() { return _nmethod_heaps; }
 139 
 140   // Allocation/administration
 141   static CodeBlob* allocate(int size, int code_blob_type, int orig_code_blob_type = CodeBlobType::All); // allocates a new CodeBlob
 142   static void commit(CodeBlob* cb);                        // called when the allocated CodeBlob has been filled
 143   static int  alignment_unit();                            // guaranteed alignment of all CodeBlobs
 144   static int  alignment_offset();                          // guaranteed offset of first CodeBlob byte within alignment unit (i.e., allocation header)
 145   static void free(CodeBlob* cb);                          // frees a CodeBlob
 146   static void free_unused_tail(CodeBlob* cb, size_t used); // frees the unused tail of a CodeBlob (only used by TemplateInterpreter::initialize())
 147   static bool contains(void *p);                           // returns whether p is included
 148   static bool contains(nmethod* nm);                       // returns whether nm is included
 149   static void blobs_do(void f(CodeBlob* cb));              // iterates over all CodeBlobs
 150   static void blobs_do(CodeBlobClosure* f);                // iterates over all CodeBlobs
 151   static void nmethods_do(void f(nmethod* nm));            // iterates over all nmethods
 152   static void metadata_do(MetadataClosure* f);             // iterates over metadata in alive nmethods
 153 
 154   // Lookup
 155   static CodeBlob* find_blob(void* start);              // Returns the CodeBlob containing the given address
 156   static CodeBlob* find_blob_unsafe(void* start);       // Same as find_blob but does not fail if looking up a zombie method
 157   static CodeBlob* find_blob_fast(void* start);         // Returns the CodeBlob containing the given address
 158   static CodeBlob* find_blob_and_oopmap(void* start, int& slot);         // Returns the CodeBlob containing the given address
 159   static nmethod*  find_nmethod(void* start);           // Returns the nmethod containing the given address
 160   static CompiledMethod* find_compiled(void* start);
 161 
 162   static int       blob_count();                        // Returns the total number of CodeBlobs in the cache
 163   static int       blob_count(int code_blob_type);
 164   static int       adapter_count();                     // Returns the total number of Adapters in the cache
 165   static int       adapter_count(int code_blob_type);
 166   static int       nmethod_count();                     // Returns the total number of nmethods in the cache
 167   static int       nmethod_count(int code_blob_type);
 168 
 169   // GC support
 170   static void verify_oops();
 171   // If any oops are not marked this method unloads (i.e., breaks root links
 172   // to) any unmarked codeBlobs in the cache.  Sets "marked_for_unloading"
 173   // to "true" iff some code got unloaded.
 174   // "unloading_occurred" controls whether metadata should be cleaned because of class unloading.
 175   class UnloadingScope: StackObj {
 176     ClosureIsUnloadingBehaviour _is_unloading_behaviour;
 177     IsUnloadingBehaviour*       _saved_behaviour;
 178 


< prev index next >