Path: blob/master/src/hotspot/share/gc/parallel/psCompactionManager.inline.hpp
41152 views
/*1* Copyright (c) 2010, 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_INLINE_HPP25#define SHARE_GC_PARALLEL_PSCOMPACTIONMANAGER_INLINE_HPP2627#include "gc/parallel/psCompactionManager.hpp"2829#include "classfile/classLoaderData.hpp"30#include "classfile/javaClasses.inline.hpp"31#include "gc/parallel/parMarkBitMap.hpp"32#include "gc/parallel/psParallelCompact.inline.hpp"33#include "gc/shared/taskqueue.inline.hpp"34#include "oops/access.inline.hpp"35#include "oops/arrayOop.hpp"36#include "oops/compressedOops.inline.hpp"37#include "oops/objArrayOop.inline.hpp"38#include "oops/oop.inline.hpp"39#include "utilities/debug.hpp"40#include "utilities/globalDefinitions.hpp"4142class PCMarkAndPushClosure: public OopClosure {43private:44ParCompactionManager* _compaction_manager;45public:46PCMarkAndPushClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }4748template <typename T> void do_oop_nv(T* p) { _compaction_manager->mark_and_push(p); }49virtual void do_oop(oop* p) { do_oop_nv(p); }50virtual void do_oop(narrowOop* p) { do_oop_nv(p); }51};5253class PCIterateMarkAndPushClosure: public MetadataVisitingOopIterateClosure {54private:55ParCompactionManager* _compaction_manager;56public:57PCIterateMarkAndPushClosure(ParCompactionManager* cm, ReferenceProcessor* rp) : MetadataVisitingOopIterateClosure(rp), _compaction_manager(cm) { }5859template <typename T> void do_oop_nv(T* p) { _compaction_manager->mark_and_push(p); }60virtual void do_oop(oop* p) { do_oop_nv(p); }61virtual void do_oop(narrowOop* p) { do_oop_nv(p); }6263void do_klass_nv(Klass* k) { _compaction_manager->follow_klass(k); }64void do_cld_nv(ClassLoaderData* cld) { _compaction_manager->follow_class_loader(cld); }65};6667inline bool ParCompactionManager::steal(int queue_num, oop& t) {68return oop_task_queues()->steal(queue_num, t);69}7071inline bool ParCompactionManager::steal_objarray(int queue_num, ObjArrayTask& t) {72return _objarray_task_queues->steal(queue_num, t);73}7475inline bool ParCompactionManager::steal(int queue_num, size_t& region) {76return region_task_queues()->steal(queue_num, region);77}7879inline void ParCompactionManager::push(oop obj) {80_marking_stack.push(obj);81}8283void ParCompactionManager::push_objarray(oop obj, size_t index)84{85ObjArrayTask task(obj, index);86assert(task.is_valid(), "bad ObjArrayTask");87_objarray_stack.push(task);88}8990void ParCompactionManager::push_region(size_t index)91{92#ifdef ASSERT93const ParallelCompactData& sd = PSParallelCompact::summary_data();94ParallelCompactData::RegionData* const region_ptr = sd.region(index);95assert(region_ptr->claimed(), "must be claimed");96assert(region_ptr->_pushed++ == 0, "should only be pushed once");97#endif98region_stack()->push(index);99}100101template <typename T>102inline void ParCompactionManager::mark_and_push(T* p) {103T heap_oop = RawAccess<>::oop_load(p);104if (!CompressedOops::is_null(heap_oop)) {105oop obj = CompressedOops::decode_not_null(heap_oop);106assert(ParallelScavengeHeap::heap()->is_in(obj), "should be in heap");107108if (mark_bitmap()->is_unmarked(obj) && PSParallelCompact::mark_obj(obj)) {109push(obj);110}111}112}113114inline void ParCompactionManager::follow_klass(Klass* klass) {115oop holder = klass->class_loader_data()->holder_no_keepalive();116mark_and_push(&holder);117}118119inline void ParCompactionManager::FollowStackClosure::do_void() {120_compaction_manager->follow_marking_stacks();121if (_terminator != nullptr) {122steal_marking_work(*_terminator, _worker_id);123}124}125126template <typename T>127inline void follow_array_specialized(objArrayOop obj, int index, ParCompactionManager* cm) {128const size_t len = size_t(obj->length());129const size_t beg_index = size_t(index);130assert(beg_index < len || len == 0, "index too large");131132const size_t stride = MIN2(len - beg_index, (size_t)ObjArrayMarkingStride);133const size_t end_index = beg_index + stride;134T* const base = (T*)obj->base();135T* const beg = base + beg_index;136T* const end = base + end_index;137138if (end_index < len) {139cm->push_objarray(obj, end_index); // Push the continuation.140}141142// Push the non-NULL elements of the next stride on the marking stack.143for (T* e = beg; e < end; e++) {144cm->mark_and_push<T>(e);145}146}147148inline void ParCompactionManager::follow_array(objArrayOop obj, int index) {149if (UseCompressedOops) {150follow_array_specialized<narrowOop>(obj, index, this);151} else {152follow_array_specialized<oop>(obj, index, this);153}154}155156inline void ParCompactionManager::update_contents(oop obj) {157if (!obj->klass()->is_typeArray_klass()) {158PCAdjustPointerClosure apc(this);159obj->oop_iterate(&apc);160}161}162163inline void ParCompactionManager::follow_class_loader(ClassLoaderData* cld) {164PCMarkAndPushClosure mark_and_push_closure(this);165cld->oops_do(&mark_and_push_closure, true);166}167168inline void ParCompactionManager::follow_contents(oop obj) {169assert(PSParallelCompact::mark_bitmap()->is_marked(obj), "should be marked");170if (obj->is_objArray()) {171follow_array(objArrayOop(obj), 0);172} else {173PCIterateMarkAndPushClosure cl(this, PSParallelCompact::ref_processor());174obj->oop_iterate(&cl);175}176}177178#endif // SHARE_GC_PARALLEL_PSCOMPACTIONMANAGER_INLINE_HPP179180181