Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/shenandoah/preservedMarks.cpp
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#include "precompiled.hpp"25#include "gc_implementation/shenandoah/preservedMarks.inline.hpp"26#include "utilities/workgroup.hpp"27#include "memory/allocation.inline.hpp"28#include "memory/resourceArea.hpp"29#include "oops/oop.inline.hpp"30#include "utilities/macros.hpp"3132void PreservedMarks::restore() {33while (!_stack.is_empty()) {34const OopAndMarkOop elem = _stack.pop();35elem.set_mark();36}37assert_empty();38}3940void PreservedMarks::adjust_during_full_gc() {41StackIterator<OopAndMarkOop, mtGC> iter(_stack);42while (!iter.is_empty()) {43OopAndMarkOop* elem = iter.next_addr();4445oop obj = elem->get_oop();46if (obj->is_forwarded()) {47elem->set_oop(obj->forwardee());48}49}50}5152void PreservedMarks::restore_and_increment(volatile size_t* const total_size_addr) {53const size_t stack_size = size();54restore();55// Only do the atomic add if the size is > 0.56if (stack_size > 0) {57Atomic::add(stack_size, (volatile jlong*)total_size_addr);58}59}6061#ifndef PRODUCT62void PreservedMarks::assert_empty() {63assert(_stack.is_empty(), err_msg("stack expected to be empty, size = " SIZE_FORMAT,64_stack.size()));65assert(_stack.cache_size() == 0,66err_msg("stack expected to have no cached segments, cache size = " SIZE_FORMAT,67_stack.cache_size()));68}69#endif // ndef PRODUCT7071void RemoveForwardedPointerClosure::do_object(oop obj) {72if (obj->is_forwarded()) {73PreservedMarks::init_forwarded_mark(obj);74}75}7677void PreservedMarksSet::init(uint num) {78assert(_stacks == NULL && _num == 0, "do not re-initialize");79assert(num > 0, "pre-condition");80if (_in_c_heap) {81_stacks = NEW_C_HEAP_ARRAY(Padded<PreservedMarks>, num, mtGC);82} else {83_stacks = NEW_RESOURCE_ARRAY(Padded<PreservedMarks>, num);84}85for (uint i = 0; i < num; i += 1) {86::new (_stacks + i) PreservedMarks();87}88_num = num;8990assert_empty();91}9293class ParRestoreTask : public AbstractGangTask {94private:95PreservedMarksSet* const _preserved_marks_set;96SequentialSubTasksDone _sub_tasks;97volatile size_t* const _total_size_addr;9899public:100virtual void work(uint worker_id) {101uint task_id = 0;102while (!_sub_tasks.is_task_claimed(/* reference */ task_id)) {103_preserved_marks_set->get(task_id)->restore_and_increment(_total_size_addr);104}105_sub_tasks.all_tasks_completed();106}107108ParRestoreTask(uint worker_num,109PreservedMarksSet* preserved_marks_set,110volatile size_t* total_size_addr)111: AbstractGangTask("Parallel Preserved Mark Restoration"),112_preserved_marks_set(preserved_marks_set),113_total_size_addr(total_size_addr) {114_sub_tasks.set_n_threads(worker_num);115_sub_tasks.set_n_tasks(preserved_marks_set->num());116}117};118119void PreservedMarksSet::reclaim() {120assert_empty();121122for (uint i = 0; i < _num; i += 1) {123_stacks[i].~Padded<PreservedMarks>();124}125126if (_in_c_heap) {127FREE_C_HEAP_ARRAY(Padded<PreservedMarks>, _stacks, mtGC);128} else {129// the array was resource-allocated, so nothing to do130}131_stacks = NULL;132_num = 0;133}134135#ifndef PRODUCT136void PreservedMarksSet::assert_empty() {137assert(_stacks != NULL && _num > 0, "should have been initialized");138for (uint i = 0; i < _num; i += 1) {139get(i)->assert_empty();140}141}142#endif // ndef PRODUCT143144void SharedRestorePreservedMarksTaskExecutor::restore(PreservedMarksSet* preserved_marks_set,145volatile size_t* total_size_addr) {146if (_workers == NULL) {147for (uint i = 0; i < preserved_marks_set->num(); i += 1) {148*total_size_addr += preserved_marks_set->get(i)->size();149preserved_marks_set->get(i)->restore();150}151} else {152ParRestoreTask task(_workers->active_workers(), preserved_marks_set, total_size_addr);153_workers->run_task(&task);154}155}156157158