Wed, 27 Apr 2016 01:25:04 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2005, 2013, 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 | #include "precompiled.hpp" |
aoqi@0 | 26 | #include "gc_implementation/parallelScavenge/parMarkBitMap.hpp" |
aoqi@0 | 27 | #include "gc_implementation/parallelScavenge/psParallelCompact.hpp" |
aoqi@0 | 28 | #include "oops/oop.inline.hpp" |
aoqi@0 | 29 | #include "runtime/os.hpp" |
aoqi@0 | 30 | #include "utilities/bitMap.inline.hpp" |
aoqi@0 | 31 | #include "services/memTracker.hpp" |
aoqi@0 | 32 | #ifdef TARGET_OS_FAMILY_linux |
aoqi@0 | 33 | # include "os_linux.inline.hpp" |
aoqi@0 | 34 | #endif |
aoqi@0 | 35 | #ifdef TARGET_OS_FAMILY_solaris |
aoqi@0 | 36 | # include "os_solaris.inline.hpp" |
aoqi@0 | 37 | #endif |
aoqi@0 | 38 | #ifdef TARGET_OS_FAMILY_windows |
aoqi@0 | 39 | # include "os_windows.inline.hpp" |
aoqi@0 | 40 | #endif |
aoqi@0 | 41 | #ifdef TARGET_OS_FAMILY_aix |
aoqi@0 | 42 | # include "os_aix.inline.hpp" |
aoqi@0 | 43 | #endif |
aoqi@0 | 44 | #ifdef TARGET_OS_FAMILY_bsd |
aoqi@0 | 45 | # include "os_bsd.inline.hpp" |
aoqi@0 | 46 | #endif |
aoqi@0 | 47 | |
aoqi@0 | 48 | bool |
aoqi@0 | 49 | ParMarkBitMap::initialize(MemRegion covered_region) |
aoqi@0 | 50 | { |
aoqi@0 | 51 | const idx_t bits = bits_required(covered_region); |
aoqi@0 | 52 | // The bits will be divided evenly between two bitmaps; each of them should be |
aoqi@0 | 53 | // an integral number of words. |
aoqi@0 | 54 | assert(bits % (BitsPerWord * 2) == 0, "region size unaligned"); |
aoqi@0 | 55 | |
aoqi@0 | 56 | const size_t words = bits / BitsPerWord; |
aoqi@0 | 57 | const size_t raw_bytes = words * sizeof(idx_t); |
aoqi@0 | 58 | const size_t page_sz = os::page_size_for_region(raw_bytes, raw_bytes, 10); |
aoqi@0 | 59 | const size_t granularity = os::vm_allocation_granularity(); |
aoqi@0 | 60 | _reserved_byte_size = align_size_up(raw_bytes, MAX2(page_sz, granularity)); |
aoqi@0 | 61 | |
aoqi@0 | 62 | const size_t rs_align = page_sz == (size_t) os::vm_page_size() ? 0 : |
aoqi@0 | 63 | MAX2(page_sz, granularity); |
aoqi@0 | 64 | ReservedSpace rs(_reserved_byte_size, rs_align, rs_align > 0); |
aoqi@0 | 65 | os::trace_page_sizes("par bitmap", raw_bytes, raw_bytes, page_sz, |
aoqi@0 | 66 | rs.base(), rs.size()); |
aoqi@0 | 67 | |
aoqi@0 | 68 | MemTracker::record_virtual_memory_type((address)rs.base(), mtGC); |
aoqi@0 | 69 | |
aoqi@0 | 70 | _virtual_space = new PSVirtualSpace(rs, page_sz); |
aoqi@0 | 71 | if (_virtual_space != NULL && _virtual_space->expand_by(_reserved_byte_size)) { |
aoqi@0 | 72 | _region_start = covered_region.start(); |
aoqi@0 | 73 | _region_size = covered_region.word_size(); |
aoqi@0 | 74 | idx_t* map = (idx_t*)_virtual_space->reserved_low_addr(); |
aoqi@0 | 75 | _beg_bits.set_map(map); |
aoqi@0 | 76 | _beg_bits.set_size(bits / 2); |
aoqi@0 | 77 | _end_bits.set_map(map + words / 2); |
aoqi@0 | 78 | _end_bits.set_size(bits / 2); |
aoqi@0 | 79 | return true; |
aoqi@0 | 80 | } |
aoqi@0 | 81 | |
aoqi@0 | 82 | _region_start = 0; |
aoqi@0 | 83 | _region_size = 0; |
aoqi@0 | 84 | if (_virtual_space != NULL) { |
aoqi@0 | 85 | delete _virtual_space; |
aoqi@0 | 86 | _virtual_space = NULL; |
aoqi@0 | 87 | // Release memory reserved in the space. |
aoqi@0 | 88 | rs.release(); |
aoqi@0 | 89 | } |
aoqi@0 | 90 | return false; |
aoqi@0 | 91 | } |
aoqi@0 | 92 | |
aoqi@0 | 93 | #ifdef ASSERT |
aoqi@0 | 94 | extern size_t mark_bitmap_count; |
aoqi@0 | 95 | extern size_t mark_bitmap_size; |
aoqi@0 | 96 | #endif // #ifdef ASSERT |
aoqi@0 | 97 | |
aoqi@0 | 98 | bool |
aoqi@0 | 99 | ParMarkBitMap::mark_obj(HeapWord* addr, size_t size) |
aoqi@0 | 100 | { |
aoqi@0 | 101 | const idx_t beg_bit = addr_to_bit(addr); |
aoqi@0 | 102 | if (_beg_bits.par_set_bit(beg_bit)) { |
aoqi@0 | 103 | const idx_t end_bit = addr_to_bit(addr + size - 1); |
aoqi@0 | 104 | bool end_bit_ok = _end_bits.par_set_bit(end_bit); |
aoqi@0 | 105 | assert(end_bit_ok, "concurrency problem"); |
aoqi@0 | 106 | DEBUG_ONLY(Atomic::inc_ptr(&mark_bitmap_count)); |
aoqi@0 | 107 | DEBUG_ONLY(Atomic::add_ptr(size, &mark_bitmap_size)); |
aoqi@0 | 108 | return true; |
aoqi@0 | 109 | } |
aoqi@0 | 110 | return false; |
aoqi@0 | 111 | } |
aoqi@0 | 112 | |
aoqi@0 | 113 | size_t ParMarkBitMap::live_words_in_range(HeapWord* beg_addr, oop end_obj) const |
aoqi@0 | 114 | { |
aoqi@0 | 115 | assert(beg_addr <= (HeapWord*)end_obj, "bad range"); |
aoqi@0 | 116 | assert(is_marked(end_obj), "end_obj must be live"); |
aoqi@0 | 117 | |
aoqi@0 | 118 | idx_t live_bits = 0; |
aoqi@0 | 119 | |
aoqi@0 | 120 | // The bitmap routines require the right boundary to be word-aligned. |
aoqi@0 | 121 | const idx_t end_bit = addr_to_bit((HeapWord*)end_obj); |
aoqi@0 | 122 | const idx_t range_end = BitMap::word_align_up(end_bit); |
aoqi@0 | 123 | |
aoqi@0 | 124 | idx_t beg_bit = find_obj_beg(addr_to_bit(beg_addr), range_end); |
aoqi@0 | 125 | while (beg_bit < end_bit) { |
aoqi@0 | 126 | idx_t tmp_end = find_obj_end(beg_bit, range_end); |
aoqi@0 | 127 | assert(tmp_end < end_bit, "missing end bit"); |
aoqi@0 | 128 | live_bits += tmp_end - beg_bit + 1; |
aoqi@0 | 129 | beg_bit = find_obj_beg(tmp_end + 1, range_end); |
aoqi@0 | 130 | } |
aoqi@0 | 131 | return bits_to_words(live_bits); |
aoqi@0 | 132 | } |
aoqi@0 | 133 | |
aoqi@0 | 134 | ParMarkBitMap::IterationStatus |
aoqi@0 | 135 | ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure, |
aoqi@0 | 136 | idx_t range_beg, idx_t range_end) const |
aoqi@0 | 137 | { |
aoqi@0 | 138 | DEBUG_ONLY(verify_bit(range_beg);) |
aoqi@0 | 139 | DEBUG_ONLY(verify_bit(range_end);) |
aoqi@0 | 140 | assert(range_beg <= range_end, "live range invalid"); |
aoqi@0 | 141 | |
aoqi@0 | 142 | // The bitmap routines require the right boundary to be word-aligned. |
aoqi@0 | 143 | const idx_t search_end = BitMap::word_align_up(range_end); |
aoqi@0 | 144 | |
aoqi@0 | 145 | idx_t cur_beg = find_obj_beg(range_beg, search_end); |
aoqi@0 | 146 | while (cur_beg < range_end) { |
aoqi@0 | 147 | const idx_t cur_end = find_obj_end(cur_beg, search_end); |
aoqi@0 | 148 | if (cur_end >= range_end) { |
aoqi@0 | 149 | // The obj ends outside the range. |
aoqi@0 | 150 | live_closure->set_source(bit_to_addr(cur_beg)); |
aoqi@0 | 151 | return incomplete; |
aoqi@0 | 152 | } |
aoqi@0 | 153 | |
aoqi@0 | 154 | const size_t size = obj_size(cur_beg, cur_end); |
aoqi@0 | 155 | IterationStatus status = live_closure->do_addr(bit_to_addr(cur_beg), size); |
aoqi@0 | 156 | if (status != incomplete) { |
aoqi@0 | 157 | assert(status == would_overflow || status == full, "sanity"); |
aoqi@0 | 158 | return status; |
aoqi@0 | 159 | } |
aoqi@0 | 160 | |
aoqi@0 | 161 | // Successfully processed the object; look for the next object. |
aoqi@0 | 162 | cur_beg = find_obj_beg(cur_end + 1, search_end); |
aoqi@0 | 163 | } |
aoqi@0 | 164 | |
aoqi@0 | 165 | live_closure->set_source(bit_to_addr(range_end)); |
aoqi@0 | 166 | return complete; |
aoqi@0 | 167 | } |
aoqi@0 | 168 | |
aoqi@0 | 169 | ParMarkBitMap::IterationStatus |
aoqi@0 | 170 | ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure, |
aoqi@0 | 171 | ParMarkBitMapClosure* dead_closure, |
aoqi@0 | 172 | idx_t range_beg, idx_t range_end, |
aoqi@0 | 173 | idx_t dead_range_end) const |
aoqi@0 | 174 | { |
aoqi@0 | 175 | DEBUG_ONLY(verify_bit(range_beg);) |
aoqi@0 | 176 | DEBUG_ONLY(verify_bit(range_end);) |
aoqi@0 | 177 | DEBUG_ONLY(verify_bit(dead_range_end);) |
aoqi@0 | 178 | assert(range_beg <= range_end, "live range invalid"); |
aoqi@0 | 179 | assert(range_end <= dead_range_end, "dead range invalid"); |
aoqi@0 | 180 | |
aoqi@0 | 181 | // The bitmap routines require the right boundary to be word-aligned. |
aoqi@0 | 182 | const idx_t live_search_end = BitMap::word_align_up(range_end); |
aoqi@0 | 183 | const idx_t dead_search_end = BitMap::word_align_up(dead_range_end); |
aoqi@0 | 184 | |
aoqi@0 | 185 | idx_t cur_beg = range_beg; |
aoqi@0 | 186 | if (range_beg < range_end && is_unmarked(range_beg)) { |
aoqi@0 | 187 | // The range starts with dead space. Look for the next object, then fill. |
aoqi@0 | 188 | cur_beg = find_obj_beg(range_beg + 1, dead_search_end); |
aoqi@0 | 189 | const idx_t dead_space_end = MIN2(cur_beg - 1, dead_range_end - 1); |
aoqi@0 | 190 | const size_t size = obj_size(range_beg, dead_space_end); |
aoqi@0 | 191 | dead_closure->do_addr(bit_to_addr(range_beg), size); |
aoqi@0 | 192 | } |
aoqi@0 | 193 | |
aoqi@0 | 194 | while (cur_beg < range_end) { |
aoqi@0 | 195 | const idx_t cur_end = find_obj_end(cur_beg, live_search_end); |
aoqi@0 | 196 | if (cur_end >= range_end) { |
aoqi@0 | 197 | // The obj ends outside the range. |
aoqi@0 | 198 | live_closure->set_source(bit_to_addr(cur_beg)); |
aoqi@0 | 199 | return incomplete; |
aoqi@0 | 200 | } |
aoqi@0 | 201 | |
aoqi@0 | 202 | const size_t size = obj_size(cur_beg, cur_end); |
aoqi@0 | 203 | IterationStatus status = live_closure->do_addr(bit_to_addr(cur_beg), size); |
aoqi@0 | 204 | if (status != incomplete) { |
aoqi@0 | 205 | assert(status == would_overflow || status == full, "sanity"); |
aoqi@0 | 206 | return status; |
aoqi@0 | 207 | } |
aoqi@0 | 208 | |
aoqi@0 | 209 | // Look for the start of the next object. |
aoqi@0 | 210 | const idx_t dead_space_beg = cur_end + 1; |
aoqi@0 | 211 | cur_beg = find_obj_beg(dead_space_beg, dead_search_end); |
aoqi@0 | 212 | if (cur_beg > dead_space_beg) { |
aoqi@0 | 213 | // Found dead space; compute the size and invoke the dead closure. |
aoqi@0 | 214 | const idx_t dead_space_end = MIN2(cur_beg - 1, dead_range_end - 1); |
aoqi@0 | 215 | const size_t size = obj_size(dead_space_beg, dead_space_end); |
aoqi@0 | 216 | dead_closure->do_addr(bit_to_addr(dead_space_beg), size); |
aoqi@0 | 217 | } |
aoqi@0 | 218 | } |
aoqi@0 | 219 | |
aoqi@0 | 220 | live_closure->set_source(bit_to_addr(range_end)); |
aoqi@0 | 221 | return complete; |
aoqi@0 | 222 | } |
aoqi@0 | 223 | |
aoqi@0 | 224 | #ifdef ASSERT |
aoqi@0 | 225 | void ParMarkBitMap::verify_clear() const |
aoqi@0 | 226 | { |
aoqi@0 | 227 | const idx_t* const beg = (const idx_t*)_virtual_space->committed_low_addr(); |
aoqi@0 | 228 | const idx_t* const end = (const idx_t*)_virtual_space->committed_high_addr(); |
aoqi@0 | 229 | for (const idx_t* p = beg; p < end; ++p) { |
aoqi@0 | 230 | assert(*p == 0, "bitmap not clear"); |
aoqi@0 | 231 | } |
aoqi@0 | 232 | } |
aoqi@0 | 233 | #endif // #ifdef ASSERT |