0N/A/*
2945N/A * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_INLINE_HPP
1879N/A#define SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_INLINE_HPP
1879N/A
1879N/A#include "gc_implementation/shared/markSweep.hpp"
1879N/A#include "gc_interface/collectedHeap.hpp"
1879N/A#include "utilities/stack.inline.hpp"
1879N/A#ifndef SERIALGC
1879N/A#include "gc_implementation/parallelScavenge/psParallelCompact.hpp"
1879N/A#endif
1879N/A
0N/Ainline void MarkSweep::mark_object(oop obj) {
0N/A // some marks may contain information we need to preserve so we store them away
0N/A // and overwrite the mark. We'll restore it at the end of markSweep.
0N/A markOop mark = obj->mark();
0N/A obj->set_mark(markOopDesc::prototype()->set_marked());
0N/A
0N/A if (mark->must_be_preserved(obj)) {
0N/A preserve_mark(obj, mark);
0N/A }
0N/A}
113N/A
113N/Atemplate <class T> inline void MarkSweep::follow_root(T* p) {
113N/A assert(!Universe::heap()->is_in_reserved(p),
113N/A "roots shouldn't be things within the heap");
113N/A#ifdef VALIDATE_MARK_SWEEP
113N/A if (ValidateMarkSweep) {
113N/A guarantee(!_root_refs_stack->contains(p), "should only be in here once");
113N/A _root_refs_stack->push(p);
113N/A }
113N/A#endif
113N/A T heap_oop = oopDesc::load_heap_oop(p);
113N/A if (!oopDesc::is_null(heap_oop)) {
113N/A oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
113N/A if (!obj->mark()->is_marked()) {
113N/A mark_object(obj);
113N/A obj->follow_contents();
113N/A }
113N/A }
113N/A follow_stack();
113N/A}
113N/A
113N/Atemplate <class T> inline void MarkSweep::mark_and_push(T* p) {
113N/A// assert(Universe::heap()->is_in_reserved(p), "should be in object space");
113N/A T heap_oop = oopDesc::load_heap_oop(p);
113N/A if (!oopDesc::is_null(heap_oop)) {
113N/A oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
113N/A if (!obj->mark()->is_marked()) {
113N/A mark_object(obj);
1756N/A _marking_stack.push(obj);
113N/A }
113N/A }
113N/A}
113N/A
1311N/Avoid MarkSweep::push_objarray(oop obj, size_t index) {
1311N/A ObjArrayTask task(obj, index);
1311N/A assert(task.is_valid(), "bad ObjArrayTask");
1756N/A _objarray_stack.push(task);
1311N/A}
1311N/A
113N/Atemplate <class T> inline void MarkSweep::adjust_pointer(T* p, bool isroot) {
113N/A T heap_oop = oopDesc::load_heap_oop(p);
113N/A if (!oopDesc::is_null(heap_oop)) {
113N/A oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
113N/A oop new_obj = oop(obj->mark()->decode_pointer());
113N/A assert(new_obj != NULL || // is forwarding ptr?
113N/A obj->mark() == markOopDesc::prototype() || // not gc marked?
113N/A (UseBiasedLocking && obj->mark()->has_bias_pattern()) ||
113N/A // not gc marked?
113N/A obj->is_shared(), // never forwarded?
113N/A "should be forwarded");
113N/A if (new_obj != NULL) {
113N/A assert(Universe::heap()->is_in_reserved(new_obj),
113N/A "should be in object space");
113N/A oopDesc::encode_store_heap_oop_not_null(p, new_obj);
113N/A }
113N/A }
113N/A VALIDATE_MARK_SWEEP_ONLY(track_adjusted_pointer(p, isroot));
113N/A}
113N/A
113N/Atemplate <class T> inline void MarkSweep::KeepAliveClosure::do_oop_work(T* p) {
113N/A#ifdef VALIDATE_MARK_SWEEP
113N/A if (ValidateMarkSweep) {
113N/A if (!Universe::heap()->is_in_reserved(p)) {
113N/A _root_refs_stack->push(p);
113N/A } else {
113N/A _other_refs_stack->push(p);
113N/A }
113N/A }
113N/A#endif
113N/A mark_and_push(p);
113N/A}
1879N/A
1879N/A#endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_INLINE_HPP