1 /* 2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_INLINE_HPP 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_INLINE_HPP 27 28 #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp" 29 30 inline HeapWord* G1OffsetTableContigSpace::allocate(size_t size) { 31 HeapWord* res = ContiguousSpace::allocate(size); 32 if (res != NULL) { 33 _offsets.alloc_block(res, size); 34 } 35 return res; 36 } 37 38 // Because of the requirement of keeping "_offsets" up to date with the 39 // allocations, we sequentialize these with a lock. Therefore, best if 40 // this is used for larger LAB allocations only. 41 inline HeapWord* G1OffsetTableContigSpace::par_allocate(size_t size) { 42 MutexLocker x(&_par_alloc_lock); 43 // Given that we take the lock no need to use par_allocate() here. 44 HeapWord* res = ContiguousSpace::allocate(size); 45 if (res != NULL) { 46 _offsets.alloc_block(res, size); 47 } 48 return res; 49 } 50 51 inline HeapWord* G1OffsetTableContigSpace::block_start(const void* p) { 52 return _offsets.block_start(p); 53 } 54 55 inline HeapWord* 56 G1OffsetTableContigSpace::block_start_const(const void* p) const { 57 return _offsets.block_start_const(p); 58 } 59 60 inline void HeapRegion::note_start_of_marking() { 61 _next_marked_bytes = 0; 62 _next_top_at_mark_start = top(); 63 } 64 65 inline void HeapRegion::note_end_of_marking() { 66 _prev_top_at_mark_start = _next_top_at_mark_start; 67 _prev_marked_bytes = _next_marked_bytes; 68 _next_marked_bytes = 0; 69 70 assert(_prev_marked_bytes <= 71 (size_t) pointer_delta(prev_top_at_mark_start(), bottom()) * 72 HeapWordSize, "invariant"); 73 } 74 75 inline void HeapRegion::note_start_of_copying(bool during_initial_mark) { 76 if (is_survivor()) { 77 // This is how we always allocate survivors. 78 assert(_next_top_at_mark_start == bottom(), "invariant"); 79 } else { 80 if (during_initial_mark) { 81 // During initial-mark we'll explicitly mark any objects on old 82 // regions that are pointed to by roots. Given that explicit 83 // marks only make sense under NTAMS it'd be nice if we could 84 // check that condition if we wanted to. Given that we don't 85 // know where the top of this region will end up, we simply set 86 // NTAMS to the end of the region so all marks will be below 87 // NTAMS. We'll set it to the actual top when we retire this region. 88 _next_top_at_mark_start = end(); 89 } else { 90 // We could have re-used this old region as to-space over a 91 // couple of GCs since the start of the concurrent marking 92 // cycle. This means that [bottom,NTAMS) will contain objects 93 // copied up to and including initial-mark and [NTAMS, top) 94 // will contain objects copied during the concurrent marking cycle. 95 assert(top() >= _next_top_at_mark_start, "invariant"); 96 } 97 } 98 } 99 100 inline void HeapRegion::note_end_of_copying(bool during_initial_mark) { 101 if (is_survivor()) { 102 // This is how we always allocate survivors. 103 assert(_next_top_at_mark_start == bottom(), "invariant"); 104 } else { 105 if (during_initial_mark) { 106 // See the comment for note_start_of_copying() for the details 107 // on this. 108 assert(_next_top_at_mark_start == end(), "pre-condition"); 109 _next_top_at_mark_start = top(); 110 } else { 111 // See the comment for note_start_of_copying() for the details 112 // on this. 113 assert(top() >= _next_top_at_mark_start, "invariant"); 114 } 115 } 116 } 117 118 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_INLINE_HPP