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