Path: blob/master/src/hotspot/share/gc/serial/markSweep.inline.hpp
41152 views
/*1* Copyright (c) 2000, 2019, 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_SERIAL_MARKSWEEP_INLINE_HPP25#define SHARE_GC_SERIAL_MARKSWEEP_INLINE_HPP2627#include "gc/serial/markSweep.hpp"2829#include "classfile/classLoaderData.inline.hpp"30#include "memory/universe.hpp"31#include "oops/markWord.inline.hpp"32#include "oops/access.inline.hpp"33#include "oops/compressedOops.inline.hpp"34#include "oops/oop.inline.hpp"35#include "utilities/align.hpp"36#include "utilities/stack.inline.hpp"3738inline void MarkSweep::mark_object(oop obj) {39// some marks may contain information we need to preserve so we store them away40// and overwrite the mark. We'll restore it at the end of markSweep.41markWord mark = obj->mark();42obj->set_mark(markWord::prototype().set_marked());4344if (obj->mark_must_be_preserved(mark)) {45preserve_mark(obj, mark);46}47}4849template <class T> inline void MarkSweep::mark_and_push(T* p) {50T heap_oop = RawAccess<>::oop_load(p);51if (!CompressedOops::is_null(heap_oop)) {52oop obj = CompressedOops::decode_not_null(heap_oop);53if (!obj->mark().is_marked()) {54mark_object(obj);55_marking_stack.push(obj);56}57}58}5960inline void MarkSweep::follow_klass(Klass* klass) {61oop op = klass->class_loader_data()->holder_no_keepalive();62MarkSweep::mark_and_push(&op);63}6465inline void MarkSweep::follow_cld(ClassLoaderData* cld) {66MarkSweep::follow_cld_closure.do_cld(cld);67}6869template <typename T>70inline void MarkAndPushClosure::do_oop_work(T* p) { MarkSweep::mark_and_push(p); }71inline void MarkAndPushClosure::do_oop(oop* p) { do_oop_work(p); }72inline void MarkAndPushClosure::do_oop(narrowOop* p) { do_oop_work(p); }73inline void MarkAndPushClosure::do_klass(Klass* k) { MarkSweep::follow_klass(k); }74inline void MarkAndPushClosure::do_cld(ClassLoaderData* cld) { MarkSweep::follow_cld(cld); }7576template <class T> inline void MarkSweep::adjust_pointer(T* p) {77T heap_oop = RawAccess<>::oop_load(p);78if (!CompressedOops::is_null(heap_oop)) {79oop obj = CompressedOops::decode_not_null(heap_oop);80assert(Universe::heap()->is_in(obj), "should be in heap");8182oop new_obj = cast_to_oop(obj->mark().decode_pointer());8384assert(new_obj != NULL || // is forwarding ptr?85obj->mark() == markWord::prototype() || // not gc marked?86(UseBiasedLocking && obj->mark().has_bias_pattern()),87// not gc marked?88"should be forwarded");8990if (new_obj != NULL) {91assert(is_object_aligned(new_obj), "oop must be aligned");92RawAccess<IS_NOT_NULL>::oop_store(p, new_obj);93}94}95}9697template <typename T>98void AdjustPointerClosure::do_oop_work(T* p) { MarkSweep::adjust_pointer(p); }99inline void AdjustPointerClosure::do_oop(oop* p) { do_oop_work(p); }100inline void AdjustPointerClosure::do_oop(narrowOop* p) { do_oop_work(p); }101102103inline int MarkSweep::adjust_pointers(oop obj) {104return obj->oop_iterate_size(&MarkSweep::adjust_pointer_closure);105}106107#endif // SHARE_GC_SERIAL_MARKSWEEP_INLINE_HPP108109110