1 /* |
1 /* |
2 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
25 #ifndef SHARE_VM_MEMORY_SHAREDHEAP_HPP |
25 #ifndef SHARE_VM_MEMORY_SHAREDHEAP_HPP |
26 #define SHARE_VM_MEMORY_SHAREDHEAP_HPP |
26 #define SHARE_VM_MEMORY_SHAREDHEAP_HPP |
27 |
27 |
28 #include "gc_interface/collectedHeap.hpp" |
28 #include "gc_interface/collectedHeap.hpp" |
29 #include "memory/generation.hpp" |
29 #include "memory/generation.hpp" |
30 #include "memory/permGen.hpp" |
|
31 |
30 |
32 // A "SharedHeap" is an implementation of a java heap for HotSpot. This |
31 // A "SharedHeap" is an implementation of a java heap for HotSpot. This |
33 // is an abstract class: there may be many different kinds of heaps. This |
32 // is an abstract class: there may be many different kinds of heaps. This |
34 // class defines the functions that a heap must implement, and contains |
33 // class defines the functions that a heap must implement, and contains |
35 // infrastructure common to all heaps. |
34 // infrastructure common to all heaps. |
36 |
35 |
37 class PermGen; |
|
38 class Generation; |
36 class Generation; |
39 class BarrierSet; |
37 class BarrierSet; |
40 class GenRemSet; |
38 class GenRemSet; |
41 class Space; |
39 class Space; |
42 class SpaceClosure; |
40 class SpaceClosure; |
71 // number of active GC workers. CompactibleFreeListSpace and Space |
69 // number of active GC workers. CompactibleFreeListSpace and Space |
72 // have SequentialSubTasksDone's. |
70 // have SequentialSubTasksDone's. |
73 // Example of using SubTasksDone and SequentialSubTasksDone |
71 // Example of using SubTasksDone and SequentialSubTasksDone |
74 // G1CollectedHeap::g1_process_strong_roots() calls |
72 // G1CollectedHeap::g1_process_strong_roots() calls |
75 // process_strong_roots(false, // no scoping; this is parallel code |
73 // process_strong_roots(false, // no scoping; this is parallel code |
76 // collecting_perm_gen, so, |
74 // is_scavenging, so, |
77 // &buf_scan_non_heap_roots, |
75 // &buf_scan_non_heap_roots, |
78 // &eager_scan_code_roots, |
76 // &eager_scan_code_roots); |
79 // &buf_scan_perm); |
|
80 // which delegates to SharedHeap::process_strong_roots() and uses |
77 // which delegates to SharedHeap::process_strong_roots() and uses |
81 // SubTasksDone* _process_strong_tasks to claim tasks. |
78 // SubTasksDone* _process_strong_tasks to claim tasks. |
82 // process_strong_roots() calls |
79 // process_strong_roots() calls |
83 // rem_set()->younger_refs_iterate(perm_gen(), perm_blk); |
80 // rem_set()->younger_refs_iterate() |
84 // to scan the card table and which eventually calls down into |
81 // to scan the card table and which eventually calls down into |
85 // CardTableModRefBS::par_non_clean_card_iterate_work(). This method |
82 // CardTableModRefBS::par_non_clean_card_iterate_work(). This method |
86 // uses SequentialSubTasksDone* _pst to claim tasks. |
83 // uses SequentialSubTasksDone* _pst to claim tasks. |
87 // Both SubTasksDone and SequentialSubTasksDone call their method |
84 // Both SubTasksDone and SequentialSubTasksDone call their method |
88 // all_tasks_completed() to count the number of GC workers that have |
85 // all_tasks_completed() to count the number of GC workers that have |
119 // There should be only a single instance of "SharedHeap" in a program. |
116 // There should be only a single instance of "SharedHeap" in a program. |
120 // This is enforced with the protected constructor below, which will also |
117 // This is enforced with the protected constructor below, which will also |
121 // set the static pointer "_sh" to that instance. |
118 // set the static pointer "_sh" to that instance. |
122 static SharedHeap* _sh; |
119 static SharedHeap* _sh; |
123 |
120 |
124 // All heaps contain a "permanent generation." This is some ways |
|
125 // similar to a generation in a generational system, in other ways not. |
|
126 // See the "PermGen" class. |
|
127 PermGen* _perm_gen; |
|
128 |
|
129 // and the Gen Remembered Set, at least one good enough to scan the perm |
121 // and the Gen Remembered Set, at least one good enough to scan the perm |
130 // gen. |
122 // gen. |
131 GenRemSet* _rem_set; |
123 GenRemSet* _rem_set; |
132 |
124 |
133 // A gc policy, controls global gc resource issues |
125 // A gc policy, controls global gc resource issues |
153 bool _thread_holds_heap_lock_for_gc; |
145 bool _thread_holds_heap_lock_for_gc; |
154 |
146 |
155 public: |
147 public: |
156 static SharedHeap* heap() { return _sh; } |
148 static SharedHeap* heap() { return _sh; } |
157 |
149 |
158 CollectorPolicy *collector_policy() const { return _collector_policy; } |
|
159 |
|
160 void set_barrier_set(BarrierSet* bs); |
150 void set_barrier_set(BarrierSet* bs); |
161 SubTasksDone* process_strong_tasks() { return _process_strong_tasks; } |
151 SubTasksDone* process_strong_tasks() { return _process_strong_tasks; } |
162 |
152 |
163 // Does operations required after initialization has been done. |
153 // Does operations required after initialization has been done. |
164 virtual void post_initialize(); |
154 virtual void post_initialize(); |
165 |
155 |
166 // Initialization of ("weak") reference processing support |
156 // Initialization of ("weak") reference processing support |
167 virtual void ref_processing_init(); |
157 virtual void ref_processing_init(); |
168 |
158 |
169 void set_perm(PermGen* perm_gen) { _perm_gen = perm_gen; } |
|
170 |
|
171 // This function returns the "GenRemSet" object that allows us to scan |
159 // This function returns the "GenRemSet" object that allows us to scan |
172 // generations; at least the perm gen, possibly more in a fully |
160 // generations in a fully generational heap. |
173 // generational heap. |
|
174 GenRemSet* rem_set() { return _rem_set; } |
161 GenRemSet* rem_set() { return _rem_set; } |
175 |
162 |
176 // These function return the "permanent" generation, in which |
|
177 // reflective objects are allocated and stored. Two versions, the second |
|
178 // of which returns the view of the perm gen as a generation. |
|
179 PermGen* perm() const { return _perm_gen; } |
|
180 Generation* perm_gen() const { return _perm_gen->as_gen(); } |
|
181 |
|
182 // Iteration functions. |
163 // Iteration functions. |
183 void oop_iterate(OopClosure* cl) = 0; |
164 void oop_iterate(ExtendedOopClosure* cl) = 0; |
184 |
165 |
185 // Same as above, restricted to a memory region. |
166 // Same as above, restricted to a memory region. |
186 virtual void oop_iterate(MemRegion mr, OopClosure* cl) = 0; |
167 virtual void oop_iterate(MemRegion mr, ExtendedOopClosure* cl) = 0; |
187 |
168 |
188 // Iterate over all objects allocated since the last collection, calling |
169 // Iterate over all objects allocated since the last collection, calling |
189 // "cl->do_object" on each. The heap must have been initialized properly |
170 // "cl->do_object" on each. The heap must have been initialized properly |
190 // to support this function, or else this call will fail. |
171 // to support this function, or else this call will fail. |
191 virtual void object_iterate_since_last_GC(ObjectClosure* cl) = 0; |
172 virtual void object_iterate_since_last_GC(ObjectClosure* cl) = 0; |
249 }; |
230 }; |
250 |
231 |
251 FlexibleWorkGang* workers() const { return _workers; } |
232 FlexibleWorkGang* workers() const { return _workers; } |
252 |
233 |
253 // Invoke the "do_oop" method the closure "roots" on all root locations. |
234 // Invoke the "do_oop" method the closure "roots" on all root locations. |
254 // If "collecting_perm_gen" is false, then roots that may only contain |
235 // The "so" argument determines which roots the closure is applied to: |
255 // references to permGen objects are not scanned; instead, in that case, |
|
256 // the "perm_blk" closure is applied to all outgoing refs in the |
|
257 // permanent generation. The "so" argument determines which of roots |
|
258 // the closure is applied to: |
|
259 // "SO_None" does none; |
236 // "SO_None" does none; |
260 // "SO_AllClasses" applies the closure to all entries in the SystemDictionary; |
237 // "SO_AllClasses" applies the closure to all entries in the SystemDictionary; |
261 // "SO_SystemClasses" to all the "system" classes and loaders; |
238 // "SO_SystemClasses" to all the "system" classes and loaders; |
262 // "SO_Strings" applies the closure to all entries in StringTable; |
239 // "SO_Strings" applies the closure to all entries in StringTable; |
263 // "SO_CodeCache" applies the closure to all elements of the CodeCache. |
240 // "SO_CodeCache" applies the closure to all elements of the CodeCache. |
264 void process_strong_roots(bool activate_scope, |
241 void process_strong_roots(bool activate_scope, |
265 bool collecting_perm_gen, |
242 bool is_scavenging, |
266 ScanningOption so, |
243 ScanningOption so, |
267 OopClosure* roots, |
244 OopClosure* roots, |
268 CodeBlobClosure* code_roots, |
245 CodeBlobClosure* code_roots, |
269 OopsInGenClosure* perm_blk); |
246 KlassClosure* klass_closure); |
270 |
247 |
271 // Apply "blk" to all the weak roots of the system. These include |
248 // Apply "blk" to all the weak roots of the system. These include |
272 // JNI weak roots, the code cache, system dictionary, symbol table, |
249 // JNI weak roots, the code cache, system dictionary, symbol table, |
273 // string table. |
250 // string table. |
274 void process_weak_roots(OopClosure* root_closure, |
251 void process_weak_roots(OopClosure* root_closure, |
294 |
271 |
295 // |
272 // |
296 // New methods from CollectedHeap |
273 // New methods from CollectedHeap |
297 // |
274 // |
298 |
275 |
299 size_t permanent_capacity() const { |
|
300 assert(perm_gen(), "NULL perm gen"); |
|
301 return perm_gen()->capacity(); |
|
302 } |
|
303 |
|
304 size_t permanent_used() const { |
|
305 assert(perm_gen(), "NULL perm gen"); |
|
306 return perm_gen()->used(); |
|
307 } |
|
308 |
|
309 bool is_in_permanent(const void *p) const { |
|
310 assert(perm_gen(), "NULL perm gen"); |
|
311 return perm_gen()->is_in_reserved(p); |
|
312 } |
|
313 |
|
314 // Different from is_in_permanent in that is_in_permanent |
|
315 // only checks if p is in the reserved area of the heap |
|
316 // and this checks to see if it in the commited area. |
|
317 // This is typically used by things like the forte stackwalker |
|
318 // during verification of suspicious frame values. |
|
319 bool is_permanent(const void *p) const { |
|
320 assert(perm_gen(), "NULL perm gen"); |
|
321 return perm_gen()->is_in(p); |
|
322 } |
|
323 |
|
324 HeapWord* permanent_mem_allocate(size_t size) { |
|
325 assert(perm_gen(), "NULL perm gen"); |
|
326 return _perm_gen->mem_allocate(size); |
|
327 } |
|
328 |
|
329 void permanent_oop_iterate(OopClosure* cl) { |
|
330 assert(perm_gen(), "NULL perm gen"); |
|
331 _perm_gen->oop_iterate(cl); |
|
332 } |
|
333 |
|
334 void permanent_object_iterate(ObjectClosure* cl) { |
|
335 assert(perm_gen(), "NULL perm gen"); |
|
336 _perm_gen->object_iterate(cl); |
|
337 } |
|
338 |
|
339 // Some utilities. |
276 // Some utilities. |
340 void print_size_transition(outputStream* out, |
277 void print_size_transition(outputStream* out, |
341 size_t bytes_before, |
278 size_t bytes_before, |
342 size_t bytes_after, |
279 size_t bytes_after, |
343 size_t capacity); |
280 size_t capacity); |