53 // Depending on the availability of compilers and TieredCompilation there
54 // may be fewer heaps. The size of the code heaps depends on the values of
55 // ReservedCodeCacheSize, NonProfiledCodeHeapSize and ProfiledCodeHeapSize
56 // (see CodeCache::heap_available(..) and CodeCache::initialize_heaps(..)
57 // for details).
58 //
59 // Code cache segmentation is controlled by the flag SegmentedCodeCache.
60 // If turned off, all code types are stored in a single code heap. By default
61 // code cache segmentation is turned on if TieredCompilation is enabled and
62 // ReservedCodeCacheSize >= 240 MB.
63 //
64 // All methods of the CodeCache accepting a CodeBlobType only apply to
65 // CodeBlobs of the given type. For example, iteration over the
66 // CodeBlobs of a specific type can be done by using CodeCache::first_blob(..)
67 // and CodeCache::next_blob(..) and providing the corresponding CodeBlobType.
68 //
69 // IMPORTANT: If you add new CodeHeaps to the code cache or change the
70 // existing ones, make sure to adapt the dtrace scripts (jhelper.d) for
71 // Solaris and BSD.
72
73 class OopClosure;
74 class KlassDepChange;
75
76 class CodeCache : AllStatic {
77 friend class VMStructs;
78 friend class JVMCIVMStructs;
79 template <class T, class Filter> friend class CodeBlobIterator;
80 friend class WhiteBox;
81 friend class CodeCacheLoader;
82 private:
83 // CodeHeaps of the cache
84 static GrowableArray<CodeHeap*>* _heaps;
85 static GrowableArray<CodeHeap*>* _compiled_heaps;
86 static GrowableArray<CodeHeap*>* _nmethod_heaps;
87 static GrowableArray<CodeHeap*>* _allocable_heaps;
88
89 static address _low_bound; // Lower bound of CodeHeap addresses
90 static address _high_bound; // Upper bound of CodeHeap addresses
91 static int _number_of_nmethods_with_dependencies; // Total number of nmethods with dependencies
92 static bool _needs_cache_clean; // True if inline caches of the nmethods needs to be flushed
93 static nmethod* _scavenge_root_nmethods; // linked via nm->scavenge_root_link()
94
95 static void mark_scavenge_root_nmethods() PRODUCT_RETURN;
96 static void verify_perm_nmethods(CodeBlobClosure* f_or_null) PRODUCT_RETURN;
97
98 // CodeHeap management
99 static void initialize_heaps(); // Initializes the CodeHeaps
100 // Check the code heap sizes set by the user via command line
101 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_s
102 // Creates a new heap with the given name and size, containing CodeBlobs of the given type
103 static void add_heap(ReservedSpace rs, const char* name, int code_blob_type);
104 static CodeHeap* get_code_heap_containing(void* p); // Returns the CodeHeap containing the given pointer, or NULL
105 static CodeHeap* get_code_heap(const CodeBlob* cb); // Returns the CodeHeap for the given CodeBlob
106 static CodeHeap* get_code_heap(int code_blob_type); // Returns the CodeHeap for the given CodeBlobType
107 // Returns the name of the VM option to set the size of the corresponding CodeHeap
108 static const char* get_code_heap_flag_name(int code_blob_type);
109 static size_t page_size(bool aligned = true); // Returns the page size used by the CodeCache
110 static ReservedCodeSpace reserve_heap_memory(size_t size); // Reserves one continuous chunk of memory for the CodeHeaps
111
112 // Iteration
113 static CodeBlob* first_blob(CodeHeap* heap); // Returns the first CodeBlob on the given CodeHeap
|
53 // Depending on the availability of compilers and TieredCompilation there
54 // may be fewer heaps. The size of the code heaps depends on the values of
55 // ReservedCodeCacheSize, NonProfiledCodeHeapSize and ProfiledCodeHeapSize
56 // (see CodeCache::heap_available(..) and CodeCache::initialize_heaps(..)
57 // for details).
58 //
59 // Code cache segmentation is controlled by the flag SegmentedCodeCache.
60 // If turned off, all code types are stored in a single code heap. By default
61 // code cache segmentation is turned on if TieredCompilation is enabled and
62 // ReservedCodeCacheSize >= 240 MB.
63 //
64 // All methods of the CodeCache accepting a CodeBlobType only apply to
65 // CodeBlobs of the given type. For example, iteration over the
66 // CodeBlobs of a specific type can be done by using CodeCache::first_blob(..)
67 // and CodeCache::next_blob(..) and providing the corresponding CodeBlobType.
68 //
69 // IMPORTANT: If you add new CodeHeaps to the code cache or change the
70 // existing ones, make sure to adapt the dtrace scripts (jhelper.d) for
71 // Solaris and BSD.
72
73 class ExceptionCache;
74 class KlassDepChange;
75 class OopClosure;
76
77 class CodeCache : AllStatic {
78 friend class VMStructs;
79 friend class JVMCIVMStructs;
80 template <class T, class Filter> friend class CodeBlobIterator;
81 friend class WhiteBox;
82 friend class CodeCacheLoader;
83 private:
84 // CodeHeaps of the cache
85 static GrowableArray<CodeHeap*>* _heaps;
86 static GrowableArray<CodeHeap*>* _compiled_heaps;
87 static GrowableArray<CodeHeap*>* _nmethod_heaps;
88 static GrowableArray<CodeHeap*>* _allocable_heaps;
89
90 static address _low_bound; // Lower bound of CodeHeap addresses
91 static address _high_bound; // Upper bound of CodeHeap addresses
92 static int _number_of_nmethods_with_dependencies; // Total number of nmethods with dependencies
93 static bool _needs_cache_clean; // True if inline caches of the nmethods needs to be flushed
94 static nmethod* _scavenge_root_nmethods; // linked via nm->scavenge_root_link()
95
96 static ExceptionCache* volatile _exception_cache_purge_list;
97
98 static void mark_scavenge_root_nmethods() PRODUCT_RETURN;
99 static void verify_perm_nmethods(CodeBlobClosure* f_or_null) PRODUCT_RETURN;
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_s
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 size_t page_size(bool aligned = true); // Returns the page size used by the CodeCache
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
|
156 static nmethod* find_nmethod(void* start); // Returns the nmethod containing the given address
157 static CompiledMethod* find_compiled(void* start);
158
159 static int blob_count(); // Returns the total number of CodeBlobs in the cache
160 static int blob_count(int code_blob_type);
161 static int adapter_count(); // Returns the total number of Adapters in the cache
162 static int adapter_count(int code_blob_type);
163 static int nmethod_count(); // Returns the total number of nmethods in the cache
164 static int nmethod_count(int code_blob_type);
165
166 // GC support
167 static void gc_epilogue();
168 static void gc_prologue();
169 static void verify_oops();
170 // If any oops are not marked this method unloads (i.e., breaks root links
171 // to) any unmarked codeBlobs in the cache. Sets "marked_for_unloading"
172 // to "true" iff some code got unloaded.
173 // "unloading_occurred" controls whether metadata should be cleaned because of class unloading.
174 static void do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred);
175 static void asserted_non_scavengable_nmethods_do(CodeBlobClosure* f = NULL) PRODUCT_RETURN;
176
177 // Apply f to every live code blob in scavengable nmethods. Prune nmethods
178 // from the list of scavengable nmethods if f->fix_relocations() and a nmethod
179 // no longer has scavengable oops. If f->fix_relocations(), then f must copy
180 // objects to their new location immediately to avoid fixing nmethods on the
181 // basis of the old object locations.
182 static void scavenge_root_nmethods_do(CodeBlobToOopClosure* f);
183
184 static nmethod* scavenge_root_nmethods() { return _scavenge_root_nmethods; }
185 // register_scavenge_root_nmethod() conditionally adds the nmethod to the list
186 // if it is not already on the list and has a scavengeable root
187 static void register_scavenge_root_nmethod(nmethod* nm);
188 static void verify_scavenge_root_nmethod(nmethod* nm);
189 static void add_scavenge_root_nmethod(nmethod* nm);
190 static void drop_scavenge_root_nmethod(nmethod* nm);
191
192 // Printing/debugging
193 static void print(); // prints summary
194 static void print_internals();
|
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 gc_epilogue();
171 static void gc_prologue();
172 static void verify_oops();
173 // If any oops are not marked this method unloads (i.e., breaks root links
174 // to) any unmarked codeBlobs in the cache. Sets "marked_for_unloading"
175 // to "true" iff some code got unloaded.
176 // "unloading_occurred" controls whether metadata should be cleaned because of class unloading.
177 static void do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred);
178 static void asserted_non_scavengable_nmethods_do(CodeBlobClosure* f = NULL) PRODUCT_RETURN;
179 static void release_exception_cache(ExceptionCache* entry);
180 static void purge_exception_caches();
181
182 // Apply f to every live code blob in scavengable nmethods. Prune nmethods
183 // from the list of scavengable nmethods if f->fix_relocations() and a nmethod
184 // no longer has scavengable oops. If f->fix_relocations(), then f must copy
185 // objects to their new location immediately to avoid fixing nmethods on the
186 // basis of the old object locations.
187 static void scavenge_root_nmethods_do(CodeBlobToOopClosure* f);
188
189 static nmethod* scavenge_root_nmethods() { return _scavenge_root_nmethods; }
190 // register_scavenge_root_nmethod() conditionally adds the nmethod to the list
191 // if it is not already on the list and has a scavengeable root
192 static void register_scavenge_root_nmethod(nmethod* nm);
193 static void verify_scavenge_root_nmethod(nmethod* nm);
194 static void add_scavenge_root_nmethod(nmethod* nm);
195 static void drop_scavenge_root_nmethod(nmethod* nm);
196
197 // Printing/debugging
198 static void print(); // prints summary
199 static void print_internals();
|