0N/A/*
3679N/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_MEMORY_DEFNEWGENERATION_HPP
1879N/A#define SHARE_VM_MEMORY_DEFNEWGENERATION_HPP
1879N/A
1879N/A#include "gc_implementation/shared/ageTable.hpp"
1879N/A#include "gc_implementation/shared/cSpaceCounters.hpp"
1879N/A#include "gc_implementation/shared/generationCounters.hpp"
4309N/A#include "gc_implementation/shared/copyFailedInfo.hpp"
1879N/A#include "memory/generation.inline.hpp"
1879N/A#include "utilities/stack.hpp"
1879N/A
0N/Aclass EdenSpace;
0N/Aclass ContiguousSpace;
113N/Aclass ScanClosure;
4141N/Aclass STWGCTimer;
0N/A
0N/A// DefNewGeneration is a young generation containing eden, from- and
0N/A// to-space.
0N/A
0N/Aclass DefNewGeneration: public Generation {
0N/A friend class VMStructs;
0N/A
0N/Aprotected:
0N/A Generation* _next_gen;
0N/A int _tenuring_threshold; // Tenuring threshold for next collection.
0N/A ageTable _age_table;
0N/A // Size of object to pretenure in words; command line provides bytes
4302N/A size_t _pretenure_size_threshold_words;
0N/A
0N/A ageTable* age_table() { return &_age_table; }
4302N/A
0N/A // Initialize state to optimistically assume no promotion failure will
0N/A // happen.
0N/A void init_assuming_no_promotion_failure();
0N/A // True iff a promotion has failed in the current collection.
0N/A bool _promotion_failed;
0N/A bool promotion_failed() { return _promotion_failed; }
4302N/A PromotionFailedInfo _promotion_failed_info;
0N/A
0N/A // Handling promotion failure. A young generation collection
0N/A // can fail if a live object cannot be copied out of its
0N/A // location in eden or from-space during the collection. If
0N/A // a collection fails, the young generation is left in a
0N/A // consistent state such that it can be collected by a
0N/A // full collection.
0N/A // Before the collection
0N/A // Objects are in eden or from-space
0N/A // All roots into the young generation point into eden or from-space.
0N/A //
0N/A // After a failed collection
0N/A // Objects may be in eden, from-space, or to-space
0N/A // An object A in eden or from-space may have a copy B
0N/A // in to-space. If B exists, all roots that once pointed
0N/A // to A must now point to B.
0N/A // All objects in the young generation are unmarked.
0N/A // Eden, from-space, and to-space will all be collected by
0N/A // the full collection.
0N/A void handle_promotion_failure(oop);
0N/A
0N/A // In the absence of promotion failure, we wouldn't look at "from-space"
0N/A // objects after a young-gen collection. When promotion fails, however,
0N/A // the subsequent full collection will look at from-space objects:
0N/A // therefore we must remove their forwarding pointers.
0N/A void remove_forwarding_pointers();
0N/A
0N/A // Preserve the mark of "obj", if necessary, in preparation for its mark
0N/A // word being overwritten with a self-forwarding-pointer.
0N/A void preserve_mark_if_necessary(oop obj, markOop m);
1945N/A void preserve_mark(oop obj, markOop m); // work routine used by the above
0N/A
1756N/A // Together, these keep <object with a preserved mark, mark value> pairs.
1756N/A // They should always contain the same number of elements.
3863N/A Stack<oop, mtGC> _objs_with_preserved_marks;
3863N/A Stack<markOop, mtGC> _preserved_marks_of_objs;
0N/A
0N/A // Promotion failure handling
0N/A OopClosure *_promo_failure_scan_stack_closure;
0N/A void set_promo_failure_scan_stack_closure(OopClosure *scan_stack_closure) {
0N/A _promo_failure_scan_stack_closure = scan_stack_closure;
0N/A }
0N/A
3863N/A Stack<oop, mtGC> _promo_failure_scan_stack;
0N/A void drain_promo_failure_scan_stack(void);
0N/A bool _promo_failure_drain_in_progress;
0N/A
0N/A // Performance Counters
0N/A GenerationCounters* _gen_counters;
0N/A CSpaceCounters* _eden_counters;
0N/A CSpaceCounters* _from_counters;
0N/A CSpaceCounters* _to_counters;
0N/A
0N/A // sizing information
0N/A size_t _max_eden_size;
0N/A size_t _max_survivor_size;
0N/A
0N/A // Allocation support
0N/A bool _should_allocate_from_space;
0N/A bool should_allocate_from_space() const {
0N/A return _should_allocate_from_space;
0N/A }
0N/A void clear_should_allocate_from_space() {
0N/A _should_allocate_from_space = false;
0N/A }
0N/A void set_should_allocate_from_space() {
0N/A _should_allocate_from_space = true;
0N/A }
0N/A
0N/A protected:
0N/A // Spaces
0N/A EdenSpace* _eden_space;
0N/A ContiguousSpace* _from_space;
0N/A ContiguousSpace* _to_space;
0N/A
4141N/A STWGCTimer* _gc_timer;
4141N/A
0N/A enum SomeProtectedConstants {
0N/A // Generations are GenGrain-aligned and have size that are multiples of
0N/A // GenGrain.
0N/A MinFreeScratchWords = 100
0N/A };
0N/A
0N/A // Return the size of a survivor space if this generation were of size
0N/A // gen_size.
0N/A size_t compute_survivor_size(size_t gen_size, size_t alignment) const {
0N/A size_t n = gen_size / (SurvivorRatio + 2);
0N/A return n > alignment ? align_size_down(n, alignment) : alignment;
0N/A }
0N/A
0N/A public: // was "protected" but caused compile error on win32
0N/A class IsAliveClosure: public BoolObjectClosure {
0N/A Generation* _g;
0N/A public:
0N/A IsAliveClosure(Generation* g);
0N/A void do_object(oop p);
0N/A bool do_object_b(oop p);
0N/A };
0N/A
0N/A class KeepAliveClosure: public OopClosure {
0N/A protected:
0N/A ScanWeakRefClosure* _cl;
0N/A CardTableRS* _rs;
113N/A template <class T> void do_oop_work(T* p);
0N/A public:
0N/A KeepAliveClosure(ScanWeakRefClosure* cl);
113N/A virtual void do_oop(oop* p);
113N/A virtual void do_oop(narrowOop* p);
0N/A };
0N/A
0N/A class FastKeepAliveClosure: public KeepAliveClosure {
0N/A protected:
0N/A HeapWord* _boundary;
113N/A template <class T> void do_oop_work(T* p);
0N/A public:
0N/A FastKeepAliveClosure(DefNewGeneration* g, ScanWeakRefClosure* cl);
113N/A virtual void do_oop(oop* p);
113N/A virtual void do_oop(narrowOop* p);
0N/A };
0N/A
0N/A class EvacuateFollowersClosure: public VoidClosure {
0N/A GenCollectedHeap* _gch;
0N/A int _level;
0N/A ScanClosure* _scan_cur_or_nonheap;
0N/A ScanClosure* _scan_older;
0N/A public:
0N/A EvacuateFollowersClosure(GenCollectedHeap* gch, int level,
0N/A ScanClosure* cur, ScanClosure* older);
0N/A void do_void();
0N/A };
0N/A
0N/A class FastEvacuateFollowersClosure: public VoidClosure {
0N/A GenCollectedHeap* _gch;
0N/A int _level;
0N/A DefNewGeneration* _gen;
0N/A FastScanClosure* _scan_cur_or_nonheap;
0N/A FastScanClosure* _scan_older;
0N/A public:
0N/A FastEvacuateFollowersClosure(GenCollectedHeap* gch, int level,
0N/A DefNewGeneration* gen,
0N/A FastScanClosure* cur,
0N/A FastScanClosure* older);
0N/A void do_void();
0N/A };
0N/A
0N/A public:
0N/A DefNewGeneration(ReservedSpace rs, size_t initial_byte_size, int level,
0N/A const char* policy="Copy");
0N/A
4141N/A virtual void ref_processor_init();
4141N/A
0N/A virtual Generation::Name kind() { return Generation::DefNew; }
0N/A
0N/A // Accessing spaces
0N/A EdenSpace* eden() const { return _eden_space; }
0N/A ContiguousSpace* from() const { return _from_space; }
0N/A ContiguousSpace* to() const { return _to_space; }
0N/A
113N/A virtual CompactibleSpace* first_compaction_space() const;
0N/A
0N/A // Space enquiries
0N/A size_t capacity() const;
0N/A size_t used() const;
0N/A size_t free() const;
0N/A size_t max_capacity() const;
0N/A size_t capacity_before_gc() const;
0N/A size_t unsafe_max_alloc_nogc() const;
0N/A size_t contiguous_available() const;
0N/A
0N/A size_t max_eden_size() const { return _max_eden_size; }
0N/A size_t max_survivor_size() const { return _max_survivor_size; }
0N/A
0N/A bool supports_inline_contig_alloc() const { return true; }
0N/A HeapWord** top_addr() const;
0N/A HeapWord** end_addr() const;
0N/A
0N/A // Thread-local allocation buffers
0N/A bool supports_tlab_allocation() const { return true; }
113N/A size_t tlab_capacity() const;
113N/A size_t unsafe_max_tlab_alloc() const;
0N/A
0N/A // Grow the generation by the specified number of bytes.
0N/A // The size of bytes is assumed to be properly aligned.
0N/A // Return true if the expansion was successful.
0N/A bool expand(size_t bytes);
0N/A
0N/A // DefNewGeneration cannot currently expand except at
0N/A // a GC.
0N/A virtual bool is_maximal_no_gc() const { return true; }
0N/A
0N/A // Iteration
0N/A void object_iterate(ObjectClosure* blk);
0N/A void object_iterate_since_last_GC(ObjectClosure* cl);
0N/A
0N/A void younger_refs_iterate(OopsInGenClosure* cl);
0N/A
0N/A void space_iterate(SpaceClosure* blk, bool usedOnly = false);
0N/A
0N/A // Allocation support
0N/A virtual bool should_allocate(size_t word_size, bool is_tlab) {
0N/A assert(UseTLAB || !is_tlab, "Should not allocate tlab");
0N/A
0N/A size_t overflow_limit = (size_t)1 << (BitsPerSize_t - LogHeapWordSize);
0N/A
0N/A const bool non_zero = word_size > 0;
0N/A const bool overflows = word_size >= overflow_limit;
0N/A const bool check_too_big = _pretenure_size_threshold_words > 0;
0N/A const bool not_too_big = word_size < _pretenure_size_threshold_words;
0N/A const bool size_ok = is_tlab || !check_too_big || not_too_big;
0N/A
0N/A bool result = !overflows &&
0N/A non_zero &&
0N/A size_ok;
0N/A
0N/A return result;
0N/A }
0N/A
113N/A HeapWord* allocate(size_t word_size, bool is_tlab);
0N/A HeapWord* allocate_from_space(size_t word_size);
0N/A
113N/A HeapWord* par_allocate(size_t word_size, bool is_tlab);
0N/A
0N/A // Prologue & Epilogue
113N/A virtual void gc_prologue(bool full);
0N/A virtual void gc_epilogue(bool full);
0N/A
263N/A // Save the tops for eden, from, and to
263N/A virtual void record_spaces_top();
263N/A
0N/A // Doesn't require additional work during GC prologue and epilogue
0N/A virtual bool performs_in_place_marking() const { return false; }
0N/A
0N/A // Accessing marks
0N/A void save_marks();
0N/A void reset_saved_marks();
0N/A bool no_allocs_since_save_marks();
0N/A
0N/A // Need to declare the full complement of closures, whether we'll
0N/A // override them or not, or get message from the compiler:
0N/A // oop_since_save_marks_iterate_nv hides virtual function...
0N/A#define DefNew_SINCE_SAVE_MARKS_DECL(OopClosureType, nv_suffix) \
0N/A void oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl);
0N/A
0N/A ALL_SINCE_SAVE_MARKS_CLOSURES(DefNew_SINCE_SAVE_MARKS_DECL)
0N/A
0N/A#undef DefNew_SINCE_SAVE_MARKS_DECL
0N/A
0N/A // For non-youngest collection, the DefNewGeneration can contribute
0N/A // "to-space".
263N/A virtual void contribute_scratch(ScratchBlock*& list, Generation* requestor,
0N/A size_t max_alloc_words);
0N/A
263N/A // Reset for contribution of "to-space".
263N/A virtual void reset_scratch();
263N/A
0N/A // GC support
0N/A virtual void compute_new_size();
1808N/A
1808N/A // Returns true if the collection is likely to be safely
1808N/A // completed. Even if this method returns true, a collection
1808N/A // may not be guaranteed to succeed, and the system should be
1808N/A // able to safely unwind and recover from that failure, albeit
1808N/A // at some additional cost. Override superclass's implementation.
1808N/A virtual bool collection_attempt_is_safe();
1808N/A
0N/A virtual void collect(bool full,
0N/A bool clear_all_soft_refs,
0N/A size_t size,
0N/A bool is_tlab);
0N/A HeapWord* expand_and_allocate(size_t size,
0N/A bool is_tlab,
0N/A bool parallel = false);
0N/A
113N/A oop copy_to_survivor_space(oop old);
0N/A int tenuring_threshold() { return _tenuring_threshold; }
0N/A
0N/A // Performance Counter support
0N/A void update_counters();
0N/A
0N/A // Printing
0N/A virtual const char* name() const;
0N/A virtual const char* short_name() const { return "DefNew"; }
0N/A
0N/A bool must_be_youngest() const { return true; }
0N/A bool must_be_oldest() const { return false; }
0N/A
0N/A // PrintHeapAtGC support.
0N/A void print_on(outputStream* st) const;
0N/A
3679N/A void verify();
0N/A
1756N/A bool promo_failure_scan_is_complete() const {
1756N/A return _promo_failure_scan_stack.is_empty();
1756N/A }
1756N/A
0N/A protected:
263N/A // If clear_space is true, clear the survivor spaces. Eden is
263N/A // cleared if the minimum size of eden is 0. If mangle_space
263N/A // is true, also mangle the space in debug mode.
263N/A void compute_space_boundaries(uintx minimum_eden_size,
263N/A bool clear_space,
263N/A bool mangle_space);
0N/A // Scavenge support
0N/A void swap_spaces();
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_MEMORY_DEFNEWGENERATION_HPP