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

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6680
78bbf4d43a14
parent 421
7af4c98e9b67
child 9138
b56ab8e56604
permissions
-rw-r--r--

merge

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

mercurial