Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/shenandoah/preservedMarks.hpp
38920 views
/*1* Copyright (c) 2016, 2018, 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_SHARED_PRESERVEDMARKS_HPP25#define SHARE_VM_GC_SHARED_PRESERVEDMARKS_HPP2627#include "memory/allocation.hpp"28#include "memory/padded.hpp"29#include "oops/oop.hpp"30#include "utilities/stack.hpp"3132class PreservedMarksSet;33class WorkGang;3435class PreservedMarks {36private:37class OopAndMarkOop {38private:39oop _o;40markOop _m;4142public:43OopAndMarkOop(oop obj, markOop m) : _o(obj), _m(m) { }4445oop get_oop() { return _o; }46inline void set_mark() const;47void set_oop(oop obj) { _o = obj; }48};49typedef Stack<OopAndMarkOop, mtGC> OopAndMarkOopStack;5051OopAndMarkOopStack _stack;5253inline bool should_preserve_mark(oop obj, markOop m) const;5455public:56size_t size() const { return _stack.size(); }57inline void push(oop obj, markOop m);58inline void push_if_necessary(oop obj, markOop m);59// Iterate over the stack, restore all preserved marks, and60// reclaim the memory taken up by the stack segments.61void restore();62// Iterate over the stack, adjust all preserved marks according63// to their forwarding location stored in the mark.64void adjust_during_full_gc();6566void restore_and_increment(volatile size_t* const _total_size_addr);67inline static void init_forwarded_mark(oop obj);6869// Assert the stack is empty and has no cached segments.70void assert_empty() PRODUCT_RETURN;7172inline PreservedMarks();73~PreservedMarks() { assert_empty(); }74};7576class RemoveForwardedPointerClosure: public ObjectClosure {77public:78virtual void do_object(oop obj);79};8081class RestorePreservedMarksTaskExecutor {82public:83void virtual restore(PreservedMarksSet* preserved_marks_set,84volatile size_t* total_size_addr) = 0;85};8687class SharedRestorePreservedMarksTaskExecutor : public RestorePreservedMarksTaskExecutor {88private:89WorkGang* _workers;9091public:92SharedRestorePreservedMarksTaskExecutor(WorkGang* workers) : _workers(workers) { }9394void restore(PreservedMarksSet* preserved_marks_set,95volatile size_t* total_size_addr);9697};9899class PreservedMarksSet : public CHeapObj<mtGC> {100private:101// true -> _stacks will be allocated in the C heap102// false -> _stacks will be allocated in the resource arena103const bool _in_c_heap;104105// Number of stacks we have allocated (typically, one stack per GC worker).106// This should be >= 1 if the stacks have been initialized,107// or == 0 if they have not.108uint _num;109110// Stack array (typically, one stack per GC worker) of length _num.111// This should be != NULL if the stacks have been initialized,112// or == NULL if they have not.113Padded<PreservedMarks>* _stacks;114115public:116uint num() const { return _num; }117118// Return the i'th stack.119PreservedMarks* get(uint i = 0) const {120assert(_num > 0 && _stacks != NULL, "stacks should have been initialized");121assert(i < _num, "pre-condition");122return (_stacks + i);123}124125// Allocate stack array.126void init(uint num);127128// Iterate over all stacks, restore all preserved marks, and reclaim129// the memory taken up by the stack segments.130// Supported executors: SharedRestorePreservedMarksTaskExecutor (Serial, CMS, G1),131// PSRestorePreservedMarksTaskExecutor (PS).132inline void restore(RestorePreservedMarksTaskExecutor* executor);133134// Reclaim stack array.135void reclaim();136137// Assert all the stacks are empty and have no cached segments.138void assert_empty() PRODUCT_RETURN;139140PreservedMarksSet(bool in_c_heap)141: _in_c_heap(in_c_heap), _num(0), _stacks(NULL) { }142143~PreservedMarksSet() {144assert(_stacks == NULL && _num == 0, "stacks should have been reclaimed");145}146};147148#endif // SHARE_VM_GC_SHARED_PRESERVEDMARKS_HPP149150151