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