Path: blob/master/src/hotspot/share/gc/parallel/psScavenge.hpp
41152 views
/*1* Copyright (c) 2002, 2020, 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_PARALLEL_PSSCAVENGE_HPP25#define SHARE_GC_PARALLEL_PSSCAVENGE_HPP2627#include "gc/parallel/psCardTable.hpp"28#include "gc/parallel/psVirtualspace.hpp"29#include "gc/shared/collectorCounters.hpp"30#include "gc/shared/gcTrace.hpp"31#include "memory/allocation.hpp"32#include "oops/oop.hpp"33#include "utilities/stack.hpp"3435class OopStack;36class ReferenceProcessor;37class ParallelScavengeHeap;38class ParallelScavengeTracer;39class PSIsAliveClosure;40class PSRefProcTaskExecutor;41class STWGCTimer;4243class PSScavenge: AllStatic {44friend class PSIsAliveClosure;45friend class PSKeepAliveClosure;46friend class PSPromotionManager;4748enum ScavengeSkippedCause {49not_skipped = 0,50to_space_not_empty,51promoted_too_large,52full_follows_scavenge53};5455// Saved value of to_space->top(), used to prevent objects in to_space from56// being rescanned.57static HeapWord* _to_space_top_before_gc;5859// Number of consecutive attempts to scavenge that were skipped60static int _consecutive_skipped_scavenges;616263protected:64// Flags/counters65static SpanSubjectToDiscoveryClosure _span_based_discoverer;66static ReferenceProcessor* _ref_processor; // Reference processor for scavenging.67static PSIsAliveClosure _is_alive_closure; // Closure used for reference processing68static PSCardTable* _card_table; // We cache the card table for fast access.69static bool _survivor_overflow; // Overflow this collection70static uint _tenuring_threshold; // tenuring threshold for next scavenge71static elapsedTimer _accumulated_time; // total time spent on scavenge72static STWGCTimer _gc_timer; // GC time book keeper73static ParallelScavengeTracer _gc_tracer; // GC tracing74// The lowest address possible for the young_gen.75// This is used to decide if an oop should be scavenged,76// cards should be marked, etc.77static HeapWord* _young_generation_boundary;78// Used to optimize compressed oops young gen boundary checking.79static uintptr_t _young_generation_boundary_compressed;80static CollectorCounters* _counters; // collector performance counters8182static void clean_up_failed_promotion();8384static bool should_attempt_scavenge();8586static HeapWord* to_space_top_before_gc() { return _to_space_top_before_gc; }87static inline void save_to_space_top_before_gc();8889// Private accessors90static PSCardTable* const card_table() { assert(_card_table != NULL, "Sanity"); return _card_table; }91static const ParallelScavengeTracer* gc_tracer() { return &_gc_tracer; }9293public:94// Accessors95static uint tenuring_threshold() { return _tenuring_threshold; }96static elapsedTimer* accumulated_time() { return &_accumulated_time; }97static int consecutive_skipped_scavenges()98{ return _consecutive_skipped_scavenges; }99100// Performance Counters101static CollectorCounters* counters() { return _counters; }102103static void set_subject_to_discovery_span(MemRegion mr) {104_span_based_discoverer.set_span(mr);105}106// Used by scavenge_contents107static ReferenceProcessor* const reference_processor() {108assert(_ref_processor != NULL, "Sanity");109return _ref_processor;110}111// The promotion managers tell us if they encountered overflow112static void set_survivor_overflow(bool state) {113_survivor_overflow = state;114}115// Adaptive size policy support.116static void set_young_generation_boundary(HeapWord* v);117118// Called by parallelScavengeHeap to init the tenuring threshold119static void initialize();120121// Scavenge entry point. This may invoke a full gc; return true if so.122static bool invoke();123// Return true if a collection was done; false otherwise.124static bool invoke_no_policy();125126template <class T> static inline bool should_scavenge(T* p);127128// These call should_scavenge() above and, if it returns true, also check that129// the object was not newly copied into to_space. The version with the bool130// argument is a convenience wrapper that fetches the to_space pointer from131// the heap and calls the other version (if the arg is true).132template <class T> static inline bool should_scavenge(T* p, MutableSpace* to_space);133template <class T> static inline bool should_scavenge(T* p, bool check_to_space);134135static void copy_and_push_safe_barrier_from_klass(PSPromotionManager* pm, oop* p);136137// Is an object in the young generation138// This assumes that the 'o' is in the heap,139// so it only checks one side of the complete predicate.140141inline static bool is_obj_in_young(oop o) {142return cast_from_oop<HeapWord*>(o) >= _young_generation_boundary;143}144145inline static bool is_obj_in_young(narrowOop o) {146return (uintptr_t)o >= _young_generation_boundary_compressed;147}148149inline static bool is_obj_in_young(HeapWord* o) {150return o >= _young_generation_boundary;151}152};153154#endif // SHARE_GC_PARALLEL_PSSCAVENGE_HPP155156157