1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/objectStartArray.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,144 @@ 1.4 +/* 1.5 + * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "gc_implementation/parallelScavenge/objectStartArray.hpp" 1.30 +#include "memory/allocation.inline.hpp" 1.31 +#include "memory/cardTableModRefBS.hpp" 1.32 +#include "oops/oop.inline.hpp" 1.33 +#include "runtime/java.hpp" 1.34 +#include "services/memTracker.hpp" 1.35 + 1.36 +void ObjectStartArray::initialize(MemRegion reserved_region) { 1.37 + // We're based on the assumption that we use the same 1.38 + // size blocks as the card table. 1.39 + assert((int)block_size == (int)CardTableModRefBS::card_size, "Sanity"); 1.40 + assert((int)block_size <= 512, "block_size must be less than or equal to 512"); 1.41 + 1.42 + // Calculate how much space must be reserved 1.43 + _reserved_region = reserved_region; 1.44 + 1.45 + size_t bytes_to_reserve = reserved_region.word_size() / block_size_in_words; 1.46 + assert(bytes_to_reserve > 0, "Sanity"); 1.47 + 1.48 + bytes_to_reserve = 1.49 + align_size_up(bytes_to_reserve, os::vm_allocation_granularity()); 1.50 + 1.51 + // Do not use large-pages for the backing store. The one large page region 1.52 + // will be used for the heap proper. 1.53 + ReservedSpace backing_store(bytes_to_reserve); 1.54 + if (!backing_store.is_reserved()) { 1.55 + vm_exit_during_initialization("Could not reserve space for ObjectStartArray"); 1.56 + } 1.57 + MemTracker::record_virtual_memory_type((address)backing_store.base(), mtGC); 1.58 + 1.59 + // We do not commit any memory initially 1.60 + if (!_virtual_space.initialize(backing_store, 0)) { 1.61 + vm_exit_during_initialization("Could not commit space for ObjectStartArray"); 1.62 + } 1.63 + 1.64 + _raw_base = (jbyte*)_virtual_space.low_boundary(); 1.65 + 1.66 + if (_raw_base == NULL) { 1.67 + vm_exit_during_initialization("Could not get raw_base address"); 1.68 + } 1.69 + 1.70 + MemTracker::record_virtual_memory_type((address)_raw_base, mtGC); 1.71 + 1.72 + 1.73 + _offset_base = _raw_base - (size_t(reserved_region.start()) >> block_shift); 1.74 + 1.75 + _covered_region.set_start(reserved_region.start()); 1.76 + _covered_region.set_word_size(0); 1.77 + 1.78 + _blocks_region.set_start((HeapWord*)_raw_base); 1.79 + _blocks_region.set_word_size(0); 1.80 +} 1.81 + 1.82 +void ObjectStartArray::set_covered_region(MemRegion mr) { 1.83 + assert(_reserved_region.contains(mr), "MemRegion outside of reserved space"); 1.84 + assert(_reserved_region.start() == mr.start(), "Attempt to move covered region"); 1.85 + 1.86 + HeapWord* low_bound = mr.start(); 1.87 + HeapWord* high_bound = mr.end(); 1.88 + assert((uintptr_t(low_bound) & (block_size - 1)) == 0, "heap must start at block boundary"); 1.89 + assert((uintptr_t(high_bound) & (block_size - 1)) == 0, "heap must end at block boundary"); 1.90 + 1.91 + size_t requested_blocks_size_in_bytes = mr.word_size() / block_size_in_words; 1.92 + 1.93 + // Only commit memory in page sized chunks 1.94 + requested_blocks_size_in_bytes = 1.95 + align_size_up(requested_blocks_size_in_bytes, os::vm_page_size()); 1.96 + 1.97 + _covered_region = mr; 1.98 + 1.99 + size_t current_blocks_size_in_bytes = _blocks_region.byte_size(); 1.100 + 1.101 + if (requested_blocks_size_in_bytes > current_blocks_size_in_bytes) { 1.102 + // Expand 1.103 + size_t expand_by = requested_blocks_size_in_bytes - current_blocks_size_in_bytes; 1.104 + if (!_virtual_space.expand_by(expand_by)) { 1.105 + vm_exit_out_of_memory(expand_by, OOM_MMAP_ERROR, "object start array expansion"); 1.106 + } 1.107 + // Clear *only* the newly allocated region 1.108 + memset(_blocks_region.end(), clean_block, expand_by); 1.109 + } 1.110 + 1.111 + if (requested_blocks_size_in_bytes < current_blocks_size_in_bytes) { 1.112 + // Shrink 1.113 + size_t shrink_by = current_blocks_size_in_bytes - requested_blocks_size_in_bytes; 1.114 + _virtual_space.shrink_by(shrink_by); 1.115 + } 1.116 + 1.117 + _blocks_region.set_word_size(requested_blocks_size_in_bytes / sizeof(HeapWord)); 1.118 + 1.119 + assert(requested_blocks_size_in_bytes % sizeof(HeapWord) == 0, "Block table not expanded in word sized increment"); 1.120 + assert(requested_blocks_size_in_bytes == _blocks_region.byte_size(), "Sanity"); 1.121 + assert(block_for_addr(low_bound) == &_raw_base[0], "Checking start of map"); 1.122 + assert(block_for_addr(high_bound-1) <= &_raw_base[_blocks_region.byte_size()-1], "Checking end of map"); 1.123 +} 1.124 + 1.125 +void ObjectStartArray::reset() { 1.126 + memset(_blocks_region.start(), clean_block, _blocks_region.byte_size()); 1.127 +} 1.128 + 1.129 + 1.130 +bool ObjectStartArray::object_starts_in_range(HeapWord* start_addr, 1.131 + HeapWord* end_addr) const { 1.132 + assert(start_addr <= end_addr, "range is wrong"); 1.133 + if (start_addr > end_addr) { 1.134 + return false; 1.135 + } 1.136 + 1.137 + jbyte* start_block = block_for_addr(start_addr); 1.138 + jbyte* end_block = block_for_addr(end_addr); 1.139 + 1.140 + for (jbyte* block = start_block; block <= end_block; block++) { 1.141 + if (*block != clean_block) { 1.142 + return true; 1.143 + } 1.144 + } 1.145 + 1.146 + return false; 1.147 +}