0N/A/*
3198N/A * Copyright (c) 2002, 2012, 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_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP
1879N/A#define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP
1879N/A
1879N/A#include "gc_implementation/parallelScavenge/cardTableExtension.hpp"
1879N/A#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
1879N/A#include "gc_implementation/parallelScavenge/psPromotionManager.hpp"
3198N/A#include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
1879N/A#include "gc_implementation/parallelScavenge/psScavenge.hpp"
1879N/A
0N/Ainline void PSScavenge::save_to_space_top_before_gc() {
0N/A ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
0N/A _to_space_top_before_gc = heap->young_gen()->to_space()->top();
0N/A}
0N/A
113N/Atemplate <class T> inline bool PSScavenge::should_scavenge(T* p) {
113N/A T heap_oop = oopDesc::load_heap_oop(p);
113N/A if (oopDesc::is_null(heap_oop)) return false;
113N/A oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
113N/A return PSScavenge::is_obj_in_young((HeapWord*)obj);
0N/A}
0N/A
113N/Atemplate <class T>
113N/Ainline bool PSScavenge::should_scavenge(T* p, MutableSpace* to_space) {
0N/A if (should_scavenge(p)) {
113N/A oop obj = oopDesc::load_decode_heap_oop_not_null(p);
0N/A // Skip objects copied to to_space since the scavenge started.
113N/A HeapWord* const addr = (HeapWord*)obj;
0N/A return addr < to_space_top_before_gc() || addr >= to_space->end();
0N/A }
0N/A return false;
0N/A}
0N/A
113N/Atemplate <class T>
113N/Ainline bool PSScavenge::should_scavenge(T* p, bool check_to_space) {
0N/A if (check_to_space) {
113N/A ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
0N/A return should_scavenge(p, heap->young_gen()->to_space());
0N/A }
0N/A return should_scavenge(p);
0N/A}
0N/A
0N/A// Attempt to "claim" oop at p via CAS, push the new obj if successful
0N/A// This version tests the oop* to make sure it is within the heap before
0N/A// attempting marking.
3198N/Atemplate <class T, bool promote_immediately>
0N/Ainline void PSScavenge::copy_and_push_safe_barrier(PSPromotionManager* pm,
113N/A T* p) {
113N/A assert(should_scavenge(p, true), "revisiting object?");
0N/A
113N/A oop o = oopDesc::load_decode_heap_oop_not_null(p);
113N/A oop new_obj = o->is_forwarded()
113N/A ? o->forwardee()
3198N/A : pm->copy_to_survivor_space<promote_immediately>(o);
113N/A oopDesc::encode_store_heap_oop_not_null(p, new_obj);
0N/A
0N/A // We cannot mark without test, as some code passes us pointers
0N/A // that are outside the heap.
113N/A if ((!PSScavenge::is_obj_in_young((HeapWord*)p)) &&
0N/A Universe::heap()->is_in_reserved(p)) {
113N/A if (PSScavenge::is_obj_in_young((HeapWord*)new_obj)) {
113N/A card_table()->inline_write_ref_field_gc(p, new_obj);
0N/A }
0N/A }
0N/A}
1879N/A
3198N/Atemplate<bool promote_immediately>
3198N/Aclass PSRootsClosure: public OopClosure {
2226N/A private:
2226N/A PSPromotionManager* _promotion_manager;
2226N/A
2226N/A protected:
2226N/A template <class T> void do_oop_work(T *p) {
2226N/A if (PSScavenge::should_scavenge(p)) {
2226N/A // We never card mark roots, maybe call a func without test?
3198N/A PSScavenge::copy_and_push_safe_barrier<T, promote_immediately>(_promotion_manager, p);
2226N/A }
2226N/A }
2226N/A public:
3198N/A PSRootsClosure(PSPromotionManager* pm) : _promotion_manager(pm) { }
3198N/A void do_oop(oop* p) { PSRootsClosure::do_oop_work(p); }
3198N/A void do_oop(narrowOop* p) { PSRootsClosure::do_oop_work(p); }
2226N/A};
2226N/A
3198N/Atypedef PSRootsClosure</*promote_immediately=*/false> PSScavengeRootsClosure;
3198N/Atypedef PSRootsClosure</*promote_immediately=*/true> PSPromoteRootsClosure;
3198N/A
1879N/A#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP