1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/objectStartArray.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,137 @@ 1.4 +/* 1.5 + * Copyright 2001-2005 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +# include "incls/_precompiled.incl" 1.29 +# include "incls/_objectStartArray.cpp.incl" 1.30 + 1.31 +void ObjectStartArray::initialize(MemRegion reserved_region) { 1.32 + // We're based on the assumption that we use the same 1.33 + // size blocks as the card table. 1.34 + assert((int)block_size == (int)CardTableModRefBS::card_size, "Sanity"); 1.35 + assert((int)block_size <= 512, "block_size must be less than or equal to 512"); 1.36 + 1.37 + // Calculate how much space must be reserved 1.38 + _reserved_region = reserved_region; 1.39 + 1.40 + size_t bytes_to_reserve = reserved_region.word_size() / block_size_in_words; 1.41 + assert(bytes_to_reserve > 0, "Sanity"); 1.42 + 1.43 + bytes_to_reserve = 1.44 + align_size_up(bytes_to_reserve, os::vm_allocation_granularity()); 1.45 + 1.46 + // Do not use large-pages for the backing store. The one large page region 1.47 + // will be used for the heap proper. 1.48 + ReservedSpace backing_store(bytes_to_reserve); 1.49 + if (!backing_store.is_reserved()) { 1.50 + vm_exit_during_initialization("Could not reserve space for ObjectStartArray"); 1.51 + } 1.52 + 1.53 + // We do not commit any memory initially 1.54 + if (!_virtual_space.initialize(backing_store, 0)) { 1.55 + vm_exit_during_initialization("Could not commit space for ObjectStartArray"); 1.56 + } 1.57 + 1.58 + _raw_base = (jbyte*)_virtual_space.low_boundary(); 1.59 + if (_raw_base == NULL) { 1.60 + vm_exit_during_initialization("Could not get raw_base address"); 1.61 + } 1.62 + 1.63 + _offset_base = _raw_base - (size_t(reserved_region.start()) >> block_shift); 1.64 + 1.65 + _covered_region.set_start(reserved_region.start()); 1.66 + _covered_region.set_word_size(0); 1.67 + 1.68 + _blocks_region.set_start((HeapWord*)_raw_base); 1.69 + _blocks_region.set_word_size(0); 1.70 +} 1.71 + 1.72 +void ObjectStartArray::set_covered_region(MemRegion mr) { 1.73 + assert(_reserved_region.contains(mr), "MemRegion outside of reserved space"); 1.74 + assert(_reserved_region.start() == mr.start(), "Attempt to move covered region"); 1.75 + 1.76 + HeapWord* low_bound = mr.start(); 1.77 + HeapWord* high_bound = mr.end(); 1.78 + assert((uintptr_t(low_bound) & (block_size - 1)) == 0, "heap must start at block boundary"); 1.79 + assert((uintptr_t(high_bound) & (block_size - 1)) == 0, "heap must end at block boundary"); 1.80 + 1.81 + size_t requested_blocks_size_in_bytes = mr.word_size() / block_size_in_words; 1.82 + 1.83 + // Only commit memory in page sized chunks 1.84 + requested_blocks_size_in_bytes = 1.85 + align_size_up(requested_blocks_size_in_bytes, os::vm_page_size()); 1.86 + 1.87 + _covered_region = mr; 1.88 + 1.89 + size_t current_blocks_size_in_bytes = _blocks_region.byte_size(); 1.90 + 1.91 + if (requested_blocks_size_in_bytes > current_blocks_size_in_bytes) { 1.92 + // Expand 1.93 + size_t expand_by = requested_blocks_size_in_bytes - current_blocks_size_in_bytes; 1.94 + if (!_virtual_space.expand_by(expand_by)) { 1.95 + vm_exit_out_of_memory(expand_by, "object start array expansion"); 1.96 + } 1.97 + // Clear *only* the newly allocated region 1.98 + memset(_blocks_region.end(), clean_block, expand_by); 1.99 + } 1.100 + 1.101 + if (requested_blocks_size_in_bytes < current_blocks_size_in_bytes) { 1.102 + // Shrink 1.103 + size_t shrink_by = current_blocks_size_in_bytes - requested_blocks_size_in_bytes; 1.104 + _virtual_space.shrink_by(shrink_by); 1.105 + } 1.106 + 1.107 + _blocks_region.set_word_size(requested_blocks_size_in_bytes / sizeof(HeapWord)); 1.108 + 1.109 + assert(requested_blocks_size_in_bytes % sizeof(HeapWord) == 0, "Block table not expanded in word sized increment"); 1.110 + assert(requested_blocks_size_in_bytes == _blocks_region.byte_size(), "Sanity"); 1.111 + assert(block_for_addr(low_bound) == &_raw_base[0], "Checking start of map"); 1.112 + assert(block_for_addr(high_bound-1) <= &_raw_base[_blocks_region.byte_size()-1], "Checking end of map"); 1.113 +} 1.114 + 1.115 +void ObjectStartArray::reset() { 1.116 + memset(_blocks_region.start(), clean_block, _blocks_region.byte_size()); 1.117 +} 1.118 + 1.119 + 1.120 +bool ObjectStartArray::object_starts_in_range(HeapWord* start_addr, 1.121 + HeapWord* end_addr) const { 1.122 + assert(start_addr <= end_addr, "range is wrong"); 1.123 + if (start_addr > end_addr) { 1.124 + return false; 1.125 + } 1.126 + 1.127 + jbyte* start_block = block_for_addr(start_addr); 1.128 + jbyte* end_block = block_for_addr(end_addr); 1.129 + 1.130 + for (jbyte* block = start_block; block <= end_block; block++) { 1.131 + if (*block != clean_block) { 1.132 + return true; 1.133 + } 1.134 + } 1.135 + // No object starts in this slice; verify this using 1.136 + // more traditional methods: 1.137 + assert(object_start(end_addr - 1) <= start_addr, 1.138 + "Oops an object does start in this slice?"); 1.139 + return false; 1.140 +}