Path: blob/master/src/hotspot/share/gc/serial/defNewGeneration.hpp
41149 views
/*1* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_GC_SERIAL_DEFNEWGENERATION_HPP25#define SHARE_GC_SERIAL_DEFNEWGENERATION_HPP2627#include "gc/serial/cSpaceCounters.hpp"28#include "gc/shared/ageTable.hpp"29#include "gc/shared/copyFailedInfo.hpp"30#include "gc/shared/generation.hpp"31#include "gc/shared/generationCounters.hpp"32#include "gc/shared/preservedMarks.hpp"33#include "gc/shared/tlab_globals.hpp"34#include "utilities/align.hpp"35#include "utilities/stack.hpp"3637class ContiguousSpace;38class CSpaceCounters;39class DefNewYoungerGenClosure;40class DefNewScanClosure;41class ScanWeakRefClosure;42class SerialHeap;43class STWGCTimer;4445// DefNewGeneration is a young generation containing eden, from- and46// to-space.4748class DefNewGeneration: public Generation {49friend class VMStructs;5051protected:52Generation* _old_gen;53uint _tenuring_threshold; // Tenuring threshold for next collection.54AgeTable _age_table;55// Size of object to pretenure in words; command line provides bytes56size_t _pretenure_size_threshold_words;5758AgeTable* age_table() { return &_age_table; }5960// Initialize state to optimistically assume no promotion failure will61// happen.62void init_assuming_no_promotion_failure();63// True iff a promotion has failed in the current collection.64bool _promotion_failed;65bool promotion_failed() { return _promotion_failed; }66PromotionFailedInfo _promotion_failed_info;6768// Handling promotion failure. A young generation collection69// can fail if a live object cannot be copied out of its70// location in eden or from-space during the collection. If71// a collection fails, the young generation is left in a72// consistent state such that it can be collected by a73// full collection.74// Before the collection75// Objects are in eden or from-space76// All roots into the young generation point into eden or from-space.77//78// After a failed collection79// Objects may be in eden, from-space, or to-space80// An object A in eden or from-space may have a copy B81// in to-space. If B exists, all roots that once pointed82// to A must now point to B.83// All objects in the young generation are unmarked.84// Eden, from-space, and to-space will all be collected by85// the full collection.86void handle_promotion_failure(oop);8788// In the absence of promotion failure, we wouldn't look at "from-space"89// objects after a young-gen collection. When promotion fails, however,90// the subsequent full collection will look at from-space objects:91// therefore we must remove their forwarding pointers.92void remove_forwarding_pointers();9394virtual void restore_preserved_marks();9596// Preserved marks97PreservedMarksSet _preserved_marks_set;9899// Promotion failure handling100OopIterateClosure *_promo_failure_scan_stack_closure;101void set_promo_failure_scan_stack_closure(OopIterateClosure *scan_stack_closure) {102_promo_failure_scan_stack_closure = scan_stack_closure;103}104105Stack<oop, mtGC> _promo_failure_scan_stack;106void drain_promo_failure_scan_stack(void);107bool _promo_failure_drain_in_progress;108109// Performance Counters110GenerationCounters* _gen_counters;111CSpaceCounters* _eden_counters;112CSpaceCounters* _from_counters;113CSpaceCounters* _to_counters;114115// sizing information116size_t _max_eden_size;117size_t _max_survivor_size;118119// Allocation support120bool _should_allocate_from_space;121bool should_allocate_from_space() const {122return _should_allocate_from_space;123}124void clear_should_allocate_from_space() {125_should_allocate_from_space = false;126}127void set_should_allocate_from_space() {128_should_allocate_from_space = true;129}130131// Tenuring132void adjust_desired_tenuring_threshold();133134// Spaces135ContiguousSpace* _eden_space;136ContiguousSpace* _from_space;137ContiguousSpace* _to_space;138139STWGCTimer* _gc_timer;140141enum SomeProtectedConstants {142// Generations are GenGrain-aligned and have size that are multiples of143// GenGrain.144MinFreeScratchWords = 100145};146147// Return the size of a survivor space if this generation were of size148// gen_size.149size_t compute_survivor_size(size_t gen_size, size_t alignment) const {150size_t n = gen_size / (SurvivorRatio + 2);151return n > alignment ? align_down(n, alignment) : alignment;152}153154public: // was "protected" but caused compile error on win32155class IsAliveClosure: public BoolObjectClosure {156Generation* _young_gen;157public:158IsAliveClosure(Generation* young_gen);159bool do_object_b(oop p);160};161162class KeepAliveClosure: public OopClosure {163protected:164ScanWeakRefClosure* _cl;165CardTableRS* _rs;166template <class T> void do_oop_work(T* p);167public:168KeepAliveClosure(ScanWeakRefClosure* cl);169virtual void do_oop(oop* p);170virtual void do_oop(narrowOop* p);171};172173class FastKeepAliveClosure: public KeepAliveClosure {174protected:175HeapWord* _boundary;176template <class T> void do_oop_work(T* p);177public:178FastKeepAliveClosure(DefNewGeneration* g, ScanWeakRefClosure* cl);179virtual void do_oop(oop* p);180virtual void do_oop(narrowOop* p);181};182183class FastEvacuateFollowersClosure: public VoidClosure {184SerialHeap* _heap;185DefNewScanClosure* _scan_cur_or_nonheap;186DefNewYoungerGenClosure* _scan_older;187public:188FastEvacuateFollowersClosure(SerialHeap* heap,189DefNewScanClosure* cur,190DefNewYoungerGenClosure* older);191void do_void();192};193194public:195DefNewGeneration(ReservedSpace rs,196size_t initial_byte_size,197size_t min_byte_size,198size_t max_byte_size,199const char* policy="Serial young collection pauses");200201virtual void ref_processor_init();202203virtual Generation::Name kind() { return Generation::DefNew; }204205// Accessing spaces206ContiguousSpace* eden() const { return _eden_space; }207ContiguousSpace* from() const { return _from_space; }208ContiguousSpace* to() const { return _to_space; }209210virtual CompactibleSpace* first_compaction_space() const;211212// Space enquiries213size_t capacity() const;214size_t used() const;215size_t free() const;216size_t max_capacity() const;217size_t capacity_before_gc() const;218size_t unsafe_max_alloc_nogc() const;219size_t contiguous_available() const;220221size_t max_eden_size() const { return _max_eden_size; }222size_t max_survivor_size() const { return _max_survivor_size; }223224bool supports_inline_contig_alloc() const { return true; }225HeapWord* volatile* top_addr() const;226HeapWord** end_addr() const;227228// Thread-local allocation buffers229bool supports_tlab_allocation() const { return true; }230size_t tlab_capacity() const;231size_t tlab_used() const;232size_t unsafe_max_tlab_alloc() const;233234// Grow the generation by the specified number of bytes.235// The size of bytes is assumed to be properly aligned.236// Return true if the expansion was successful.237bool expand(size_t bytes);238239// DefNewGeneration cannot currently expand except at240// a GC.241virtual bool is_maximal_no_gc() const { return true; }242243// Iteration244void object_iterate(ObjectClosure* blk);245246void space_iterate(SpaceClosure* blk, bool usedOnly = false);247248// Allocation support249virtual bool should_allocate(size_t word_size, bool is_tlab) {250assert(UseTLAB || !is_tlab, "Should not allocate tlab");251252size_t overflow_limit = (size_t)1 << (BitsPerSize_t - LogHeapWordSize);253254const bool non_zero = word_size > 0;255const bool overflows = word_size >= overflow_limit;256const bool check_too_big = _pretenure_size_threshold_words > 0;257const bool not_too_big = word_size < _pretenure_size_threshold_words;258const bool size_ok = is_tlab || !check_too_big || not_too_big;259260bool result = !overflows &&261non_zero &&262size_ok;263264return result;265}266267HeapWord* allocate(size_t word_size, bool is_tlab);268HeapWord* allocate_from_space(size_t word_size);269270HeapWord* par_allocate(size_t word_size, bool is_tlab);271272virtual void gc_epilogue(bool full);273274// Save the tops for eden, from, and to275virtual void record_spaces_top();276277// Accessing marks278void save_marks();279void reset_saved_marks();280bool no_allocs_since_save_marks();281282// Need to declare the full complement of closures, whether we'll283// override them or not, or get message from the compiler:284// oop_since_save_marks_iterate_nv hides virtual function...285template <typename OopClosureType>286void oop_since_save_marks_iterate(OopClosureType* cl);287288// For non-youngest collection, the DefNewGeneration can contribute289// "to-space".290virtual void contribute_scratch(ScratchBlock*& list, Generation* requestor,291size_t max_alloc_words);292293// Reset for contribution of "to-space".294virtual void reset_scratch();295296// GC support297virtual void compute_new_size();298299// Returns true if the collection is likely to be safely300// completed. Even if this method returns true, a collection301// may not be guaranteed to succeed, and the system should be302// able to safely unwind and recover from that failure, albeit303// at some additional cost. Override superclass's implementation.304virtual bool collection_attempt_is_safe();305306virtual void collect(bool full,307bool clear_all_soft_refs,308size_t size,309bool is_tlab);310HeapWord* expand_and_allocate(size_t size,311bool is_tlab,312bool parallel = false);313314oop copy_to_survivor_space(oop old);315uint tenuring_threshold() { return _tenuring_threshold; }316317// Performance Counter support318void update_counters();319320// Printing321virtual const char* name() const;322virtual const char* short_name() const { return "DefNew"; }323324void print_on(outputStream* st) const;325326void verify();327328bool promo_failure_scan_is_complete() const {329return _promo_failure_scan_stack.is_empty();330}331332protected:333// If clear_space is true, clear the survivor spaces. Eden is334// cleared if the minimum size of eden is 0. If mangle_space335// is true, also mangle the space in debug mode.336void compute_space_boundaries(uintx minimum_eden_size,337bool clear_space,338bool mangle_space);339340// Return adjusted new size for NewSizeThreadIncrease.341// If any overflow happens, revert to previous new size.342size_t adjust_for_thread_increase(size_t new_size_candidate,343size_t new_size_before,344size_t alignment) const;345346347// Scavenge support348void swap_spaces();349};350351#endif // SHARE_GC_SERIAL_DEFNEWGENERATION_HPP352353354