Mercurial > hg > graal-compiler
annotate src/share/vm/memory/sharedHeap.cpp @ 1578:ca3dceda776c
6930994: Code cache is full warning should be visible in product
Reviewed-by: kvn, twisti, ysr
author | never |
---|---|
date | Wed, 02 Jun 2010 20:15:33 -0700 |
parents | 148e5441d916 |
children | c18cbe5936b8 |
rev | line source |
---|---|
0 | 1 /* |
579 | 2 * Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved. |
0 | 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 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_sharedHeap.cpp.incl" | |
27 | |
28 SharedHeap* SharedHeap::_sh; | |
29 | |
30 // The set of potentially parallel tasks in strong root scanning. | |
31 enum SH_process_strong_roots_tasks { | |
32 SH_PS_Universe_oops_do, | |
33 SH_PS_JNIHandles_oops_do, | |
34 SH_PS_ObjectSynchronizer_oops_do, | |
35 SH_PS_FlatProfiler_oops_do, | |
36 SH_PS_Management_oops_do, | |
37 SH_PS_SystemDictionary_oops_do, | |
38 SH_PS_jvmti_oops_do, | |
39 SH_PS_vmSymbols_oops_do, | |
40 SH_PS_SymbolTable_oops_do, | |
41 SH_PS_StringTable_oops_do, | |
42 SH_PS_CodeCache_oops_do, | |
43 // Leave this one last. | |
44 SH_PS_NumElements | |
45 }; | |
46 | |
47 SharedHeap::SharedHeap(CollectorPolicy* policy_) : | |
48 CollectedHeap(), | |
49 _collector_policy(policy_), | |
50 _perm_gen(NULL), _rem_set(NULL), | |
51 _strong_roots_parity(0), | |
52 _process_strong_tasks(new SubTasksDone(SH_PS_NumElements)), | |
53 _workers(NULL), _n_par_threads(0) | |
54 { | |
55 if (_process_strong_tasks == NULL || !_process_strong_tasks->valid()) { | |
56 vm_exit_during_initialization("Failed necessary allocation."); | |
57 } | |
58 _sh = this; // ch is static, should be set only once. | |
59 if ((UseParNewGC || | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
60 (UseConcMarkSweepGC && CMSParallelRemarkEnabled) || |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
61 UseG1GC) && |
0 | 62 ParallelGCThreads > 0) { |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
63 _workers = new WorkGang("Parallel GC Threads", ParallelGCThreads, |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
64 /* are_GC_task_threads */true, |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
65 /* are_ConcurrentGC_threads */false); |
0 | 66 if (_workers == NULL) { |
67 vm_exit_during_initialization("Failed necessary allocation."); | |
68 } | |
69 } | |
70 } | |
71 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
72 bool SharedHeap::heap_lock_held_for_gc() { |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
73 Thread* t = Thread::current(); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
74 return Heap_lock->owned_by_self() |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
75 || ( (t->is_GC_task_thread() || t->is_VM_thread()) |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
76 && _thread_holds_heap_lock_for_gc); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
77 } |
0 | 78 |
79 void SharedHeap::set_par_threads(int t) { | |
80 _n_par_threads = t; | |
81 _process_strong_tasks->set_par_threads(t); | |
82 } | |
83 | |
84 class AssertIsPermClosure: public OopClosure { | |
85 public: | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
86 virtual void do_oop(oop* p) { |
0 | 87 assert((*p) == NULL || (*p)->is_perm(), "Referent should be perm."); |
88 } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
89 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
0 | 90 }; |
91 static AssertIsPermClosure assert_is_perm_closure; | |
92 | |
93 void SharedHeap::change_strong_roots_parity() { | |
94 // Also set the new collection parity. | |
95 assert(_strong_roots_parity >= 0 && _strong_roots_parity <= 2, | |
96 "Not in range."); | |
97 _strong_roots_parity++; | |
98 if (_strong_roots_parity == 3) _strong_roots_parity = 1; | |
99 assert(_strong_roots_parity >= 1 && _strong_roots_parity <= 2, | |
100 "Not in range."); | |
101 } | |
102 | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
103 SharedHeap::StrongRootsScope::StrongRootsScope(SharedHeap* outer, bool activate) |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
104 : MarkScope(activate) |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
105 { |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
106 if (_active) { |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
107 outer->change_strong_roots_parity(); |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
108 } |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
109 } |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
110 |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
111 SharedHeap::StrongRootsScope::~StrongRootsScope() { |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
112 // nothing particular |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
113 } |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
114 |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
115 void SharedHeap::process_strong_roots(bool activate_scope, |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
116 bool collecting_perm_gen, |
0 | 117 ScanningOption so, |
118 OopClosure* roots, | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
119 CodeBlobClosure* code_roots, |
0 | 120 OopsInGenClosure* perm_blk) { |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
121 StrongRootsScope srs(this, activate_scope); |
0 | 122 // General strong roots. |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
123 assert(_strong_roots_parity != 0, "must have called prologue code"); |
0 | 124 if (!_process_strong_tasks->is_task_claimed(SH_PS_Universe_oops_do)) { |
125 Universe::oops_do(roots); | |
126 ReferenceProcessor::oops_do(roots); | |
127 // Consider perm-gen discovered lists to be strong. | |
128 perm_gen()->ref_processor()->weak_oops_do(roots); | |
129 } | |
130 // Global (strong) JNI handles | |
131 if (!_process_strong_tasks->is_task_claimed(SH_PS_JNIHandles_oops_do)) | |
132 JNIHandles::oops_do(roots); | |
133 // All threads execute this; the individual threads are task groups. | |
134 if (ParallelGCThreads > 0) { | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
135 Threads::possibly_parallel_oops_do(roots, code_roots); |
0 | 136 } else { |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
137 Threads::oops_do(roots, code_roots); |
0 | 138 } |
139 if (!_process_strong_tasks-> is_task_claimed(SH_PS_ObjectSynchronizer_oops_do)) | |
140 ObjectSynchronizer::oops_do(roots); | |
141 if (!_process_strong_tasks->is_task_claimed(SH_PS_FlatProfiler_oops_do)) | |
142 FlatProfiler::oops_do(roots); | |
143 if (!_process_strong_tasks->is_task_claimed(SH_PS_Management_oops_do)) | |
144 Management::oops_do(roots); | |
145 if (!_process_strong_tasks->is_task_claimed(SH_PS_jvmti_oops_do)) | |
146 JvmtiExport::oops_do(roots); | |
147 | |
148 if (!_process_strong_tasks->is_task_claimed(SH_PS_SystemDictionary_oops_do)) { | |
149 if (so & SO_AllClasses) { | |
150 SystemDictionary::oops_do(roots); | |
151 } else | |
152 if (so & SO_SystemClasses) { | |
153 SystemDictionary::always_strong_oops_do(roots); | |
154 } | |
155 } | |
156 | |
157 if (!_process_strong_tasks->is_task_claimed(SH_PS_SymbolTable_oops_do)) { | |
158 if (so & SO_Symbols) { | |
159 SymbolTable::oops_do(roots); | |
160 } | |
161 // Verify if the symbol table contents are in the perm gen | |
162 NOT_PRODUCT(SymbolTable::oops_do(&assert_is_perm_closure)); | |
163 } | |
164 | |
165 if (!_process_strong_tasks->is_task_claimed(SH_PS_StringTable_oops_do)) { | |
166 if (so & SO_Strings) { | |
167 StringTable::oops_do(roots); | |
168 } | |
169 // Verify if the string table contents are in the perm gen | |
170 NOT_PRODUCT(StringTable::oops_do(&assert_is_perm_closure)); | |
171 } | |
172 | |
173 if (!_process_strong_tasks->is_task_claimed(SH_PS_CodeCache_oops_do)) { | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
174 if (so & SO_CodeCache) { |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
175 // (Currently, CMSCollector uses this to do intermediate-strength collections.) |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
176 assert(collecting_perm_gen, "scanning all of code cache"); |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
177 assert(code_roots != NULL, "must supply closure for code cache"); |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
178 if (code_roots != NULL) { |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
179 CodeCache::blobs_do(code_roots); |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
180 } |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
181 } else if (so & (SO_SystemClasses|SO_AllClasses)) { |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
182 if (!collecting_perm_gen) { |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
183 // If we are collecting from class statics, but we are not going to |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
184 // visit all of the CodeCache, collect from the non-perm roots if any. |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
185 // This makes the code cache function temporarily as a source of strong |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
186 // roots for oops, until the next major collection. |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
187 // |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
188 // If collecting_perm_gen is true, we require that this phase will call |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
189 // CodeCache::do_unloading. This will kill off nmethods with expired |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
190 // weak references, such as stale invokedynamic targets. |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
191 CodeCache::scavenge_root_nmethods_do(code_roots); |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
192 } |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
193 } |
0 | 194 // Verify if the code cache contents are in the perm gen |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
195 NOT_PRODUCT(CodeBlobToOopClosure assert_code_is_perm(&assert_is_perm_closure, /*do_marking=*/ false)); |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
196 NOT_PRODUCT(CodeCache::asserted_non_scavengable_nmethods_do(&assert_code_is_perm)); |
0 | 197 } |
198 | |
199 // Roots that should point only into permanent generation. | |
200 { | |
201 OopClosure* blk = NULL; | |
202 if (collecting_perm_gen) { | |
203 blk = roots; | |
204 } else { | |
205 debug_only(blk = &assert_is_perm_closure); | |
206 } | |
207 if (blk != NULL) { | |
208 if (!_process_strong_tasks->is_task_claimed(SH_PS_vmSymbols_oops_do)) | |
209 vmSymbols::oops_do(blk); | |
210 } | |
211 } | |
212 | |
213 if (!collecting_perm_gen) { | |
214 // All threads perform this; coordination is handled internally. | |
215 | |
216 rem_set()->younger_refs_iterate(perm_gen(), perm_blk); | |
217 } | |
218 _process_strong_tasks->all_tasks_completed(); | |
219 } | |
220 | |
221 class AlwaysTrueClosure: public BoolObjectClosure { | |
222 public: | |
223 void do_object(oop p) { ShouldNotReachHere(); } | |
224 bool do_object_b(oop p) { return true; } | |
225 }; | |
226 static AlwaysTrueClosure always_true; | |
227 | |
228 class SkipAdjustingSharedStrings: public OopClosure { | |
229 OopClosure* _clo; | |
230 public: | |
231 SkipAdjustingSharedStrings(OopClosure* clo) : _clo(clo) {} | |
232 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
233 virtual void do_oop(oop* p) { |
0 | 234 oop o = (*p); |
235 if (!o->is_shared_readwrite()) { | |
236 _clo->do_oop(p); | |
237 } | |
238 } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
239 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
0 | 240 }; |
241 | |
242 // Unmarked shared Strings in the StringTable (which got there due to | |
243 // being in the constant pools of as-yet unloaded shared classes) were | |
244 // not marked and therefore did not have their mark words preserved. | |
245 // These entries are also deliberately not purged from the string | |
246 // table during unloading of unmarked strings. If an identity hash | |
247 // code was computed for any of these objects, it will not have been | |
248 // cleared to zero during the forwarding process or by the | |
249 // RecursiveAdjustSharedObjectClosure, and will be confused by the | |
250 // adjusting process as a forwarding pointer. We need to skip | |
251 // forwarding StringTable entries which contain unmarked shared | |
252 // Strings. Actually, since shared strings won't be moving, we can | |
253 // just skip adjusting any shared entries in the string table. | |
254 | |
255 void SharedHeap::process_weak_roots(OopClosure* root_closure, | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
256 CodeBlobClosure* code_roots, |
0 | 257 OopClosure* non_root_closure) { |
258 // Global (weak) JNI handles | |
259 JNIHandles::weak_oops_do(&always_true, root_closure); | |
260 | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
261 CodeCache::blobs_do(code_roots); |
0 | 262 SymbolTable::oops_do(root_closure); |
263 if (UseSharedSpaces && !DumpSharedSpaces) { | |
264 SkipAdjustingSharedStrings skip_closure(root_closure); | |
265 StringTable::oops_do(&skip_closure); | |
266 } else { | |
267 StringTable::oops_do(root_closure); | |
268 } | |
269 } | |
270 | |
271 void SharedHeap::set_barrier_set(BarrierSet* bs) { | |
272 _barrier_set = bs; | |
273 // Cached barrier set for fast access in oops | |
274 oopDesc::set_bs(bs); | |
275 } | |
276 | |
277 void SharedHeap::post_initialize() { | |
278 ref_processing_init(); | |
279 } | |
280 | |
281 void SharedHeap::ref_processing_init() { | |
282 perm_gen()->ref_processor_init(); | |
283 } | |
284 | |
285 // Some utilities. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
286 void SharedHeap::print_size_transition(outputStream* out, |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
287 size_t bytes_before, |
0 | 288 size_t bytes_after, |
289 size_t capacity) { | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
290 out->print(" %d%s->%d%s(%d%s)", |
0 | 291 byte_size_in_proper_unit(bytes_before), |
292 proper_unit_for_byte_size(bytes_before), | |
293 byte_size_in_proper_unit(bytes_after), | |
294 proper_unit_for_byte_size(bytes_after), | |
295 byte_size_in_proper_unit(capacity), | |
296 proper_unit_for_byte_size(capacity)); | |
297 } |