collectedHeap.hpp revision 3157
0N/A/*
1753N/A * Copyright (c) 2001, 2012, 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
1879N/A#ifndef SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_HPP
1879N/A#define SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_HPP
1879N/A
1879N/A#include "gc_interface/gcCause.hpp"
1879N/A#include "memory/allocation.hpp"
1879N/A#include "memory/barrierSet.hpp"
1879N/A#include "runtime/handles.hpp"
1879N/A#include "runtime/perfData.hpp"
1879N/A#include "runtime/safepoint.hpp"
1879N/A#include "utilities/events.hpp"
1879N/A
1879N/A// A "CollectedHeap" is an implementation of a java heap for HotSpot. This
1879N/A// is an abstract class: there may be many different kinds of heaps. This
1879N/A// class defines the functions that a heap must implement, and contains
1879N/A// infrastructure common to all heaps.
1879N/A
1879N/Aclass BarrierSet;
0N/Aclass ThreadClosure;
0N/Aclass AdaptiveSizePolicy;
0N/Aclass Thread;
0N/Aclass CollectorPolicy;
0N/A
0N/Aclass GCMessage : public FormatBuffer<1024> {
481N/A public:
481N/A bool is_before;
0N/A
0N/A public:
1753N/A GCMessage() {}
1753N/A};
1753N/A
481N/Aclass GCHeapLog : public EventLogBase<GCMessage> {
481N/A private:
481N/A void log_heap(bool before);
481N/A
481N/A public:
481N/A GCHeapLog() : EventLogBase<GCMessage>("GC Heap History") {}
481N/A
481N/A void log_heap_before() {
481N/A log_heap(true);
481N/A }
0N/A void log_heap_after() {
0N/A log_heap(false);
0N/A }
0N/A};
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;
1166N/A friend class IsGCActiveMark; // Block structured external access to _is_gc_active
0N/A friend class constantPoolCacheKlass; // allocate() method inserts is_conc_safe
0N/A
1166N/A#ifdef ASSERT
1166N/A static int _fire_out_of_memory_count;
1166N/A#endif
1468N/A
1194N/A // Used for filler objects (static, but initialized in ctor).
1194N/A static size_t _filler_array_max_size;
1166N/A
1166N/A GCHeapLog* _gc_heap_log;
1166N/A
1166N/A // Used in support of ReduceInitialCardMarks; only consulted if COMPILER2 is being used
0N/A bool _defer_initial_card_mark;
0N/A
0N/A protected:
0N/A MemRegion _reserved;
0N/A BarrierSet* _barrier_set;
0N/A bool _is_gc_active;
0N/A uint _n_par_threads;
0N/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
0N/A // Do common initializations that must follow instance construction,
0N/A // for example, those needing virtual calls.
0N/A // This code could perhaps be moved into initialize() but would
0N/A // be slightly more awkward because we want the latter to be a
0N/A // pure virtual.
0N/A void pre_initialize();
0N/A
0N/A // Create a new tlab. All TLAB allocations must go through this.
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, 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, 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);
1027N/A
1027N/A // Filler object utilities.
1027N/A static inline size_t filler_array_hdr_size();
1166N/A static inline size_t filler_array_min_size();
1027N/A static inline size_t filler_array_max_size();
1027N/A
1027N/A DEBUG_ONLY(static void fill_args_check(HeapWord* start, size_t words);)
1027N/A DEBUG_ONLY(static void zap_filler_array(HeapWord* start, size_t words, bool zap = true);)
1027N/A
1166N/A // Fill with a single array; caller must ensure filler_array_min_size() <=
1027N/A // words <= filler_array_max_size().
1027N/A static inline void fill_with_array(HeapWord* start, size_t words, bool zap = true);
1027N/A
1027N/A // Fill with a single object (either an int array or a java.lang.Object).
1027N/A static inline void fill_with_object_impl(HeapWord* start, size_t words, bool zap = true);
1027N/A
1027N/A // Verification functions
1027N/A virtual void check_for_bad_heap_word_value(HeapWord* addr, size_t size)
1027N/A PRODUCT_RETURN;
1027N/A virtual void check_for_non_bad_heap_word_value(HeapWord* addr, size_t size)
1027N/A PRODUCT_RETURN;
1027N/A debug_only(static void check_for_valid_allocation_state();)
1027N/A
1027N/A public:
1027N/A enum Name {
1027N/A Abstract,
1027N/A SharedHeap,
1027N/A GenCollectedHeap,
1027N/A ParallelScavengeHeap,
1027N/A G1CollectedHeap
1027N/A };
1027N/A
1027N/A virtual CollectedHeap::Name kind() const { return CollectedHeap::Abstract; }
1027N/A
1027N/A /**
1027N/A * Returns JNI error code JNI_ENOMEM if memory could not be allocated,
1027N/A * and JNI_OK on success.
1027N/A */
1166N/A virtual jint initialize() = 0;
1027N/A
1027N/A // In many heaps, there will be a need to perform some initialization activities
1027N/A // after the Universe is fully formed, but before general heap allocation is allowed.
1027N/A // This is the correct place to place such initialization methods.
1027N/A virtual void post_initialize() = 0;
1027N/A
1027N/A MemRegion reserved_region() const { return _reserved; }
1027N/A address base() const { return (address)reserved_region().start(); }
1027N/A
1027N/A // Future cleanup here. The following functions should specify bytes or
1027N/A // heapwords as part of their signature.
1027N/A virtual size_t capacity() const = 0;
1027N/A virtual size_t used() const = 0;
1027N/A
1027N/A // Return "true" if the part of the heap that allocates Java
1027N/A // objects has reached the maximal committed limit that it can
1027N/A // reach, without a garbage collection.
1027N/A virtual bool is_maximal_no_gc() const = 0;
1027N/A
1027N/A virtual size_t permanent_capacity() const = 0;
1027N/A virtual size_t permanent_used() const = 0;
1027N/A
1166N/A // Support for java.lang.Runtime.maxMemory(): return the maximum amount of
1166N/A // memory that the vm could make available for storing 'normal' java objects.
1027N/A // This is based on the reserved address space, but should not include space
1166N/A // that the vm uses internally for bookkeeping or temporary storage (e.g.,
1166N/A // perm gen space or, in the case of the young gen, one of the survivor
1166N/A // spaces).
1166N/A virtual size_t max_capacity() const = 0;
1027N/A
1027N/A // Returns "TRUE" if "p" points into the reserved area of the heap.
1027N/A bool is_in_reserved(const void* p) const {
1027N/A return _reserved.contains(p);
1027N/A }
1027N/A
1027N/A bool is_in_reserved_or_null(const void* p) const {
1166N/A return p == NULL || is_in_reserved(p);
1166N/A }
1166N/A
1166N/A // Returns "TRUE" iff "p" points into the committed areas of the heap.
1166N/A // Since this method can be expensive in general, we restrict its
1166N/A // use to assertion checking only.
1166N/A virtual bool is_in(const void* p) const = 0;
1166N/A
1166N/A bool is_in_or_null(const void* p) const {
1166N/A return p == NULL || is_in(p);
1166N/A }
1027N/A
1027N/A // Let's define some terms: a "closed" subset of a heap is one that
1027N/A //
1027N/A // 1) contains all currently-allocated objects, and
481N/A //
1491N/A // 2) is closed under reference: no object in the closed subset
481N/A // references one outside the closed subset.
481N/A //
481N/A // Membership in a heap's closed subset is useful for assertions.
1491N/A // Clearly, the entire heap is a closed subset, so the default
481N/A // implementation is to use "is_in_reserved". But this may not be too
481N/A // liberal to perform useful checking. Also, the "is_in" predicate
481N/A // defines a closed subset, but may be too expensive, since "is_in"
481N/A // verifies that its argument points to an object head. The
481N/A // "closed_subset" method allows a heap to define an intermediate
481N/A // predicate, allowing more precise checking than "is_in_reserved" at
481N/A // lower cost than "is_in."
481N/A
481N/A // One important case is a heap composed of disjoint contiguous spaces,
481N/A // such as the Garbage-First collector. Such heaps have a convenient
481N/A // closed subset consisting of the allocated portions of those
481N/A // contiguous spaces.
481N/A
481N/A // Return "TRUE" iff the given pointer points into the heap's defined
481N/A // closed subset (which defaults to the entire heap).
1165N/A virtual bool is_in_closed_subset(const void* p) const {
481N/A return is_in_reserved(p);
1165N/A }
481N/A
481N/A bool is_in_closed_subset_or_null(const void* p) const {
481N/A return p == NULL || is_in_closed_subset(p);
481N/A }
481N/A
481N/A // XXX is_permanent() and is_in_permanent() should be better named
481N/A // to distinguish one from the other.
1165N/A
481N/A // Returns "TRUE" if "p" is allocated as "permanent" data.
481N/A // If the heap does not use "permanent" data, returns the same
481N/A // value is_in_reserved() would return.
481N/A // NOTE: this actually returns true if "p" is in reserved space
481N/A // for the space not that it is actually allocated (i.e. in committed
481N/A // space). If you need the more conservative answer use is_permanent().
481N/A virtual bool is_in_permanent(const void *p) const = 0;
481N/A
481N/A
494N/A#ifdef ASSERT
1165N/A // Returns true if "p" is in the part of the
481N/A // heap being collected.
481N/A virtual bool is_in_partial_collection(const void *p) = 0;
481N/A#endif
1165N/A
481N/A bool is_in_permanent_or_null(const void *p) const {
481N/A return p == NULL || is_in_permanent(p);
481N/A }
481N/A
1165N/A // Returns "TRUE" if "p" is in the committed area of "permanent" data.
481N/A // If the heap does not use "permanent" data, returns the same
481N/A // value is_in() would return.
1142N/A virtual bool is_permanent(const void *p) const = 0;
481N/A
481N/A bool is_permanent_or_null(const void *p) const {
481N/A return p == NULL || is_permanent(p);
481N/A }
1165N/A
481N/A // An object is scavengable if its location may move during a scavenge.
481N/A // (A scavenge is a GC which is not a full GC.)
481N/A virtual bool is_scavengable(const void *p) = 0;
1165N/A
481N/A // Returns "TRUE" if "p" is a method oop in the
481N/A // current heap, with high probability. This predicate
1165N/A // is not stable, in general.
481N/A bool is_valid_method(oop p) const;
481N/A
481N/A void set_gc_cause(GCCause::Cause v) {
481N/A if (UsePerfData) {
1469N/A _gc_lastcause = _gc_cause;
481N/A _perf_gc_lastcause->set_value(GCCause::to_string(_gc_lastcause));
481N/A _perf_gc_cause->set_value(GCCause::to_string(v));
481N/A }
481N/A _gc_cause = v;
481N/A }
481N/A GCCause::Cause gc_cause() { return _gc_cause; }
481N/A
1165N/A // Number of threads currently working on GC tasks.
481N/A uint n_par_threads() { return _n_par_threads; }
481N/A
481N/A // May be overridden to set additional parallelism.
481N/A virtual void set_par_threads(uint t) { _n_par_threads = t; };
481N/A
1165N/A // Preload classes into the shared portion of the heap, and then dump
481N/A // that data to a file so that it can be loaded directly by another
481N/A // VM (then terminate).
0N/A virtual void preload_and_dump(TRAPS) { ShouldNotReachHere(); }
0N/A
0N/A // Allocate and initialize instances of Class
0N/A static oop Class_obj_allocate(KlassHandle klass, int size, KlassHandle real_klass, TRAPS);
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 array_allocate_nozero(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
1166N/A // klass pointer.
1166N/A inline static oop permanent_obj_allocate_no_klass_install(KlassHandle klass,
1166N/A int size,
1166N/A TRAPS);
1166N/A inline static void post_allocation_install_obj_klass(KlassHandle klass,
1166N/A oop obj,
1166N/A int size);
1166N/A inline static oop permanent_array_allocate(KlassHandle klass, int size, int length, TRAPS);
1166N/A
1166N/A // Raw memory allocation facilities
1166N/A // The obj and array allocate methods are covers for these methods.
1166N/A // The permanent allocation method should default to mem_allocate if
1166N/A // permanent memory isn't supported. mem_allocate() should never be
1166N/A // called to allocate TLABs, only individual objects.
1166N/A virtual HeapWord* mem_allocate(size_t size,
1166N/A bool* gc_overhead_limit_was_exceeded) = 0;
1166N/A virtual HeapWord* permanent_mem_allocate(size_t size) = 0;
1166N/A
0N/A // Utilities for turning raw memory into filler objects.
0N/A //
0N/A // min_fill_size() is the smallest region that can be filled.
0N/A // fill_with_objects() can fill arbitrary-sized regions of the heap using
0N/A // multiple objects. fill_with_object() is for regions known to be smaller
0N/A // than the largest array of integers; it uses a single object to fill the
0N/A // region and has slightly less overhead.
0N/A static size_t min_fill_size() {
0N/A return size_t(align_object_size(oopDesc::header_size()));
0N/A }
0N/A
0N/A static void fill_with_objects(HeapWord* start, size_t words, bool zap = true);
0N/A
0N/A static void fill_with_object(HeapWord* start, size_t words, bool zap = true);
0N/A static void fill_with_object(MemRegion region, bool zap = true) {
0N/A fill_with_object(region.start(), region.word_size(), zap);
0N/A }
0N/A static void fill_with_object(HeapWord* start, HeapWord* end, bool zap = true) {
0N/A fill_with_object(start, pointer_delta(end, start), zap);
0N/A }
0N/A
0N/A // Some heaps may offer a contiguous region for shared non-blocking
615N/A // allocation, via inlined code (by exporting the address of the top and
615N/A // end fields defining the extent of the contiguous allocation region.)
615N/A
615N/A // This function returns "true" iff the heap supports this kind of
615N/A // allocation. (Default is "no".)
615N/A virtual bool supports_inline_contig_alloc() const {
615N/A return false;
615N/A }
615N/A // These functions return the addresses of the fields that define the
615N/A // boundaries of the contiguous allocation area. (These fields should be
615N/A // physically near to one another.)
615N/A virtual HeapWord** top_addr() const {
615N/A guarantee(false, "inline contiguous allocation not supported");
615N/A return NULL;
615N/A }
615N/A virtual HeapWord** end_addr() const {
615N/A guarantee(false, "inline contiguous allocation not supported");
615N/A return NULL;
615N/A }
615N/A
615N/A // Some heaps may be in an unparseable state at certain times between
615N/A // collections. This may be necessary for efficient implementation of
615N/A // certain allocation-related activities. Calling this function before
615N/A // attempting to parse a heap ensures that the heap is in a parsable
615N/A // state (provided other concurrent activity does not introduce
615N/A // unparsability). It is normally expected, therefore, that this
// method is invoked with the world stopped.
// NOTE: if you override this method, make sure you call
// super::ensure_parsability so that the non-generational
// part of the work gets done. See implementation of
// CollectedHeap::ensure_parsability and, for instance,
// that of GenCollectedHeap::ensure_parsability().
// The argument "retire_tlabs" controls whether existing TLABs
// are merely filled or also retired, thus preventing further
// allocation from them and necessitating allocation of new TLABs.
virtual void ensure_parsability(bool retire_tlabs);
// Return an estimate of the maximum allocation that could be performed
// without triggering any collection or expansion activity. In a
// generational collector, for example, this is probably the largest
// allocation that could be supported (without expansion) in the youngest
// generation. It is "unsafe" because no locks are taken; the result
// should be treated as an approximation, not a guarantee, for use in
// heuristic resizing decisions.
virtual size_t unsafe_max_alloc() = 0;
// Section on thread-local allocation buffers (TLABs)
// If the heap supports thread-local allocation buffers, it should override
// the following methods:
// Returns "true" iff the heap supports thread-local allocation buffers.
// The default is "no".
virtual bool supports_tlab_allocation() const {
return false;
}
// The amount of space available for thread-local allocation buffers.
virtual size_t tlab_capacity(Thread *thr) const {
guarantee(false, "thread-local allocation buffers not supported");
return 0;
}
// An estimate of the maximum allocation that could be performed
// for thread-local allocation buffers without triggering any
// collection or expansion activity.
virtual size_t unsafe_max_tlab_alloc(Thread *thr) const {
guarantee(false, "thread-local allocation buffers not supported");
return 0;
}
// Can a compiler initialize a new object without store barriers?
// This permission only extends from the creation of a new object
// via a TLAB up to the first subsequent safepoint. If such permission
// is granted for this heap type, the compiler promises to call
// defer_store_barrier() below on any slow path allocation of
// a new object for which such initializing store barriers will
// have been elided.
virtual bool can_elide_tlab_store_barriers() const = 0;
// If a compiler is eliding store barriers for TLAB-allocated objects,
// there is probably a corresponding slow path which can produce
// an object allocated anywhere. The compiler's runtime support
// promises to call this function on such a slow-path-allocated
// object before performing initializations that have elided
// store barriers. Returns new_obj, or maybe a safer copy thereof.
virtual oop new_store_pre_barrier(JavaThread* thread, oop new_obj);
// Answers whether an initializing store to a new object currently
// allocated at the given address doesn't need a store
// barrier. Returns "true" if it doesn't need an initializing
// store barrier; answers "false" if it does.
virtual bool can_elide_initializing_store_barrier(oop new_obj) = 0;
// If a compiler is eliding store barriers for TLAB-allocated objects,
// we will be informed of a slow-path allocation by a call
// to new_store_pre_barrier() above. Such a call precedes the
// initialization of the object itself, and no post-store-barriers will
// be issued. Some heap types require that the barrier strictly follows
// the initializing stores. (This is currently implemented by deferring the
// barrier until the next slow-path allocation or gc-related safepoint.)
// This interface answers whether a particular heap type needs the card
// mark to be thus strictly sequenced after the stores.
virtual bool card_mark_must_follow_store() const = 0;
// If the CollectedHeap was asked to defer a store barrier above,
// this informs it to flush such a deferred store barrier to the
// remembered set.
virtual void flush_deferred_store_barrier(JavaThread* thread);
// Can a compiler elide a store barrier when it writes
// a permanent oop into the heap? Applies when the compiler
// is storing x to the heap, where x->is_perm() is true.
virtual bool can_elide_permanent_oop_store_barriers() const = 0;
// Does this heap support heap inspection (+PrintClassHistogram?)
virtual bool supports_heap_inspection() const = 0;
// Perform a collection of the heap; intended for use in implementing
// "System.gc". This probably implies as full a collection as the
// "CollectedHeap" supports.
virtual void collect(GCCause::Cause cause) = 0;
// This interface assumes that it's being called by the
// vm thread. It collects the heap assuming that the
// heap lock is already held and that we are executing in
// the context of the vm thread.
virtual void collect_as_vm_thread(GCCause::Cause cause) = 0;
// Returns the barrier set for this heap
BarrierSet* barrier_set() { return _barrier_set; }
// Returns "true" iff there is a stop-world GC in progress. (I assume
// that it should answer "false" for the concurrent part of a concurrent
// collector -- dld).
bool is_gc_active() const { return _is_gc_active; }
// Total number of GC collections (started)
unsigned int total_collections() const { return _total_collections; }
unsigned int total_full_collections() const { return _total_full_collections;}
// Increment total number of GC collections (started)
// Should be protected but used by PSMarkSweep - cleanup for 1.4.2
void increment_total_collections(bool full = false) {
_total_collections++;
if (full) {
increment_total_full_collections();
}
}
void increment_total_full_collections() { _total_full_collections++; }
// Return the AdaptiveSizePolicy for the heap.
virtual AdaptiveSizePolicy* size_policy() = 0;
// Return the CollectorPolicy for the heap
virtual CollectorPolicy* collector_policy() const = 0;
// Iterate over all the ref-containing fields of all objects, calling
// "cl.do_oop" on each. This includes objects in permanent memory.
virtual void oop_iterate(OopClosure* cl) = 0;
// Iterate over all objects, calling "cl.do_object" on each.
// This includes objects in permanent memory.
virtual void object_iterate(ObjectClosure* cl) = 0;
// Similar to object_iterate() except iterates only
// over live objects.
virtual void safe_object_iterate(ObjectClosure* cl) = 0;
// Behaves the same as oop_iterate, except only traverses
// interior pointers contained in permanent memory. If there
// is no permanent memory, does nothing.
virtual void permanent_oop_iterate(OopClosure* cl) = 0;
// Behaves the same as object_iterate, except only traverses
// object contained in permanent memory. If there is no
// permanent memory, does nothing.
virtual void permanent_object_iterate(ObjectClosure* cl) = 0;
// NOTE! There is no requirement that a collector implement these
// functions.
//
// A CollectedHeap is divided into a dense sequence of "blocks"; that is,
// each address in the (reserved) heap is a member of exactly
// one block. The defining characteristic of a block is that it is
// possible to find its size, and thus to progress forward to the next
// block. (Blocks may be of different sizes.) Thus, blocks may
// represent Java objects, or they might be free blocks in a
// free-list-based heap (or subheap), as long as the two kinds are
// distinguishable and the size of each is determinable.
// Returns the address of the start of the "block" that contains the
// address "addr". We say "blocks" instead of "object" since some heaps
// may not pack objects densely; a chunk may either be an object or a
// non-object.
virtual HeapWord* block_start(const void* addr) const = 0;
// Requires "addr" to be the start of a chunk, and returns its size.
// "addr + size" is required to be the start of a new chunk, or the end
// of the active area of the heap.
virtual size_t block_size(const HeapWord* addr) const = 0;
// Requires "addr" to be the start of a block, and returns "TRUE" iff
// the block is an object.
virtual bool block_is_obj(const HeapWord* addr) const = 0;
// Returns the longest time (in ms) that has elapsed since the last
// time that any part of the heap was examined by a garbage collection.
virtual jlong millis_since_last_gc() = 0;
// Perform any cleanup actions necessary before allowing a verification.
virtual void prepare_for_verify() = 0;
// Generate any dumps preceding or following a full gc
void pre_full_gc_dump();
void post_full_gc_dump();
// Print heap information on the given outputStream.
virtual void print_on(outputStream* st) const = 0;
// The default behavior is to call print_on() on tty.
virtual void print() const {
print_on(tty);
}
// Print more detailed heap information on the given
// outputStream. The default behaviour is to call print_on(). It is
// up to each subclass to override it and add any additional output
// it needs.
virtual void print_extended_on(outputStream* st) const {
print_on(st);
}
// Print all GC threads (other than the VM thread)
// used by this heap.
virtual void print_gc_threads_on(outputStream* st) const = 0;
// The default behavior is to call print_gc_threads_on() on tty.
void print_gc_threads() {
print_gc_threads_on(tty);
}
// Iterator for all GC threads (other than VM thread)
virtual void gc_threads_do(ThreadClosure* tc) const = 0;
// Print any relevant tracing info that flags imply.
// Default implementation does nothing.
virtual void print_tracing_info() const = 0;
// If PrintHeapAtGC is set call the appropriate routi
void print_heap_before_gc() {
if (PrintHeapAtGC) {
Universe::print_heap_before_gc();
}
if (_gc_heap_log != NULL) {
_gc_heap_log->log_heap_before();
}
}
void print_heap_after_gc() {
if (PrintHeapAtGC) {
Universe::print_heap_after_gc();
}
if (_gc_heap_log != NULL) {
_gc_heap_log->log_heap_after();
}
}
// Allocate GCHeapLog during VM startup
static void initialize_heap_log();
// Heap verification
virtual void verify(bool allow_dirty, bool silent, VerifyOption option) = 0;
// Non product verification and debugging.
#ifndef PRODUCT
// Support for PromotionFailureALot. Return true if it's time to cause a
// promotion failure. The no-argument version uses
// this->_promotion_failure_alot_count as the counter.
inline bool promotion_should_fail(volatile size_t* count);
inline bool promotion_should_fail();
// Reset the PromotionFailureALot counters. Should be called at the end of a
// GC in which promotion failure ocurred.
inline void reset_promotion_should_fail(volatile size_t* count);
inline void reset_promotion_should_fail();
#endif // #ifndef PRODUCT
#ifdef ASSERT
static int fired_fake_oom() {
return (CIFireOOMAt > 1 && _fire_out_of_memory_count >= CIFireOOMAt);
}
#endif
public:
// This is a convenience method that is used in cases where
// the actual number of GC worker threads is not pertinent but
// only whether there more than 0. Use of this method helps
// reduce the occurrence of ParallelGCThreads to uses where the
// actual number may be germane.
static bool use_parallel_gc_threads() { return ParallelGCThreads > 0; }
/////////////// Unit tests ///////////////
NOT_PRODUCT(static void test_is_in();)
};
// Class to set and reset the GC cause for a CollectedHeap.
class GCCauseSetter : StackObj {
CollectedHeap* _heap;
GCCause::Cause _previous_cause;
public:
GCCauseSetter(CollectedHeap* heap, GCCause::Cause cause) {
assert(SafepointSynchronize::is_at_safepoint(),
"This method manipulates heap state without locking");
_heap = heap;
_previous_cause = _heap->gc_cause();
_heap->set_gc_cause(cause);
}
~GCCauseSetter() {
assert(SafepointSynchronize::is_at_safepoint(),
"This method manipulates heap state without locking");
_heap->set_gc_cause(_previous_cause);
}
};
#endif // SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_HPP