/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "gc_implementation/shared/adaptiveSizePolicy.hpp"
#include "memory/collectorPolicy.hpp"
#include "memory/generation.hpp"
#include "memory/sharedHeap.hpp"
class SubTasksDone;
// A "GenCollectedHeap" is a SharedHeap that uses generational
// collection. It is represented with a sequence of Generation's.
friend class GenCollectorPolicy;
friend class Generation;
friend class DefNewGeneration;
friend class TenuredGeneration;
friend class ConcurrentMarkSweepGeneration;
friend class CMSCollector;
friend class GenMarkSweep;
friend class VM_GenCollectForAllocation;
friend class VM_GenCollectForPermanentAllocation;
friend class VM_GenCollectFull;
friend class VM_GenCollectFullConcurrent;
friend class VM_GC_HeapInspection;
friend class VM_HeapDumper;
friend class HeapInspection;
friend class GCCauseSetter;
friend class VMStructs;
public:
enum SomeConstants {
};
friend class VM_PopulateDumpSharedSpace;
protected:
// Fields:
private:
int _n_gens;
// The generational collector policy.
// Indicates that the most recent previous incremental collection failed.
// The flag is cleared when an action is taken that might clear the
// condition that caused that incremental collection to fail.
// In support of ExplicitGCInvokesConcurrent functionality
unsigned int _full_collections_completed;
// Data structure for claiming the (potentially) parallel tasks in
// (gen-specific) strong roots processing.
// In block contents verification, the number of header words to skip
// GC is not allowed during the dump of the shared classes. Keep track
// of this in order to provide an reasonable error message when terminating.
protected:
// Directs each generation up to and including "collectedGen" to recompute
// its desired size.
void compute_new_generation_sizes(int collectedGen);
// Helper functions for allocation
bool is_tlab,
bool first_only);
// Helper function for two callbacks below.
// Considers collection of the first max_level+1 generations.
void do_collection(bool full,
bool clear_all_soft_refs,
bool is_tlab,
int max_level);
// Callback from VM_GenCollectForAllocation operation.
// allocation request that failed in the youngest generation that should
// have handled it (including collection, expansion, etc.)
// Callback from VM_GenCollectFull operation.
// Perform a full collection of the first max_level+1 generations.
// Does the "cause" of GC indicate that
// we absolutely __must__ clear soft refs?
bool must_clear_all_soft_refs();
public:
// Returns JNI_OK on success
virtual jint initialize();
// Does operations required after initialization has been done.
void post_initialize();
// Initialize ("weak") refs processing support
virtual void ref_processing_init();
return CollectedHeap::GenCollectedHeap;
}
// The generational collector policy.
// Adaptive size policy
return gen_policy()->size_policy();
}
// Save the "used_region" for generations level and lower,
// and, if perm is true, for perm gen.
size_t max_capacity() const;
bool* gc_overhead_limit_was_exceeded);
// We may support a shared contiguous allocation area, if the youngest
// generation does.
bool supports_inline_contig_alloc() const;
// Return an estimate of the maximum allocation that could be performed
// without triggering any collection activity. In a generational
// collector, for example, this is probably the largest allocation that
// could be supported in the youngest generation. It is "unsafe" because
// no locks are taken; the result should be treated as an approximation,
// not a guarantee.
// Does this heap support heap inspection? (+PrintClassHistogram)
virtual bool supports_heap_inspection() const { return true; }
// Perform a full collection of the heap; intended for use in implementing
// "System.gc". This implies as full a collection as the CollectedHeap
// supports. Caller does not hold the Heap_lock on entry.
// 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.
// The same as above but assume that the caller holds the Heap_lock.
// Perform a full collection of the first max_level+1 generations.
// Mostly used for testing purposes. Caller does not hold the Heap_lock on entry.
// Returns "TRUE" iff "p" points into the committed areas of the heap.
// The methods is_in(), is_in_closed_subset() and is_in_youngest() may
// be expensive to compute in general, so, to prevent
// their inadvertent use in product jvm's, we restrict their use to
// assertion checking or verification only.
bool is_in(const void* p) const;
// override
bool is_in_closed_subset(const void* p) const {
if (UseConcMarkSweepGC) {
return is_in_reserved(p);
} else {
return is_in(p);
}
}
// Returns true if the reference is to an object in the reserved space
// for the young generation.
// Assumes the the young gen address range is less than that of the old gen.
bool is_in_young(oop p);
#ifdef ASSERT
virtual bool is_in_partial_collection(const void* p);
#endif
}
// Iteration 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.
// 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. Assumes (and verifies in non-product
// builds) that addr is in the allocated part of the heap and is
// the start of a chunk.
// Requires "addr" to be the start of a block, and returns "TRUE" iff
// the block is an object. Assumes (and verifies in non-product
// builds) that addr is in the allocated part of the heap and is
// the start of a chunk.
// Section on TLAB's.
virtual bool supports_tlab_allocation() const;
// 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.
virtual bool can_elide_tlab_store_barriers() const {
return true;
}
virtual bool card_mark_must_follow_store() const {
return UseConcMarkSweepGC;
}
// We don't need barriers for stores to objects in the
// young gen and, a fortiori, for initializing stores to
// objects therein. This applies to {DefNew,ParNew}+{Tenured,CMS}
// only and may need to be re-examined in case other
// kinds of collectors are implemented in the future.
// We wanted to assert that:-
// assert(UseParNewGC || UseSerialGC || UseConcMarkSweepGC,
// "Check can_elide_initializing_store_barrier() for this collector");
// but unfortunately the flag UseSerialGC need not necessarily always
// be set when DefNew+Tenured are being used.
return is_in_young(new_obj);
}
// 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 {
// CMS needs to see all, even intra-generational, ref updates.
return !UseConcMarkSweepGC;
}
// The "requestor" generation is performing some garbage collection
// action for which it would be useful to have scratch space. The
// requestor promises to allocate no more than "max_alloc_words" in any
// older generation (via promotion say.) Any blocks of space that can
// be provided are returned as a list of ScratchBlocks, sorted by
// decreasing size.
// Allow each generation to reset any scratch space that it has
// contributed as it needs.
void release_scratch();
// Ensure parsability: override
virtual void ensure_parsability(bool retire_tlabs);
// Time in ms since the longest time a collector ran in
// in any generation.
virtual jlong millis_since_last_gc();
// Total number of full collections completed.
unsigned int total_full_collections_completed() {
"Can't complete more collections than were started");
return _full_collections_completed;
}
// Update above counter, as appropriate, at the end of a stop-world GC cycle
unsigned int update_full_collections_completed();
// Update above counter, as appropriate, at the end of a concurrent GC cycle
unsigned int update_full_collections_completed(unsigned int count);
// Update "time of last gc" for all constituent generations
// to "now".
for (int i = 0; i < _n_gens; i++) {
}
}
// Update the gc statistics for each generation.
// "level" is the level of the lastest collection
for (int i = 0; i < _n_gens; i++) {
}
}
// Override.
// Override.
void prepare_for_verify();
// Override.
// Override.
virtual void print_tracing_info() const;
// PrintGC, PrintGCDetails support
// The functions below are helper functions that a subclass of
// "CollectedHeap" can use in the implementation of its virtual
// functions.
public:
};
// Apply "cl.do_generation" to all generations in the heap (not including
// the permanent generation). If "old_to_young" determines the order.
// Return "true" if all generations (but perm) have reached the
// maximal committed limit that they can reach, without a garbage
// collection.
virtual bool is_maximal_no_gc() const;
// Return the generation before "gen", or else NULL.
if (l == 0) return NULL;
else return _gens[l-1];
}
// Return the generation after "gen", or else NULL.
else return _gens[l];
}
if (i >= 0 && i < _n_gens)
return _gens[i];
else
return NULL;
}
int n_gens() const {
return _n_gens;
}
// Convenience function to be used in situations where the heap type can be
// asserted to be this type.
static GenCollectedHeap* heap();
void set_par_threads(uint t);
// Invoke the "do_oop" method of one of the closures "not_older_gens"
// or "older_gens" on root locations for the generation at
// "level". (The "older_gens" closure is used for scanning references
// from older generations; "not_older_gens" is used everywhere else.)
// If "younger_gens_as_roots" is false, younger generations are
// not scanned as roots; in this case, the caller must be arranging to
// scan the younger generations itself. (For example, a generation might
// explicitly mark reachable objects in younger generations, to avoid
// excess storage retention.) If "collecting_perm_gen" is false, then
// roots that may only contain references to permGen objects are not
// scanned; instead, the older_gens closure is applied to all outgoing
// references in the perm gen. The "so" argument determines which of the roots
// the closure is applied to:
// "SO_None" does none;
// "SO_AllClasses" applies the closure to all entries in the SystemDictionary;
// "SO_SystemClasses" to all the "system" classes and loaders;
// "SO_Strings" applies the closure to all entries in the StringTable.
void gen_process_strong_roots(int level,
bool younger_gens_as_roots,
// The remaining arguments are in an order
// consistent with SharedHeap::process_strong_roots:
bool activate_scope,
bool collecting_perm_gen,
bool do_code_roots,
// Apply "blk" to all the weak roots of the system. These include
// JNI weak roots, the code cache, system dictionary, symbol table,
// string table, and referents of reachable weak refs.
// Set the saved marks of generations, if that makes sense.
// In particular, if any generation might iterate over the oops
// in other generations, it should call this method.
void save_marks();
// Apply "cur->do_oop" or "older->do_oop" to all the oops in objects
// allocated since the last call to save_marks in generations at or above
// "level" (including the permanent generation.) The "cur" closure is
// applied to references in the generation at "level", and the "older"
// closure to older (and permanent) generations.
void oop_since_save_marks_iterate(int level, \
OopClosureType* cur, \
// Returns "true" iff no allocations have occurred in any generation at
// "level" or above (including the permanent generation) since the last
// call to "save_marks".
bool no_allocs_since_save_marks(int level);
// Returns true if an incremental collection is likely to fail.
// We optionally consult the young gen, if asked to do so;
// otherwise we base our answer on whether the previous incremental
// collection attempt failed with no corrective action as of yet.
// Assumes a 2-generation system; the first disjunct remembers if an
// incremental collection failed, even when we thought (second disjunct)
// that it would not.
"the following definition may not be suitable for an n(>2)-generation system");
return incremental_collection_failed() ||
}
// If a generation bails out of an incremental collection,
// it sets this flag.
bool incremental_collection_failed() const {
return _incremental_collection_failed;
}
void set_incremental_collection_failed() {
_incremental_collection_failed = true;
}
void clear_incremental_collection_failed() {
_incremental_collection_failed = false;
}
// Promotion of obj into gen failed. Try to promote obj to higher non-perm
// gens in ascending order; return the new location of obj if successful.
// Otherwise, try expand-and-allocate for obj in each generation starting at
// gen; return the new location of obj if successful. Otherwise, return NULL.
private:
// Accessor for memory state verification support
)
// Override
// For use by mark-sweep. As implemented, mark-sweep-compact is global
// in an essential way: compaction is performed across generations, by
// iterating over spaces.
void prepare_for_compaction();
// Perform a full collection of the first max_level+1 generations.
// This is the low level interface used by the public versions of
// collect() and collect_locked(). Caller holds the Heap_lock on entry.
// Returns success or failure.
bool create_cms_collector();
// In support of ExplicitGCInvokesConcurrent functionality
// Save the tops of the spaces in all generations
protected:
virtual void gc_prologue(bool full);
virtual void gc_epilogue(bool full);
public:
virtual void preload_and_dump(TRAPS);
};
#endif // SHARE_VM_MEMORY_GENCOLLECTEDHEAP_HPP