duke@435: /* coleenp@6626: * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_HPP stefank@2314: #define SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_HPP stefank@2314: stefank@2314: #include "gc_interface/gcCause.hpp" sla@5237: #include "gc_implementation/shared/gcWhen.hpp" stefank@2314: #include "memory/allocation.hpp" stefank@2314: #include "memory/barrierSet.hpp" stefank@2314: #include "runtime/handles.hpp" stefank@2314: #include "runtime/perfData.hpp" stefank@2314: #include "runtime/safepoint.hpp" never@3499: #include "utilities/events.hpp" stefank@2314: duke@435: // A "CollectedHeap" is an implementation of a java heap for HotSpot. This duke@435: // is an abstract class: there may be many different kinds of heaps. This duke@435: // class defines the functions that a heap must implement, and contains duke@435: // infrastructure common to all heaps. duke@435: sla@5237: class AdaptiveSizePolicy; duke@435: class BarrierSet; sla@5237: class CollectorPolicy; sla@5237: class GCHeapSummary; sla@5237: class GCTimer; sla@5237: class GCTracer; sla@5237: class MetaspaceSummary; sla@5237: class Thread; duke@435: class ThreadClosure; sla@5237: class VirtualSpaceSummary; johnc@5548: class nmethod; duke@435: never@3499: class GCMessage : public FormatBuffer<1024> { never@3499: public: never@3499: bool is_before; never@3499: never@3499: public: never@3499: GCMessage() {} never@3499: }; never@3499: never@3499: class GCHeapLog : public EventLogBase { never@3499: private: never@3499: void log_heap(bool before); never@3499: never@3499: public: never@3499: GCHeapLog() : EventLogBase("GC Heap History") {} never@3499: never@3499: void log_heap_before() { never@3499: log_heap(true); never@3499: } never@3499: void log_heap_after() { never@3499: log_heap(false); never@3499: } never@3499: }; never@3499: duke@435: // duke@435: // CollectedHeap duke@435: // SharedHeap duke@435: // GenCollectedHeap duke@435: // G1CollectedHeap duke@435: // ParallelScavengeHeap duke@435: // zgu@3900: class CollectedHeap : public CHeapObj { duke@435: friend class VMStructs; duke@435: friend class IsGCActiveMark; // Block structured external access to _is_gc_active duke@435: duke@435: #ifdef ASSERT duke@435: static int _fire_out_of_memory_count; duke@435: #endif duke@435: jcoomes@916: // Used for filler objects (static, but initialized in ctor). jcoomes@916: static size_t _filler_array_max_size; jcoomes@916: never@3499: GCHeapLog* _gc_heap_log; never@3499: ysr@1601: // Used in support of ReduceInitialCardMarks; only consulted if COMPILER2 is being used ysr@1601: bool _defer_initial_card_mark; ysr@1601: duke@435: protected: duke@435: MemRegion _reserved; duke@435: BarrierSet* _barrier_set; duke@435: bool _is_gc_active; jmasa@3357: uint _n_par_threads; jmasa@2188: duke@435: unsigned int _total_collections; // ... started duke@435: unsigned int _total_full_collections; // ... started duke@435: NOT_PRODUCT(volatile size_t _promotion_failure_alot_count;) duke@435: NOT_PRODUCT(volatile size_t _promotion_failure_alot_gc_number;) duke@435: duke@435: // Reason for current garbage collection. Should be set to duke@435: // a value reflecting no collection between collections. duke@435: GCCause::Cause _gc_cause; duke@435: GCCause::Cause _gc_lastcause; duke@435: PerfStringVariable* _perf_gc_cause; duke@435: PerfStringVariable* _perf_gc_lastcause; duke@435: duke@435: // Constructor duke@435: CollectedHeap(); duke@435: ysr@1601: // Do common initializations that must follow instance construction, ysr@1601: // for example, those needing virtual calls. ysr@1601: // This code could perhaps be moved into initialize() but would ysr@1601: // be slightly more awkward because we want the latter to be a ysr@1601: // pure virtual. ysr@1601: void pre_initialize(); ysr@1601: tonyp@2971: // Create a new tlab. All TLAB allocations must go through this. duke@435: virtual HeapWord* allocate_new_tlab(size_t size); duke@435: duke@435: // Accumulate statistics on all tlabs. duke@435: virtual void accumulate_statistics_all_tlabs(); duke@435: duke@435: // Reinitialize tlabs before resuming mutators. duke@435: virtual void resize_all_tlabs(); duke@435: duke@435: // Allocate from the current thread's TLAB, with broken-out slow path. sla@5237: inline static HeapWord* allocate_from_tlab(KlassHandle klass, Thread* thread, size_t size); sla@5237: static HeapWord* allocate_from_tlab_slow(KlassHandle klass, Thread* thread, size_t size); duke@435: duke@435: // Allocate an uninitialized block of the given size, or returns NULL if duke@435: // this is impossible. sla@5237: inline static HeapWord* common_mem_allocate_noinit(KlassHandle klass, size_t size, TRAPS); duke@435: duke@435: // Like allocate_init, but the block returned by a successful allocation duke@435: // is guaranteed initialized to zeros. sla@5237: inline static HeapWord* common_mem_allocate_init(KlassHandle klass, size_t size, TRAPS); duke@435: duke@435: // Helper functions for (VM) allocation. brutisso@3675: inline static void post_allocation_setup_common(KlassHandle klass, HeapWord* obj); duke@435: inline static void post_allocation_setup_no_klass_install(KlassHandle klass, brutisso@3675: HeapWord* objPtr); duke@435: coleenp@6627: inline static void post_allocation_setup_obj(KlassHandle klass, HeapWord* obj, int size); duke@435: duke@435: inline static void post_allocation_setup_array(KlassHandle klass, brutisso@3675: HeapWord* obj, int length); duke@435: duke@435: // Clears an allocated object. duke@435: inline static void init_obj(HeapWord* obj, size_t size); duke@435: jcoomes@916: // Filler object utilities. jcoomes@916: static inline size_t filler_array_hdr_size(); jcoomes@916: static inline size_t filler_array_min_size(); jcoomes@916: jcoomes@916: DEBUG_ONLY(static void fill_args_check(HeapWord* start, size_t words);) johnc@1600: DEBUG_ONLY(static void zap_filler_array(HeapWord* start, size_t words, bool zap = true);) jcoomes@916: jcoomes@916: // Fill with a single array; caller must ensure filler_array_min_size() <= jcoomes@916: // words <= filler_array_max_size(). johnc@1600: static inline void fill_with_array(HeapWord* start, size_t words, bool zap = true); jcoomes@916: jcoomes@916: // Fill with a single object (either an int array or a java.lang.Object). johnc@1600: static inline void fill_with_object_impl(HeapWord* start, size_t words, bool zap = true); jcoomes@916: sla@5237: virtual void trace_heap(GCWhen::Type when, GCTracer* tracer); sla@5237: duke@435: // Verification functions duke@435: virtual void check_for_bad_heap_word_value(HeapWord* addr, size_t size) duke@435: PRODUCT_RETURN; duke@435: virtual void check_for_non_bad_heap_word_value(HeapWord* addr, size_t size) duke@435: PRODUCT_RETURN; jmasa@977: debug_only(static void check_for_valid_allocation_state();) duke@435: duke@435: public: duke@435: enum Name { duke@435: Abstract, duke@435: SharedHeap, duke@435: GenCollectedHeap, duke@435: ParallelScavengeHeap, duke@435: G1CollectedHeap duke@435: }; duke@435: brutisso@3668: static inline size_t filler_array_max_size() { brutisso@3668: return _filler_array_max_size; brutisso@3668: } brutisso@3668: duke@435: virtual CollectedHeap::Name kind() const { return CollectedHeap::Abstract; } duke@435: duke@435: /** duke@435: * Returns JNI error code JNI_ENOMEM if memory could not be allocated, duke@435: * and JNI_OK on success. duke@435: */ duke@435: virtual jint initialize() = 0; duke@435: duke@435: // In many heaps, there will be a need to perform some initialization activities duke@435: // after the Universe is fully formed, but before general heap allocation is allowed. duke@435: // This is the correct place to place such initialization methods. duke@435: virtual void post_initialize() = 0; duke@435: pliden@6690: // Stop any onging concurrent work and prepare for exit. pliden@6690: virtual void stop() {} pliden@6690: duke@435: MemRegion reserved_region() const { return _reserved; } coleenp@548: address base() const { return (address)reserved_region().start(); } duke@435: duke@435: virtual size_t capacity() const = 0; duke@435: virtual size_t used() const = 0; duke@435: duke@435: // Return "true" if the part of the heap that allocates Java duke@435: // objects has reached the maximal committed limit that it can duke@435: // reach, without a garbage collection. duke@435: virtual bool is_maximal_no_gc() const = 0; duke@435: duke@435: // Support for java.lang.Runtime.maxMemory(): return the maximum amount of duke@435: // memory that the vm could make available for storing 'normal' java objects. duke@435: // This is based on the reserved address space, but should not include space coleenp@4037: // that the vm uses internally for bookkeeping or temporary storage coleenp@4037: // (e.g., in the case of the young gen, one of the survivor duke@435: // spaces). duke@435: virtual size_t max_capacity() const = 0; duke@435: duke@435: // Returns "TRUE" if "p" points into the reserved area of the heap. duke@435: bool is_in_reserved(const void* p) const { duke@435: return _reserved.contains(p); duke@435: } duke@435: duke@435: bool is_in_reserved_or_null(const void* p) const { duke@435: return p == NULL || is_in_reserved(p); duke@435: } duke@435: stefank@3335: // Returns "TRUE" iff "p" points into the committed areas of the heap. stefank@3335: // Since this method can be expensive in general, we restrict its duke@435: // use to assertion checking only. duke@435: virtual bool is_in(const void* p) const = 0; duke@435: duke@435: bool is_in_or_null(const void* p) const { duke@435: return p == NULL || is_in(p); duke@435: } duke@435: coleenp@4037: bool is_in_place(Metadata** p) { coleenp@4037: return !Universe::heap()->is_in(p); coleenp@4037: } coleenp@4037: bool is_in_place(oop* p) { return Universe::heap()->is_in(p); } coleenp@4037: bool is_in_place(narrowOop* p) { coleenp@4037: oop o = oopDesc::load_decode_heap_oop_not_null(p); coleenp@4037: return Universe::heap()->is_in((const void*)o); coleenp@4037: } coleenp@4037: duke@435: // Let's define some terms: a "closed" subset of a heap is one that duke@435: // duke@435: // 1) contains all currently-allocated objects, and duke@435: // duke@435: // 2) is closed under reference: no object in the closed subset duke@435: // references one outside the closed subset. duke@435: // duke@435: // Membership in a heap's closed subset is useful for assertions. duke@435: // Clearly, the entire heap is a closed subset, so the default duke@435: // implementation is to use "is_in_reserved". But this may not be too duke@435: // liberal to perform useful checking. Also, the "is_in" predicate duke@435: // defines a closed subset, but may be too expensive, since "is_in" duke@435: // verifies that its argument points to an object head. The duke@435: // "closed_subset" method allows a heap to define an intermediate duke@435: // predicate, allowing more precise checking than "is_in_reserved" at duke@435: // lower cost than "is_in." duke@435: duke@435: // One important case is a heap composed of disjoint contiguous spaces, duke@435: // such as the Garbage-First collector. Such heaps have a convenient duke@435: // closed subset consisting of the allocated portions of those duke@435: // contiguous spaces. duke@435: duke@435: // Return "TRUE" iff the given pointer points into the heap's defined duke@435: // closed subset (which defaults to the entire heap). duke@435: virtual bool is_in_closed_subset(const void* p) const { duke@435: return is_in_reserved(p); duke@435: } duke@435: duke@435: bool is_in_closed_subset_or_null(const void* p) const { duke@435: return p == NULL || is_in_closed_subset(p); duke@435: } duke@435: jmasa@2909: #ifdef ASSERT jmasa@2909: // Returns true if "p" is in the part of the jmasa@2909: // heap being collected. jmasa@2909: virtual bool is_in_partial_collection(const void *p) = 0; jmasa@2909: #endif jmasa@2909: jrose@1424: // An object is scavengable if its location may move during a scavenge. jrose@1424: // (A scavenge is a GC which is not a full GC.) jmasa@2909: virtual bool is_scavengable(const void *p) = 0; jrose@1424: duke@435: void set_gc_cause(GCCause::Cause v) { duke@435: if (UsePerfData) { duke@435: _gc_lastcause = _gc_cause; duke@435: _perf_gc_lastcause->set_value(GCCause::to_string(_gc_lastcause)); duke@435: _perf_gc_cause->set_value(GCCause::to_string(v)); duke@435: } duke@435: _gc_cause = v; duke@435: } duke@435: GCCause::Cause gc_cause() { return _gc_cause; } duke@435: jmasa@2188: // Number of threads currently working on GC tasks. jmasa@3357: uint n_par_threads() { return _n_par_threads; } jmasa@2188: jmasa@2188: // May be overridden to set additional parallelism. jmasa@3357: virtual void set_par_threads(uint t) { _n_par_threads = t; }; jmasa@2188: duke@435: // General obj/array allocation facilities. duke@435: inline static oop obj_allocate(KlassHandle klass, int size, TRAPS); duke@435: inline static oop array_allocate(KlassHandle klass, int size, int length, TRAPS); kvn@3157: inline static oop array_allocate_nozero(KlassHandle klass, int size, int length, TRAPS); duke@435: coleenp@4037: inline static void post_allocation_install_obj_klass(KlassHandle klass, coleenp@4037: oop obj); duke@435: duke@435: // Raw memory allocation facilities duke@435: // The obj and array allocate methods are covers for these methods. coleenp@4037: // mem_allocate() should never be tonyp@2971: // called to allocate TLABs, only individual objects. duke@435: virtual HeapWord* mem_allocate(size_t size, duke@435: bool* gc_overhead_limit_was_exceeded) = 0; duke@435: jcoomes@916: // Utilities for turning raw memory into filler objects. jcoomes@916: // jcoomes@916: // min_fill_size() is the smallest region that can be filled. jcoomes@916: // fill_with_objects() can fill arbitrary-sized regions of the heap using jcoomes@916: // multiple objects. fill_with_object() is for regions known to be smaller jcoomes@916: // than the largest array of integers; it uses a single object to fill the jcoomes@916: // region and has slightly less overhead. jcoomes@916: static size_t min_fill_size() { jcoomes@916: return size_t(align_object_size(oopDesc::header_size())); jcoomes@916: } jcoomes@916: johnc@1600: static void fill_with_objects(HeapWord* start, size_t words, bool zap = true); jcoomes@916: johnc@1600: static void fill_with_object(HeapWord* start, size_t words, bool zap = true); johnc@1600: static void fill_with_object(MemRegion region, bool zap = true) { johnc@1600: fill_with_object(region.start(), region.word_size(), zap); jcoomes@916: } johnc@1600: static void fill_with_object(HeapWord* start, HeapWord* end, bool zap = true) { johnc@1600: fill_with_object(start, pointer_delta(end, start), zap); jcoomes@916: } jcoomes@916: jmasa@7031: // Return the address "addr" aligned by "alignment_in_bytes" if such jmasa@7031: // an address is below "end". Return NULL otherwise. jmasa@7031: inline static HeapWord* align_allocation_or_fail(HeapWord* addr, jmasa@7031: HeapWord* end, jmasa@7031: unsigned short alignment_in_bytes); jmasa@7031: duke@435: // Some heaps may offer a contiguous region for shared non-blocking duke@435: // allocation, via inlined code (by exporting the address of the top and duke@435: // end fields defining the extent of the contiguous allocation region.) duke@435: duke@435: // This function returns "true" iff the heap supports this kind of duke@435: // allocation. (Default is "no".) duke@435: virtual bool supports_inline_contig_alloc() const { duke@435: return false; duke@435: } duke@435: // These functions return the addresses of the fields that define the duke@435: // boundaries of the contiguous allocation area. (These fields should be duke@435: // physically near to one another.) duke@435: virtual HeapWord** top_addr() const { duke@435: guarantee(false, "inline contiguous allocation not supported"); duke@435: return NULL; duke@435: } duke@435: virtual HeapWord** end_addr() const { duke@435: guarantee(false, "inline contiguous allocation not supported"); duke@435: return NULL; duke@435: } duke@435: duke@435: // Some heaps may be in an unparseable state at certain times between duke@435: // collections. This may be necessary for efficient implementation of duke@435: // certain allocation-related activities. Calling this function before duke@435: // attempting to parse a heap ensures that the heap is in a parsable duke@435: // state (provided other concurrent activity does not introduce duke@435: // unparsability). It is normally expected, therefore, that this duke@435: // method is invoked with the world stopped. duke@435: // NOTE: if you override this method, make sure you call duke@435: // super::ensure_parsability so that the non-generational duke@435: // part of the work gets done. See implementation of duke@435: // CollectedHeap::ensure_parsability and, for instance, duke@435: // that of GenCollectedHeap::ensure_parsability(). duke@435: // The argument "retire_tlabs" controls whether existing TLABs duke@435: // are merely filled or also retired, thus preventing further duke@435: // allocation from them and necessitating allocation of new TLABs. duke@435: virtual void ensure_parsability(bool retire_tlabs); duke@435: duke@435: // Section on thread-local allocation buffers (TLABs) duke@435: // If the heap supports thread-local allocation buffers, it should override duke@435: // the following methods: duke@435: // Returns "true" iff the heap supports thread-local allocation buffers. duke@435: // The default is "no". brutisso@6376: virtual bool supports_tlab_allocation() const = 0; brutisso@6376: duke@435: // The amount of space available for thread-local allocation buffers. brutisso@6376: virtual size_t tlab_capacity(Thread *thr) const = 0; brutisso@6376: brutisso@6376: // The amount of used space for thread-local allocation buffers for the given thread. brutisso@6376: virtual size_t tlab_used(Thread *thr) const = 0; brutisso@6376: brutisso@6376: virtual size_t max_tlab_size() const; brutisso@6376: duke@435: // An estimate of the maximum allocation that could be performed duke@435: // for thread-local allocation buffers without triggering any duke@435: // collection or expansion activity. duke@435: virtual size_t unsafe_max_tlab_alloc(Thread *thr) const { duke@435: guarantee(false, "thread-local allocation buffers not supported"); duke@435: return 0; duke@435: } ysr@1462: duke@435: // Can a compiler initialize a new object without store barriers? duke@435: // This permission only extends from the creation of a new object ysr@1462: // via a TLAB up to the first subsequent safepoint. If such permission ysr@1462: // is granted for this heap type, the compiler promises to call ysr@1462: // defer_store_barrier() below on any slow path allocation of ysr@1462: // a new object for which such initializing store barriers will ysr@1462: // have been elided. ysr@777: virtual bool can_elide_tlab_store_barriers() const = 0; ysr@777: duke@435: // If a compiler is eliding store barriers for TLAB-allocated objects, duke@435: // there is probably a corresponding slow path which can produce duke@435: // an object allocated anywhere. The compiler's runtime support duke@435: // promises to call this function on such a slow-path-allocated duke@435: // object before performing initializations that have elided ysr@1462: // store barriers. Returns new_obj, or maybe a safer copy thereof. ysr@1601: virtual oop new_store_pre_barrier(JavaThread* thread, oop new_obj); ysr@1462: ysr@1462: // Answers whether an initializing store to a new object currently ysr@1601: // allocated at the given address doesn't need a store ysr@1462: // barrier. Returns "true" if it doesn't need an initializing ysr@1462: // store barrier; answers "false" if it does. ysr@1462: virtual bool can_elide_initializing_store_barrier(oop new_obj) = 0; ysr@1462: ysr@1601: // If a compiler is eliding store barriers for TLAB-allocated objects, ysr@1601: // we will be informed of a slow-path allocation by a call ysr@1601: // to new_store_pre_barrier() above. Such a call precedes the ysr@1601: // initialization of the object itself, and no post-store-barriers will ysr@1601: // be issued. Some heap types require that the barrier strictly follows ysr@1601: // the initializing stores. (This is currently implemented by deferring the ysr@1601: // barrier until the next slow-path allocation or gc-related safepoint.) ysr@1601: // This interface answers whether a particular heap type needs the card ysr@1601: // mark to be thus strictly sequenced after the stores. ysr@1601: virtual bool card_mark_must_follow_store() const = 0; ysr@1601: ysr@1462: // If the CollectedHeap was asked to defer a store barrier above, ysr@1462: // this informs it to flush such a deferred store barrier to the ysr@1462: // remembered set. ysr@1462: virtual void flush_deferred_store_barrier(JavaThread* thread); duke@435: duke@435: // Does this heap support heap inspection (+PrintClassHistogram?) ysr@777: virtual bool supports_heap_inspection() const = 0; duke@435: duke@435: // Perform a collection of the heap; intended for use in implementing duke@435: // "System.gc". This probably implies as full a collection as the duke@435: // "CollectedHeap" supports. duke@435: virtual void collect(GCCause::Cause cause) = 0; duke@435: coleenp@4037: // Perform a full collection coleenp@4037: virtual void do_full_collection(bool clear_all_soft_refs) = 0; coleenp@4037: duke@435: // This interface assumes that it's being called by the duke@435: // vm thread. It collects the heap assuming that the duke@435: // heap lock is already held and that we are executing in duke@435: // the context of the vm thread. coleenp@4037: virtual void collect_as_vm_thread(GCCause::Cause cause); coleenp@4037: duke@435: // Returns the barrier set for this heap duke@435: BarrierSet* barrier_set() { return _barrier_set; } duke@435: duke@435: // Returns "true" iff there is a stop-world GC in progress. (I assume duke@435: // that it should answer "false" for the concurrent part of a concurrent duke@435: // collector -- dld). duke@435: bool is_gc_active() const { return _is_gc_active; } duke@435: duke@435: // Total number of GC collections (started) duke@435: unsigned int total_collections() const { return _total_collections; } duke@435: unsigned int total_full_collections() const { return _total_full_collections;} duke@435: duke@435: // Increment total number of GC collections (started) duke@435: // Should be protected but used by PSMarkSweep - cleanup for 1.4.2 duke@435: void increment_total_collections(bool full = false) { duke@435: _total_collections++; duke@435: if (full) { duke@435: increment_total_full_collections(); duke@435: } duke@435: } duke@435: duke@435: void increment_total_full_collections() { _total_full_collections++; } duke@435: duke@435: // Return the AdaptiveSizePolicy for the heap. duke@435: virtual AdaptiveSizePolicy* size_policy() = 0; duke@435: jmasa@1822: // Return the CollectorPolicy for the heap jmasa@1822: virtual CollectorPolicy* collector_policy() const = 0; jmasa@1822: coleenp@4037: void oop_iterate_no_header(OopClosure* cl); coleenp@4037: duke@435: // Iterate over all the ref-containing fields of all objects, calling coleenp@4037: // "cl.do_oop" on each. coleenp@4037: virtual void oop_iterate(ExtendedOopClosure* cl) = 0; duke@435: duke@435: // Iterate over all objects, calling "cl.do_object" on each. duke@435: virtual void object_iterate(ObjectClosure* cl) = 0; duke@435: jmasa@952: // Similar to object_iterate() except iterates only jmasa@952: // over live objects. jmasa@952: virtual void safe_object_iterate(ObjectClosure* cl) = 0; jmasa@952: duke@435: // NOTE! There is no requirement that a collector implement these duke@435: // functions. duke@435: // duke@435: // A CollectedHeap is divided into a dense sequence of "blocks"; that is, duke@435: // each address in the (reserved) heap is a member of exactly duke@435: // one block. The defining characteristic of a block is that it is duke@435: // possible to find its size, and thus to progress forward to the next duke@435: // block. (Blocks may be of different sizes.) Thus, blocks may duke@435: // represent Java objects, or they might be free blocks in a duke@435: // free-list-based heap (or subheap), as long as the two kinds are duke@435: // distinguishable and the size of each is determinable. duke@435: duke@435: // Returns the address of the start of the "block" that contains the duke@435: // address "addr". We say "blocks" instead of "object" since some heaps duke@435: // may not pack objects densely; a chunk may either be an object or a duke@435: // non-object. duke@435: virtual HeapWord* block_start(const void* addr) const = 0; duke@435: duke@435: // Requires "addr" to be the start of a chunk, and returns its size. duke@435: // "addr + size" is required to be the start of a new chunk, or the end duke@435: // of the active area of the heap. duke@435: virtual size_t block_size(const HeapWord* addr) const = 0; duke@435: duke@435: // Requires "addr" to be the start of a block, and returns "TRUE" iff duke@435: // the block is an object. duke@435: virtual bool block_is_obj(const HeapWord* addr) const = 0; duke@435: duke@435: // Returns the longest time (in ms) that has elapsed since the last duke@435: // time that any part of the heap was examined by a garbage collection. duke@435: virtual jlong millis_since_last_gc() = 0; duke@435: duke@435: // Perform any cleanup actions necessary before allowing a verification. duke@435: virtual void prepare_for_verify() = 0; duke@435: ysr@1050: // Generate any dumps preceding or following a full gc sla@5237: void pre_full_gc_dump(GCTimer* timer); sla@5237: void post_full_gc_dump(GCTimer* timer); sla@5237: sla@5237: VirtualSpaceSummary create_heap_space_summary(); sla@5237: GCHeapSummary create_heap_summary(); sla@5237: sla@5237: MetaspaceSummary create_metaspace_summary(); ysr@1050: tonyp@3269: // Print heap information on the given outputStream. duke@435: virtual void print_on(outputStream* st) const = 0; tonyp@3269: // The default behavior is to call print_on() on tty. tonyp@3269: virtual void print() const { tonyp@3269: print_on(tty); tonyp@3269: } tonyp@3269: // Print more detailed heap information on the given sla@5237: // outputStream. The default behavior is to call print_on(). It is tonyp@3269: // up to each subclass to override it and add any additional output tonyp@3269: // it needs. tonyp@3269: virtual void print_extended_on(outputStream* st) const { tonyp@3269: print_on(st); tonyp@3269: } duke@435: stefank@4904: virtual void print_on_error(outputStream* st) const { stefank@4904: st->print_cr("Heap:"); stefank@4904: print_extended_on(st); stefank@4904: st->cr(); stefank@4904: stefank@4904: _barrier_set->print_on(st); stefank@4904: } stefank@4904: duke@435: // Print all GC threads (other than the VM thread) duke@435: // used by this heap. duke@435: virtual void print_gc_threads_on(outputStream* st) const = 0; tonyp@3269: // The default behavior is to call print_gc_threads_on() on tty. tonyp@3269: void print_gc_threads() { tonyp@3269: print_gc_threads_on(tty); tonyp@3269: } duke@435: // Iterator for all GC threads (other than VM thread) duke@435: virtual void gc_threads_do(ThreadClosure* tc) const = 0; duke@435: duke@435: // Print any relevant tracing info that flags imply. duke@435: // Default implementation does nothing. duke@435: virtual void print_tracing_info() const = 0; duke@435: sla@5237: void print_heap_before_gc(); sla@5237: void print_heap_after_gc(); sla@5237: johnc@5548: // Registering and unregistering an nmethod (compiled code) with the heap. johnc@5548: // Override with specific mechanism for each specialized heap type. johnc@5548: virtual void register_nmethod(nmethod* nm); johnc@5548: virtual void unregister_nmethod(nmethod* nm); johnc@5548: sla@5237: void trace_heap_before_gc(GCTracer* gc_tracer); sla@5237: void trace_heap_after_gc(GCTracer* gc_tracer); never@3499: duke@435: // Heap verification brutisso@3711: virtual void verify(bool silent, VerifyOption option) = 0; duke@435: duke@435: // Non product verification and debugging. duke@435: #ifndef PRODUCT duke@435: // Support for PromotionFailureALot. Return true if it's time to cause a duke@435: // promotion failure. The no-argument version uses duke@435: // this->_promotion_failure_alot_count as the counter. duke@435: inline bool promotion_should_fail(volatile size_t* count); duke@435: inline bool promotion_should_fail(); duke@435: duke@435: // Reset the PromotionFailureALot counters. Should be called at the end of a sla@5237: // GC in which promotion failure occurred. duke@435: inline void reset_promotion_should_fail(volatile size_t* count); duke@435: inline void reset_promotion_should_fail(); duke@435: #endif // #ifndef PRODUCT duke@435: duke@435: #ifdef ASSERT duke@435: static int fired_fake_oom() { duke@435: return (CIFireOOMAt > 1 && _fire_out_of_memory_count >= CIFireOOMAt); duke@435: } duke@435: #endif jmasa@2188: jmasa@2188: public: jmasa@2188: // This is a convenience method that is used in cases where jmasa@2188: // the actual number of GC worker threads is not pertinent but jmasa@2188: // only whether there more than 0. Use of this method helps jmasa@2188: // reduce the occurrence of ParallelGCThreads to uses where the jmasa@2188: // actual number may be germane. jmasa@2188: static bool use_parallel_gc_threads() { return ParallelGCThreads > 0; } stefank@3335: jcoomes@7160: // Copy the current allocation context statistics for the specified contexts. jcoomes@7160: // For each context in contexts, set the corresponding entries in the totals jcoomes@7160: // and accuracy arrays to the current values held by the statistics. Each jcoomes@7160: // array should be of length len. sjohanss@7298: // Returns true if there are more stats available. sjohanss@7298: virtual bool copy_allocation_context_stats(const jint* contexts, jcoomes@7160: jlong* totals, jcoomes@7160: jbyte* accuracy, sjohanss@7298: jint len) { sjohanss@7298: return false; sjohanss@7298: } jcoomes@7160: stefank@3335: /////////////// Unit tests /////////////// stefank@3335: stefank@3335: NOT_PRODUCT(static void test_is_in();) duke@435: }; duke@435: duke@435: // Class to set and reset the GC cause for a CollectedHeap. duke@435: duke@435: class GCCauseSetter : StackObj { duke@435: CollectedHeap* _heap; duke@435: GCCause::Cause _previous_cause; duke@435: public: duke@435: GCCauseSetter(CollectedHeap* heap, GCCause::Cause cause) { duke@435: assert(SafepointSynchronize::is_at_safepoint(), duke@435: "This method manipulates heap state without locking"); duke@435: _heap = heap; duke@435: _previous_cause = _heap->gc_cause(); duke@435: _heap->set_gc_cause(cause); duke@435: } duke@435: duke@435: ~GCCauseSetter() { duke@435: assert(SafepointSynchronize::is_at_safepoint(), duke@435: "This method manipulates heap state without locking"); duke@435: _heap->set_gc_cause(_previous_cause); duke@435: } duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_HPP