defNewGeneration.hpp revision 1879
/*
* 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/ageTable.hpp"
#include "gc_implementation/shared/cSpaceCounters.hpp"
#include "gc_implementation/shared/generationCounters.hpp"
#include "memory/generation.inline.hpp"
class EdenSpace;
class ContiguousSpace;
class ScanClosure;
// DefNewGeneration is a young generation containing eden, from- and
// to-space.
class DefNewGeneration: public Generation {
friend class VMStructs;
protected:
int _tenuring_threshold; // Tenuring threshold for next collection.
// Size of object to pretenure in words; command line provides bytes
// Initialize state to optimistically assume no promotion failure will
// happen.
// True iff a promotion has failed in the current collection.
bool _promotion_failed;
bool promotion_failed() { return _promotion_failed; }
// Handling promotion failure. A young generation collection
// can fail if a live object cannot be copied out of its
// location in eden or from-space during the collection. If
// a collection fails, the young generation is left in a
// consistent state such that it can be collected by a
// full collection.
// Before the collection
// Objects are in eden or from-space
// All roots into the young generation point into eden or from-space.
//
// After a failed collection
// Objects may be in eden, from-space, or to-space
// An object A in eden or from-space may have a copy B
// in to-space. If B exists, all roots that once pointed
// to A must now point to B.
// All objects in the young generation are unmarked.
// Eden, from-space, and to-space will all be collected by
// the full collection.
void handle_promotion_failure(oop);
// In the absence of promotion failure, we wouldn't look at "from-space"
// objects after a young-gen collection. When promotion fails, however,
// the subsequent full collection will look at from-space objects:
// therefore we must remove their forwarding pointers.
void remove_forwarding_pointers();
// Preserve the mark of "obj", if necessary, in preparation for its mark
// word being overwritten with a self-forwarding-pointer.
// Together, these keep <object with a preserved mark, mark value> pairs.
// They should always contain the same number of elements.
// Promotion failure handling
}
void drain_promo_failure_scan_stack(void);
// Performance Counters
// sizing information
// Allocation support
bool should_allocate_from_space() const {
return _should_allocate_from_space;
}
void clear_should_allocate_from_space() {
_should_allocate_from_space = false;
}
void set_should_allocate_from_space() {
_should_allocate_from_space = true;
}
protected:
// Spaces
enum SomeProtectedConstants {
// Generations are GenGrain-aligned and have size that are multiples of
// GenGrain.
MinFreeScratchWords = 100
};
// Return the size of a survivor space if this generation were of size
// gen_size.
}
public: // was "protected" but caused compile error on win32
class IsAliveClosure: public BoolObjectClosure {
Generation* _g;
public:
IsAliveClosure(Generation* g);
bool do_object_b(oop p);
};
class KeepAliveClosure: public OopClosure {
protected:
template <class T> void do_oop_work(T* p);
public:
};
class FastKeepAliveClosure: public KeepAliveClosure {
protected:
template <class T> void do_oop_work(T* p);
public:
};
class EvacuateFollowersClosure: public VoidClosure {
int _level;
public:
void do_void();
};
class FastEvacuateFollowersClosure: public VoidClosure {
int _level;
public:
void do_void();
};
public:
const char* policy="Copy");
// Accessing spaces
virtual CompactibleSpace* first_compaction_space() const;
// Space enquiries
size_t max_capacity() const;
size_t capacity_before_gc() const;
size_t unsafe_max_alloc_nogc() const;
size_t contiguous_available() const;
bool supports_inline_contig_alloc() const { return true; }
// Thread-local allocation buffers
bool supports_tlab_allocation() const { return true; }
size_t tlab_capacity() const;
size_t unsafe_max_tlab_alloc() const;
// Grow the generation by the specified number of bytes.
// The size of bytes is assumed to be properly aligned.
// Return true if the expansion was successful.
// DefNewGeneration cannot currently expand except at
// a GC.
virtual bool is_maximal_no_gc() const { return true; }
// Iteration
// Allocation support
const bool check_too_big = _pretenure_size_threshold_words > 0;
non_zero &&
return result;
}
// Prologue & Epilogue
virtual void gc_prologue(bool full);
virtual void gc_epilogue(bool full);
// Save the tops for eden, from, and to
virtual void record_spaces_top();
// Doesn't require additional work during GC prologue and epilogue
virtual bool performs_in_place_marking() const { return false; }
// Accessing marks
void save_marks();
void reset_saved_marks();
bool no_allocs_since_save_marks();
// Need to declare the full complement of closures, whether we'll
// override them or not, or get message from the compiler:
// oop_since_save_marks_iterate_nv hides virtual function...
// For non-youngest collection, the DefNewGeneration can contribute
// "to-space".
// Reset for contribution of "to-space".
virtual void reset_scratch();
// GC support
virtual void compute_new_size();
// Returns true if the collection is likely to be safely
// completed. Even if this method returns true, a collection
// may not be guaranteed to succeed, and the system should be
// able to safely unwind and recover from that failure, albeit
// at some additional cost. Override superclass's implementation.
virtual bool collection_attempt_is_safe();
bool clear_all_soft_refs,
bool is_tlab);
bool is_tlab,
bool parallel = false);
int tenuring_threshold() { return _tenuring_threshold; }
// Performance Counter support
void update_counters();
// Printing
virtual const char* name() const;
virtual const char* short_name() const { return "DefNew"; }
bool must_be_youngest() const { return true; }
bool must_be_oldest() const { return false; }
// PrintHeapAtGC support.
void verify(bool allow_dirty);
bool promo_failure_scan_is_complete() const {
return _promo_failure_scan_stack.is_empty();
}
protected:
// If clear_space is true, clear the survivor spaces. Eden is
// cleared if the minimum size of eden is 0. If mangle_space
// is true, also mangle the space in debug mode.
bool clear_space,
bool mangle_space);
// Scavenge support
void swap_spaces();
};
#endif // SHARE_VM_MEMORY_DEFNEWGENERATION_HPP