Mercurial > hg > truffle
annotate src/share/vm/gc_interface/collectedHeap.hpp @ 1959:9eecf81a02fb
7000578: CMS: assert(SafepointSynchronize::is_at_safepoint()) failed: Else races are possible
Summary: Weakened assert in onj_is_alive() to allow its use at initialization time when is_at_safepoint() normally reports false; added some related asserts to check order of is_init_completed() after Universe::is_fully_initialized().
Reviewed-by: jcoomes
author | ysr |
---|---|
date | Tue, 16 Nov 2010 13:58:48 -0800 |
parents | 8b10f48633dc |
children | f95d63e2154a |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1387
diff
changeset
|
2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1387
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1387
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1387
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 // A "CollectedHeap" 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 BarrierSet; | |
31 class ThreadClosure; | |
32 class AdaptiveSizePolicy; | |
33 class Thread; | |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1166
diff
changeset
|
34 class CollectorPolicy; |
0 | 35 |
36 // | |
37 // CollectedHeap | |
38 // SharedHeap | |
39 // GenCollectedHeap | |
40 // G1CollectedHeap | |
41 // ParallelScavengeHeap | |
42 // | |
43 class CollectedHeap : public CHeapObj { | |
44 friend class VMStructs; | |
45 friend class IsGCActiveMark; // Block structured external access to _is_gc_active | |
542
9a25e0c45327
6792421: assert(_bitMap->isMarked(addr+size-1),inconsistent Printezis mark)
jmasa
parents:
517
diff
changeset
|
46 friend class constantPoolCacheKlass; // allocate() method inserts is_conc_safe |
0 | 47 |
48 #ifdef ASSERT | |
49 static int _fire_out_of_memory_count; | |
50 #endif | |
51 | |
481
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
52 // Used for filler objects (static, but initialized in ctor). |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
53 static size_t _filler_array_max_size; |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
54 |
1166 | 55 // Used in support of ReduceInitialCardMarks; only consulted if COMPILER2 is being used |
56 bool _defer_initial_card_mark; | |
57 | |
0 | 58 protected: |
59 MemRegion _reserved; | |
60 BarrierSet* _barrier_set; | |
61 bool _is_gc_active; | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
62 int _n_par_threads; |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
63 |
0 | 64 unsigned int _total_collections; // ... started |
65 unsigned int _total_full_collections; // ... started | |
66 NOT_PRODUCT(volatile size_t _promotion_failure_alot_count;) | |
67 NOT_PRODUCT(volatile size_t _promotion_failure_alot_gc_number;) | |
68 | |
69 // Reason for current garbage collection. Should be set to | |
70 // a value reflecting no collection between collections. | |
71 GCCause::Cause _gc_cause; | |
72 GCCause::Cause _gc_lastcause; | |
73 PerfStringVariable* _perf_gc_cause; | |
74 PerfStringVariable* _perf_gc_lastcause; | |
75 | |
76 // Constructor | |
77 CollectedHeap(); | |
78 | |
1166 | 79 // Do common initializations that must follow instance construction, |
80 // for example, those needing virtual calls. | |
81 // This code could perhaps be moved into initialize() but would | |
82 // be slightly more awkward because we want the latter to be a | |
83 // pure virtual. | |
84 void pre_initialize(); | |
85 | |
0 | 86 // Create a new tlab |
87 virtual HeapWord* allocate_new_tlab(size_t size); | |
88 | |
89 // Accumulate statistics on all tlabs. | |
90 virtual void accumulate_statistics_all_tlabs(); | |
91 | |
92 // Reinitialize tlabs before resuming mutators. | |
93 virtual void resize_all_tlabs(); | |
94 | |
95 protected: | |
96 // Allocate from the current thread's TLAB, with broken-out slow path. | |
97 inline static HeapWord* allocate_from_tlab(Thread* thread, size_t size); | |
98 static HeapWord* allocate_from_tlab_slow(Thread* thread, size_t size); | |
99 | |
100 // Allocate an uninitialized block of the given size, or returns NULL if | |
101 // this is impossible. | |
102 inline static HeapWord* common_mem_allocate_noinit(size_t size, bool is_noref, TRAPS); | |
103 | |
104 // Like allocate_init, but the block returned by a successful allocation | |
105 // is guaranteed initialized to zeros. | |
106 inline static HeapWord* common_mem_allocate_init(size_t size, bool is_noref, TRAPS); | |
107 | |
108 // Same as common_mem version, except memory is allocated in the permanent area | |
109 // If there is no permanent area, revert to common_mem_allocate_noinit | |
110 inline static HeapWord* common_permanent_mem_allocate_noinit(size_t size, TRAPS); | |
111 | |
112 // Same as common_mem version, except memory is allocated in the permanent area | |
113 // If there is no permanent area, revert to common_mem_allocate_init | |
114 inline static HeapWord* common_permanent_mem_allocate_init(size_t size, TRAPS); | |
115 | |
116 // Helper functions for (VM) allocation. | |
117 inline static void post_allocation_setup_common(KlassHandle klass, | |
118 HeapWord* obj, size_t size); | |
119 inline static void post_allocation_setup_no_klass_install(KlassHandle klass, | |
120 HeapWord* objPtr, | |
121 size_t size); | |
122 | |
123 inline static void post_allocation_setup_obj(KlassHandle klass, | |
124 HeapWord* obj, size_t size); | |
125 | |
126 inline static void post_allocation_setup_array(KlassHandle klass, | |
127 HeapWord* obj, size_t size, | |
128 int length); | |
129 | |
130 // Clears an allocated object. | |
131 inline static void init_obj(HeapWord* obj, size_t size); | |
132 | |
481
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
133 // Filler object utilities. |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
134 static inline size_t filler_array_hdr_size(); |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
135 static inline size_t filler_array_min_size(); |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
136 static inline size_t filler_array_max_size(); |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
137 |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
138 DEBUG_ONLY(static void fill_args_check(HeapWord* start, size_t words);) |
1165
2dd52dea6d28
6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents:
1027
diff
changeset
|
139 DEBUG_ONLY(static void zap_filler_array(HeapWord* start, size_t words, bool zap = true);) |
481
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
140 |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
141 // Fill with a single array; caller must ensure filler_array_min_size() <= |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
142 // words <= filler_array_max_size(). |
1165
2dd52dea6d28
6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents:
1027
diff
changeset
|
143 static inline void fill_with_array(HeapWord* start, size_t words, bool zap = true); |
481
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
144 |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
145 // Fill with a single object (either an int array or a java.lang.Object). |
1165
2dd52dea6d28
6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents:
1027
diff
changeset
|
146 static inline void fill_with_object_impl(HeapWord* start, size_t words, bool zap = true); |
481
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
147 |
0 | 148 // Verification functions |
149 virtual void check_for_bad_heap_word_value(HeapWord* addr, size_t size) | |
150 PRODUCT_RETURN; | |
151 virtual void check_for_non_bad_heap_word_value(HeapWord* addr, size_t size) | |
152 PRODUCT_RETURN; | |
542
9a25e0c45327
6792421: assert(_bitMap->isMarked(addr+size-1),inconsistent Printezis mark)
jmasa
parents:
517
diff
changeset
|
153 debug_only(static void check_for_valid_allocation_state();) |
0 | 154 |
155 public: | |
156 enum Name { | |
157 Abstract, | |
158 SharedHeap, | |
159 GenCollectedHeap, | |
160 ParallelScavengeHeap, | |
161 G1CollectedHeap | |
162 }; | |
163 | |
164 virtual CollectedHeap::Name kind() const { return CollectedHeap::Abstract; } | |
165 | |
166 /** | |
167 * Returns JNI error code JNI_ENOMEM if memory could not be allocated, | |
168 * and JNI_OK on success. | |
169 */ | |
170 virtual jint initialize() = 0; | |
171 | |
172 // In many heaps, there will be a need to perform some initialization activities | |
173 // after the Universe is fully formed, but before general heap allocation is allowed. | |
174 // This is the correct place to place such initialization methods. | |
175 virtual void post_initialize() = 0; | |
176 | |
177 MemRegion reserved_region() const { return _reserved; } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
178 address base() const { return (address)reserved_region().start(); } |
0 | 179 |
180 // Future cleanup here. The following functions should specify bytes or | |
181 // heapwords as part of their signature. | |
182 virtual size_t capacity() const = 0; | |
183 virtual size_t used() const = 0; | |
184 | |
185 // Return "true" if the part of the heap that allocates Java | |
186 // objects has reached the maximal committed limit that it can | |
187 // reach, without a garbage collection. | |
188 virtual bool is_maximal_no_gc() const = 0; | |
189 | |
190 virtual size_t permanent_capacity() const = 0; | |
191 virtual size_t permanent_used() const = 0; | |
192 | |
193 // Support for java.lang.Runtime.maxMemory(): return the maximum amount of | |
194 // memory that the vm could make available for storing 'normal' java objects. | |
195 // This is based on the reserved address space, but should not include space | |
196 // that the vm uses internally for bookkeeping or temporary storage (e.g., | |
197 // perm gen space or, in the case of the young gen, one of the survivor | |
198 // spaces). | |
199 virtual size_t max_capacity() const = 0; | |
200 | |
201 // Returns "TRUE" if "p" points into the reserved area of the heap. | |
202 bool is_in_reserved(const void* p) const { | |
203 return _reserved.contains(p); | |
204 } | |
205 | |
206 bool is_in_reserved_or_null(const void* p) const { | |
207 return p == NULL || is_in_reserved(p); | |
208 } | |
209 | |
210 // Returns "TRUE" if "p" points to the head of an allocated object in the | |
211 // heap. Since this method can be expensive in general, we restrict its | |
212 // use to assertion checking only. | |
213 virtual bool is_in(const void* p) const = 0; | |
214 | |
215 bool is_in_or_null(const void* p) const { | |
216 return p == NULL || is_in(p); | |
217 } | |
218 | |
219 // Let's define some terms: a "closed" subset of a heap is one that | |
220 // | |
221 // 1) contains all currently-allocated objects, and | |
222 // | |
223 // 2) is closed under reference: no object in the closed subset | |
224 // references one outside the closed subset. | |
225 // | |
226 // Membership in a heap's closed subset is useful for assertions. | |
227 // Clearly, the entire heap is a closed subset, so the default | |
228 // implementation is to use "is_in_reserved". But this may not be too | |
229 // liberal to perform useful checking. Also, the "is_in" predicate | |
230 // defines a closed subset, but may be too expensive, since "is_in" | |
231 // verifies that its argument points to an object head. The | |
232 // "closed_subset" method allows a heap to define an intermediate | |
233 // predicate, allowing more precise checking than "is_in_reserved" at | |
234 // lower cost than "is_in." | |
235 | |
236 // One important case is a heap composed of disjoint contiguous spaces, | |
237 // such as the Garbage-First collector. Such heaps have a convenient | |
238 // closed subset consisting of the allocated portions of those | |
239 // contiguous spaces. | |
240 | |
241 // Return "TRUE" iff the given pointer points into the heap's defined | |
242 // closed subset (which defaults to the entire heap). | |
243 virtual bool is_in_closed_subset(const void* p) const { | |
244 return is_in_reserved(p); | |
245 } | |
246 | |
247 bool is_in_closed_subset_or_null(const void* p) const { | |
248 return p == NULL || is_in_closed_subset(p); | |
249 } | |
250 | |
941 | 251 // XXX is_permanent() and is_in_permanent() should be better named |
252 // to distinguish one from the other. | |
253 | |
0 | 254 // Returns "TRUE" if "p" is allocated as "permanent" data. |
255 // If the heap does not use "permanent" data, returns the same | |
256 // value is_in_reserved() would return. | |
257 // NOTE: this actually returns true if "p" is in reserved space | |
258 // for the space not that it is actually allocated (i.e. in committed | |
259 // space). If you need the more conservative answer use is_permanent(). | |
260 virtual bool is_in_permanent(const void *p) const = 0; | |
261 | |
941 | 262 bool is_in_permanent_or_null(const void *p) const { |
263 return p == NULL || is_in_permanent(p); | |
264 } | |
265 | |
0 | 266 // Returns "TRUE" if "p" is in the committed area of "permanent" data. |
267 // If the heap does not use "permanent" data, returns the same | |
268 // value is_in() would return. | |
269 virtual bool is_permanent(const void *p) const = 0; | |
270 | |
941 | 271 bool is_permanent_or_null(const void *p) const { |
272 return p == NULL || is_permanent(p); | |
0 | 273 } |
274 | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
845
diff
changeset
|
275 // An object is scavengable if its location may move during a scavenge. |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
845
diff
changeset
|
276 // (A scavenge is a GC which is not a full GC.) |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
845
diff
changeset
|
277 // Currently, this just means it is not perm (and not null). |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
845
diff
changeset
|
278 // This could change if we rethink what's in perm-gen. |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
845
diff
changeset
|
279 bool is_scavengable(const void *p) const { |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
845
diff
changeset
|
280 return !is_in_permanent_or_null(p); |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
845
diff
changeset
|
281 } |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
845
diff
changeset
|
282 |
0 | 283 // Returns "TRUE" if "p" is a method oop in the |
284 // current heap, with high probability. This predicate | |
285 // is not stable, in general. | |
286 bool is_valid_method(oop p) const; | |
287 | |
288 void set_gc_cause(GCCause::Cause v) { | |
289 if (UsePerfData) { | |
290 _gc_lastcause = _gc_cause; | |
291 _perf_gc_lastcause->set_value(GCCause::to_string(_gc_lastcause)); | |
292 _perf_gc_cause->set_value(GCCause::to_string(v)); | |
293 } | |
294 _gc_cause = v; | |
295 } | |
296 GCCause::Cause gc_cause() { return _gc_cause; } | |
297 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
298 // Number of threads currently working on GC tasks. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
299 int n_par_threads() { return _n_par_threads; } |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
300 |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
301 // May be overridden to set additional parallelism. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
302 virtual void set_par_threads(int t) { _n_par_threads = t; }; |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
303 |
0 | 304 // Preload classes into the shared portion of the heap, and then dump |
305 // that data to a file so that it can be loaded directly by another | |
306 // VM (then terminate). | |
307 virtual void preload_and_dump(TRAPS) { ShouldNotReachHere(); } | |
308 | |
309 // General obj/array allocation facilities. | |
310 inline static oop obj_allocate(KlassHandle klass, int size, TRAPS); | |
311 inline static oop array_allocate(KlassHandle klass, int size, int length, TRAPS); | |
312 inline static oop large_typearray_allocate(KlassHandle klass, int size, int length, TRAPS); | |
313 | |
314 // Special obj/array allocation facilities. | |
315 // Some heaps may want to manage "permanent" data uniquely. These default | |
316 // to the general routines if the heap does not support such handling. | |
317 inline static oop permanent_obj_allocate(KlassHandle klass, int size, TRAPS); | |
318 // permanent_obj_allocate_no_klass_install() does not do the installation of | |
319 // the klass pointer in the newly created object (as permanent_obj_allocate() | |
320 // above does). This allows for a delay in the installation of the klass | |
321 // pointer that is needed during the create of klassKlass's. The | |
322 // method post_allocation_install_obj_klass() is used to install the | |
323 // klass pointer. | |
324 inline static oop permanent_obj_allocate_no_klass_install(KlassHandle klass, | |
325 int size, | |
326 TRAPS); | |
327 inline static void post_allocation_install_obj_klass(KlassHandle klass, | |
328 oop obj, | |
329 int size); | |
330 inline static oop permanent_array_allocate(KlassHandle klass, int size, int length, TRAPS); | |
331 | |
332 // Raw memory allocation facilities | |
333 // The obj and array allocate methods are covers for these methods. | |
334 // The permanent allocation method should default to mem_allocate if | |
335 // permanent memory isn't supported. | |
336 virtual HeapWord* mem_allocate(size_t size, | |
337 bool is_noref, | |
338 bool is_tlab, | |
339 bool* gc_overhead_limit_was_exceeded) = 0; | |
340 virtual HeapWord* permanent_mem_allocate(size_t size) = 0; | |
341 | |
342 // The boundary between a "large" and "small" array of primitives, in words. | |
343 virtual size_t large_typearray_limit() = 0; | |
344 | |
481
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
345 // Utilities for turning raw memory into filler objects. |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
346 // |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
347 // min_fill_size() is the smallest region that can be filled. |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
348 // fill_with_objects() can fill arbitrary-sized regions of the heap using |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
349 // multiple objects. fill_with_object() is for regions known to be smaller |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
350 // than the largest array of integers; it uses a single object to fill the |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
351 // region and has slightly less overhead. |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
352 static size_t min_fill_size() { |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
353 return size_t(align_object_size(oopDesc::header_size())); |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
354 } |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
355 |
1165
2dd52dea6d28
6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents:
1027
diff
changeset
|
356 static void fill_with_objects(HeapWord* start, size_t words, bool zap = true); |
481
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
357 |
1165
2dd52dea6d28
6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents:
1027
diff
changeset
|
358 static void fill_with_object(HeapWord* start, size_t words, bool zap = true); |
2dd52dea6d28
6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents:
1027
diff
changeset
|
359 static void fill_with_object(MemRegion region, bool zap = true) { |
2dd52dea6d28
6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents:
1027
diff
changeset
|
360 fill_with_object(region.start(), region.word_size(), zap); |
481
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
361 } |
1165
2dd52dea6d28
6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents:
1027
diff
changeset
|
362 static void fill_with_object(HeapWord* start, HeapWord* end, bool zap = true) { |
2dd52dea6d28
6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents:
1027
diff
changeset
|
363 fill_with_object(start, pointer_delta(end, start), zap); |
481
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
364 } |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
365 |
0 | 366 // Some heaps may offer a contiguous region for shared non-blocking |
367 // allocation, via inlined code (by exporting the address of the top and | |
368 // end fields defining the extent of the contiguous allocation region.) | |
369 | |
370 // This function returns "true" iff the heap supports this kind of | |
371 // allocation. (Default is "no".) | |
372 virtual bool supports_inline_contig_alloc() const { | |
373 return false; | |
374 } | |
375 // These functions return the addresses of the fields that define the | |
376 // boundaries of the contiguous allocation area. (These fields should be | |
377 // physically near to one another.) | |
378 virtual HeapWord** top_addr() const { | |
379 guarantee(false, "inline contiguous allocation not supported"); | |
380 return NULL; | |
381 } | |
382 virtual HeapWord** end_addr() const { | |
383 guarantee(false, "inline contiguous allocation not supported"); | |
384 return NULL; | |
385 } | |
386 | |
387 // Some heaps may be in an unparseable state at certain times between | |
388 // collections. This may be necessary for efficient implementation of | |
389 // certain allocation-related activities. Calling this function before | |
390 // attempting to parse a heap ensures that the heap is in a parsable | |
391 // state (provided other concurrent activity does not introduce | |
392 // unparsability). It is normally expected, therefore, that this | |
393 // method is invoked with the world stopped. | |
394 // NOTE: if you override this method, make sure you call | |
395 // super::ensure_parsability so that the non-generational | |
396 // part of the work gets done. See implementation of | |
397 // CollectedHeap::ensure_parsability and, for instance, | |
398 // that of GenCollectedHeap::ensure_parsability(). | |
399 // The argument "retire_tlabs" controls whether existing TLABs | |
400 // are merely filled or also retired, thus preventing further | |
401 // allocation from them and necessitating allocation of new TLABs. | |
402 virtual void ensure_parsability(bool retire_tlabs); | |
403 | |
404 // Return an estimate of the maximum allocation that could be performed | |
405 // without triggering any collection or expansion activity. In a | |
406 // generational collector, for example, this is probably the largest | |
407 // allocation that could be supported (without expansion) in the youngest | |
408 // generation. It is "unsafe" because no locks are taken; the result | |
409 // should be treated as an approximation, not a guarantee, for use in | |
410 // heuristic resizing decisions. | |
411 virtual size_t unsafe_max_alloc() = 0; | |
412 | |
413 // Section on thread-local allocation buffers (TLABs) | |
414 // If the heap supports thread-local allocation buffers, it should override | |
415 // the following methods: | |
416 // Returns "true" iff the heap supports thread-local allocation buffers. | |
417 // The default is "no". | |
418 virtual bool supports_tlab_allocation() const { | |
419 return false; | |
420 } | |
421 // The amount of space available for thread-local allocation buffers. | |
422 virtual size_t tlab_capacity(Thread *thr) const { | |
423 guarantee(false, "thread-local allocation buffers not supported"); | |
424 return 0; | |
425 } | |
426 // An estimate of the maximum allocation that could be performed | |
427 // for thread-local allocation buffers without triggering any | |
428 // collection or expansion activity. | |
429 virtual size_t unsafe_max_tlab_alloc(Thread *thr) const { | |
430 guarantee(false, "thread-local allocation buffers not supported"); | |
431 return 0; | |
432 } | |
1027
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
993
diff
changeset
|
433 |
0 | 434 // Can a compiler initialize a new object without store barriers? |
435 // This permission only extends from the creation of a new object | |
1027
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
993
diff
changeset
|
436 // via a TLAB up to the first subsequent safepoint. If such permission |
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
993
diff
changeset
|
437 // is granted for this heap type, the compiler promises to call |
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
993
diff
changeset
|
438 // defer_store_barrier() below on any slow path allocation of |
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
993
diff
changeset
|
439 // a new object for which such initializing store barriers will |
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
993
diff
changeset
|
440 // have been elided. |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
441 virtual bool can_elide_tlab_store_barriers() const = 0; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
442 |
0 | 443 // If a compiler is eliding store barriers for TLAB-allocated objects, |
444 // there is probably a corresponding slow path which can produce | |
445 // an object allocated anywhere. The compiler's runtime support | |
446 // promises to call this function on such a slow-path-allocated | |
447 // object before performing initializations that have elided | |
1027
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
993
diff
changeset
|
448 // store barriers. Returns new_obj, or maybe a safer copy thereof. |
1166 | 449 virtual oop new_store_pre_barrier(JavaThread* thread, oop new_obj); |
1027
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
993
diff
changeset
|
450 |
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
993
diff
changeset
|
451 // Answers whether an initializing store to a new object currently |
1166 | 452 // allocated at the given address doesn't need a store |
1027
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
993
diff
changeset
|
453 // barrier. Returns "true" if it doesn't need an initializing |
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
993
diff
changeset
|
454 // store barrier; answers "false" if it does. |
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
993
diff
changeset
|
455 virtual bool can_elide_initializing_store_barrier(oop new_obj) = 0; |
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
993
diff
changeset
|
456 |
1166 | 457 // If a compiler is eliding store barriers for TLAB-allocated objects, |
458 // we will be informed of a slow-path allocation by a call | |
459 // to new_store_pre_barrier() above. Such a call precedes the | |
460 // initialization of the object itself, and no post-store-barriers will | |
461 // be issued. Some heap types require that the barrier strictly follows | |
462 // the initializing stores. (This is currently implemented by deferring the | |
463 // barrier until the next slow-path allocation or gc-related safepoint.) | |
464 // This interface answers whether a particular heap type needs the card | |
465 // mark to be thus strictly sequenced after the stores. | |
466 virtual bool card_mark_must_follow_store() const = 0; | |
467 | |
1027
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
993
diff
changeset
|
468 // If the CollectedHeap was asked to defer a store barrier above, |
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
993
diff
changeset
|
469 // this informs it to flush such a deferred store barrier to the |
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
993
diff
changeset
|
470 // remembered set. |
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
993
diff
changeset
|
471 virtual void flush_deferred_store_barrier(JavaThread* thread); |
0 | 472 |
473 // Can a compiler elide a store barrier when it writes | |
474 // a permanent oop into the heap? Applies when the compiler | |
475 // is storing x to the heap, where x->is_perm() is true. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
476 virtual bool can_elide_permanent_oop_store_barriers() const = 0; |
0 | 477 |
478 // Does this heap support heap inspection (+PrintClassHistogram?) | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
479 virtual bool supports_heap_inspection() const = 0; |
0 | 480 |
481 // Perform a collection of the heap; intended for use in implementing | |
482 // "System.gc". This probably implies as full a collection as the | |
483 // "CollectedHeap" supports. | |
484 virtual void collect(GCCause::Cause cause) = 0; | |
485 | |
486 // This interface assumes that it's being called by the | |
487 // vm thread. It collects the heap assuming that the | |
488 // heap lock is already held and that we are executing in | |
489 // the context of the vm thread. | |
490 virtual void collect_as_vm_thread(GCCause::Cause cause) = 0; | |
491 | |
492 // Returns the barrier set for this heap | |
493 BarrierSet* barrier_set() { return _barrier_set; } | |
494 | |
495 // Returns "true" iff there is a stop-world GC in progress. (I assume | |
496 // that it should answer "false" for the concurrent part of a concurrent | |
497 // collector -- dld). | |
498 bool is_gc_active() const { return _is_gc_active; } | |
499 | |
500 // Total number of GC collections (started) | |
501 unsigned int total_collections() const { return _total_collections; } | |
502 unsigned int total_full_collections() const { return _total_full_collections;} | |
503 | |
504 // Increment total number of GC collections (started) | |
505 // Should be protected but used by PSMarkSweep - cleanup for 1.4.2 | |
506 void increment_total_collections(bool full = false) { | |
507 _total_collections++; | |
508 if (full) { | |
509 increment_total_full_collections(); | |
510 } | |
511 } | |
512 | |
513 void increment_total_full_collections() { _total_full_collections++; } | |
514 | |
515 // Return the AdaptiveSizePolicy for the heap. | |
516 virtual AdaptiveSizePolicy* size_policy() = 0; | |
517 | |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1166
diff
changeset
|
518 // Return the CollectorPolicy for the heap |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1166
diff
changeset
|
519 virtual CollectorPolicy* collector_policy() const = 0; |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1166
diff
changeset
|
520 |
0 | 521 // Iterate over all the ref-containing fields of all objects, calling |
522 // "cl.do_oop" on each. This includes objects in permanent memory. | |
523 virtual void oop_iterate(OopClosure* cl) = 0; | |
524 | |
525 // Iterate over all objects, calling "cl.do_object" on each. | |
526 // This includes objects in permanent memory. | |
527 virtual void object_iterate(ObjectClosure* cl) = 0; | |
528 | |
517
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
481
diff
changeset
|
529 // Similar to object_iterate() except iterates only |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
481
diff
changeset
|
530 // over live objects. |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
481
diff
changeset
|
531 virtual void safe_object_iterate(ObjectClosure* cl) = 0; |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
481
diff
changeset
|
532 |
0 | 533 // Behaves the same as oop_iterate, except only traverses |
534 // interior pointers contained in permanent memory. If there | |
535 // is no permanent memory, does nothing. | |
536 virtual void permanent_oop_iterate(OopClosure* cl) = 0; | |
537 | |
538 // Behaves the same as object_iterate, except only traverses | |
539 // object contained in permanent memory. If there is no | |
540 // permanent memory, does nothing. | |
541 virtual void permanent_object_iterate(ObjectClosure* cl) = 0; | |
542 | |
543 // NOTE! There is no requirement that a collector implement these | |
544 // functions. | |
545 // | |
546 // A CollectedHeap is divided into a dense sequence of "blocks"; that is, | |
547 // each address in the (reserved) heap is a member of exactly | |
548 // one block. The defining characteristic of a block is that it is | |
549 // possible to find its size, and thus to progress forward to the next | |
550 // block. (Blocks may be of different sizes.) Thus, blocks may | |
551 // represent Java objects, or they might be free blocks in a | |
552 // free-list-based heap (or subheap), as long as the two kinds are | |
553 // distinguishable and the size of each is determinable. | |
554 | |
555 // Returns the address of the start of the "block" that contains the | |
556 // address "addr". We say "blocks" instead of "object" since some heaps | |
557 // may not pack objects densely; a chunk may either be an object or a | |
558 // non-object. | |
559 virtual HeapWord* block_start(const void* addr) const = 0; | |
560 | |
561 // Requires "addr" to be the start of a chunk, and returns its size. | |
562 // "addr + size" is required to be the start of a new chunk, or the end | |
563 // of the active area of the heap. | |
564 virtual size_t block_size(const HeapWord* addr) const = 0; | |
565 | |
566 // Requires "addr" to be the start of a block, and returns "TRUE" iff | |
567 // the block is an object. | |
568 virtual bool block_is_obj(const HeapWord* addr) const = 0; | |
569 | |
570 // Returns the longest time (in ms) that has elapsed since the last | |
571 // time that any part of the heap was examined by a garbage collection. | |
572 virtual jlong millis_since_last_gc() = 0; | |
573 | |
574 // Perform any cleanup actions necessary before allowing a verification. | |
575 virtual void prepare_for_verify() = 0; | |
576 | |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
542
diff
changeset
|
577 // Generate any dumps preceding or following a full gc |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
542
diff
changeset
|
578 void pre_full_gc_dump(); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
542
diff
changeset
|
579 void post_full_gc_dump(); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
542
diff
changeset
|
580 |
0 | 581 virtual void print() const = 0; |
582 virtual void print_on(outputStream* st) const = 0; | |
583 | |
584 // Print all GC threads (other than the VM thread) | |
585 // used by this heap. | |
586 virtual void print_gc_threads_on(outputStream* st) const = 0; | |
587 void print_gc_threads() { print_gc_threads_on(tty); } | |
588 // Iterator for all GC threads (other than VM thread) | |
589 virtual void gc_threads_do(ThreadClosure* tc) const = 0; | |
590 | |
591 // Print any relevant tracing info that flags imply. | |
592 // Default implementation does nothing. | |
593 virtual void print_tracing_info() const = 0; | |
594 | |
595 // Heap verification | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
628
diff
changeset
|
596 virtual void verify(bool allow_dirty, bool silent, bool option) = 0; |
0 | 597 |
598 // Non product verification and debugging. | |
599 #ifndef PRODUCT | |
600 // Support for PromotionFailureALot. Return true if it's time to cause a | |
601 // promotion failure. The no-argument version uses | |
602 // this->_promotion_failure_alot_count as the counter. | |
603 inline bool promotion_should_fail(volatile size_t* count); | |
604 inline bool promotion_should_fail(); | |
605 | |
606 // Reset the PromotionFailureALot counters. Should be called at the end of a | |
607 // GC in which promotion failure ocurred. | |
608 inline void reset_promotion_should_fail(volatile size_t* count); | |
609 inline void reset_promotion_should_fail(); | |
610 #endif // #ifndef PRODUCT | |
611 | |
612 #ifdef ASSERT | |
613 static int fired_fake_oom() { | |
614 return (CIFireOOMAt > 1 && _fire_out_of_memory_count >= CIFireOOMAt); | |
615 } | |
616 #endif | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
617 |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
618 public: |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
619 // This is a convenience method that is used in cases where |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
620 // the actual number of GC worker threads is not pertinent but |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
621 // only whether there more than 0. Use of this method helps |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
622 // reduce the occurrence of ParallelGCThreads to uses where the |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
623 // actual number may be germane. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
624 static bool use_parallel_gc_threads() { return ParallelGCThreads > 0; } |
0 | 625 }; |
626 | |
627 // Class to set and reset the GC cause for a CollectedHeap. | |
628 | |
629 class GCCauseSetter : StackObj { | |
630 CollectedHeap* _heap; | |
631 GCCause::Cause _previous_cause; | |
632 public: | |
633 GCCauseSetter(CollectedHeap* heap, GCCause::Cause cause) { | |
634 assert(SafepointSynchronize::is_at_safepoint(), | |
635 "This method manipulates heap state without locking"); | |
636 _heap = heap; | |
637 _previous_cause = _heap->gc_cause(); | |
638 _heap->set_gc_cause(cause); | |
639 } | |
640 | |
641 ~GCCauseSetter() { | |
642 assert(SafepointSynchronize::is_at_safepoint(), | |
643 "This method manipulates heap state without locking"); | |
644 _heap->set_gc_cause(_previous_cause); | |
645 } | |
646 }; |