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