Path: blob/master/src/hotspot/share/gc/parallel/psPromotionManager.hpp
41152 views
/*1* Copyright (c) 2002, 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_PSPROMOTIONMANAGER_HPP25#define SHARE_GC_PARALLEL_PSPROMOTIONMANAGER_HPP2627#include "gc/parallel/psPromotionLAB.hpp"28#include "gc/shared/copyFailedInfo.hpp"29#include "gc/shared/gcTrace.hpp"30#include "gc/shared/preservedMarks.hpp"31#include "gc/shared/taskqueue.hpp"32#include "memory/padded.hpp"33#include "utilities/globalDefinitions.hpp"3435//36// psPromotionManager is used by a single thread to manage object survival37// during a scavenge. The promotion manager contains thread local data only.38//39// NOTE! Be careful when allocating the stacks on cheap. If you are going40// to use a promotion manager in more than one thread, the stacks MUST be41// on cheap. This can lead to memory leaks, though, as they are not auto42// deallocated.43//44// FIX ME FIX ME Add a destructor, and don't rely on the user to drain/flush/deallocate!45//4647class MutableSpace;48class PSOldGen;49class ParCompactionManager;5051class PSPromotionManager {52friend class PSScavenge;53friend class ScavengeRootsTask;5455private:56typedef OverflowTaskQueue<ScannerTask, mtGC> PSScannerTasksQueue;57typedef GenericTaskQueueSet<PSScannerTasksQueue, mtGC> PSScannerTasksQueueSet;5859static PaddedEnd<PSPromotionManager>* _manager_array;60static PSScannerTasksQueueSet* _stack_array_depth;61static PreservedMarksSet* _preserved_marks_set;62static PSOldGen* _old_gen;63static MutableSpace* _young_space;6465#if TASKQUEUE_STATS66size_t _array_chunk_pushes;67size_t _array_chunk_steals;68size_t _arrays_chunked;69size_t _array_chunks_processed;7071void print_local_stats(outputStream* const out, uint i) const;72static void print_taskqueue_stats();7374void reset_stats();75#endif // TASKQUEUE_STATS7677PSYoungPromotionLAB _young_lab;78PSOldPromotionLAB _old_lab;79bool _young_gen_is_full;80bool _old_gen_is_full;8182PSScannerTasksQueue _claimed_stack_depth;83OverflowTaskQueue<oop, mtGC> _claimed_stack_breadth;8485bool _totally_drain;86uint _target_stack_size;8788uint _array_chunk_size;89uint _min_array_size_for_chunking;9091PreservedMarks* _preserved_marks;92PromotionFailedInfo _promotion_failed_info;9394// Accessors95static PSOldGen* old_gen() { return _old_gen; }96static MutableSpace* young_space() { return _young_space; }9798inline static PSPromotionManager* manager_array(uint index);99100template <class T> void process_array_chunk_work(oop obj,101int start, int end);102void process_array_chunk(PartialArrayScanTask task);103104void push_depth(ScannerTask task);105106inline void promotion_trace_event(oop new_obj, oop old_obj, size_t obj_size,107uint age, bool tenured,108const PSPromotionLAB* lab);109110static PSScannerTasksQueueSet* stack_array_depth() { return _stack_array_depth; }111112public:113// Static114static void initialize();115116static void pre_scavenge();117static bool post_scavenge(YoungGCTracer& gc_tracer);118119static PSPromotionManager* gc_thread_promotion_manager(uint index);120static PSPromotionManager* vm_thread_promotion_manager();121122static bool steal_depth(int queue_num, ScannerTask& t);123124PSPromotionManager();125126// Accessors127PSScannerTasksQueue* claimed_stack_depth() {128return &_claimed_stack_depth;129}130131bool young_gen_is_full() { return _young_gen_is_full; }132133bool old_gen_is_full() { return _old_gen_is_full; }134void set_old_gen_is_full(bool state) { _old_gen_is_full = state; }135136// Promotion methods137template<bool promote_immediately> oop copy_to_survivor_space(oop o);138oop oop_promotion_failed(oop obj, markWord obj_mark);139140void reset();141void register_preserved_marks(PreservedMarks* preserved_marks);142static void restore_preserved_marks();143144void flush_labs();145void drain_stacks(bool totally_drain) {146drain_stacks_depth(totally_drain);147}148public:149void drain_stacks_cond_depth() {150if (claimed_stack_depth()->size() > _target_stack_size) {151drain_stacks_depth(false);152}153}154void drain_stacks_depth(bool totally_drain);155156bool stacks_empty() {157return claimed_stack_depth()->is_empty();158}159160inline void process_popped_location_depth(ScannerTask task);161162static bool should_scavenge(oop* p, bool check_to_space = false);163static bool should_scavenge(narrowOop* p, bool check_to_space = false);164165template <bool promote_immediately, class T>166void copy_and_push_safe_barrier(T* p);167168template <class T> inline void claim_or_forward_depth(T* p);169170TASKQUEUE_STATS_ONLY(inline void record_steal(ScannerTask task);)171172void push_contents(oop obj);173};174175#endif // SHARE_GC_PARALLEL_PSPROMOTIONMANAGER_HPP176177178