9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_CODE_CODECACHE_HPP
26 #define SHARE_VM_CODE_CODECACHE_HPP
27
28 #include "code/codeBlob.hpp"
29 #include "code/nmethod.hpp"
30 #include "memory/allocation.hpp"
31 #include "memory/heap.hpp"
32 #include "oops/instanceKlass.hpp"
33 #include "oops/oopsHierarchy.hpp"
34 #include "runtime/mutexLocker.hpp"
35
36 // The CodeCache implements the code cache for various pieces of generated
37 // code, e.g., compiled java methods, runtime stubs, transition frames, etc.
38 // The entries in the CodeCache are all CodeBlob's.
39
40 // -- Implementation --
41 // The CodeCache consists of one or more CodeHeaps, each of which contains
42 // CodeBlobs of a specific CodeBlobType. Currently heaps for the following
43 // types are available:
44 // - Non-nmethods: Non-nmethods like Buffers, Adapters and Runtime Stubs
45 // - Profiled nmethods: nmethods that are profiled, i.e., those
46 // executed at level 2 or 3
47 // - Non-Profiled nmethods: nmethods that are not profiled, i.e., those
48 // executed at level 1 or 4 and native methods
60 // Code cache segmentation is controlled by the flag SegmentedCodeCache.
61 // If turned off, all code types are stored in a single code heap. By default
62 // code cache segmentation is turned on if TieredCompilation is enabled and
63 // ReservedCodeCacheSize >= 240 MB.
64 //
65 // All methods of the CodeCache accepting a CodeBlobType only apply to
66 // CodeBlobs of the given type. For example, iteration over the
67 // CodeBlobs of a specific type can be done by using CodeCache::first_blob(..)
68 // and CodeCache::next_blob(..) and providing the corresponding CodeBlobType.
69 //
70 // IMPORTANT: If you add new CodeHeaps to the code cache or change the
71 // existing ones, make sure to adapt the dtrace scripts (jhelper.d) for
72 // Solaris and BSD.
73
74 class OopClosure;
75 class KlassDepChange;
76
77 class CodeCache : AllStatic {
78 friend class VMStructs;
79 friend class JVMCIVMStructs;
80 friend class NMethodIterator;
81 friend class CompiledMethodIterator;
82 friend class WhiteBox;
83 friend class CodeCacheLoader;
84 private:
85 // CodeHeaps of the cache
86 static GrowableArray<CodeHeap*>* _heaps;
87
88 static address _low_bound; // Lower bound of CodeHeap addresses
89 static address _high_bound; // Upper bound of CodeHeap addresses
90 static int _number_of_nmethods_with_dependencies; // Total number of nmethods with dependencies
91 static bool _needs_cache_clean; // True if inline caches of the nmethods needs to be flushed
92 static nmethod* _scavenge_root_nmethods; // linked via nm->scavenge_root_link()
93
94 static void mark_scavenge_root_nmethods() PRODUCT_RETURN;
95 static void verify_perm_nmethods(CodeBlobClosure* f_or_null) PRODUCT_RETURN;
96
97 // CodeHeap management
98 static void initialize_heaps(); // Initializes the CodeHeaps
99 // Check the code heap sizes set by the user via command line
100 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);
101 // Creates a new heap with the given name and size, containing CodeBlobs of the given type
102 static void add_heap(ReservedSpace rs, const char* name, int code_blob_type);
103 static CodeHeap* get_code_heap(const CodeBlob* cb); // Returns the CodeHeap for the given CodeBlob
104 static CodeHeap* get_code_heap(int code_blob_type); // Returns the CodeHeap for the given CodeBlobType
105 // Returns the name of the VM option to set the size of the corresponding CodeHeap
106 static const char* get_code_heap_flag_name(int code_blob_type);
107 static size_t heap_alignment(); // Returns the alignment of the CodeHeaps in bytes
108 static ReservedCodeSpace reserve_heap_memory(size_t size); // Reserves one continuous chunk of memory for the CodeHeaps
109
110 // Iteration
111 static CodeBlob* first_blob(CodeHeap* heap); // Returns the first CodeBlob on the given CodeHeap
112 static CodeBlob* first_blob(int code_blob_type); // Returns the first CodeBlob of the given type
113 static CodeBlob* next_blob(CodeHeap* heap, CodeBlob* cb); // Returns the first alive CodeBlob on the given CodeHeap
114 static CodeBlob* next_blob(CodeBlob* cb); // Returns the next CodeBlob of the given type succeeding the given CodeBlob
115
116 static size_t bytes_allocated_in_freelists();
117 static int allocated_segments();
118 static size_t freelists_length();
119
120 static void set_scavenge_root_nmethods(nmethod* nm) { _scavenge_root_nmethods = nm; }
121 static void prune_scavenge_root_nmethods();
122 static void unlink_scavenge_root_nmethod(nmethod* nm, nmethod* prev);
123
124 public:
125 // Initialization
126 static void initialize();
127
128 // Allocation/administration
129 static CodeBlob* allocate(int size, int code_blob_type, int orig_code_blob_type = CodeBlobType::All); // allocates a new CodeBlob
130 static void commit(CodeBlob* cb); // called when the allocated CodeBlob has been filled
131 static int alignment_unit(); // guaranteed alignment of all CodeBlobs
132 static int alignment_offset(); // guaranteed offset of first CodeBlob byte within alignment unit (i.e., allocation header)
133 static void free(CodeBlob* cb); // frees a CodeBlob
134 static bool contains(void *p); // returns whether p is included
135 static void blobs_do(void f(CodeBlob* cb)); // iterates over all CodeBlobs
136 static void blobs_do(CodeBlobClosure* f); // iterates over all CodeBlobs
137 static void nmethods_do(void f(nmethod* nm)); // iterates over all nmethods
138 static void metadata_do(void f(Metadata* m)); // iterates over metadata in alive nmethods
139
140 // Lookup
141 static CodeBlob* find_blob(void* start); // Returns the CodeBlob containing the given address
142 static CodeBlob* find_blob_unsafe(void* start); // Same as find_blob but does not fail if looking up a zombie method
143 static nmethod* find_nmethod(void* start); // Returns the nmethod containing the given address
144 static CompiledMethod* find_compiled(void* start);
145
146 static int blob_count(); // Returns the total number of CodeBlobs in the cache
147 static int blob_count(int code_blob_type);
148 static int adapter_count(); // Returns the total number of Adapters in the cache
149 static int adapter_count(int code_blob_type);
150 static int nmethod_count(); // Returns the total number of nmethods in the cache
151 static int nmethod_count(int code_blob_type);
152
153 // GC support
154 static void gc_epilogue();
175 static void print(); // prints summary
176 static void print_internals();
177 static void print_memory_overhead();
178 static void verify(); // verifies the code cache
179 static void print_trace(const char* event, CodeBlob* cb, int size = 0) PRODUCT_RETURN;
180 static void print_summary(outputStream* st, bool detailed = true); // Prints a summary of the code cache usage
181 static void log_state(outputStream* st);
182 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"); }
183 static void report_codemem_full(int code_blob_type, bool print);
184
185 // Dcmd (Diagnostic commands)
186 static void print_codelist(outputStream* st);
187 static void print_layout(outputStream* st);
188
189 // The full limits of the codeCache
190 static address low_bound() { return _low_bound; }
191 static address low_bound(int code_blob_type);
192 static address high_bound() { return _high_bound; }
193 static address high_bound(int code_blob_type);
194
195 // Profiling
196 static size_t capacity();
197 static size_t unallocated_capacity(int code_blob_type);
198 static size_t unallocated_capacity();
199 static size_t max_capacity();
200
201 static double reverse_free_ratio(int code_blob_type);
202
203 static bool needs_cache_clean() { return _needs_cache_clean; }
204 static void set_needs_cache_clean(bool v) { _needs_cache_clean = v; }
205 static void clear_inline_caches(); // clear all inline caches
206 static void cleanup_inline_caches();
207
208 // Returns true if an own CodeHeap for the given CodeBlobType is available
209 static bool heap_available(int code_blob_type);
210
211 // Returns the CodeBlobType for the given nmethod
212 static int get_code_blob_type(CompiledMethod* cm) {
213 return get_code_heap(cm)->code_blob_type();
214 }
215
216 // Returns the CodeBlobType for the given compilation level
217 static int get_code_blob_type(int comp_level) {
218 if (comp_level == CompLevel_none ||
219 comp_level == CompLevel_simple ||
220 comp_level == CompLevel_full_optimization) {
221 // Non profiled methods
222 return CodeBlobType::MethodNonProfiled;
223 } else if (comp_level == CompLevel_limited_profile ||
224 comp_level == CompLevel_full_profile) {
225 // Profiled methods
226 return CodeBlobType::MethodProfiled;
227 }
228 ShouldNotReachHere();
229 return 0;
230 }
231
232 static void verify_clean_inline_caches();
233 static void verify_icholder_relocations();
234
235 // Deoptimization
247 // Flushing and deoptimization
248 static void flush_dependents_on(instanceKlassHandle dependee);
249 #ifdef HOTSWAP
250 // Flushing and deoptimization in case of evolution
251 static void flush_evol_dependents_on(instanceKlassHandle dependee);
252 #endif // HOTSWAP
253 // Support for fullspeed debugging
254 static void flush_dependents_on_method(methodHandle dependee);
255
256 // tells how many nmethods have dependencies
257 static int number_of_nmethods_with_dependencies();
258
259 static int get_codemem_full_count(int code_blob_type) {
260 CodeHeap* heap = get_code_heap(code_blob_type);
261 return (heap != NULL) ? heap->full_count() : 0;
262 }
263 };
264
265
266 // Iterator to iterate over nmethods in the CodeCache.
267 class NMethodIterator : public StackObj {
268 private:
269 CodeBlob* _code_blob; // Current CodeBlob
270 int _code_blob_type; // Refers to current CodeHeap
271
272 public:
273 NMethodIterator() {
274 initialize(NULL); // Set to NULL, initialized by first call to next()
275 }
276
277 NMethodIterator(nmethod* nm) {
278 initialize(nm);
279 }
280
281 // Advance iterator to next nmethod
282 bool next() {
283 assert_locked_or_safepoint(CodeCache_lock);
284 assert(_code_blob_type < CodeBlobType::NumTypes, "end reached");
285
286 bool result = next_nmethod();
287 while (!result && (_code_blob_type < CodeBlobType::MethodProfiled)) {
288 // Advance to next code heap if segmented code cache
289 _code_blob_type++;
290 result = next_nmethod();
291 }
292 return result;
293 }
294
295 // Advance iterator to next alive nmethod
296 bool next_alive() {
297 bool result = next();
298 while(result && !_code_blob->is_alive()) {
299 result = next();
300 }
301 return result;
302 }
303
304 bool end() const { return _code_blob == NULL; }
305 nmethod* method() const { return (nmethod*)_code_blob; }
306
307 private:
308 // Initialize iterator to given nmethod
309 void initialize(nmethod* nm) {
310 _code_blob = (CodeBlob*)nm;
311 if (!SegmentedCodeCache) {
312 // Iterate over all CodeBlobs
313 _code_blob_type = CodeBlobType::All;
314 } else if (nm != NULL) {
315 _code_blob_type = CodeCache::get_code_blob_type(nm);
316 } else {
317 // Only iterate over method code heaps, starting with non-profiled
318 _code_blob_type = CodeBlobType::MethodNonProfiled;
319 }
320 }
321
322 // Advance iterator to the next nmethod in the current code heap
323 bool next_nmethod() {
324 // Get first method CodeBlob
325 if (_code_blob == NULL) {
326 _code_blob = CodeCache::first_blob(_code_blob_type);
327 if (_code_blob == NULL) {
328 return false;
329 } else if (_code_blob->is_nmethod()) {
330 return true;
331 }
332 }
333 // Search for next method CodeBlob
334 _code_blob = CodeCache::next_blob(_code_blob);
335 while (_code_blob != NULL && !_code_blob->is_nmethod()) {
336 _code_blob = CodeCache::next_blob(_code_blob);
337 }
338 return _code_blob != NULL;
339 }
340 };
341
342 // Iterator to iterate over compiled methods in the CodeCache.
343 class CompiledMethodIterator : public StackObj {
344 private:
345 CodeBlob* _code_blob; // Current CodeBlob
346 int _code_blob_type; // Refers to current CodeHeap
347
348 public:
349 CompiledMethodIterator() {
350 initialize(NULL); // Set to NULL, initialized by first call to next()
351 }
352
353 CompiledMethodIterator(CompiledMethod* cm) {
354 initialize(cm);
355 }
356
357 // Advance iterator to next compiled method
358 bool next() {
359 assert_locked_or_safepoint(CodeCache_lock);
360 assert(_code_blob_type < CodeBlobType::NumTypes, "end reached");
361
362 bool result = next_compiled_method();
363 while (!result && (_code_blob_type < CodeBlobType::MethodProfiled)) {
364 // Advance to next code heap if segmented code cache
365 _code_blob_type++;
366 result = next_compiled_method();
367 }
368 return result;
369 }
370
371 // Advance iterator to next alive compiled method
372 bool next_alive() {
373 bool result = next();
374 while(result && !_code_blob->is_alive()) {
375 result = next();
376 }
377 return result;
378 }
379
380 bool end() const { return _code_blob == NULL; }
381 CompiledMethod* method() const { return (_code_blob != NULL) ? _code_blob->as_compiled_method() : NULL; }
382
383 private:
384 // Initialize iterator to given compiled method
385 void initialize(CompiledMethod* cm);
386
387 // Advance iterator to the next compiled method in the current code heap
388 bool next_compiled_method();
389 };
390
391 #endif // SHARE_VM_CODE_CODECACHE_HPP
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_CODE_CODECACHE_HPP
26 #define SHARE_VM_CODE_CODECACHE_HPP
27
28 #include "code/codeBlob.hpp"
29 #include "code/codeCacheExtensions.hpp"
30 #include "code/nmethod.hpp"
31 #include "memory/allocation.hpp"
32 #include "memory/heap.hpp"
33 #include "oops/instanceKlass.hpp"
34 #include "oops/oopsHierarchy.hpp"
35 #include "runtime/mutexLocker.hpp"
36
37 // The CodeCache implements the code cache for various pieces of generated
38 // code, e.g., compiled java methods, runtime stubs, transition frames, etc.
39 // The entries in the CodeCache are all CodeBlob's.
40
41 // -- Implementation --
42 // The CodeCache consists of one or more CodeHeaps, each of which contains
43 // CodeBlobs of a specific CodeBlobType. Currently heaps for the following
44 // types are available:
45 // - Non-nmethods: Non-nmethods like Buffers, Adapters and Runtime Stubs
46 // - Profiled nmethods: nmethods that are profiled, i.e., those
47 // executed at level 2 or 3
48 // - Non-Profiled nmethods: nmethods that are not profiled, i.e., those
49 // executed at level 1 or 4 and native methods
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 OopClosure;
76 class KlassDepChange;
77
78 class CodeCache : AllStatic {
79 friend class VMStructs;
80 friend class JVMCIVMStructs;
81 template <class T, class Filter> friend class CodeBlobIterator;
82 friend class WhiteBox;
83 friend class CodeCacheLoader;
84 private:
85 // CodeHeaps of the cache
86 static GrowableArray<CodeHeap*>* _heaps;
87 static GrowableArray<CodeHeap*>* _compiled_heaps;
88 static GrowableArray<CodeHeap*>* _nmethod_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 void mark_scavenge_root_nmethods() PRODUCT_RETURN;
97 static void verify_perm_nmethods(CodeBlobClosure* f_or_null) PRODUCT_RETURN;
98
99 // CodeHeap management
100 static void initialize_heaps(); // Initializes the CodeHeaps
101 // Check the code heap sizes set by the user via command line
102 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);
103 // Creates a new heap with the given name and size, containing CodeBlobs of the given type
104 static void add_heap(ReservedSpace rs, const char* name, int code_blob_type);
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 heap_alignment(); // Returns the alignment of the CodeHeaps in bytes
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
114 static CodeBlob* first_blob(int code_blob_type); // Returns the first CodeBlob of the given type
115 static CodeBlob* next_blob(CodeHeap* heap, CodeBlob* cb); // Returns the next CodeBlob on the given CodeHeap
116
117 static size_t bytes_allocated_in_freelists();
118 static int allocated_segments();
119 static size_t freelists_length();
120
121 static void set_scavenge_root_nmethods(nmethod* nm) { _scavenge_root_nmethods = nm; }
122 static void prune_scavenge_root_nmethods();
123 static void unlink_scavenge_root_nmethod(nmethod* nm, nmethod* prev);
124
125 // Make private to prevent unsafe calls. Not all CodeBlob*'s are embedded in a CodeHeap.
126 static bool contains(CodeBlob *p) { fatal("don't call me!"); return false; }
127
128 public:
129 // Initialization
130 static void initialize();
131
132 static int code_heap_compare(CodeHeap* const &lhs, CodeHeap* const &rhs);
133
134 static void add_heap(CodeHeap* heap);
135 static const GrowableArray<CodeHeap*>* heaps() { return _heaps; }
136 static const GrowableArray<CodeHeap*>* compiled_heaps() { return _compiled_heaps; }
137 static const GrowableArray<CodeHeap*>* nmethod_heaps() { return _nmethod_heaps; }
138
139 // Allocation/administration
140 static CodeBlob* allocate(int size, int code_blob_type, int orig_code_blob_type = CodeBlobType::All); // allocates a new CodeBlob
141 static void commit(CodeBlob* cb); // called when the allocated CodeBlob has been filled
142 static int alignment_unit(); // guaranteed alignment of all CodeBlobs
143 static int alignment_offset(); // guaranteed offset of first CodeBlob byte within alignment unit (i.e., allocation header)
144 static void free(CodeBlob* cb); // frees a CodeBlob
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(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 gc_epilogue();
187 static void print(); // prints summary
188 static void print_internals();
189 static void print_memory_overhead();
190 static void verify(); // verifies the code cache
191 static void print_trace(const char* event, CodeBlob* cb, int size = 0) PRODUCT_RETURN;
192 static void print_summary(outputStream* st, bool detailed = true); // Prints a summary of the code cache usage
193 static void log_state(outputStream* st);
194 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"); }
195 static void report_codemem_full(int code_blob_type, bool print);
196
197 // Dcmd (Diagnostic commands)
198 static void print_codelist(outputStream* st);
199 static void print_layout(outputStream* st);
200
201 // The full limits of the codeCache
202 static address low_bound() { return _low_bound; }
203 static address low_bound(int code_blob_type);
204 static address high_bound() { return _high_bound; }
205 static address high_bound(int code_blob_type);
206
207 // Have to use far call instructions to call this pc.
208 static bool is_far_target(address pc);
209
210 // Profiling
211 static size_t capacity();
212 static size_t unallocated_capacity(int code_blob_type);
213 static size_t unallocated_capacity();
214 static size_t max_capacity();
215
216 static double reverse_free_ratio(int code_blob_type);
217
218 static bool needs_cache_clean() { return _needs_cache_clean; }
219 static void set_needs_cache_clean(bool v) { _needs_cache_clean = v; }
220 static void clear_inline_caches(); // clear all inline caches
221 static void cleanup_inline_caches();
222
223 // Returns true if an own CodeHeap for the given CodeBlobType is available
224 static bool heap_available(int code_blob_type);
225
226 // Returns the CodeBlobType for the given CompiledMethod
227 static int get_code_blob_type(CompiledMethod* cm) {
228 return get_code_heap(cm)->code_blob_type();
229 }
230
231 static bool code_blob_type_accepts_compiled(int type) {
232 bool result = type == CodeBlobType::All || type <= CodeBlobType::MethodProfiled;
233 AOT_ONLY( result = result || type == CodeBlobType::AOT; )
234 return result;
235 }
236
237 static bool code_blob_type_accepts_nmethod(int type) {
238 return type == CodeBlobType::All || type <= CodeBlobType::MethodProfiled;
239 }
240
241 // Returns the CodeBlobType for the given compilation level
242 static int get_code_blob_type(int comp_level) {
243 if (comp_level == CompLevel_none ||
244 comp_level == CompLevel_simple ||
245 comp_level == CompLevel_full_optimization) {
246 // Non profiled methods
247 return CodeBlobType::MethodNonProfiled;
248 } else if (comp_level == CompLevel_limited_profile ||
249 comp_level == CompLevel_full_profile) {
250 // Profiled methods
251 return CodeBlobType::MethodProfiled;
252 }
253 ShouldNotReachHere();
254 return 0;
255 }
256
257 static void verify_clean_inline_caches();
258 static void verify_icholder_relocations();
259
260 // Deoptimization
272 // Flushing and deoptimization
273 static void flush_dependents_on(instanceKlassHandle dependee);
274 #ifdef HOTSWAP
275 // Flushing and deoptimization in case of evolution
276 static void flush_evol_dependents_on(instanceKlassHandle dependee);
277 #endif // HOTSWAP
278 // Support for fullspeed debugging
279 static void flush_dependents_on_method(methodHandle dependee);
280
281 // tells how many nmethods have dependencies
282 static int number_of_nmethods_with_dependencies();
283
284 static int get_codemem_full_count(int code_blob_type) {
285 CodeHeap* heap = get_code_heap(code_blob_type);
286 return (heap != NULL) ? heap->full_count() : 0;
287 }
288 };
289
290
291 // Iterator to iterate over nmethods in the CodeCache.
292 template <class T, class Filter> class CodeBlobIterator : public StackObj {
293 private:
294 CodeBlob* _code_blob; // Current CodeBlob
295 GrowableArrayIterator<CodeHeap*> _heap;
296 GrowableArrayIterator<CodeHeap*> _end;
297
298 public:
299 CodeBlobIterator(T* nm = NULL) {
300 if (Filter::heaps() == NULL) {
301 return;
302 }
303 _heap = Filter::heaps()->begin();
304 _end = Filter::heaps()->end();
305 // If set to NULL, initialized by first call to next()
306 _code_blob = (CodeBlob*)nm;
307 if (nm != NULL) {
308 address start = nm->code_begin();
309 while(!(*_heap)->contains(start)) {
310 ++_heap;
311 }
312 assert((*_heap)->contains(start), "match not found");
313 }
314 }
315
316 // Advance iterator to next blob
317 bool next() {
318 assert_locked_or_safepoint(CodeCache_lock);
319
320 bool result = next_blob();
321 while (!result && _heap != _end) {
322 // Advance to next code heap of segmented code cache
323 if (++_heap == _end) {
324 break;
325 }
326 result = next_blob();
327 }
328
329 return result;
330 }
331
332 // Advance iterator to next alive blob
333 bool next_alive() {
334 bool result = next();
335 while(result && !_code_blob->is_alive()) {
336 result = next();
337 }
338 return result;
339 }
340
341 bool end() const { return _code_blob == NULL; }
342 T* method() const { return (T*)_code_blob; }
343
344 private:
345
346 // Advance iterator to the next blob in the current code heap
347 bool next_blob() {
348 if (_heap == _end) {
349 return false;
350 }
351 CodeHeap *heap = *_heap;
352 // Get first method CodeBlob
353 if (_code_blob == NULL) {
354 _code_blob = CodeCache::first_blob(heap);
355 if (_code_blob == NULL) {
356 return false;
357 } else if (Filter::apply(_code_blob)) {
358 return true;
359 }
360 }
361 // Search for next method CodeBlob
362 _code_blob = CodeCache::next_blob(heap, _code_blob);
363 while (_code_blob != NULL && !Filter::apply(_code_blob)) {
364 _code_blob = CodeCache::next_blob(heap, _code_blob);
365 }
366 return _code_blob != NULL;
367 }
368 };
369
370
371 struct CompiledMethodFilter {
372 static bool apply(CodeBlob* cb) { return cb->is_compiled(); }
373 static const GrowableArray<CodeHeap*>* heaps() { return CodeCache::compiled_heaps(); }
374 };
375
376
377 struct NMethodFilter {
378 static bool apply(CodeBlob* cb) { return cb->is_nmethod(); }
379 static const GrowableArray<CodeHeap*>* heaps() { return CodeCache::nmethod_heaps(); }
380 };
381
382
383 typedef CodeBlobIterator<CompiledMethod, CompiledMethodFilter> CompiledMethodIterator;
384 typedef CodeBlobIterator<nmethod, NMethodFilter> NMethodIterator;
385
386 #endif // SHARE_VM_CODE_CODECACHE_HPP
|