Path: blob/master/src/hotspot/share/gc/parallel/psCompactionManager.hpp
41149 views
/*1* Copyright (c) 2005, 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_PSCOMPACTIONMANAGER_HPP25#define SHARE_GC_PARALLEL_PSCOMPACTIONMANAGER_HPP2627#include "gc/parallel/psParallelCompact.hpp"28#include "gc/shared/taskqueue.hpp"29#include "gc/shared/taskTerminator.hpp"30#include "memory/allocation.hpp"31#include "utilities/stack.hpp"3233class MutableSpace;34class PSOldGen;35class ParCompactionManager;36class ObjectStartArray;37class ParallelCompactData;38class ParMarkBitMap;3940class ParCompactionManager : public CHeapObj<mtGC> {41friend class MarkFromRootsTask;42friend class ParallelCompactRefProcProxyTask;43friend class ParallelScavengeRefProcProxyTask;44friend class ParMarkBitMap;45friend class PSParallelCompact;46friend class UpdateDensePrefixAndCompactionTask;4748private:49typedef GenericTaskQueue<oop, mtGC> OopTaskQueue;50typedef GenericTaskQueueSet<OopTaskQueue, mtGC> OopTaskQueueSet;5152// 32-bit: 4K * 8 = 32KiB; 64-bit: 8K * 16 = 128KiB53#define QUEUE_SIZE (1 << NOT_LP64(12) LP64_ONLY(13))54typedef OverflowTaskQueue<ObjArrayTask, mtGC, QUEUE_SIZE> ObjArrayTaskQueue;55typedef GenericTaskQueueSet<ObjArrayTaskQueue, mtGC> ObjArrayTaskQueueSet;56#undef QUEUE_SIZE57typedef OverflowTaskQueue<size_t, mtGC> RegionTaskQueue;58typedef GenericTaskQueueSet<RegionTaskQueue, mtGC> RegionTaskQueueSet;5960static ParCompactionManager** _manager_array;61static OopTaskQueueSet* _oop_task_queues;62static ObjArrayTaskQueueSet* _objarray_task_queues;63static ObjectStartArray* _start_array;64static RegionTaskQueueSet* _region_task_queues;65static PSOldGen* _old_gen;6667OverflowTaskQueue<oop, mtGC> _marking_stack;68ObjArrayTaskQueue _objarray_stack;69size_t _next_shadow_region;7071// Is there a way to reuse the _marking_stack for the72// saving empty regions? For now just create a different73// type of TaskQueue.74RegionTaskQueue _region_stack;7576static ParMarkBitMap* _mark_bitmap;7778// Contains currently free shadow regions. We use it in79// a LIFO fashion for better data locality and utilization.80static GrowableArray<size_t>* _shadow_region_array;8182// Provides mutual exclusive access of _shadow_region_array.83// See pop/push_shadow_region_mt_safe() below84static Monitor* _shadow_region_monitor;8586HeapWord* _last_query_beg;87oop _last_query_obj;88size_t _last_query_ret;8990static PSOldGen* old_gen() { return _old_gen; }91static ObjectStartArray* start_array() { return _start_array; }92static OopTaskQueueSet* oop_task_queues() { return _oop_task_queues; }9394static void initialize(ParMarkBitMap* mbm);9596protected:97// Array of task queues. Needed by the task terminator.98static RegionTaskQueueSet* region_task_queues() { return _region_task_queues; }99OverflowTaskQueue<oop, mtGC>* marking_stack() { return &_marking_stack; }100101// Pushes onto the marking stack. If the marking stack is full,102// pushes onto the overflow stack.103void stack_push(oop obj);104// Do not implement an equivalent stack_pop. Deal with the105// marking stack and overflow stack directly.106107public:108static const size_t InvalidShadow = ~0;109static size_t pop_shadow_region_mt_safe(PSParallelCompact::RegionData* region_ptr);110static void push_shadow_region_mt_safe(size_t shadow_region);111static void push_shadow_region(size_t shadow_region);112static void remove_all_shadow_regions();113114inline size_t next_shadow_region() { return _next_shadow_region; }115inline void set_next_shadow_region(size_t record) { _next_shadow_region = record; }116inline size_t move_next_shadow_region_by(size_t workers) {117_next_shadow_region += workers;118return next_shadow_region();119}120121void reset_bitmap_query_cache() {122_last_query_beg = NULL;123_last_query_obj = NULL;124_last_query_ret = 0;125}126127// Bitmap query support, cache last query and result128HeapWord* last_query_begin() { return _last_query_beg; }129oop last_query_object() { return _last_query_obj; }130size_t last_query_return() { return _last_query_ret; }131132void set_last_query_begin(HeapWord *new_beg) { _last_query_beg = new_beg; }133void set_last_query_object(oop new_obj) { _last_query_obj = new_obj; }134void set_last_query_return(size_t new_ret) { _last_query_ret = new_ret; }135136static void reset_all_bitmap_query_caches();137138RegionTaskQueue* region_stack() { return &_region_stack; }139140static ParCompactionManager* get_vmthread_cm() { return _manager_array[ParallelGCThreads]; }141142ParCompactionManager();143144// Pushes onto the region stack at the given index. If the145// region stack is full,146// pushes onto the region overflow stack.147static void verify_region_list_empty(uint stack_index);148ParMarkBitMap* mark_bitmap() { return _mark_bitmap; }149150// void drain_stacks();151152bool should_update();153bool should_copy();154155// Save for later processing. Must not fail.156inline void push(oop obj);157inline void push_objarray(oop objarray, size_t index);158inline void push_region(size_t index);159160// Check mark and maybe push on marking stack.161template <typename T> inline void mark_and_push(T* p);162163inline void follow_klass(Klass* klass);164165void follow_class_loader(ClassLoaderData* klass);166167// Access function for compaction managers168static ParCompactionManager* gc_thread_compaction_manager(uint index);169170static bool steal(int queue_num, oop& t);171static bool steal_objarray(int queue_num, ObjArrayTask& t);172static bool steal(int queue_num, size_t& region);173174// Process tasks remaining on any marking stack175void follow_marking_stacks();176inline bool marking_stacks_empty() const;177178// Process tasks remaining on any stack179void drain_region_stacks();180181void follow_contents(oop obj);182void follow_array(objArrayOop array, int index);183184void update_contents(oop obj);185186class FollowStackClosure: public VoidClosure {187private:188ParCompactionManager* _compaction_manager;189TaskTerminator* _terminator;190uint _worker_id;191public:192FollowStackClosure(ParCompactionManager* cm, TaskTerminator* terminator, uint worker_id)193: _compaction_manager(cm), _terminator(terminator), _worker_id(worker_id) { }194virtual void do_void();195};196197// Called after marking.198static void verify_all_marking_stack_empty() NOT_DEBUG_RETURN;199200// Region staks hold regions in from-space; called after compaction.201static void verify_all_region_stack_empty() NOT_DEBUG_RETURN;202};203204bool ParCompactionManager::marking_stacks_empty() const {205return _marking_stack.is_empty() && _objarray_stack.is_empty();206}207208#endif // SHARE_GC_PARALLEL_PSCOMPACTIONMANAGER_HPP209210211