duke@435: /* iveresov@3536: * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP stefank@2314: #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP stefank@2314: stefank@2314: #include "gc_implementation/parallelScavenge/cardTableExtension.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psPromotionManager.hpp" iveresov@3536: #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psScavenge.hpp" coleenp@4037: #include "memory/iterator.hpp" stefank@2314: duke@435: inline void PSScavenge::save_to_space_top_before_gc() { duke@435: ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); duke@435: _to_space_top_before_gc = heap->young_gen()->to_space()->top(); duke@435: } duke@435: coleenp@548: template inline bool PSScavenge::should_scavenge(T* p) { coleenp@548: T heap_oop = oopDesc::load_heap_oop(p); coleenp@548: if (oopDesc::is_null(heap_oop)) return false; coleenp@548: oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); coleenp@548: return PSScavenge::is_obj_in_young((HeapWord*)obj); duke@435: } duke@435: coleenp@548: template coleenp@548: inline bool PSScavenge::should_scavenge(T* p, MutableSpace* to_space) { duke@435: if (should_scavenge(p)) { coleenp@548: oop obj = oopDesc::load_decode_heap_oop_not_null(p); duke@435: // Skip objects copied to to_space since the scavenge started. coleenp@548: HeapWord* const addr = (HeapWord*)obj; duke@435: return addr < to_space_top_before_gc() || addr >= to_space->end(); duke@435: } duke@435: return false; duke@435: } duke@435: coleenp@548: template coleenp@548: inline bool PSScavenge::should_scavenge(T* p, bool check_to_space) { duke@435: if (check_to_space) { coleenp@548: ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); duke@435: return should_scavenge(p, heap->young_gen()->to_space()); duke@435: } duke@435: return should_scavenge(p); duke@435: } duke@435: duke@435: // Attempt to "claim" oop at p via CAS, push the new obj if successful duke@435: // This version tests the oop* to make sure it is within the heap before duke@435: // attempting marking. iveresov@3536: template duke@435: inline void PSScavenge::copy_and_push_safe_barrier(PSPromotionManager* pm, coleenp@548: T* p) { coleenp@548: assert(should_scavenge(p, true), "revisiting object?"); duke@435: coleenp@548: oop o = oopDesc::load_decode_heap_oop_not_null(p); coleenp@548: oop new_obj = o->is_forwarded() coleenp@548: ? o->forwardee() iveresov@3536: : pm->copy_to_survivor_space(o); coleenp@4037: coleenp@4037: #ifndef PRODUCT coleenp@4037: // This code must come after the CAS test, or it will print incorrect coleenp@4037: // information. coleenp@4037: if (TraceScavenge && o->is_forwarded()) { coleenp@4037: gclog_or_tty->print_cr("{%s %s " PTR_FORMAT " -> " PTR_FORMAT " (%d)}", coleenp@4037: "forwarding", coleenp@4037: new_obj->klass()->internal_name(), o, new_obj, new_obj->size()); coleenp@4037: } coleenp@4037: #endif coleenp@4037: coleenp@548: oopDesc::encode_store_heap_oop_not_null(p, new_obj); duke@435: duke@435: // We cannot mark without test, as some code passes us pointers coleenp@4037: // that are outside the heap. These pointers are either from roots coleenp@4037: // or from metadata. coleenp@548: if ((!PSScavenge::is_obj_in_young((HeapWord*)p)) && duke@435: Universe::heap()->is_in_reserved(p)) { coleenp@548: if (PSScavenge::is_obj_in_young((HeapWord*)new_obj)) { coleenp@548: card_table()->inline_write_ref_field_gc(p, new_obj); duke@435: } duke@435: } duke@435: } stefank@2314: iveresov@3536: template iveresov@3536: class PSRootsClosure: public OopClosure { jcoomes@2661: private: jcoomes@2661: PSPromotionManager* _promotion_manager; jcoomes@2661: jcoomes@2661: protected: jcoomes@2661: template void do_oop_work(T *p) { jcoomes@2661: if (PSScavenge::should_scavenge(p)) { jcoomes@2661: // We never card mark roots, maybe call a func without test? iveresov@3536: PSScavenge::copy_and_push_safe_barrier(_promotion_manager, p); jcoomes@2661: } jcoomes@2661: } jcoomes@2661: public: iveresov@3536: PSRootsClosure(PSPromotionManager* pm) : _promotion_manager(pm) { } iveresov@3536: void do_oop(oop* p) { PSRootsClosure::do_oop_work(p); } iveresov@3536: void do_oop(narrowOop* p) { PSRootsClosure::do_oop_work(p); } jcoomes@2661: }; jcoomes@2661: iveresov@3536: typedef PSRootsClosure PSScavengeRootsClosure; iveresov@3536: typedef PSRootsClosure PSPromoteRootsClosure; iveresov@3536: coleenp@4037: // Scavenges a single oop in a Klass. coleenp@4037: class PSScavengeFromKlassClosure: public OopClosure { coleenp@4037: private: coleenp@4037: PSPromotionManager* _pm; coleenp@4037: // Used to redirty a scanned klass if it has oops coleenp@4037: // pointing to the young generation after being scanned. coleenp@4037: Klass* _scanned_klass; coleenp@4037: public: coleenp@4037: PSScavengeFromKlassClosure(PSPromotionManager* pm) : _pm(pm), _scanned_klass(NULL) { } coleenp@4037: void do_oop(narrowOop* p) { ShouldNotReachHere(); } coleenp@4037: void do_oop(oop* p) { coleenp@4037: ParallelScavengeHeap* psh = ParallelScavengeHeap::heap(); coleenp@4037: assert(!psh->is_in_reserved(p), "GC barrier needed"); coleenp@4037: if (PSScavenge::should_scavenge(p)) { coleenp@4037: assert(!Universe::heap()->is_in_reserved(p), "Not from meta-data?"); coleenp@4037: assert(PSScavenge::should_scavenge(p, true), "revisiting object?"); coleenp@4037: coleenp@4037: oop o = *p; coleenp@4037: oop new_obj; coleenp@4037: if (o->is_forwarded()) { coleenp@4037: new_obj = o->forwardee(); coleenp@4037: } else { coleenp@4037: new_obj = _pm->copy_to_survivor_space(o); coleenp@4037: } coleenp@4037: oopDesc::encode_store_heap_oop_not_null(p, new_obj); coleenp@4037: coleenp@4037: if (PSScavenge::is_obj_in_young((HeapWord*)new_obj)) { coleenp@4037: do_klass_barrier(); coleenp@4037: } coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: void set_scanned_klass(Klass* klass) { coleenp@4037: assert(_scanned_klass == NULL || klass == NULL, "Should always only handling one klass at a time"); coleenp@4037: _scanned_klass = klass; coleenp@4037: } coleenp@4037: coleenp@4037: private: coleenp@4037: void do_klass_barrier() { coleenp@4037: assert(_scanned_klass != NULL, "Should not be called without having a scanned klass"); coleenp@4037: _scanned_klass->record_modified_oops(); coleenp@4037: } coleenp@4037: coleenp@4037: }; coleenp@4037: coleenp@4037: // Scavenges the oop in a Klass. coleenp@4037: class PSScavengeKlassClosure: public KlassClosure { coleenp@4037: private: coleenp@4037: PSScavengeFromKlassClosure _oop_closure; coleenp@4037: protected: coleenp@4037: public: coleenp@4037: PSScavengeKlassClosure(PSPromotionManager* pm) : _oop_closure(pm) { } coleenp@4037: void do_klass(Klass* klass) { coleenp@4037: // If the klass has not been dirtied we know that there's coleenp@4037: // no references into the young gen and we can skip it. coleenp@4037: coleenp@4037: #ifndef PRODUCT coleenp@4037: if (TraceScavenge) { coleenp@4037: ResourceMark rm; coleenp@4037: gclog_or_tty->print_cr("PSScavengeKlassClosure::do_klass %p, %s, dirty: %s", coleenp@4037: klass, coleenp@4037: klass->external_name(), coleenp@4037: klass->has_modified_oops() ? "true" : "false"); coleenp@4037: } coleenp@4037: #endif coleenp@4037: coleenp@4037: if (klass->has_modified_oops()) { coleenp@4037: // Clean the klass since we're going to scavenge all the metadata. coleenp@4037: klass->clear_modified_oops(); coleenp@4037: coleenp@4037: // Setup the promotion manager to redirty this klass coleenp@4037: // if references are left in the young gen. coleenp@4037: _oop_closure.set_scanned_klass(klass); coleenp@4037: coleenp@4037: klass->oops_do(&_oop_closure); coleenp@4037: coleenp@4037: _oop_closure.set_scanned_klass(NULL); coleenp@4037: } coleenp@4037: } coleenp@4037: }; coleenp@4037: stefank@2314: #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP