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 nmethod* _scavenge_root_nmethods; // linked via nm->scavenge_root_link() 98 static uint8_t _unloading_cycle; // Global state for recognizing old nmethods that need to be unloaded 99 100 static ExceptionCache* volatile _exception_cache_purge_list; 101 102 static void mark_scavenge_root_nmethods() PRODUCT_RETURN; 103 static void verify_perm_nmethods(CodeBlobClosure* f_or_null) PRODUCT_RETURN; 104 105 // CodeHeap management 106 static void initialize_heaps(); // Initializes the CodeHeaps 107 // Check the code heap sizes set by the user via command line 108 static void check_heap_sizes(size_t non_nmethod_size, size_t profiled_size, size_t non_profiled_size, size_t cache_size, bool all_set); 109 // Creates a new heap with the given name and size, containing CodeBlobs of the given type 110 static void add_heap(ReservedSpace rs, const char* name, int code_blob_type); 111 static CodeHeap* get_code_heap_containing(void* p); // Returns the CodeHeap containing the given pointer, or NULL 112 static CodeHeap* get_code_heap(const CodeBlob* cb); // Returns the CodeHeap for the given CodeBlob 113 static CodeHeap* get_code_heap(int code_blob_type); // Returns the CodeHeap for the given CodeBlobType 114 // Returns the name of the VM option to set the size of the corresponding CodeHeap 115 static const char* get_code_heap_flag_name(int code_blob_type); 116 static ReservedCodeSpace reserve_heap_memory(size_t size); // Reserves one continuous chunk of memory for the CodeHeaps 117 118 // Iteration 119 static CodeBlob* first_blob(CodeHeap* heap); // Returns the first CodeBlob on the given CodeHeap 120 static CodeBlob* first_blob(int code_blob_type); // Returns the first CodeBlob of the given type 121 static CodeBlob* next_blob(CodeHeap* heap, CodeBlob* cb); // Returns the next CodeBlob on the given CodeHeap 122 123 static size_t bytes_allocated_in_freelists(); 124 static int allocated_segments(); 125 static size_t freelists_length(); 126 127 static void set_scavenge_root_nmethods(nmethod* nm) { _scavenge_root_nmethods = nm; } 128 static void prune_scavenge_root_nmethods(); 129 static void unlink_scavenge_root_nmethod(nmethod* nm, nmethod* prev); 130 131 // Make private to prevent unsafe calls. Not all CodeBlob*'s are embedded in a CodeHeap. 132 static bool contains(CodeBlob *p) { fatal("don't call me!"); return false; } 133 134 public: 135 // Initialization 136 static void initialize(); 137 static size_t page_size(bool aligned = true, size_t min_pages = 1); // Returns the page size used by the CodeCache 138 139 static int code_heap_compare(CodeHeap* const &lhs, CodeHeap* const &rhs); 140 141 static void add_heap(CodeHeap* heap); 142 static const GrowableArray<CodeHeap*>* heaps() { return _heaps; } 143 static const GrowableArray<CodeHeap*>* compiled_heaps() { return _compiled_heaps; } 144 static const GrowableArray<CodeHeap*>* nmethod_heaps() { return _nmethod_heaps; } 145 146 // Allocation/administration 147 static CodeBlob* allocate(int size, int code_blob_type, int orig_code_blob_type = CodeBlobType::All); // allocates a new CodeBlob 148 static void commit(CodeBlob* cb); // called when the allocated CodeBlob has been filled 149 static int alignment_unit(); // guaranteed alignment of all CodeBlobs 150 static int alignment_offset(); // guaranteed offset of first CodeBlob byte within alignment unit (i.e., allocation header) 154 static bool contains(nmethod* nm); // returns whether nm is included 155 static void blobs_do(void f(CodeBlob* cb)); // iterates over all CodeBlobs 156 static void blobs_do(CodeBlobClosure* f); // iterates over all CodeBlobs 157 static void nmethods_do(void f(nmethod* nm)); // iterates over all nmethods 158 static void metadata_do(void f(Metadata* m)); // iterates over metadata in alive nmethods 159 160 // Lookup 161 static CodeBlob* find_blob(void* start); // Returns the CodeBlob containing the given address 162 static CodeBlob* find_blob_unsafe(void* start); // Same as find_blob but does not fail if looking up a zombie method 163 static nmethod* find_nmethod(void* start); // Returns the nmethod containing the given address 164 static CompiledMethod* find_compiled(void* start); 165 166 static int blob_count(); // Returns the total number of CodeBlobs in the cache 167 static int blob_count(int code_blob_type); 168 static int adapter_count(); // Returns the total number of Adapters in the cache 169 static int adapter_count(int code_blob_type); 170 static int nmethod_count(); // Returns the total number of nmethods in the cache 171 static int nmethod_count(int code_blob_type); 172 173 // GC support 174 static void gc_epilogue(); 175 static void gc_prologue(); 176 static void verify_oops(); 177 // If any oops are not marked this method unloads (i.e., breaks root links 178 // to) any unmarked codeBlobs in the cache. Sets "marked_for_unloading" 179 // to "true" iff some code got unloaded. 180 // "unloading_occurred" controls whether metadata should be cleaned because of class unloading. 181 class UnloadingScope: StackObj { 182 ClosureIsUnloadingBehaviour _is_unloading_behaviour; 183 184 public: 185 UnloadingScope(BoolObjectClosure* is_alive); 186 ~UnloadingScope(); 187 }; 188 189 static void do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred); 190 static uint8_t unloading_cycle() { return _unloading_cycle; } 191 static void increment_unloading_cycle(); 192 static void asserted_non_scavengable_nmethods_do(CodeBlobClosure* f = NULL) PRODUCT_RETURN; 193 static void release_exception_cache(ExceptionCache* entry); 194 static void purge_exception_caches(); 195 196 // Apply f to every live code blob in scavengable nmethods. Prune nmethods 197 // from the list of scavengable nmethods if f->fix_relocations() and a nmethod 198 // no longer has scavengable oops. If f->fix_relocations(), then f must copy 199 // objects to their new location immediately to avoid fixing nmethods on the 200 // basis of the old object locations. 201 static void scavenge_root_nmethods_do(CodeBlobToOopClosure* f); 202 203 static nmethod* scavenge_root_nmethods() { return _scavenge_root_nmethods; } 204 // register_scavenge_root_nmethod() conditionally adds the nmethod to the list 205 // if it is not already on the list and has a scavengeable root 206 static void register_scavenge_root_nmethod(nmethod* nm); 207 static void verify_scavenge_root_nmethod(nmethod* nm); 208 static void add_scavenge_root_nmethod(nmethod* nm); 209 static void drop_scavenge_root_nmethod(nmethod* nm); 210 211 // Printing/debugging 212 static void print(); // prints summary 213 static void print_internals(); 214 static void print_memory_overhead(); 215 static void verify(); // verifies the code cache 216 static void print_trace(const char* event, CodeBlob* cb, int size = 0) PRODUCT_RETURN; 217 static void print_summary(outputStream* st, bool detailed = true); // Prints a summary of the code cache usage 218 static void log_state(outputStream* st); 219 static const char* get_code_heap_name(int code_blob_type) { return (heap_available(code_blob_type) ? get_code_heap(code_blob_type)->name() : "Unused"); } 220 static void report_codemem_full(int code_blob_type, bool print); 221 222 // Dcmd (Diagnostic commands) 223 static void print_codelist(outputStream* st); 224 static void print_layout(outputStream* st); 225 226 // The full limits of the codeCache 227 static address low_bound() { return _low_bound; } 228 static address low_bound(int code_blob_type); 229 static address high_bound() { return _high_bound; } | 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 99 static ExceptionCache* volatile _exception_cache_purge_list; 100 101 // CodeHeap management 102 static void initialize_heaps(); // Initializes the CodeHeaps 103 // Check the code heap sizes set by the user via command line 104 static void check_heap_sizes(size_t non_nmethod_size, size_t profiled_size, size_t non_profiled_size, size_t cache_size, bool all_set); 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) 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(void f(Metadata* m)); // 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 174 public: 175 UnloadingScope(BoolObjectClosure* is_alive); 176 ~UnloadingScope(); 177 }; 178 179 static void do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred); 180 static uint8_t unloading_cycle() { return _unloading_cycle; } 181 static void increment_unloading_cycle(); 182 static void release_exception_cache(ExceptionCache* entry); 183 static void purge_exception_caches(); 184 185 // Printing/debugging 186 static void print(); // prints summary 187 static void print_internals(); 188 static void print_memory_overhead(); 189 static void verify(); // verifies the code cache 190 static void print_trace(const char* event, CodeBlob* cb, int size = 0) PRODUCT_RETURN; 191 static void print_summary(outputStream* st, bool detailed = true); // Prints a summary of the code cache usage 192 static void log_state(outputStream* st); 193 static const char* get_code_heap_name(int code_blob_type) { return (heap_available(code_blob_type) ? get_code_heap(code_blob_type)->name() : "Unused"); } 194 static void report_codemem_full(int code_blob_type, bool print); 195 196 // Dcmd (Diagnostic commands) 197 static void print_codelist(outputStream* st); 198 static void print_layout(outputStream* st); 199 200 // The full limits of the codeCache 201 static address low_bound() { return _low_bound; } 202 static address low_bound(int code_blob_type); 203 static address high_bound() { return _high_bound; } |