Mercurial > hg > graal-jvmci-8
annotate src/share/vm/memory/sharedHeap.hpp @ 1051:26f1542097f1
6801625: CDS: HeapDump tests crash with internal error in compactingPermGenGen.cpp
Summary: Allow iteration over the shared spaces when using CDS, repealing previous proscription. Deferred further required CDS-related cleanups of perm gen to CR 6897789.
Reviewed-by: phh, jmasa
author | ysr |
---|---|
date | Tue, 03 Nov 2009 16:43:16 -0800 |
parents | 148e5441d916 |
children | 3fc996d4edd2 |
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 // A "SharedHeap" is an implementation of a java heap for HotSpot. This | |
26 // is an abstract class: there may be many different kinds of heaps. This | |
27 // class defines the functions that a heap must implement, and contains | |
28 // infrastructure common to all heaps. | |
29 | |
30 class PermGen; | |
31 class Generation; | |
32 class BarrierSet; | |
33 class GenRemSet; | |
34 class Space; | |
35 class SpaceClosure; | |
36 class OopClosure; | |
37 class OopsInGenClosure; | |
38 class ObjectClosure; | |
39 class SubTasksDone; | |
40 class WorkGang; | |
41 class CollectorPolicy; | |
42 class KlassHandle; | |
43 | |
44 class SharedHeap : public CollectedHeap { | |
45 friend class VMStructs; | |
46 | |
342 | 47 friend class VM_GC_Operation; |
48 friend class VM_CGC_Operation; | |
49 | |
0 | 50 private: |
51 // For claiming strong_roots tasks. | |
52 SubTasksDone* _process_strong_tasks; | |
53 | |
54 protected: | |
55 // There should be only a single instance of "SharedHeap" in a program. | |
56 // This is enforced with the protected constructor below, which will also | |
57 // set the static pointer "_sh" to that instance. | |
58 static SharedHeap* _sh; | |
59 | |
60 // All heaps contain a "permanent generation." This is some ways | |
61 // similar to a generation in a generational system, in other ways not. | |
62 // See the "PermGen" class. | |
63 PermGen* _perm_gen; | |
64 | |
65 // and the Gen Remembered Set, at least one good enough to scan the perm | |
66 // gen. | |
67 GenRemSet* _rem_set; | |
68 | |
69 // A gc policy, controls global gc resource issues | |
70 CollectorPolicy *_collector_policy; | |
71 | |
72 // See the discussion below, in the specification of the reader function | |
73 // for this variable. | |
74 int _strong_roots_parity; | |
75 | |
76 // If we're doing parallel GC, use this gang of threads. | |
77 WorkGang* _workers; | |
78 | |
79 // Number of parallel threads currently working on GC tasks. | |
80 // O indicates use sequential code; 1 means use parallel code even with | |
81 // only one thread, for performance testing purposes. | |
82 int _n_par_threads; | |
83 | |
84 // Full initialization is done in a concrete subtype's "initialize" | |
85 // function. | |
86 SharedHeap(CollectorPolicy* policy_); | |
87 | |
342 | 88 // Returns true if the calling thread holds the heap lock, |
89 // or the calling thread is a par gc thread and the heap_lock is held | |
90 // by the vm thread doing a gc operation. | |
91 bool heap_lock_held_for_gc(); | |
92 // True if the heap_lock is held by the a non-gc thread invoking a gc | |
93 // operation. | |
94 bool _thread_holds_heap_lock_for_gc; | |
95 | |
0 | 96 public: |
97 static SharedHeap* heap() { return _sh; } | |
98 | |
99 CollectorPolicy *collector_policy() const { return _collector_policy; } | |
100 | |
101 void set_barrier_set(BarrierSet* bs); | |
102 | |
103 // Does operations required after initialization has been done. | |
104 virtual void post_initialize(); | |
105 | |
106 // Initialization of ("weak") reference processing support | |
107 virtual void ref_processing_init(); | |
108 | |
109 void set_perm(PermGen* perm_gen) { _perm_gen = perm_gen; } | |
110 | |
111 // This function returns the "GenRemSet" object that allows us to scan | |
112 // generations; at least the perm gen, possibly more in a fully | |
113 // generational heap. | |
114 GenRemSet* rem_set() { return _rem_set; } | |
115 | |
116 // These function return the "permanent" generation, in which | |
117 // reflective objects are allocated and stored. Two versions, the second | |
118 // of which returns the view of the perm gen as a generation. | |
119 PermGen* perm() const { return _perm_gen; } | |
120 Generation* perm_gen() const { return _perm_gen->as_gen(); } | |
121 | |
122 // Iteration functions. | |
123 void oop_iterate(OopClosure* cl) = 0; | |
124 | |
125 // Same as above, restricted to a memory region. | |
126 virtual void oop_iterate(MemRegion mr, OopClosure* cl) = 0; | |
127 | |
128 // Iterate over all objects allocated since the last collection, calling | |
129 // "cl->do_object" on each. The heap must have been initialized properly | |
130 // to support this function, or else this call will fail. | |
131 virtual void object_iterate_since_last_GC(ObjectClosure* cl) = 0; | |
132 | |
133 // Iterate over all spaces in use in the heap, in an undefined order. | |
134 virtual void space_iterate(SpaceClosure* cl) = 0; | |
135 | |
136 // A SharedHeap will contain some number of spaces. This finds the | |
137 // space whose reserved area contains the given address, or else returns | |
138 // NULL. | |
139 virtual Space* space_containing(const void* addr) const = 0; | |
140 | |
141 bool no_gc_in_progress() { return !is_gc_active(); } | |
142 | |
143 // Some collectors will perform "process_strong_roots" in parallel. | |
144 // Such a call will involve claiming some fine-grained tasks, such as | |
145 // scanning of threads. To make this process simpler, we provide the | |
146 // "strong_roots_parity()" method. Collectors that start parallel tasks | |
147 // whose threads invoke "process_strong_roots" must | |
148 // call "change_strong_roots_parity" in sequential code starting such a | |
149 // task. (This also means that a parallel thread may only call | |
150 // process_strong_roots once.) | |
151 // | |
152 // For calls to process_strong_roots by sequential code, the parity is | |
153 // updated automatically. | |
154 // | |
155 // The idea is that objects representing fine-grained tasks, such as | |
156 // threads, will contain a "parity" field. A task will is claimed in the | |
157 // current "process_strong_roots" call only if its parity field is the | |
158 // same as the "strong_roots_parity"; task claiming is accomplished by | |
159 // updating the parity field to the strong_roots_parity with a CAS. | |
160 // | |
161 // If the client meats this spec, then strong_roots_parity() will have | |
162 // the following properties: | |
163 // a) to return a different value than was returned before the last | |
164 // call to change_strong_roots_parity, and | |
165 // c) to never return a distinguished value (zero) with which such | |
166 // task-claiming variables may be initialized, to indicate "never | |
167 // claimed". | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
168 private: |
0 | 169 void change_strong_roots_parity(); |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
170 public: |
0 | 171 int strong_roots_parity() { return _strong_roots_parity; } |
172 | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
173 // Call these in sequential code around process_strong_roots. |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
174 // strong_roots_prologue calls change_strong_roots_parity, if |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
175 // parallel tasks are enabled. |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
176 class StrongRootsScope : public MarkingCodeBlobClosure::MarkScope { |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
177 public: |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
178 StrongRootsScope(SharedHeap* outer, bool activate = true); |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
179 ~StrongRootsScope(); |
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 friend class StrongRootsScope; |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
182 |
0 | 183 enum ScanningOption { |
184 SO_None = 0x0, | |
185 SO_AllClasses = 0x1, | |
186 SO_SystemClasses = 0x2, | |
187 SO_Symbols = 0x4, | |
188 SO_Strings = 0x8, | |
189 SO_CodeCache = 0x10 | |
190 }; | |
191 | |
192 WorkGang* workers() const { return _workers; } | |
193 | |
194 // Sets the number of parallel threads that will be doing tasks | |
195 // (such as process strong roots) subsequently. | |
196 virtual void set_par_threads(int t); | |
197 | |
198 // Number of threads currently working on GC tasks. | |
199 int n_par_threads() { return _n_par_threads; } | |
200 | |
201 // Invoke the "do_oop" method the closure "roots" on all root locations. | |
202 // If "collecting_perm_gen" is false, then roots that may only contain | |
203 // references to permGen objects are not scanned. If true, the | |
204 // "perm_gen" closure is applied to all older-to-younger refs in the | |
205 // permanent generation. The "so" argument determines which of roots | |
206 // the closure is applied to: | |
207 // "SO_None" does none; | |
208 // "SO_AllClasses" applies the closure to all entries in the SystemDictionary; | |
209 // "SO_SystemClasses" to all the "system" classes and loaders; | |
210 // "SO_Symbols" applies the closure to all entries in SymbolsTable; | |
211 // "SO_Strings" applies the closure to all entries in StringTable; | |
212 // "SO_CodeCache" applies the closure to all elements of the CodeCache. | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
213 void process_strong_roots(bool activate_scope, |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
214 bool collecting_perm_gen, |
0 | 215 ScanningOption so, |
216 OopClosure* roots, | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
217 CodeBlobClosure* code_roots, |
0 | 218 OopsInGenClosure* perm_blk); |
219 | |
220 // Apply "blk" to all the weak roots of the system. These include | |
221 // JNI weak roots, the code cache, system dictionary, symbol table, | |
222 // string table. | |
223 void process_weak_roots(OopClosure* root_closure, | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
224 CodeBlobClosure* code_roots, |
0 | 225 OopClosure* non_root_closure); |
226 | |
227 | |
228 // Like CollectedHeap::collect, but assume that the caller holds the Heap_lock. | |
229 virtual void collect_locked(GCCause::Cause cause) = 0; | |
230 | |
231 // The functions below are helper functions that a subclass of | |
232 // "SharedHeap" can use in the implementation of its virtual | |
233 // functions. | |
234 | |
342 | 235 public: |
0 | 236 |
237 // Do anything common to GC's. | |
238 virtual void gc_prologue(bool full) = 0; | |
239 virtual void gc_epilogue(bool full) = 0; | |
240 | |
241 // | |
242 // New methods from CollectedHeap | |
243 // | |
244 | |
245 size_t permanent_capacity() const { | |
246 assert(perm_gen(), "NULL perm gen"); | |
247 return perm_gen()->capacity(); | |
248 } | |
249 | |
250 size_t permanent_used() const { | |
251 assert(perm_gen(), "NULL perm gen"); | |
252 return perm_gen()->used(); | |
253 } | |
254 | |
255 bool is_in_permanent(const void *p) const { | |
256 assert(perm_gen(), "NULL perm gen"); | |
257 return perm_gen()->is_in_reserved(p); | |
258 } | |
259 | |
260 // Different from is_in_permanent in that is_in_permanent | |
261 // only checks if p is in the reserved area of the heap | |
262 // and this checks to see if it in the commited area. | |
263 // This is typically used by things like the forte stackwalker | |
264 // during verification of suspicious frame values. | |
265 bool is_permanent(const void *p) const { | |
266 assert(perm_gen(), "NULL perm gen"); | |
267 return perm_gen()->is_in(p); | |
268 } | |
269 | |
270 HeapWord* permanent_mem_allocate(size_t size) { | |
271 assert(perm_gen(), "NULL perm gen"); | |
272 return _perm_gen->mem_allocate(size); | |
273 } | |
274 | |
275 void permanent_oop_iterate(OopClosure* cl) { | |
276 assert(perm_gen(), "NULL perm gen"); | |
277 _perm_gen->oop_iterate(cl); | |
278 } | |
279 | |
280 void permanent_object_iterate(ObjectClosure* cl) { | |
281 assert(perm_gen(), "NULL perm gen"); | |
282 _perm_gen->object_iterate(cl); | |
283 } | |
284 | |
285 // Some utilities. | |
342 | 286 void print_size_transition(outputStream* out, |
287 size_t bytes_before, | |
0 | 288 size_t bytes_after, |
289 size_t capacity); | |
290 }; |