Path: blob/master/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp
41152 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_PARALLEL_PARALLELSCAVENGEHEAP_HPP25#define SHARE_GC_PARALLEL_PARALLELSCAVENGEHEAP_HPP2627#include "gc/parallel/objectStartArray.hpp"28#include "gc/parallel/psGCAdaptivePolicyCounters.hpp"29#include "gc/parallel/psOldGen.hpp"30#include "gc/parallel/psYoungGen.hpp"31#include "gc/shared/cardTableBarrierSet.hpp"32#include "gc/shared/collectedHeap.hpp"33#include "gc/shared/gcPolicyCounters.hpp"34#include "gc/shared/gcWhen.hpp"35#include "gc/shared/preGCValues.hpp"36#include "gc/shared/referenceProcessor.hpp"37#include "gc/shared/softRefPolicy.hpp"38#include "gc/shared/strongRootsScope.hpp"39#include "gc/shared/workgroup.hpp"40#include "logging/log.hpp"41#include "utilities/growableArray.hpp"42#include "utilities/ostream.hpp"4344class GCHeapSummary;45class HeapBlockClaimer;46class MemoryManager;47class MemoryPool;48class PSAdaptiveSizePolicy;49class PSCardTable;50class PSHeapSummary;5152class ParallelScavengeHeap : public CollectedHeap {53friend class VMStructs;54private:55static PSYoungGen* _young_gen;56static PSOldGen* _old_gen;5758// Sizing policy for entire heap59static PSAdaptiveSizePolicy* _size_policy;60static PSGCAdaptivePolicyCounters* _gc_policy_counters;6162SoftRefPolicy _soft_ref_policy;6364unsigned int _death_march_count;6566GCMemoryManager* _young_manager;67GCMemoryManager* _old_manager;6869MemoryPool* _eden_pool;70MemoryPool* _survivor_pool;71MemoryPool* _old_pool;7273WorkGang _workers;7475virtual void initialize_serviceability();7677void trace_actual_reserved_page_size(const size_t reserved_heap_size, const ReservedSpace rs);78void trace_heap(GCWhen::Type when, const GCTracer* tracer);7980// Allocate in oldgen and record the allocation with the size_policy.81HeapWord* allocate_old_gen_and_record(size_t word_size);8283protected:84static inline size_t total_invocations();85HeapWord* allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size);8687inline bool should_alloc_in_eden(size_t size) const;88inline void death_march_check(HeapWord* const result, size_t size);89HeapWord* mem_allocate_old_gen(size_t size);9091public:92ParallelScavengeHeap() :93CollectedHeap(),94_death_march_count(0),95_young_manager(NULL),96_old_manager(NULL),97_eden_pool(NULL),98_survivor_pool(NULL),99_old_pool(NULL),100_workers("GC Thread",101ParallelGCThreads,102true /* are_GC_task_threads */,103false /* are_ConcurrentGC_threads */) { }104105// For use by VM operations106enum CollectionType {107Scavenge,108MarkSweep109};110111virtual Name kind() const {112return CollectedHeap::Parallel;113}114115virtual const char* name() const {116return "Parallel";117}118119virtual SoftRefPolicy* soft_ref_policy() { return &_soft_ref_policy; }120121virtual GrowableArray<GCMemoryManager*> memory_managers();122virtual GrowableArray<MemoryPool*> memory_pools();123124static PSYoungGen* young_gen() { return _young_gen; }125static PSOldGen* old_gen() { return _old_gen; }126127virtual PSAdaptiveSizePolicy* size_policy() { return _size_policy; }128129static PSGCAdaptivePolicyCounters* gc_policy_counters() { return _gc_policy_counters; }130131static ParallelScavengeHeap* heap() {132return named_heap<ParallelScavengeHeap>(CollectedHeap::Parallel);133}134135CardTableBarrierSet* barrier_set();136PSCardTable* card_table();137138// Returns JNI_OK on success139virtual jint initialize();140141void post_initialize();142void update_counters();143144size_t capacity() const;145size_t used() const;146147// Return "true" if all generations have reached the148// maximal committed limit that they can reach, without a garbage149// collection.150virtual bool is_maximal_no_gc() const;151152virtual void register_nmethod(nmethod* nm);153virtual void unregister_nmethod(nmethod* nm);154virtual void verify_nmethod(nmethod* nm);155virtual void flush_nmethod(nmethod* nm);156157void prune_scavengable_nmethods();158159size_t max_capacity() const;160161// Whether p is in the allocated part of the heap162bool is_in(const void* p) const;163164bool is_in_reserved(const void* p) const;165166bool is_in_young(oop p); // reserved part167bool is_in_old(oop p); // reserved part168169MemRegion reserved_region() const { return _reserved; }170HeapWord* base() const { return _reserved.start(); }171172// Memory allocation. "gc_time_limit_was_exceeded" will173// be set to true if the adaptive size policy determine that174// an excessive amount of time is being spent doing collections175// and caused a NULL to be returned. If a NULL is not returned,176// "gc_time_limit_was_exceeded" has an undefined meaning.177HeapWord* mem_allocate(size_t size, bool* gc_overhead_limit_was_exceeded);178179// Allocation attempt(s) during a safepoint. It should never be called180// to allocate a new TLAB as this allocation might be satisfied out181// of the old generation.182HeapWord* failed_mem_allocate(size_t size);183184// Support for System.gc()185void collect(GCCause::Cause cause);186187// These also should be called by the vm thread at a safepoint (e.g., from a188// VM operation).189//190// The first collects the young generation only, unless the scavenge fails; it191// will then attempt a full gc. The second collects the entire heap; if192// maximum_compaction is true, it will compact everything and clear all soft193// references.194inline void invoke_scavenge();195196// Perform a full collection197virtual void do_full_collection(bool clear_all_soft_refs);198199bool supports_inline_contig_alloc() const { return !UseNUMA; }200201HeapWord* volatile* top_addr() const { return !UseNUMA ? young_gen()->top_addr() : (HeapWord* volatile*)-1; }202HeapWord** end_addr() const { return !UseNUMA ? young_gen()->end_addr() : (HeapWord**)-1; }203204void ensure_parsability(bool retire_tlabs);205void resize_all_tlabs();206207size_t tlab_capacity(Thread* thr) const;208size_t tlab_used(Thread* thr) const;209size_t unsafe_max_tlab_alloc(Thread* thr) const;210211void object_iterate(ObjectClosure* cl);212void object_iterate_parallel(ObjectClosure* cl, HeapBlockClaimer* claimer);213virtual ParallelObjectIterator* parallel_object_iterator(uint thread_num);214215HeapWord* block_start(const void* addr) const;216bool block_is_obj(const HeapWord* addr) const;217218void prepare_for_verify();219PSHeapSummary create_ps_heap_summary();220virtual void print_on(outputStream* st) const;221virtual void print_on_error(outputStream* st) const;222virtual void gc_threads_do(ThreadClosure* tc) const;223virtual void print_tracing_info() const;224225virtual WorkGang* safepoint_workers() { return &_workers; }226227PreGenGCValues get_pre_gc_values() const;228void print_heap_change(const PreGenGCValues& pre_gc_values) const;229230// Used to print information about locations in the hs_err file.231virtual bool print_location(outputStream* st, void* addr) const;232233void verify(VerifyOption option /* ignored */);234235// Resize the young generation. The reserved space for the236// generation may be expanded in preparation for the resize.237void resize_young_gen(size_t eden_size, size_t survivor_size);238239// Resize the old generation. The reserved space for the240// generation may be expanded in preparation for the resize.241void resize_old_gen(size_t desired_free_space);242243// Save the tops of the spaces in all generations244void record_gen_tops_before_GC() PRODUCT_RETURN;245246// Mangle the unused parts of all spaces in the heap247void gen_mangle_unused_area() PRODUCT_RETURN;248249// Call these in sequential code around the processing of strong roots.250class ParStrongRootsScope : public MarkScope {251public:252ParStrongRootsScope();253~ParStrongRootsScope();254};255256GCMemoryManager* old_gc_manager() const { return _old_manager; }257GCMemoryManager* young_gc_manager() const { return _young_manager; }258259WorkGang& workers() {260return _workers;261}262};263264// Class that can be used to print information about the265// adaptive size policy at intervals specified by266// AdaptiveSizePolicyOutputInterval. Only print information267// if an adaptive size policy is in use.268class AdaptiveSizePolicyOutput : AllStatic {269static bool enabled() {270return UseParallelGC &&271UseAdaptiveSizePolicy &&272log_is_enabled(Debug, gc, ergo);273}274public:275static void print() {276if (enabled()) {277ParallelScavengeHeap::heap()->size_policy()->print();278}279}280281static void print(AdaptiveSizePolicy* size_policy, uint count) {282bool do_print =283enabled() &&284(AdaptiveSizePolicyOutputInterval > 0) &&285(count % AdaptiveSizePolicyOutputInterval) == 0;286287if (do_print) {288size_policy->print();289}290}291};292293#endif // SHARE_GC_PARALLEL_PARALLELSCAVENGEHEAP_HPP294295296