src/share/vm/gc_implementation/parallelScavenge/psScavenge.inline.hpp

Fri, 17 May 2013 11:57:05 +0200

author
ehelin
date
Fri, 17 May 2013 11:57:05 +0200
changeset 5159
001ec9515f84
parent 4037
da91efe96a93
child 5202
47bdfb3d010f
permissions
-rw-r--r--

8014277: Remove ObjectClosure as base class for BoolObjectClosure
Reviewed-by: brutisso, tschatzl

duke@435 1 /*
iveresov@3536 2 * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP
stefank@2314 26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP
stefank@2314 27
stefank@2314 28 #include "gc_implementation/parallelScavenge/cardTableExtension.hpp"
stefank@2314 29 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
stefank@2314 30 #include "gc_implementation/parallelScavenge/psPromotionManager.hpp"
iveresov@3536 31 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
stefank@2314 32 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
coleenp@4037 33 #include "memory/iterator.hpp"
stefank@2314 34
duke@435 35 inline void PSScavenge::save_to_space_top_before_gc() {
duke@435 36 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 37 _to_space_top_before_gc = heap->young_gen()->to_space()->top();
duke@435 38 }
duke@435 39
coleenp@548 40 template <class T> inline bool PSScavenge::should_scavenge(T* p) {
coleenp@548 41 T heap_oop = oopDesc::load_heap_oop(p);
coleenp@548 42 if (oopDesc::is_null(heap_oop)) return false;
coleenp@548 43 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
coleenp@548 44 return PSScavenge::is_obj_in_young((HeapWord*)obj);
duke@435 45 }
duke@435 46
coleenp@548 47 template <class T>
coleenp@548 48 inline bool PSScavenge::should_scavenge(T* p, MutableSpace* to_space) {
duke@435 49 if (should_scavenge(p)) {
coleenp@548 50 oop obj = oopDesc::load_decode_heap_oop_not_null(p);
duke@435 51 // Skip objects copied to to_space since the scavenge started.
coleenp@548 52 HeapWord* const addr = (HeapWord*)obj;
duke@435 53 return addr < to_space_top_before_gc() || addr >= to_space->end();
duke@435 54 }
duke@435 55 return false;
duke@435 56 }
duke@435 57
coleenp@548 58 template <class T>
coleenp@548 59 inline bool PSScavenge::should_scavenge(T* p, bool check_to_space) {
duke@435 60 if (check_to_space) {
coleenp@548 61 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 62 return should_scavenge(p, heap->young_gen()->to_space());
duke@435 63 }
duke@435 64 return should_scavenge(p);
duke@435 65 }
duke@435 66
duke@435 67 // Attempt to "claim" oop at p via CAS, push the new obj if successful
duke@435 68 // This version tests the oop* to make sure it is within the heap before
duke@435 69 // attempting marking.
iveresov@3536 70 template <class T, bool promote_immediately>
duke@435 71 inline void PSScavenge::copy_and_push_safe_barrier(PSPromotionManager* pm,
coleenp@548 72 T* p) {
coleenp@548 73 assert(should_scavenge(p, true), "revisiting object?");
duke@435 74
coleenp@548 75 oop o = oopDesc::load_decode_heap_oop_not_null(p);
coleenp@548 76 oop new_obj = o->is_forwarded()
coleenp@548 77 ? o->forwardee()
iveresov@3536 78 : pm->copy_to_survivor_space<promote_immediately>(o);
coleenp@4037 79
coleenp@4037 80 #ifndef PRODUCT
coleenp@4037 81 // This code must come after the CAS test, or it will print incorrect
coleenp@4037 82 // information.
coleenp@4037 83 if (TraceScavenge && o->is_forwarded()) {
coleenp@4037 84 gclog_or_tty->print_cr("{%s %s " PTR_FORMAT " -> " PTR_FORMAT " (%d)}",
coleenp@4037 85 "forwarding",
coleenp@4037 86 new_obj->klass()->internal_name(), o, new_obj, new_obj->size());
coleenp@4037 87 }
coleenp@4037 88 #endif
coleenp@4037 89
coleenp@548 90 oopDesc::encode_store_heap_oop_not_null(p, new_obj);
duke@435 91
duke@435 92 // We cannot mark without test, as some code passes us pointers
coleenp@4037 93 // that are outside the heap. These pointers are either from roots
coleenp@4037 94 // or from metadata.
coleenp@548 95 if ((!PSScavenge::is_obj_in_young((HeapWord*)p)) &&
duke@435 96 Universe::heap()->is_in_reserved(p)) {
coleenp@548 97 if (PSScavenge::is_obj_in_young((HeapWord*)new_obj)) {
coleenp@548 98 card_table()->inline_write_ref_field_gc(p, new_obj);
duke@435 99 }
duke@435 100 }
duke@435 101 }
stefank@2314 102
iveresov@3536 103 template<bool promote_immediately>
iveresov@3536 104 class PSRootsClosure: public OopClosure {
jcoomes@2661 105 private:
jcoomes@2661 106 PSPromotionManager* _promotion_manager;
jcoomes@2661 107
jcoomes@2661 108 protected:
jcoomes@2661 109 template <class T> void do_oop_work(T *p) {
jcoomes@2661 110 if (PSScavenge::should_scavenge(p)) {
jcoomes@2661 111 // We never card mark roots, maybe call a func without test?
iveresov@3536 112 PSScavenge::copy_and_push_safe_barrier<T, promote_immediately>(_promotion_manager, p);
jcoomes@2661 113 }
jcoomes@2661 114 }
jcoomes@2661 115 public:
iveresov@3536 116 PSRootsClosure(PSPromotionManager* pm) : _promotion_manager(pm) { }
iveresov@3536 117 void do_oop(oop* p) { PSRootsClosure::do_oop_work(p); }
iveresov@3536 118 void do_oop(narrowOop* p) { PSRootsClosure::do_oop_work(p); }
jcoomes@2661 119 };
jcoomes@2661 120
iveresov@3536 121 typedef PSRootsClosure</*promote_immediately=*/false> PSScavengeRootsClosure;
iveresov@3536 122 typedef PSRootsClosure</*promote_immediately=*/true> PSPromoteRootsClosure;
iveresov@3536 123
coleenp@4037 124 // Scavenges a single oop in a Klass.
coleenp@4037 125 class PSScavengeFromKlassClosure: public OopClosure {
coleenp@4037 126 private:
coleenp@4037 127 PSPromotionManager* _pm;
coleenp@4037 128 // Used to redirty a scanned klass if it has oops
coleenp@4037 129 // pointing to the young generation after being scanned.
coleenp@4037 130 Klass* _scanned_klass;
coleenp@4037 131 public:
coleenp@4037 132 PSScavengeFromKlassClosure(PSPromotionManager* pm) : _pm(pm), _scanned_klass(NULL) { }
coleenp@4037 133 void do_oop(narrowOop* p) { ShouldNotReachHere(); }
coleenp@4037 134 void do_oop(oop* p) {
coleenp@4037 135 ParallelScavengeHeap* psh = ParallelScavengeHeap::heap();
coleenp@4037 136 assert(!psh->is_in_reserved(p), "GC barrier needed");
coleenp@4037 137 if (PSScavenge::should_scavenge(p)) {
coleenp@4037 138 assert(!Universe::heap()->is_in_reserved(p), "Not from meta-data?");
coleenp@4037 139 assert(PSScavenge::should_scavenge(p, true), "revisiting object?");
coleenp@4037 140
coleenp@4037 141 oop o = *p;
coleenp@4037 142 oop new_obj;
coleenp@4037 143 if (o->is_forwarded()) {
coleenp@4037 144 new_obj = o->forwardee();
coleenp@4037 145 } else {
coleenp@4037 146 new_obj = _pm->copy_to_survivor_space</*promote_immediately=*/false>(o);
coleenp@4037 147 }
coleenp@4037 148 oopDesc::encode_store_heap_oop_not_null(p, new_obj);
coleenp@4037 149
coleenp@4037 150 if (PSScavenge::is_obj_in_young((HeapWord*)new_obj)) {
coleenp@4037 151 do_klass_barrier();
coleenp@4037 152 }
coleenp@4037 153 }
coleenp@4037 154 }
coleenp@4037 155
coleenp@4037 156 void set_scanned_klass(Klass* klass) {
coleenp@4037 157 assert(_scanned_klass == NULL || klass == NULL, "Should always only handling one klass at a time");
coleenp@4037 158 _scanned_klass = klass;
coleenp@4037 159 }
coleenp@4037 160
coleenp@4037 161 private:
coleenp@4037 162 void do_klass_barrier() {
coleenp@4037 163 assert(_scanned_klass != NULL, "Should not be called without having a scanned klass");
coleenp@4037 164 _scanned_klass->record_modified_oops();
coleenp@4037 165 }
coleenp@4037 166
coleenp@4037 167 };
coleenp@4037 168
coleenp@4037 169 // Scavenges the oop in a Klass.
coleenp@4037 170 class PSScavengeKlassClosure: public KlassClosure {
coleenp@4037 171 private:
coleenp@4037 172 PSScavengeFromKlassClosure _oop_closure;
coleenp@4037 173 protected:
coleenp@4037 174 public:
coleenp@4037 175 PSScavengeKlassClosure(PSPromotionManager* pm) : _oop_closure(pm) { }
coleenp@4037 176 void do_klass(Klass* klass) {
coleenp@4037 177 // If the klass has not been dirtied we know that there's
coleenp@4037 178 // no references into the young gen and we can skip it.
coleenp@4037 179
coleenp@4037 180 #ifndef PRODUCT
coleenp@4037 181 if (TraceScavenge) {
coleenp@4037 182 ResourceMark rm;
coleenp@4037 183 gclog_or_tty->print_cr("PSScavengeKlassClosure::do_klass %p, %s, dirty: %s",
coleenp@4037 184 klass,
coleenp@4037 185 klass->external_name(),
coleenp@4037 186 klass->has_modified_oops() ? "true" : "false");
coleenp@4037 187 }
coleenp@4037 188 #endif
coleenp@4037 189
coleenp@4037 190 if (klass->has_modified_oops()) {
coleenp@4037 191 // Clean the klass since we're going to scavenge all the metadata.
coleenp@4037 192 klass->clear_modified_oops();
coleenp@4037 193
coleenp@4037 194 // Setup the promotion manager to redirty this klass
coleenp@4037 195 // if references are left in the young gen.
coleenp@4037 196 _oop_closure.set_scanned_klass(klass);
coleenp@4037 197
coleenp@4037 198 klass->oops_do(&_oop_closure);
coleenp@4037 199
coleenp@4037 200 _oop_closure.set_scanned_klass(NULL);
coleenp@4037 201 }
coleenp@4037 202 }
coleenp@4037 203 };
coleenp@4037 204
stefank@2314 205 #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP

mercurial