Tue, 08 Aug 2017 15:57:29 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2001, 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/objectStartArray.hpp" |
aoqi@0 | 27 | #include "memory/allocation.inline.hpp" |
aoqi@0 | 28 | #include "memory/cardTableModRefBS.hpp" |
aoqi@0 | 29 | #include "oops/oop.inline.hpp" |
aoqi@0 | 30 | #include "runtime/java.hpp" |
aoqi@0 | 31 | #include "services/memTracker.hpp" |
aoqi@0 | 32 | |
aoqi@0 | 33 | void ObjectStartArray::initialize(MemRegion reserved_region) { |
aoqi@0 | 34 | // We're based on the assumption that we use the same |
aoqi@0 | 35 | // size blocks as the card table. |
aoqi@0 | 36 | assert((int)block_size == (int)CardTableModRefBS::card_size, "Sanity"); |
aoqi@0 | 37 | assert((int)block_size <= 512, "block_size must be less than or equal to 512"); |
aoqi@0 | 38 | |
aoqi@0 | 39 | // Calculate how much space must be reserved |
aoqi@0 | 40 | _reserved_region = reserved_region; |
aoqi@0 | 41 | |
aoqi@0 | 42 | size_t bytes_to_reserve = reserved_region.word_size() / block_size_in_words; |
aoqi@0 | 43 | assert(bytes_to_reserve > 0, "Sanity"); |
aoqi@0 | 44 | |
aoqi@0 | 45 | bytes_to_reserve = |
aoqi@0 | 46 | align_size_up(bytes_to_reserve, os::vm_allocation_granularity()); |
aoqi@0 | 47 | |
aoqi@0 | 48 | // Do not use large-pages for the backing store. The one large page region |
aoqi@0 | 49 | // will be used for the heap proper. |
aoqi@0 | 50 | ReservedSpace backing_store(bytes_to_reserve); |
aoqi@0 | 51 | if (!backing_store.is_reserved()) { |
aoqi@0 | 52 | vm_exit_during_initialization("Could not reserve space for ObjectStartArray"); |
aoqi@0 | 53 | } |
aoqi@0 | 54 | MemTracker::record_virtual_memory_type((address)backing_store.base(), mtGC); |
aoqi@0 | 55 | |
aoqi@0 | 56 | // We do not commit any memory initially |
aoqi@0 | 57 | if (!_virtual_space.initialize(backing_store, 0)) { |
aoqi@0 | 58 | vm_exit_during_initialization("Could not commit space for ObjectStartArray"); |
aoqi@0 | 59 | } |
aoqi@0 | 60 | |
aoqi@0 | 61 | _raw_base = (jbyte*)_virtual_space.low_boundary(); |
aoqi@0 | 62 | |
aoqi@0 | 63 | if (_raw_base == NULL) { |
aoqi@0 | 64 | vm_exit_during_initialization("Could not get raw_base address"); |
aoqi@0 | 65 | } |
aoqi@0 | 66 | |
aoqi@0 | 67 | MemTracker::record_virtual_memory_type((address)_raw_base, mtGC); |
aoqi@0 | 68 | |
aoqi@0 | 69 | |
aoqi@0 | 70 | _offset_base = _raw_base - (size_t(reserved_region.start()) >> block_shift); |
aoqi@0 | 71 | |
aoqi@0 | 72 | _covered_region.set_start(reserved_region.start()); |
aoqi@0 | 73 | _covered_region.set_word_size(0); |
aoqi@0 | 74 | |
aoqi@0 | 75 | _blocks_region.set_start((HeapWord*)_raw_base); |
aoqi@0 | 76 | _blocks_region.set_word_size(0); |
aoqi@0 | 77 | } |
aoqi@0 | 78 | |
aoqi@0 | 79 | void ObjectStartArray::set_covered_region(MemRegion mr) { |
aoqi@0 | 80 | assert(_reserved_region.contains(mr), "MemRegion outside of reserved space"); |
aoqi@0 | 81 | assert(_reserved_region.start() == mr.start(), "Attempt to move covered region"); |
aoqi@0 | 82 | |
aoqi@0 | 83 | HeapWord* low_bound = mr.start(); |
aoqi@0 | 84 | HeapWord* high_bound = mr.end(); |
aoqi@0 | 85 | assert((uintptr_t(low_bound) & (block_size - 1)) == 0, "heap must start at block boundary"); |
aoqi@0 | 86 | assert((uintptr_t(high_bound) & (block_size - 1)) == 0, "heap must end at block boundary"); |
aoqi@0 | 87 | |
aoqi@0 | 88 | size_t requested_blocks_size_in_bytes = mr.word_size() / block_size_in_words; |
aoqi@0 | 89 | |
aoqi@0 | 90 | // Only commit memory in page sized chunks |
aoqi@0 | 91 | requested_blocks_size_in_bytes = |
aoqi@0 | 92 | align_size_up(requested_blocks_size_in_bytes, os::vm_page_size()); |
aoqi@0 | 93 | |
aoqi@0 | 94 | _covered_region = mr; |
aoqi@0 | 95 | |
aoqi@0 | 96 | size_t current_blocks_size_in_bytes = _blocks_region.byte_size(); |
aoqi@0 | 97 | |
aoqi@0 | 98 | if (requested_blocks_size_in_bytes > current_blocks_size_in_bytes) { |
aoqi@0 | 99 | // Expand |
aoqi@0 | 100 | size_t expand_by = requested_blocks_size_in_bytes - current_blocks_size_in_bytes; |
aoqi@0 | 101 | if (!_virtual_space.expand_by(expand_by)) { |
aoqi@0 | 102 | vm_exit_out_of_memory(expand_by, OOM_MMAP_ERROR, "object start array expansion"); |
aoqi@0 | 103 | } |
aoqi@0 | 104 | // Clear *only* the newly allocated region |
aoqi@0 | 105 | memset(_blocks_region.end(), clean_block, expand_by); |
aoqi@0 | 106 | } |
aoqi@0 | 107 | |
aoqi@0 | 108 | if (requested_blocks_size_in_bytes < current_blocks_size_in_bytes) { |
aoqi@0 | 109 | // Shrink |
aoqi@0 | 110 | size_t shrink_by = current_blocks_size_in_bytes - requested_blocks_size_in_bytes; |
aoqi@0 | 111 | _virtual_space.shrink_by(shrink_by); |
aoqi@0 | 112 | } |
aoqi@0 | 113 | |
aoqi@0 | 114 | _blocks_region.set_word_size(requested_blocks_size_in_bytes / sizeof(HeapWord)); |
aoqi@0 | 115 | |
aoqi@0 | 116 | assert(requested_blocks_size_in_bytes % sizeof(HeapWord) == 0, "Block table not expanded in word sized increment"); |
aoqi@0 | 117 | assert(requested_blocks_size_in_bytes == _blocks_region.byte_size(), "Sanity"); |
aoqi@0 | 118 | assert(block_for_addr(low_bound) == &_raw_base[0], "Checking start of map"); |
aoqi@0 | 119 | assert(block_for_addr(high_bound-1) <= &_raw_base[_blocks_region.byte_size()-1], "Checking end of map"); |
aoqi@0 | 120 | } |
aoqi@0 | 121 | |
aoqi@0 | 122 | void ObjectStartArray::reset() { |
aoqi@0 | 123 | memset(_blocks_region.start(), clean_block, _blocks_region.byte_size()); |
aoqi@0 | 124 | } |
aoqi@0 | 125 | |
aoqi@0 | 126 | |
aoqi@0 | 127 | bool ObjectStartArray::object_starts_in_range(HeapWord* start_addr, |
aoqi@0 | 128 | HeapWord* end_addr) const { |
aoqi@0 | 129 | assert(start_addr <= end_addr, "range is wrong"); |
aoqi@0 | 130 | if (start_addr > end_addr) { |
aoqi@0 | 131 | return false; |
aoqi@0 | 132 | } |
aoqi@0 | 133 | |
aoqi@0 | 134 | jbyte* start_block = block_for_addr(start_addr); |
aoqi@0 | 135 | jbyte* end_block = block_for_addr(end_addr); |
aoqi@0 | 136 | |
aoqi@0 | 137 | for (jbyte* block = start_block; block <= end_block; block++) { |
aoqi@0 | 138 | if (*block != clean_block) { |
aoqi@0 | 139 | return true; |
aoqi@0 | 140 | } |
aoqi@0 | 141 | } |
aoqi@0 | 142 | |
aoqi@0 | 143 | return false; |
aoqi@0 | 144 | } |