collectedHeap.hpp revision 1753
0N/A/*
1472N/A * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
0N/A// A "CollectedHeap" is an implementation of a java heap for HotSpot. This
0N/A// is an abstract class: there may be many different kinds of heaps. This
0N/A// class defines the functions that a heap must implement, and contains
0N/A// infrastructure common to all heaps.
0N/A
0N/Aclass BarrierSet;
0N/Aclass ThreadClosure;
0N/Aclass AdaptiveSizePolicy;
0N/Aclass Thread;
1387N/Aclass CollectorPolicy;
0N/A
0N/A//
0N/A// CollectedHeap
0N/A// SharedHeap
0N/A// GenCollectedHeap
0N/A// G1CollectedHeap
0N/A// ParallelScavengeHeap
0N/A//
0N/Aclass CollectedHeap : public CHeapObj {
0N/A friend class VMStructs;
0N/A friend class IsGCActiveMark; // Block structured external access to _is_gc_active
542N/A friend class constantPoolCacheKlass; // allocate() method inserts is_conc_safe
0N/A
0N/A#ifdef ASSERT
0N/A static int _fire_out_of_memory_count;
0N/A#endif
0N/A
481N/A // Used for filler objects (static, but initialized in ctor).
481N/A static size_t _filler_array_max_size;
481N/A
1166N/A // Used in support of ReduceInitialCardMarks; only consulted if COMPILER2 is being used
1166N/A bool _defer_initial_card_mark;
1166N/A
0N/A protected:
0N/A MemRegion _reserved;
0N/A BarrierSet* _barrier_set;
0N/A bool _is_gc_active;
1753N/A int _n_par_threads;
1753N/A
0N/A unsigned int _total_collections; // ... started
0N/A unsigned int _total_full_collections; // ... started
0N/A NOT_PRODUCT(volatile size_t _promotion_failure_alot_count;)
0N/A NOT_PRODUCT(volatile size_t _promotion_failure_alot_gc_number;)
0N/A
0N/A // Reason for current garbage collection. Should be set to
0N/A // a value reflecting no collection between collections.
0N/A GCCause::Cause _gc_cause;
0N/A GCCause::Cause _gc_lastcause;
0N/A PerfStringVariable* _perf_gc_cause;
0N/A PerfStringVariable* _perf_gc_lastcause;
0N/A
0N/A // Constructor
0N/A CollectedHeap();
0N/A
1166N/A // Do common initializations that must follow instance construction,
1166N/A // for example, those needing virtual calls.
1166N/A // This code could perhaps be moved into initialize() but would
1166N/A // be slightly more awkward because we want the latter to be a
1166N/A // pure virtual.
1166N/A void pre_initialize();
1166N/A
0N/A // Create a new tlab
0N/A virtual HeapWord* allocate_new_tlab(size_t size);
0N/A
0N/A // Accumulate statistics on all tlabs.
0N/A virtual void accumulate_statistics_all_tlabs();
0N/A
0N/A // Reinitialize tlabs before resuming mutators.
0N/A virtual void resize_all_tlabs();
0N/A
0N/A protected:
0N/A // Allocate from the current thread's TLAB, with broken-out slow path.
0N/A inline static HeapWord* allocate_from_tlab(Thread* thread, size_t size);
0N/A static HeapWord* allocate_from_tlab_slow(Thread* thread, size_t size);
0N/A
0N/A // Allocate an uninitialized block of the given size, or returns NULL if
0N/A // this is impossible.
0N/A inline static HeapWord* common_mem_allocate_noinit(size_t size, bool is_noref, TRAPS);
0N/A
0N/A // Like allocate_init, but the block returned by a successful allocation
0N/A // is guaranteed initialized to zeros.
0N/A inline static HeapWord* common_mem_allocate_init(size_t size, bool is_noref, TRAPS);
0N/A
0N/A // Same as common_mem version, except memory is allocated in the permanent area
0N/A // If there is no permanent area, revert to common_mem_allocate_noinit
0N/A inline static HeapWord* common_permanent_mem_allocate_noinit(size_t size, TRAPS);
0N/A
0N/A // Same as common_mem version, except memory is allocated in the permanent area
0N/A // If there is no permanent area, revert to common_mem_allocate_init
0N/A inline static HeapWord* common_permanent_mem_allocate_init(size_t size, TRAPS);
0N/A
0N/A // Helper functions for (VM) allocation.
0N/A inline static void post_allocation_setup_common(KlassHandle klass,
0N/A HeapWord* obj, size_t size);
0N/A inline static void post_allocation_setup_no_klass_install(KlassHandle klass,
0N/A HeapWord* objPtr,
0N/A size_t size);
0N/A
0N/A inline static void post_allocation_setup_obj(KlassHandle klass,
0N/A HeapWord* obj, size_t size);
0N/A
0N/A inline static void post_allocation_setup_array(KlassHandle klass,
0N/A HeapWord* obj, size_t size,
0N/A int length);
0N/A
0N/A // Clears an allocated object.
0N/A inline static void init_obj(HeapWord* obj, size_t size);
0N/A
481N/A // Filler object utilities.
481N/A static inline size_t filler_array_hdr_size();
481N/A static inline size_t filler_array_min_size();
481N/A static inline size_t filler_array_max_size();
481N/A
481N/A DEBUG_ONLY(static void fill_args_check(HeapWord* start, size_t words);)
1165N/A DEBUG_ONLY(static void zap_filler_array(HeapWord* start, size_t words, bool zap = true);)
481N/A
481N/A // Fill with a single array; caller must ensure filler_array_min_size() <=
481N/A // words <= filler_array_max_size().
1165N/A static inline void fill_with_array(HeapWord* start, size_t words, bool zap = true);
481N/A
481N/A // Fill with a single object (either an int array or a java.lang.Object).
1165N/A static inline void fill_with_object_impl(HeapWord* start, size_t words, bool zap = true);
481N/A
0N/A // Verification functions
0N/A virtual void check_for_bad_heap_word_value(HeapWord* addr, size_t size)
0N/A PRODUCT_RETURN;
0N/A virtual void check_for_non_bad_heap_word_value(HeapWord* addr, size_t size)
0N/A PRODUCT_RETURN;
542N/A debug_only(static void check_for_valid_allocation_state();)
0N/A
0N/A public:
0N/A enum Name {
0N/A Abstract,
0N/A SharedHeap,
0N/A GenCollectedHeap,
0N/A ParallelScavengeHeap,
0N/A G1CollectedHeap
0N/A };
0N/A
0N/A virtual CollectedHeap::Name kind() const { return CollectedHeap::Abstract; }
0N/A
0N/A /**
0N/A * Returns JNI error code JNI_ENOMEM if memory could not be allocated,
0N/A * and JNI_OK on success.
0N/A */
0N/A virtual jint initialize() = 0;
0N/A
0N/A // In many heaps, there will be a need to perform some initialization activities
0N/A // after the Universe is fully formed, but before general heap allocation is allowed.
0N/A // This is the correct place to place such initialization methods.
0N/A virtual void post_initialize() = 0;
0N/A
0N/A MemRegion reserved_region() const { return _reserved; }
113N/A address base() const { return (address)reserved_region().start(); }
0N/A
0N/A // Future cleanup here. The following functions should specify bytes or
0N/A // heapwords as part of their signature.
0N/A virtual size_t capacity() const = 0;
0N/A virtual size_t used() const = 0;
0N/A
0N/A // Return "true" if the part of the heap that allocates Java
0N/A // objects has reached the maximal committed limit that it can
0N/A // reach, without a garbage collection.
0N/A virtual bool is_maximal_no_gc() const = 0;
0N/A
0N/A virtual size_t permanent_capacity() const = 0;
0N/A virtual size_t permanent_used() const = 0;
0N/A
0N/A // Support for java.lang.Runtime.maxMemory(): return the maximum amount of
0N/A // memory that the vm could make available for storing 'normal' java objects.
0N/A // This is based on the reserved address space, but should not include space
0N/A // that the vm uses internally for bookkeeping or temporary storage (e.g.,
0N/A // perm gen space or, in the case of the young gen, one of the survivor
0N/A // spaces).
0N/A virtual size_t max_capacity() const = 0;
0N/A
0N/A // Returns "TRUE" if "p" points into the reserved area of the heap.
0N/A bool is_in_reserved(const void* p) const {
0N/A return _reserved.contains(p);
0N/A }
0N/A
0N/A bool is_in_reserved_or_null(const void* p) const {
0N/A return p == NULL || is_in_reserved(p);
0N/A }
0N/A
0N/A // Returns "TRUE" if "p" points to the head of an allocated object in the
0N/A // heap. Since this method can be expensive in general, we restrict its
0N/A // use to assertion checking only.
0N/A virtual bool is_in(const void* p) const = 0;
0N/A
0N/A bool is_in_or_null(const void* p) const {
0N/A return p == NULL || is_in(p);
0N/A }
0N/A
0N/A // Let's define some terms: a "closed" subset of a heap is one that
0N/A //
0N/A // 1) contains all currently-allocated objects, and
0N/A //
0N/A // 2) is closed under reference: no object in the closed subset
0N/A // references one outside the closed subset.
0N/A //
0N/A // Membership in a heap's closed subset is useful for assertions.
0N/A // Clearly, the entire heap is a closed subset, so the default
0N/A // implementation is to use "is_in_reserved". But this may not be too
0N/A // liberal to perform useful checking. Also, the "is_in" predicate
0N/A // defines a closed subset, but may be too expensive, since "is_in"
0N/A // verifies that its argument points to an object head. The
0N/A // "closed_subset" method allows a heap to define an intermediate
0N/A // predicate, allowing more precise checking than "is_in_reserved" at
0N/A // lower cost than "is_in."
0N/A
0N/A // One important case is a heap composed of disjoint contiguous spaces,
0N/A // such as the Garbage-First collector. Such heaps have a convenient
0N/A // closed subset consisting of the allocated portions of those
0N/A // contiguous spaces.
0N/A
0N/A // Return "TRUE" iff the given pointer points into the heap's defined
0N/A // closed subset (which defaults to the entire heap).
0N/A virtual bool is_in_closed_subset(const void* p) const {
0N/A return is_in_reserved(p);
0N/A }
0N/A
0N/A bool is_in_closed_subset_or_null(const void* p) const {
0N/A return p == NULL || is_in_closed_subset(p);
0N/A }
0N/A
941N/A // XXX is_permanent() and is_in_permanent() should be better named
941N/A // to distinguish one from the other.
941N/A
0N/A // Returns "TRUE" if "p" is allocated as "permanent" data.
0N/A // If the heap does not use "permanent" data, returns the same
0N/A // value is_in_reserved() would return.
0N/A // NOTE: this actually returns true if "p" is in reserved space
0N/A // for the space not that it is actually allocated (i.e. in committed
0N/A // space). If you need the more conservative answer use is_permanent().
0N/A virtual bool is_in_permanent(const void *p) const = 0;
0N/A
941N/A bool is_in_permanent_or_null(const void *p) const {
941N/A return p == NULL || is_in_permanent(p);
941N/A }
941N/A
0N/A // Returns "TRUE" if "p" is in the committed area of "permanent" data.
0N/A // If the heap does not use "permanent" data, returns the same
0N/A // value is_in() would return.
0N/A virtual bool is_permanent(const void *p) const = 0;
0N/A
941N/A bool is_permanent_or_null(const void *p) const {
941N/A return p == NULL || is_permanent(p);
0N/A }
0N/A
989N/A // An object is scavengable if its location may move during a scavenge.
989N/A // (A scavenge is a GC which is not a full GC.)
989N/A // Currently, this just means it is not perm (and not null).
989N/A // This could change if we rethink what's in perm-gen.
989N/A bool is_scavengable(const void *p) const {
989N/A return !is_in_permanent_or_null(p);
989N/A }
989N/A
0N/A // Returns "TRUE" if "p" is a method oop in the
0N/A // current heap, with high probability. This predicate
0N/A // is not stable, in general.
0N/A bool is_valid_method(oop p) const;
0N/A
0N/A void set_gc_cause(GCCause::Cause v) {
0N/A if (UsePerfData) {
0N/A _gc_lastcause = _gc_cause;
0N/A _perf_gc_lastcause->set_value(GCCause::to_string(_gc_lastcause));
0N/A _perf_gc_cause->set_value(GCCause::to_string(v));
0N/A }
0N/A _gc_cause = v;
0N/A }
0N/A GCCause::Cause gc_cause() { return _gc_cause; }
0N/A
1753N/A // Number of threads currently working on GC tasks.
1753N/A int n_par_threads() { return _n_par_threads; }
1753N/A
1753N/A // May be overridden to set additional parallelism.
1753N/A virtual void set_par_threads(int t) { _n_par_threads = t; };
1753N/A
0N/A // Preload classes into the shared portion of the heap, and then dump
0N/A // that data to a file so that it can be loaded directly by another
0N/A // VM (then terminate).
0N/A virtual void preload_and_dump(TRAPS) { ShouldNotReachHere(); }
0N/A
0N/A // General obj/array allocation facilities.
0N/A inline static oop obj_allocate(KlassHandle klass, int size, TRAPS);
0N/A inline static oop array_allocate(KlassHandle klass, int size, int length, TRAPS);
0N/A inline static oop large_typearray_allocate(KlassHandle klass, int size, int length, TRAPS);
0N/A
0N/A // Special obj/array allocation facilities.
0N/A // Some heaps may want to manage "permanent" data uniquely. These default
0N/A // to the general routines if the heap does not support such handling.
0N/A inline static oop permanent_obj_allocate(KlassHandle klass, int size, TRAPS);
0N/A // permanent_obj_allocate_no_klass_install() does not do the installation of
0N/A // the klass pointer in the newly created object (as permanent_obj_allocate()
0N/A // above does). This allows for a delay in the installation of the klass
0N/A // pointer that is needed during the create of klassKlass's. The
0N/A // method post_allocation_install_obj_klass() is used to install the
0N/A // klass pointer.
0N/A inline static oop permanent_obj_allocate_no_klass_install(KlassHandle klass,
0N/A int size,
0N/A TRAPS);
0N/A inline static void post_allocation_install_obj_klass(KlassHandle klass,
0N/A oop obj,
0N/A int size);
0N/A inline static oop permanent_array_allocate(KlassHandle klass, int size, int length, TRAPS);
0N/A
0N/A // Raw memory allocation facilities
0N/A // The obj and array allocate methods are covers for these methods.
0N/A // The permanent allocation method should default to mem_allocate if
0N/A // permanent memory isn't supported.
0N/A virtual HeapWord* mem_allocate(size_t size,
0N/A bool is_noref,
0N/A bool is_tlab,
0N/A bool* gc_overhead_limit_was_exceeded) = 0;
0N/A virtual HeapWord* permanent_mem_allocate(size_t size) = 0;
0N/A
0N/A // The boundary between a "large" and "small" array of primitives, in words.
0N/A virtual size_t large_typearray_limit() = 0;
0N/A
481N/A // Utilities for turning raw memory into filler objects.
481N/A //
481N/A // min_fill_size() is the smallest region that can be filled.
481N/A // fill_with_objects() can fill arbitrary-sized regions of the heap using
481N/A // multiple objects. fill_with_object() is for regions known to be smaller
481N/A // than the largest array of integers; it uses a single object to fill the
481N/A // region and has slightly less overhead.
481N/A static size_t min_fill_size() {
481N/A return size_t(align_object_size(oopDesc::header_size()));
481N/A }
481N/A
1165N/A static void fill_with_objects(HeapWord* start, size_t words, bool zap = true);
481N/A
1165N/A static void fill_with_object(HeapWord* start, size_t words, bool zap = true);
1165N/A static void fill_with_object(MemRegion region, bool zap = true) {
1165N/A fill_with_object(region.start(), region.word_size(), zap);
481N/A }
1165N/A static void fill_with_object(HeapWord* start, HeapWord* end, bool zap = true) {
1165N/A fill_with_object(start, pointer_delta(end, start), zap);
481N/A }
481N/A
0N/A // Some heaps may offer a contiguous region for shared non-blocking
0N/A // allocation, via inlined code (by exporting the address of the top and
0N/A // end fields defining the extent of the contiguous allocation region.)
0N/A
0N/A // This function returns "true" iff the heap supports this kind of
0N/A // allocation. (Default is "no".)
0N/A virtual bool supports_inline_contig_alloc() const {
0N/A return false;
0N/A }
0N/A // These functions return the addresses of the fields that define the
0N/A // boundaries of the contiguous allocation area. (These fields should be
0N/A // physically near to one another.)
0N/A virtual HeapWord** top_addr() const {
0N/A guarantee(false, "inline contiguous allocation not supported");
0N/A return NULL;
0N/A }
0N/A virtual HeapWord** end_addr() const {
0N/A guarantee(false, "inline contiguous allocation not supported");
0N/A return NULL;
0N/A }
0N/A
0N/A // Some heaps may be in an unparseable state at certain times between
0N/A // collections. This may be necessary for efficient implementation of
0N/A // certain allocation-related activities. Calling this function before
0N/A // attempting to parse a heap ensures that the heap is in a parsable
0N/A // state (provided other concurrent activity does not introduce
0N/A // unparsability). It is normally expected, therefore, that this
0N/A // method is invoked with the world stopped.
0N/A // NOTE: if you override this method, make sure you call
0N/A // super::ensure_parsability so that the non-generational
0N/A // part of the work gets done. See implementation of
0N/A // CollectedHeap::ensure_parsability and, for instance,
0N/A // that of GenCollectedHeap::ensure_parsability().
0N/A // The argument "retire_tlabs" controls whether existing TLABs
0N/A // are merely filled or also retired, thus preventing further
0N/A // allocation from them and necessitating allocation of new TLABs.
0N/A virtual void ensure_parsability(bool retire_tlabs);
0N/A
0N/A // Return an estimate of the maximum allocation that could be performed
0N/A // without triggering any collection or expansion activity. In a
0N/A // generational collector, for example, this is probably the largest
0N/A // allocation that could be supported (without expansion) in the youngest
0N/A // generation. It is "unsafe" because no locks are taken; the result
0N/A // should be treated as an approximation, not a guarantee, for use in
0N/A // heuristic resizing decisions.
0N/A virtual size_t unsafe_max_alloc() = 0;
0N/A
0N/A // Section on thread-local allocation buffers (TLABs)
0N/A // If the heap supports thread-local allocation buffers, it should override
0N/A // the following methods:
0N/A // Returns "true" iff the heap supports thread-local allocation buffers.
0N/A // The default is "no".
0N/A virtual bool supports_tlab_allocation() const {
0N/A return false;
0N/A }
0N/A // The amount of space available for thread-local allocation buffers.
0N/A virtual size_t tlab_capacity(Thread *thr) const {
0N/A guarantee(false, "thread-local allocation buffers not supported");
0N/A return 0;
0N/A }
0N/A // An estimate of the maximum allocation that could be performed
0N/A // for thread-local allocation buffers without triggering any
0N/A // collection or expansion activity.
0N/A virtual size_t unsafe_max_tlab_alloc(Thread *thr) const {
0N/A guarantee(false, "thread-local allocation buffers not supported");
0N/A return 0;
0N/A }
1027N/A
0N/A // Can a compiler initialize a new object without store barriers?
0N/A // This permission only extends from the creation of a new object
1027N/A // via a TLAB up to the first subsequent safepoint. If such permission
1027N/A // is granted for this heap type, the compiler promises to call
1027N/A // defer_store_barrier() below on any slow path allocation of
1027N/A // a new object for which such initializing store barriers will
1027N/A // have been elided.
342N/A virtual bool can_elide_tlab_store_barriers() const = 0;
342N/A
0N/A // If a compiler is eliding store barriers for TLAB-allocated objects,
0N/A // there is probably a corresponding slow path which can produce
0N/A // an object allocated anywhere. The compiler's runtime support
0N/A // promises to call this function on such a slow-path-allocated
0N/A // object before performing initializations that have elided
1027N/A // store barriers. Returns new_obj, or maybe a safer copy thereof.
1166N/A virtual oop new_store_pre_barrier(JavaThread* thread, oop new_obj);
1027N/A
1027N/A // Answers whether an initializing store to a new object currently
1166N/A // allocated at the given address doesn't need a store
1027N/A // barrier. Returns "true" if it doesn't need an initializing
1027N/A // store barrier; answers "false" if it does.
1027N/A virtual bool can_elide_initializing_store_barrier(oop new_obj) = 0;
1027N/A
1166N/A // If a compiler is eliding store barriers for TLAB-allocated objects,
1166N/A // we will be informed of a slow-path allocation by a call
1166N/A // to new_store_pre_barrier() above. Such a call precedes the
1166N/A // initialization of the object itself, and no post-store-barriers will
1166N/A // be issued. Some heap types require that the barrier strictly follows
1166N/A // the initializing stores. (This is currently implemented by deferring the
1166N/A // barrier until the next slow-path allocation or gc-related safepoint.)
1166N/A // This interface answers whether a particular heap type needs the card
1166N/A // mark to be thus strictly sequenced after the stores.
1166N/A virtual bool card_mark_must_follow_store() const = 0;
1166N/A
1027N/A // If the CollectedHeap was asked to defer a store barrier above,
1027N/A // this informs it to flush such a deferred store barrier to the
1027N/A // remembered set.
1027N/A virtual void flush_deferred_store_barrier(JavaThread* thread);
0N/A
0N/A // Can a compiler elide a store barrier when it writes
0N/A // a permanent oop into the heap? Applies when the compiler
0N/A // is storing x to the heap, where x->is_perm() is true.
342N/A virtual bool can_elide_permanent_oop_store_barriers() const = 0;
0N/A
0N/A // Does this heap support heap inspection (+PrintClassHistogram?)
342N/A virtual bool supports_heap_inspection() const = 0;
0N/A
0N/A // Perform a collection of the heap; intended for use in implementing
0N/A // "System.gc". This probably implies as full a collection as the
0N/A // "CollectedHeap" supports.
0N/A virtual void collect(GCCause::Cause cause) = 0;
0N/A
0N/A // This interface assumes that it's being called by the
0N/A // vm thread. It collects the heap assuming that the
0N/A // heap lock is already held and that we are executing in
0N/A // the context of the vm thread.
0N/A virtual void collect_as_vm_thread(GCCause::Cause cause) = 0;
0N/A
0N/A // Returns the barrier set for this heap
0N/A BarrierSet* barrier_set() { return _barrier_set; }
0N/A
0N/A // Returns "true" iff there is a stop-world GC in progress. (I assume
0N/A // that it should answer "false" for the concurrent part of a concurrent
0N/A // collector -- dld).
0N/A bool is_gc_active() const { return _is_gc_active; }
0N/A
0N/A // Total number of GC collections (started)
0N/A unsigned int total_collections() const { return _total_collections; }
0N/A unsigned int total_full_collections() const { return _total_full_collections;}
0N/A
0N/A // Increment total number of GC collections (started)
0N/A // Should be protected but used by PSMarkSweep - cleanup for 1.4.2
0N/A void increment_total_collections(bool full = false) {
0N/A _total_collections++;
0N/A if (full) {
0N/A increment_total_full_collections();
0N/A }
0N/A }
0N/A
0N/A void increment_total_full_collections() { _total_full_collections++; }
0N/A
0N/A // Return the AdaptiveSizePolicy for the heap.
0N/A virtual AdaptiveSizePolicy* size_policy() = 0;
0N/A
1387N/A // Return the CollectorPolicy for the heap
1387N/A virtual CollectorPolicy* collector_policy() const = 0;
1387N/A
0N/A // Iterate over all the ref-containing fields of all objects, calling
0N/A // "cl.do_oop" on each. This includes objects in permanent memory.
0N/A virtual void oop_iterate(OopClosure* cl) = 0;
0N/A
0N/A // Iterate over all objects, calling "cl.do_object" on each.
0N/A // This includes objects in permanent memory.
0N/A virtual void object_iterate(ObjectClosure* cl) = 0;
0N/A
517N/A // Similar to object_iterate() except iterates only
517N/A // over live objects.
517N/A virtual void safe_object_iterate(ObjectClosure* cl) = 0;
517N/A
0N/A // Behaves the same as oop_iterate, except only traverses
0N/A // interior pointers contained in permanent memory. If there
0N/A // is no permanent memory, does nothing.
0N/A virtual void permanent_oop_iterate(OopClosure* cl) = 0;
0N/A
0N/A // Behaves the same as object_iterate, except only traverses
0N/A // object contained in permanent memory. If there is no
0N/A // permanent memory, does nothing.
0N/A virtual void permanent_object_iterate(ObjectClosure* cl) = 0;
0N/A
0N/A // NOTE! There is no requirement that a collector implement these
0N/A // functions.
0N/A //
0N/A // A CollectedHeap is divided into a dense sequence of "blocks"; that is,
0N/A // each address in the (reserved) heap is a member of exactly
0N/A // one block. The defining characteristic of a block is that it is
0N/A // possible to find its size, and thus to progress forward to the next
0N/A // block. (Blocks may be of different sizes.) Thus, blocks may
0N/A // represent Java objects, or they might be free blocks in a
0N/A // free-list-based heap (or subheap), as long as the two kinds are
0N/A // distinguishable and the size of each is determinable.
0N/A
0N/A // Returns the address of the start of the "block" that contains the
0N/A // address "addr". We say "blocks" instead of "object" since some heaps
0N/A // may not pack objects densely; a chunk may either be an object or a
0N/A // non-object.
0N/A virtual HeapWord* block_start(const void* addr) const = 0;
0N/A
0N/A // Requires "addr" to be the start of a chunk, and returns its size.
0N/A // "addr + size" is required to be the start of a new chunk, or the end
0N/A // of the active area of the heap.
0N/A virtual size_t block_size(const HeapWord* addr) const = 0;
0N/A
0N/A // Requires "addr" to be the start of a block, and returns "TRUE" iff
0N/A // the block is an object.
0N/A virtual bool block_is_obj(const HeapWord* addr) const = 0;
0N/A
0N/A // Returns the longest time (in ms) that has elapsed since the last
0N/A // time that any part of the heap was examined by a garbage collection.
0N/A virtual jlong millis_since_last_gc() = 0;
0N/A
0N/A // Perform any cleanup actions necessary before allowing a verification.
0N/A virtual void prepare_for_verify() = 0;
0N/A
615N/A // Generate any dumps preceding or following a full gc
615N/A void pre_full_gc_dump();
615N/A void post_full_gc_dump();
615N/A
0N/A virtual void print() const = 0;
0N/A virtual void print_on(outputStream* st) const = 0;
0N/A
0N/A // Print all GC threads (other than the VM thread)
0N/A // used by this heap.
0N/A virtual void print_gc_threads_on(outputStream* st) const = 0;
0N/A void print_gc_threads() { print_gc_threads_on(tty); }
0N/A // Iterator for all GC threads (other than VM thread)
0N/A virtual void gc_threads_do(ThreadClosure* tc) const = 0;
0N/A
0N/A // Print any relevant tracing info that flags imply.
0N/A // Default implementation does nothing.
0N/A virtual void print_tracing_info() const = 0;
0N/A
0N/A // Heap verification
845N/A virtual void verify(bool allow_dirty, bool silent, bool option) = 0;
0N/A
0N/A // Non product verification and debugging.
0N/A#ifndef PRODUCT
0N/A // Support for PromotionFailureALot. Return true if it's time to cause a
0N/A // promotion failure. The no-argument version uses
0N/A // this->_promotion_failure_alot_count as the counter.
0N/A inline bool promotion_should_fail(volatile size_t* count);
0N/A inline bool promotion_should_fail();
0N/A
0N/A // Reset the PromotionFailureALot counters. Should be called at the end of a
0N/A // GC in which promotion failure ocurred.
0N/A inline void reset_promotion_should_fail(volatile size_t* count);
0N/A inline void reset_promotion_should_fail();
0N/A#endif // #ifndef PRODUCT
0N/A
0N/A#ifdef ASSERT
0N/A static int fired_fake_oom() {
0N/A return (CIFireOOMAt > 1 && _fire_out_of_memory_count >= CIFireOOMAt);
0N/A }
0N/A#endif
1753N/A
1753N/A public:
1753N/A // This is a convenience method that is used in cases where
1753N/A // the actual number of GC worker threads is not pertinent but
1753N/A // only whether there more than 0. Use of this method helps
1753N/A // reduce the occurrence of ParallelGCThreads to uses where the
1753N/A // actual number may be germane.
1753N/A static bool use_parallel_gc_threads() { return ParallelGCThreads > 0; }
0N/A};
0N/A
0N/A// Class to set and reset the GC cause for a CollectedHeap.
0N/A
0N/Aclass GCCauseSetter : StackObj {
0N/A CollectedHeap* _heap;
0N/A GCCause::Cause _previous_cause;
0N/A public:
0N/A GCCauseSetter(CollectedHeap* heap, GCCause::Cause cause) {
0N/A assert(SafepointSynchronize::is_at_safepoint(),
0N/A "This method manipulates heap state without locking");
0N/A _heap = heap;
0N/A _previous_cause = _heap->gc_cause();
0N/A _heap->set_gc_cause(cause);
0N/A }
0N/A
0N/A ~GCCauseSetter() {
0N/A assert(SafepointSynchronize::is_at_safepoint(),
0N/A "This method manipulates heap state without locking");
0N/A _heap->set_gc_cause(_previous_cause);
0N/A }
0N/A};