author | anoll |
Fri, 24 Oct 2014 14:25:46 +0200 | |
changeset 27420 | 04e6f914cce1 |
parent 27410 | dd80df7cfa2b |
child 27642 | 8c9eff693145 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
18025 | 2 |
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5533
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5533
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5533
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_CODE_CODECACHE_HPP |
26 |
#define SHARE_VM_CODE_CODECACHE_HPP |
|
27 |
||
28 |
#include "code/codeBlob.hpp" |
|
26796 | 29 |
#include "code/nmethod.hpp" |
7397 | 30 |
#include "memory/allocation.hpp" |
31 |
#include "memory/heap.hpp" |
|
32 |
#include "oops/instanceKlass.hpp" |
|
33 |
#include "oops/oopsHierarchy.hpp" |
|
26796 | 34 |
#include "runtime/mutexLocker.hpp" |
7397 | 35 |
|
1 | 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 |
||
26796 | 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: |
|
26919
361b4b4c92c0
8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents:
26796
diff
changeset
|
44 |
// - Non-nmethods: Non-nmethods like Buffers, Adapters and Runtime Stubs |
26796 | 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 |
|
49 |
// - All: Used for code of all types if code cache segmentation is disabled. |
|
50 |
// |
|
26919
361b4b4c92c0
8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents:
26796
diff
changeset
|
51 |
// In the rare case of the non-nmethod code heap getting full, non-nmethod code |
26796 | 52 |
// will be stored in the non-profiled code heap as a fallback solution. |
53 |
// |
|
54 |
// Depending on the availability of compilers and TieredCompilation there |
|
55 |
// may be fewer heaps. The size of the code heaps depends on the values of |
|
56 |
// ReservedCodeCacheSize, NonProfiledCodeHeapSize and ProfiledCodeHeapSize |
|
57 |
// (see CodeCache::heap_available(..) and CodeCache::initialize_heaps(..) |
|
58 |
// for details). |
|
59 |
// |
|
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. |
|
1 | 73 |
|
74 |
class OopClosure; |
|
75 |
class DepChange; |
|
76 |
||
77 |
class CodeCache : AllStatic { |
|
78 |
friend class VMStructs; |
|
26796 | 79 |
friend class NMethodIterator; |
1 | 80 |
private: |
26796 | 81 |
// CodeHeaps of the cache |
82 |
static GrowableArray<CodeHeap*>* _heaps; |
|
83 |
||
84 |
static address _low_bound; // Lower bound of CodeHeap addresses |
|
85 |
static address _high_bound; // Upper bound of CodeHeap addresses |
|
86 |
static int _number_of_blobs; // Total number of CodeBlobs in the cache |
|
87 |
static int _number_of_adapters; // Total number of Adapters in the cache |
|
88 |
static int _number_of_nmethods; // Total number of nmethods in the cache |
|
89 |
static int _number_of_nmethods_with_dependencies; // Total number of nmethods with dependencies |
|
90 |
static bool _needs_cache_clean; // True if inline caches of the nmethods needs to be flushed |
|
91 |
static nmethod* _scavenge_root_nmethods; // linked via nm->scavenge_root_link() |
|
92 |
static int _codemem_full_count; // Number of times a CodeHeap in the cache was full |
|
1 | 93 |
|
3908
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
670
diff
changeset
|
94 |
static void mark_scavenge_root_nmethods() PRODUCT_RETURN; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
670
diff
changeset
|
95 |
static void verify_perm_nmethods(CodeBlobClosure* f_or_null) PRODUCT_RETURN; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
670
diff
changeset
|
96 |
|
26796 | 97 |
// CodeHeap management |
98 |
static void initialize_heaps(); // Initializes the CodeHeaps |
|
99 |
// Creates a new heap with the given name and size, containing CodeBlobs of the given type |
|
100 |
static void add_heap(ReservedSpace rs, const char* name, size_t size_initial, int code_blob_type); |
|
101 |
static CodeHeap* get_code_heap(CodeBlob* cb); // Returns the CodeHeap for the given CodeBlob |
|
102 |
static CodeHeap* get_code_heap(int code_blob_type); // Returns the CodeHeap for the given CodeBlobType |
|
27410
dd80df7cfa2b
8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents:
26942
diff
changeset
|
103 |
// Returns the name of the VM option to set the size of the corresponding CodeHeap |
dd80df7cfa2b
8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents:
26942
diff
changeset
|
104 |
static const char* get_code_heap_flag_name(int code_blob_type); |
26942
fa5ea7ff078d
8059390: code cache fills up for bigapps/Weblogic+medrec/nowarnings
zmajo
parents:
26919
diff
changeset
|
105 |
static bool heap_available(int code_blob_type); // Returns true if an own CodeHeap for the given CodeBlobType is available |
26796 | 106 |
static ReservedCodeSpace reserve_heap_memory(size_t size); // Reserves one continuous chunk of memory for the CodeHeaps |
107 |
||
108 |
// Iteration |
|
109 |
static CodeBlob* first_blob(CodeHeap* heap); // Returns the first CodeBlob on the given CodeHeap |
|
110 |
static CodeBlob* first_blob(int code_blob_type); // Returns the first CodeBlob of the given type |
|
111 |
static CodeBlob* next_blob(CodeHeap* heap, CodeBlob* cb); // Returns the first alive CodeBlob on the given CodeHeap |
|
112 |
static CodeBlob* next_blob(CodeBlob* cb); // Returns the next CodeBlob of the given type succeeding the given CodeBlob |
|
113 |
||
114 |
static size_t bytes_allocated_in_freelists(); |
|
115 |
static int allocated_segments(); |
|
116 |
static size_t freelists_length(); |
|
18025 | 117 |
|
1 | 118 |
public: |
119 |
// Initialization |
|
120 |
static void initialize(); |
|
121 |
||
122 |
// Allocation/administration |
|
27420
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
27410
diff
changeset
|
123 |
static CodeBlob* allocate(int size, int code_blob_type); // allocates a new CodeBlob |
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
27410
diff
changeset
|
124 |
static void commit(CodeBlob* cb); // called when the allocated CodeBlob has been filled |
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
27410
diff
changeset
|
125 |
static int alignment_unit(); // guaranteed alignment of all CodeBlobs |
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
27410
diff
changeset
|
126 |
static int alignment_offset(); // guaranteed offset of first CodeBlob byte within alignment unit (i.e., allocation header) |
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
27410
diff
changeset
|
127 |
static void free(CodeBlob* cb); // frees a CodeBlob |
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
27410
diff
changeset
|
128 |
static bool contains(void *p); // returns whether p is included |
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
27410
diff
changeset
|
129 |
static void blobs_do(void f(CodeBlob* cb)); // iterates over all CodeBlobs |
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
27410
diff
changeset
|
130 |
static void blobs_do(CodeBlobClosure* f); // iterates over all CodeBlobs |
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
27410
diff
changeset
|
131 |
static void nmethods_do(void f(nmethod* nm)); // iterates over all nmethods |
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
27410
diff
changeset
|
132 |
static void alive_nmethods_do(void f(nmethod* nm)); // iterates over all alive nmethods |
1 | 133 |
|
134 |
// Lookup |
|
26796 | 135 |
static CodeBlob* find_blob(void* start); // Returns the CodeBlob containing the given address |
136 |
static CodeBlob* find_blob_unsafe(void* start); // Same as find_blob but does not fail if looking up a zombie method |
|
137 |
static nmethod* find_nmethod(void* start); // Returns the nmethod containing the given address |
|
13195 | 138 |
|
26796 | 139 |
static int nof_blobs() { return _number_of_blobs; } // Returns the total number of CodeBlobs in the cache |
140 |
static int nof_adapters() { return _number_of_adapters; } // Returns the total number of Adapters in the cache |
|
141 |
static int nof_nmethods() { return _number_of_nmethods; } // Returns the total number of nmethods in the cache |
|
1 | 142 |
|
143 |
// GC support |
|
144 |
static void gc_epilogue(); |
|
145 |
static void gc_prologue(); |
|
8724
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8672
diff
changeset
|
146 |
static void verify_oops(); |
1 | 147 |
// If "unloading_occurred" is true, then unloads (i.e., breaks root links |
148 |
// to) any unmarked codeBlobs in the cache. Sets "marked_for_unloading" |
|
149 |
// to "true" iff some code got unloaded. |
|
13878
6e6a462a6cff
7200470: KeepAliveClosure not needed in CodeCache::do_unloading
brutisso
parents:
13728
diff
changeset
|
150 |
static void do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred); |
3908
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
670
diff
changeset
|
151 |
static void asserted_non_scavengable_nmethods_do(CodeBlobClosure* f = NULL) PRODUCT_RETURN; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
670
diff
changeset
|
152 |
static void scavenge_root_nmethods_do(CodeBlobClosure* f); |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
670
diff
changeset
|
153 |
|
26796 | 154 |
static nmethod* scavenge_root_nmethods() { return _scavenge_root_nmethods; } |
3908
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
670
diff
changeset
|
155 |
static void set_scavenge_root_nmethods(nmethod* nm) { _scavenge_root_nmethods = nm; } |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
670
diff
changeset
|
156 |
static void add_scavenge_root_nmethod(nmethod* nm); |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
670
diff
changeset
|
157 |
static void drop_scavenge_root_nmethod(nmethod* nm); |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
670
diff
changeset
|
158 |
static void prune_scavenge_root_nmethods(); |
1 | 159 |
|
160 |
// Printing/debugging |
|
15201
f3d755b11424
8005204: Code Cache Reduction: command line options implementation
vladidan
parents:
13878
diff
changeset
|
161 |
static void print(); // prints summary |
1 | 162 |
static void print_internals(); |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
20290
diff
changeset
|
163 |
static void print_memory_overhead(); |
1 | 164 |
static void verify(); // verifies the code cache |
3908
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
670
diff
changeset
|
165 |
static void print_trace(const char* event, CodeBlob* cb, int size = 0) PRODUCT_RETURN; |
15201
f3d755b11424
8005204: Code Cache Reduction: command line options implementation
vladidan
parents:
13878
diff
changeset
|
166 |
static void print_summary(outputStream* st, bool detailed = true); // Prints a summary of the code cache usage |
8672
26a427ab6f32
7025742: Can not use CodeCache::unallocated_capacity() with fragmented CodeCache
kvn
parents:
7715
diff
changeset
|
167 |
static void log_state(outputStream* st); |
26796 | 168 |
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"); } |
169 |
static void report_codemem_full(int code_blob_type, bool print); |
|
1 | 170 |
|
26587 | 171 |
// Dcmd (Diagnostic commands) |
172 |
static void print_codelist(outputStream* st); |
|
173 |
static void print_layout(outputStream* st); |
|
174 |
||
1 | 175 |
// The full limits of the codeCache |
26796 | 176 |
static address low_bound() { return _low_bound; } |
177 |
static address high_bound() { return _high_bound; } |
|
1 | 178 |
|
179 |
// Profiling |
|
26796 | 180 |
static size_t capacity(); |
26942
fa5ea7ff078d
8059390: code cache fills up for bigapps/Weblogic+medrec/nowarnings
zmajo
parents:
26919
diff
changeset
|
181 |
static size_t unallocated_capacity(int code_blob_type); |
26796 | 182 |
static size_t unallocated_capacity(); |
183 |
static size_t max_capacity(); |
|
184 |
||
185 |
static double reverse_free_ratio(int code_blob_type); |
|
186 |
||
187 |
static bool needs_cache_clean() { return _needs_cache_clean; } |
|
188 |
static void set_needs_cache_clean(bool v) { _needs_cache_clean = v; } |
|
189 |
static void clear_inline_caches(); // clear all inline caches |
|
1 | 190 |
|
26796 | 191 |
// Returns the CodeBlobType for nmethods of the given compilation level |
192 |
static int get_code_blob_type(int comp_level) { |
|
193 |
if (comp_level == CompLevel_none || |
|
194 |
comp_level == CompLevel_simple || |
|
195 |
comp_level == CompLevel_full_optimization) { |
|
196 |
// Non profiled methods |
|
197 |
return CodeBlobType::MethodNonProfiled; |
|
198 |
} else if (comp_level == CompLevel_limited_profile || |
|
199 |
comp_level == CompLevel_full_profile) { |
|
200 |
// Profiled methods |
|
201 |
return CodeBlobType::MethodProfiled; |
|
202 |
} |
|
203 |
ShouldNotReachHere(); |
|
204 |
return 0; |
|
205 |
} |
|
1 | 206 |
|
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
207 |
static void verify_clean_inline_caches(); |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
208 |
static void verify_icholder_relocations(); |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
209 |
|
1 | 210 |
// Deoptimization |
211 |
static int mark_for_deoptimization(DepChange& changes); |
|
212 |
#ifdef HOTSWAP |
|
213 |
static int mark_for_evol_deoptimization(instanceKlassHandle dependee); |
|
214 |
#endif // HOTSWAP |
|
215 |
||
216 |
static void mark_all_nmethods_for_deoptimization(); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
217 |
static int mark_for_deoptimization(Method* dependee); |
1 | 218 |
static void make_marked_nmethods_zombies(); |
219 |
static void make_marked_nmethods_not_entrant(); |
|
220 |
||
26796 | 221 |
// tells how many nmethods have dependencies |
1 | 222 |
static int number_of_nmethods_with_dependencies(); |
18025 | 223 |
|
224 |
static int get_codemem_full_count() { return _codemem_full_count; } |
|
1 | 225 |
}; |
7397 | 226 |
|
26796 | 227 |
|
228 |
// Iterator to iterate over nmethods in the CodeCache. |
|
229 |
class NMethodIterator : public StackObj { |
|
230 |
private: |
|
231 |
CodeBlob* _code_blob; // Current CodeBlob |
|
232 |
int _code_blob_type; // Refers to current CodeHeap |
|
233 |
||
234 |
public: |
|
235 |
NMethodIterator() { |
|
236 |
initialize(NULL); // Set to NULL, initialized by first call to next() |
|
237 |
} |
|
238 |
||
239 |
NMethodIterator(nmethod* nm) { |
|
240 |
initialize(nm); |
|
241 |
} |
|
242 |
||
243 |
// Advance iterator to next nmethod |
|
244 |
bool next() { |
|
245 |
assert_locked_or_safepoint(CodeCache_lock); |
|
246 |
assert(_code_blob_type < CodeBlobType::NumTypes, "end reached"); |
|
247 |
||
248 |
bool result = next_nmethod(); |
|
249 |
while (!result && (_code_blob_type < CodeBlobType::MethodProfiled)) { |
|
250 |
// Advance to next code heap if segmented code cache |
|
251 |
_code_blob_type++; |
|
252 |
result = next_nmethod(); |
|
253 |
} |
|
254 |
return result; |
|
255 |
} |
|
256 |
||
257 |
// Advance iterator to next alive nmethod |
|
258 |
bool next_alive() { |
|
259 |
bool result = next(); |
|
260 |
while(result && !_code_blob->is_alive()) { |
|
261 |
result = next(); |
|
262 |
} |
|
263 |
return result; |
|
264 |
} |
|
265 |
||
266 |
bool end() const { return _code_blob == NULL; } |
|
267 |
nmethod* method() const { return (nmethod*)_code_blob; } |
|
268 |
||
269 |
private: |
|
270 |
// Initialize iterator to given nmethod |
|
271 |
void initialize(nmethod* nm) { |
|
272 |
_code_blob = (CodeBlob*)nm; |
|
273 |
if (!SegmentedCodeCache) { |
|
274 |
// Iterate over all CodeBlobs |
|
275 |
_code_blob_type = CodeBlobType::All; |
|
276 |
} else if (nm != NULL) { |
|
277 |
_code_blob_type = CodeCache::get_code_blob_type(nm->comp_level()); |
|
278 |
} else { |
|
279 |
// Only iterate over method code heaps, starting with non-profiled |
|
280 |
_code_blob_type = CodeBlobType::MethodNonProfiled; |
|
281 |
} |
|
282 |
} |
|
283 |
||
284 |
// Advance iterator to the next nmethod in the current code heap |
|
285 |
bool next_nmethod() { |
|
286 |
// Get first method CodeBlob |
|
287 |
if (_code_blob == NULL) { |
|
288 |
_code_blob = CodeCache::first_blob(_code_blob_type); |
|
289 |
if (_code_blob == NULL) { |
|
290 |
return false; |
|
291 |
} else if (_code_blob->is_nmethod()) { |
|
292 |
return true; |
|
293 |
} |
|
294 |
} |
|
295 |
// Search for next method CodeBlob |
|
296 |
_code_blob = CodeCache::next_blob(_code_blob); |
|
297 |
while (_code_blob != NULL && !_code_blob->is_nmethod()) { |
|
298 |
_code_blob = CodeCache::next_blob(_code_blob); |
|
299 |
} |
|
300 |
return _code_blob != NULL; |
|
301 |
} |
|
302 |
}; |
|
303 |
||
7397 | 304 |
#endif // SHARE_VM_CODE_CODECACHE_HPP |