src/share/vm/gc_implementation/g1/heapRegion.inline.hpp

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 7535
7ae4e26cb1e0
child 9448
73d689add964
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2001, 2012, 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_G1_HEAPREGION_INLINE_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_INLINE_HPP
aoqi@0 27
mgerdin@6987 28 #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp"
mgerdin@6990 29 #include "gc_implementation/g1/g1CollectedHeap.hpp"
mgerdin@6990 30 #include "gc_implementation/g1/heapRegion.hpp"
mgerdin@6990 31 #include "memory/space.hpp"
mgerdin@6990 32 #include "runtime/atomic.inline.hpp"
mgerdin@6990 33
mgerdin@6990 34 // This version requires locking.
mgerdin@6990 35 inline HeapWord* G1OffsetTableContigSpace::allocate_impl(size_t size,
mgerdin@6990 36 HeapWord* const end_value) {
mgerdin@6990 37 HeapWord* obj = top();
mgerdin@6990 38 if (pointer_delta(end_value, obj) >= size) {
mgerdin@6990 39 HeapWord* new_top = obj + size;
mgerdin@6990 40 set_top(new_top);
mgerdin@6990 41 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
mgerdin@6990 42 return obj;
mgerdin@6990 43 } else {
mgerdin@6990 44 return NULL;
mgerdin@6990 45 }
mgerdin@6990 46 }
mgerdin@6990 47
mgerdin@6990 48 // This version is lock-free.
mgerdin@6990 49 inline HeapWord* G1OffsetTableContigSpace::par_allocate_impl(size_t size,
mgerdin@6990 50 HeapWord* const end_value) {
mgerdin@6990 51 do {
mgerdin@6990 52 HeapWord* obj = top();
mgerdin@6990 53 if (pointer_delta(end_value, obj) >= size) {
mgerdin@6990 54 HeapWord* new_top = obj + size;
mgerdin@6990 55 HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
mgerdin@6990 56 // result can be one of two:
mgerdin@6990 57 // the old top value: the exchange succeeded
mgerdin@6990 58 // otherwise: the new value of the top is returned.
mgerdin@6990 59 if (result == obj) {
mgerdin@6990 60 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
mgerdin@6990 61 return obj;
mgerdin@6990 62 }
mgerdin@6990 63 } else {
mgerdin@6990 64 return NULL;
mgerdin@6990 65 }
mgerdin@6990 66 } while (true);
mgerdin@6990 67 }
mgerdin@6987 68
aoqi@0 69 inline HeapWord* G1OffsetTableContigSpace::allocate(size_t size) {
mgerdin@6990 70 HeapWord* res = allocate_impl(size, end());
aoqi@0 71 if (res != NULL) {
aoqi@0 72 _offsets.alloc_block(res, size);
aoqi@0 73 }
aoqi@0 74 return res;
aoqi@0 75 }
aoqi@0 76
aoqi@0 77 // Because of the requirement of keeping "_offsets" up to date with the
aoqi@0 78 // allocations, we sequentialize these with a lock. Therefore, best if
aoqi@0 79 // this is used for larger LAB allocations only.
aoqi@0 80 inline HeapWord* G1OffsetTableContigSpace::par_allocate(size_t size) {
aoqi@0 81 MutexLocker x(&_par_alloc_lock);
mgerdin@6990 82 return allocate(size);
aoqi@0 83 }
aoqi@0 84
aoqi@0 85 inline HeapWord* G1OffsetTableContigSpace::block_start(const void* p) {
aoqi@0 86 return _offsets.block_start(p);
aoqi@0 87 }
aoqi@0 88
aoqi@0 89 inline HeapWord*
aoqi@0 90 G1OffsetTableContigSpace::block_start_const(const void* p) const {
aoqi@0 91 return _offsets.block_start_const(p);
aoqi@0 92 }
aoqi@0 93
mgerdin@6990 94 inline bool
mgerdin@6990 95 HeapRegion::block_is_obj(const HeapWord* p) const {
stefank@6992 96 G1CollectedHeap* g1h = G1CollectedHeap::heap();
stefank@6996 97 if (ClassUnloadingWithConcurrentMark) {
stefank@6996 98 return !g1h->is_obj_dead(oop(p), this);
stefank@6996 99 }
stefank@6996 100 return p < top();
mgerdin@6990 101 }
mgerdin@6990 102
mgerdin@6990 103 inline size_t
mgerdin@6990 104 HeapRegion::block_size(const HeapWord *addr) const {
stefank@6996 105 if (addr == top()) {
stefank@6996 106 return pointer_delta(end(), addr);
stefank@6996 107 }
stefank@6996 108
stefank@6996 109 if (block_is_obj(addr)) {
stefank@6996 110 return oop(addr)->size();
stefank@6996 111 }
stefank@6996 112
stefank@6996 113 assert(ClassUnloadingWithConcurrentMark,
stefank@6996 114 err_msg("All blocks should be objects if G1 Class Unloading isn't used. "
stefank@6996 115 "HR: ["PTR_FORMAT", "PTR_FORMAT", "PTR_FORMAT") "
stefank@6996 116 "addr: " PTR_FORMAT,
stefank@6996 117 p2i(bottom()), p2i(top()), p2i(end()), p2i(addr)));
stefank@6996 118
stefank@6992 119 // Old regions' dead objects may have dead classes
stefank@6992 120 // We need to find the next live object in some other
stefank@6992 121 // manner than getting the oop size
stefank@6992 122 G1CollectedHeap* g1h = G1CollectedHeap::heap();
stefank@6996 123 HeapWord* next = g1h->concurrent_mark()->prevMarkBitMap()->
stefank@6996 124 getNextMarkedWordAddress(addr, prev_top_at_mark_start());
stefank@6992 125
stefank@6996 126 assert(next > addr, "must get the next live object");
stefank@6996 127 return pointer_delta(next, addr);
mgerdin@6990 128 }
mgerdin@6990 129
mgerdin@6990 130 inline HeapWord* HeapRegion::par_allocate_no_bot_updates(size_t word_size) {
mgerdin@6990 131 assert(is_young(), "we can only skip BOT updates on young regions");
mgerdin@6990 132 return par_allocate_impl(word_size, end());
mgerdin@6990 133 }
mgerdin@6990 134
mgerdin@6990 135 inline HeapWord* HeapRegion::allocate_no_bot_updates(size_t word_size) {
mgerdin@6990 136 assert(is_young(), "we can only skip BOT updates on young regions");
mgerdin@6990 137 return allocate_impl(word_size, end());
mgerdin@6990 138 }
mgerdin@6990 139
aoqi@0 140 inline void HeapRegion::note_start_of_marking() {
aoqi@0 141 _next_marked_bytes = 0;
aoqi@0 142 _next_top_at_mark_start = top();
aoqi@0 143 }
aoqi@0 144
aoqi@0 145 inline void HeapRegion::note_end_of_marking() {
aoqi@0 146 _prev_top_at_mark_start = _next_top_at_mark_start;
aoqi@0 147 _prev_marked_bytes = _next_marked_bytes;
aoqi@0 148 _next_marked_bytes = 0;
aoqi@0 149
aoqi@0 150 assert(_prev_marked_bytes <=
aoqi@0 151 (size_t) pointer_delta(prev_top_at_mark_start(), bottom()) *
aoqi@0 152 HeapWordSize, "invariant");
aoqi@0 153 }
aoqi@0 154
aoqi@0 155 inline void HeapRegion::note_start_of_copying(bool during_initial_mark) {
aoqi@0 156 if (is_survivor()) {
aoqi@0 157 // This is how we always allocate survivors.
aoqi@0 158 assert(_next_top_at_mark_start == bottom(), "invariant");
aoqi@0 159 } else {
aoqi@0 160 if (during_initial_mark) {
aoqi@0 161 // During initial-mark we'll explicitly mark any objects on old
aoqi@0 162 // regions that are pointed to by roots. Given that explicit
aoqi@0 163 // marks only make sense under NTAMS it'd be nice if we could
aoqi@0 164 // check that condition if we wanted to. Given that we don't
aoqi@0 165 // know where the top of this region will end up, we simply set
aoqi@0 166 // NTAMS to the end of the region so all marks will be below
aoqi@0 167 // NTAMS. We'll set it to the actual top when we retire this region.
aoqi@0 168 _next_top_at_mark_start = end();
aoqi@0 169 } else {
aoqi@0 170 // We could have re-used this old region as to-space over a
aoqi@0 171 // couple of GCs since the start of the concurrent marking
aoqi@0 172 // cycle. This means that [bottom,NTAMS) will contain objects
aoqi@0 173 // copied up to and including initial-mark and [NTAMS, top)
aoqi@0 174 // will contain objects copied during the concurrent marking cycle.
aoqi@0 175 assert(top() >= _next_top_at_mark_start, "invariant");
aoqi@0 176 }
aoqi@0 177 }
aoqi@0 178 }
aoqi@0 179
aoqi@0 180 inline void HeapRegion::note_end_of_copying(bool during_initial_mark) {
aoqi@0 181 if (is_survivor()) {
aoqi@0 182 // This is how we always allocate survivors.
aoqi@0 183 assert(_next_top_at_mark_start == bottom(), "invariant");
aoqi@0 184 } else {
aoqi@0 185 if (during_initial_mark) {
aoqi@0 186 // See the comment for note_start_of_copying() for the details
aoqi@0 187 // on this.
aoqi@0 188 assert(_next_top_at_mark_start == end(), "pre-condition");
aoqi@0 189 _next_top_at_mark_start = top();
aoqi@0 190 } else {
aoqi@0 191 // See the comment for note_start_of_copying() for the details
aoqi@0 192 // on this.
aoqi@0 193 assert(top() >= _next_top_at_mark_start, "invariant");
aoqi@0 194 }
aoqi@0 195 }
aoqi@0 196 }
aoqi@0 197
aoqi@0 198 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_INLINE_HPP

mercurial