Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.hpp
38921 views
/*1* Copyright (c) 2005, 2012, 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_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSCOMPACTIONMANAGER_HPP25#define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSCOMPACTIONMANAGER_HPP2627#include "memory/allocation.hpp"28#include "utilities/stack.hpp"29#include "utilities/taskqueue.hpp"3031// Move to some global location32#define HAS_BEEN_MOVED 0x1501d01d33// End move to some global location343536class MutableSpace;37class PSOldGen;38class ParCompactionManager;39class ObjectStartArray;40class ParallelCompactData;41class ParMarkBitMap;4243class ParCompactionManager : public CHeapObj<mtGC> {44friend class ParallelTaskTerminator;45friend class ParMarkBitMap;46friend class PSParallelCompact;47friend class StealRegionCompactionTask;48friend class UpdateAndFillClosure;49friend class RefProcTaskExecutor;50friend class IdleGCTask;5152public:5354// ------------------------ Don't putback if not needed55// Actions that the compaction manager should take.56enum Action {57Update,58Copy,59UpdateAndCopy,60CopyAndUpdate,61NotValid62};63// ------------------------ End don't putback if not needed6465private:66// 32-bit: 4K * 8 = 32KiB; 64-bit: 8K * 16 = 128KiB67#define QUEUE_SIZE (1 << NOT_LP64(12) LP64_ONLY(13))68typedef OverflowTaskQueue<ObjArrayTask, mtGC, QUEUE_SIZE> ObjArrayTaskQueue;69typedef GenericTaskQueueSet<ObjArrayTaskQueue, mtGC> ObjArrayTaskQueueSet;70#undef QUEUE_SIZE7172static ParCompactionManager** _manager_array;73static OopTaskQueueSet* _stack_array;74static ObjArrayTaskQueueSet* _objarray_queues;75static ObjectStartArray* _start_array;76static RegionTaskQueueSet* _region_array;77static PSOldGen* _old_gen;7879private:80OverflowTaskQueue<oop, mtGC> _marking_stack;81ObjArrayTaskQueue _objarray_stack;8283// Is there a way to reuse the _marking_stack for the84// saving empty regions? For now just create a different85// type of TaskQueue.86RegionTaskQueue* _region_stack;8788static RegionTaskQueue** _region_list;89// Index in _region_list for current _region_stack.90uint _region_stack_index;9192// Indexes of recycled region stacks/overflow stacks93// Stacks of regions to be compacted are embedded in the tasks doing94// the compaction. A thread that executes the task extracts the95// region stack and drains it. These threads keep these region96// stacks for use during compaction task stealing. If a thread97// gets a second draining task, it pushed its current region stack98// index into the array _recycled_stack_index and gets a new99// region stack from the task. A thread that is executing a100// compaction stealing task without ever having executing a101// draining task, will get a region stack from _recycled_stack_index.102//103// Array of indexes into the array of region stacks.104static uint* _recycled_stack_index;105// The index into _recycled_stack_index of the last region stack index106// pushed. If -1, there are no entries into _recycled_stack_index.107static int _recycled_top;108// The index into _recycled_stack_index of the last region stack index109// popped. If -1, there has not been any entry popped.110static int _recycled_bottom;111112static ParMarkBitMap* _mark_bitmap;113114Action _action;115116static PSOldGen* old_gen() { return _old_gen; }117static ObjectStartArray* start_array() { return _start_array; }118static OopTaskQueueSet* stack_array() { return _stack_array; }119120static void initialize(ParMarkBitMap* mbm);121122protected:123// Array of tasks. Needed by the ParallelTaskTerminator.124static RegionTaskQueueSet* region_array() { return _region_array; }125OverflowTaskQueue<oop, mtGC>* marking_stack() { return &_marking_stack; }126127// Pushes onto the marking stack. If the marking stack is full,128// pushes onto the overflow stack.129void stack_push(oop obj);130// Do not implement an equivalent stack_pop. Deal with the131// marking stack and overflow stack directly.132133public:134Action action() { return _action; }135void set_action(Action v) { _action = v; }136137RegionTaskQueue* region_stack() { return _region_stack; }138void set_region_stack(RegionTaskQueue* v) { _region_stack = v; }139140inline static ParCompactionManager* manager_array(int index);141142inline static RegionTaskQueue* region_list(int index) {143return _region_list[index];144}145146uint region_stack_index() { return _region_stack_index; }147void set_region_stack_index(uint v) { _region_stack_index = v; }148149// Pop and push unique reusable stack index150static int pop_recycled_stack_index();151static void push_recycled_stack_index(uint v);152static void reset_recycled_stack_index() {153_recycled_bottom = _recycled_top = -1;154}155156ParCompactionManager();157~ParCompactionManager();158159// Pushes onto the region stack at the given index. If the160// region stack is full,161// pushes onto the region overflow stack.162static void region_list_push(uint stack_index, size_t region_index);163static void verify_region_list_empty(uint stack_index);164ParMarkBitMap* mark_bitmap() { return _mark_bitmap; }165166// void drain_stacks();167168bool should_update();169bool should_copy();170171// Save for later processing. Must not fail.172inline void push(oop obj) { _marking_stack.push(obj); }173inline void push_objarray(oop objarray, size_t index);174inline void push_region(size_t index);175176// Access function for compaction managers177static ParCompactionManager* gc_thread_compaction_manager(int index);178179static bool steal(int queue_num, int* seed, oop& t) {180return stack_array()->steal(queue_num, seed, t);181}182183static bool steal_objarray(int queue_num, int* seed, ObjArrayTask& t) {184return _objarray_queues->steal(queue_num, seed, t);185}186187static bool steal(int queue_num, int* seed, size_t& region) {188return region_array()->steal(queue_num, seed, region);189}190191// Process tasks remaining on any marking stack192void follow_marking_stacks();193inline bool marking_stacks_empty() const;194195// Process tasks remaining on any stack196void drain_region_stacks();197198};199200inline ParCompactionManager* ParCompactionManager::manager_array(int index) {201assert(_manager_array != NULL, "access of NULL manager_array");202assert(index >= 0 && index <= (int)ParallelGCThreads,203"out of range manager_array access");204return _manager_array[index];205}206207bool ParCompactionManager::marking_stacks_empty() const {208return _marking_stack.is_empty() && _objarray_stack.is_empty();209}210211#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSCOMPACTIONMANAGER_HPP212213214