Mon, 20 Sep 2010 14:38:38 -0700
6984287: Regularize how GC parallel workers are specified.
Summary: Associate number of GC workers with the workgang as opposed to the task.
Reviewed-by: johnc, ysr
1 /*
2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
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.
30 class BarrierSet;
31 class ThreadClosure;
32 class AdaptiveSizePolicy;
33 class Thread;
34 class CollectorPolicy;
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
46 friend class constantPoolCacheKlass; // allocate() method inserts is_conc_safe
48 #ifdef ASSERT
49 static int _fire_out_of_memory_count;
50 #endif
52 // Used for filler objects (static, but initialized in ctor).
53 static size_t _filler_array_max_size;
55 // Used in support of ReduceInitialCardMarks; only consulted if COMPILER2 is being used
56 bool _defer_initial_card_mark;
58 protected:
59 MemRegion _reserved;
60 BarrierSet* _barrier_set;
61 bool _is_gc_active;
62 int _n_par_threads;
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;)
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;
76 // Constructor
77 CollectedHeap();
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();
86 // Create a new tlab
87 virtual HeapWord* allocate_new_tlab(size_t size);
89 // Accumulate statistics on all tlabs.
90 virtual void accumulate_statistics_all_tlabs();
92 // Reinitialize tlabs before resuming mutators.
93 virtual void resize_all_tlabs();
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);
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);
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);
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);
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);
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);
123 inline static void post_allocation_setup_obj(KlassHandle klass,
124 HeapWord* obj, size_t size);
126 inline static void post_allocation_setup_array(KlassHandle klass,
127 HeapWord* obj, size_t size,
128 int length);
130 // Clears an allocated object.
131 inline static void init_obj(HeapWord* obj, size_t size);
133 // Filler object utilities.
134 static inline size_t filler_array_hdr_size();
135 static inline size_t filler_array_min_size();
136 static inline size_t filler_array_max_size();
138 DEBUG_ONLY(static void fill_args_check(HeapWord* start, size_t words);)
139 DEBUG_ONLY(static void zap_filler_array(HeapWord* start, size_t words, bool zap = true);)
141 // Fill with a single array; caller must ensure filler_array_min_size() <=
142 // words <= filler_array_max_size().
143 static inline void fill_with_array(HeapWord* start, size_t words, bool zap = true);
145 // Fill with a single object (either an int array or a java.lang.Object).
146 static inline void fill_with_object_impl(HeapWord* start, size_t words, bool zap = true);
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;
153 debug_only(static void check_for_valid_allocation_state();)
155 public:
156 enum Name {
157 Abstract,
158 SharedHeap,
159 GenCollectedHeap,
160 ParallelScavengeHeap,
161 G1CollectedHeap
162 };
164 virtual CollectedHeap::Name kind() const { return CollectedHeap::Abstract; }
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;
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;
177 MemRegion reserved_region() const { return _reserved; }
178 address base() const { return (address)reserved_region().start(); }
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;
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;
190 virtual size_t permanent_capacity() const = 0;
191 virtual size_t permanent_used() const = 0;
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;
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 }
206 bool is_in_reserved_or_null(const void* p) const {
207 return p == NULL || is_in_reserved(p);
208 }
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;
215 bool is_in_or_null(const void* p) const {
216 return p == NULL || is_in(p);
217 }
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."
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.
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 }
247 bool is_in_closed_subset_or_null(const void* p) const {
248 return p == NULL || is_in_closed_subset(p);
249 }
251 // XXX is_permanent() and is_in_permanent() should be better named
252 // to distinguish one from the other.
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;
262 bool is_in_permanent_or_null(const void *p) const {
263 return p == NULL || is_in_permanent(p);
264 }
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;
271 bool is_permanent_or_null(const void *p) const {
272 return p == NULL || is_permanent(p);
273 }
275 // An object is scavengable if its location may move during a scavenge.
276 // (A scavenge is a GC which is not a full GC.)
277 // Currently, this just means it is not perm (and not null).
278 // This could change if we rethink what's in perm-gen.
279 bool is_scavengable(const void *p) const {
280 return !is_in_permanent_or_null(p);
281 }
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;
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; }
298 // Number of threads currently working on GC tasks.
299 int n_par_threads() { return _n_par_threads; }
301 // May be overridden to set additional parallelism.
302 virtual void set_par_threads(int t) { _n_par_threads = t; };
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(); }
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);
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);
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;
342 // The boundary between a "large" and "small" array of primitives, in words.
343 virtual size_t large_typearray_limit() = 0;
345 // Utilities for turning raw memory into filler objects.
346 //
347 // min_fill_size() is the smallest region that can be filled.
348 // fill_with_objects() can fill arbitrary-sized regions of the heap using
349 // multiple objects. fill_with_object() is for regions known to be smaller
350 // than the largest array of integers; it uses a single object to fill the
351 // region and has slightly less overhead.
352 static size_t min_fill_size() {
353 return size_t(align_object_size(oopDesc::header_size()));
354 }
356 static void fill_with_objects(HeapWord* start, size_t words, bool zap = true);
358 static void fill_with_object(HeapWord* start, size_t words, bool zap = true);
359 static void fill_with_object(MemRegion region, bool zap = true) {
360 fill_with_object(region.start(), region.word_size(), zap);
361 }
362 static void fill_with_object(HeapWord* start, HeapWord* end, bool zap = true) {
363 fill_with_object(start, pointer_delta(end, start), zap);
364 }
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.)
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 }
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);
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;
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 }
434 // Can a compiler initialize a new object without store barriers?
435 // This permission only extends from the creation of a new object
436 // via a TLAB up to the first subsequent safepoint. If such permission
437 // is granted for this heap type, the compiler promises to call
438 // defer_store_barrier() below on any slow path allocation of
439 // a new object for which such initializing store barriers will
440 // have been elided.
441 virtual bool can_elide_tlab_store_barriers() const = 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
448 // store barriers. Returns new_obj, or maybe a safer copy thereof.
449 virtual oop new_store_pre_barrier(JavaThread* thread, oop new_obj);
451 // Answers whether an initializing store to a new object currently
452 // allocated at the given address doesn't need a store
453 // barrier. Returns "true" if it doesn't need an initializing
454 // store barrier; answers "false" if it does.
455 virtual bool can_elide_initializing_store_barrier(oop new_obj) = 0;
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;
468 // If the CollectedHeap was asked to defer a store barrier above,
469 // this informs it to flush such a deferred store barrier to the
470 // remembered set.
471 virtual void flush_deferred_store_barrier(JavaThread* thread);
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.
476 virtual bool can_elide_permanent_oop_store_barriers() const = 0;
478 // Does this heap support heap inspection (+PrintClassHistogram?)
479 virtual bool supports_heap_inspection() const = 0;
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;
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;
492 // Returns the barrier set for this heap
493 BarrierSet* barrier_set() { return _barrier_set; }
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; }
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;}
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 }
513 void increment_total_full_collections() { _total_full_collections++; }
515 // Return the AdaptiveSizePolicy for the heap.
516 virtual AdaptiveSizePolicy* size_policy() = 0;
518 // Return the CollectorPolicy for the heap
519 virtual CollectorPolicy* collector_policy() const = 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;
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;
529 // Similar to object_iterate() except iterates only
530 // over live objects.
531 virtual void safe_object_iterate(ObjectClosure* cl) = 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;
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;
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.
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;
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;
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;
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;
574 // Perform any cleanup actions necessary before allowing a verification.
575 virtual void prepare_for_verify() = 0;
577 // Generate any dumps preceding or following a full gc
578 void pre_full_gc_dump();
579 void post_full_gc_dump();
581 virtual void print() const = 0;
582 virtual void print_on(outputStream* st) const = 0;
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;
591 // Print any relevant tracing info that flags imply.
592 // Default implementation does nothing.
593 virtual void print_tracing_info() const = 0;
595 // Heap verification
596 virtual void verify(bool allow_dirty, bool silent, bool option) = 0;
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();
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
612 #ifdef ASSERT
613 static int fired_fake_oom() {
614 return (CIFireOOMAt > 1 && _fire_out_of_memory_count >= CIFireOOMAt);
615 }
616 #endif
618 public:
619 // This is a convenience method that is used in cases where
620 // the actual number of GC worker threads is not pertinent but
621 // only whether there more than 0. Use of this method helps
622 // reduce the occurrence of ParallelGCThreads to uses where the
623 // actual number may be germane.
624 static bool use_parallel_gc_threads() { return ParallelGCThreads > 0; }
625 };
627 // Class to set and reset the GC cause for a CollectedHeap.
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 }
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 };