annotate src/share/vm/gc_implementation/parallelScavenge/objectStartArray.cpp @ 1091:6aa7255741f3

6906727: UseCompressedOops: some card-marking fixes related to object arrays Summary: Introduced a new write_ref_array(HeapWords* start, size_t count) method that does the requisite MemRegion range calculation so (some of the) clients of the erstwhile write_ref_array(MemRegion mr) do not need to worry. This removed all external uses of array_size(), which was also simplified and made private. Asserts were added to catch other possible issues. Further, less essential, fixes stemming from this investigation are deferred to CR 6904516 (to follow shortly in hs17). Reviewed-by: kvn, coleenp, jmasa
author ysr
date Thu, 03 Dec 2009 15:01:57 -0800
parents a61af66fc99e
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_objectStartArray.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 void ObjectStartArray::initialize(MemRegion reserved_region) {
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // We're based on the assumption that we use the same
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // size blocks as the card table.
a61af66fc99e Initial load
duke
parents:
diff changeset
31 assert((int)block_size == (int)CardTableModRefBS::card_size, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
32 assert((int)block_size <= 512, "block_size must be less than or equal to 512");
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // Calculate how much space must be reserved
a61af66fc99e Initial load
duke
parents:
diff changeset
35 _reserved_region = reserved_region;
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 size_t bytes_to_reserve = reserved_region.word_size() / block_size_in_words;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 assert(bytes_to_reserve > 0, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 bytes_to_reserve =
a61af66fc99e Initial load
duke
parents:
diff changeset
41 align_size_up(bytes_to_reserve, os::vm_allocation_granularity());
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // Do not use large-pages for the backing store. The one large page region
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // will be used for the heap proper.
a61af66fc99e Initial load
duke
parents:
diff changeset
45 ReservedSpace backing_store(bytes_to_reserve);
a61af66fc99e Initial load
duke
parents:
diff changeset
46 if (!backing_store.is_reserved()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 vm_exit_during_initialization("Could not reserve space for ObjectStartArray");
a61af66fc99e Initial load
duke
parents:
diff changeset
48 }
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // We do not commit any memory initially
a61af66fc99e Initial load
duke
parents:
diff changeset
51 if (!_virtual_space.initialize(backing_store, 0)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 vm_exit_during_initialization("Could not commit space for ObjectStartArray");
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 _raw_base = (jbyte*)_virtual_space.low_boundary();
a61af66fc99e Initial load
duke
parents:
diff changeset
56 if (_raw_base == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 vm_exit_during_initialization("Could not get raw_base address");
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 _offset_base = _raw_base - (size_t(reserved_region.start()) >> block_shift);
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 _covered_region.set_start(reserved_region.start());
a61af66fc99e Initial load
duke
parents:
diff changeset
63 _covered_region.set_word_size(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 _blocks_region.set_start((HeapWord*)_raw_base);
a61af66fc99e Initial load
duke
parents:
diff changeset
66 _blocks_region.set_word_size(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 void ObjectStartArray::set_covered_region(MemRegion mr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 assert(_reserved_region.contains(mr), "MemRegion outside of reserved space");
a61af66fc99e Initial load
duke
parents:
diff changeset
71 assert(_reserved_region.start() == mr.start(), "Attempt to move covered region");
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 HeapWord* low_bound = mr.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
74 HeapWord* high_bound = mr.end();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 assert((uintptr_t(low_bound) & (block_size - 1)) == 0, "heap must start at block boundary");
a61af66fc99e Initial load
duke
parents:
diff changeset
76 assert((uintptr_t(high_bound) & (block_size - 1)) == 0, "heap must end at block boundary");
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 size_t requested_blocks_size_in_bytes = mr.word_size() / block_size_in_words;
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // Only commit memory in page sized chunks
a61af66fc99e Initial load
duke
parents:
diff changeset
81 requested_blocks_size_in_bytes =
a61af66fc99e Initial load
duke
parents:
diff changeset
82 align_size_up(requested_blocks_size_in_bytes, os::vm_page_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 _covered_region = mr;
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 size_t current_blocks_size_in_bytes = _blocks_region.byte_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 if (requested_blocks_size_in_bytes > current_blocks_size_in_bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // Expand
a61af66fc99e Initial load
duke
parents:
diff changeset
90 size_t expand_by = requested_blocks_size_in_bytes - current_blocks_size_in_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 if (!_virtual_space.expand_by(expand_by)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 vm_exit_out_of_memory(expand_by, "object start array expansion");
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // Clear *only* the newly allocated region
a61af66fc99e Initial load
duke
parents:
diff changeset
95 memset(_blocks_region.end(), clean_block, expand_by);
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 if (requested_blocks_size_in_bytes < current_blocks_size_in_bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // Shrink
a61af66fc99e Initial load
duke
parents:
diff changeset
100 size_t shrink_by = current_blocks_size_in_bytes - requested_blocks_size_in_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 _virtual_space.shrink_by(shrink_by);
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 _blocks_region.set_word_size(requested_blocks_size_in_bytes / sizeof(HeapWord));
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 assert(requested_blocks_size_in_bytes % sizeof(HeapWord) == 0, "Block table not expanded in word sized increment");
a61af66fc99e Initial load
duke
parents:
diff changeset
107 assert(requested_blocks_size_in_bytes == _blocks_region.byte_size(), "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
108 assert(block_for_addr(low_bound) == &_raw_base[0], "Checking start of map");
a61af66fc99e Initial load
duke
parents:
diff changeset
109 assert(block_for_addr(high_bound-1) <= &_raw_base[_blocks_region.byte_size()-1], "Checking end of map");
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 void ObjectStartArray::reset() {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 memset(_blocks_region.start(), clean_block, _blocks_region.byte_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 bool ObjectStartArray::object_starts_in_range(HeapWord* start_addr,
a61af66fc99e Initial load
duke
parents:
diff changeset
118 HeapWord* end_addr) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 assert(start_addr <= end_addr, "range is wrong");
a61af66fc99e Initial load
duke
parents:
diff changeset
120 if (start_addr > end_addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 jbyte* start_block = block_for_addr(start_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
125 jbyte* end_block = block_for_addr(end_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 for (jbyte* block = start_block; block <= end_block; block++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 if (*block != clean_block) {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // No object starts in this slice; verify this using
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // more traditional methods:
a61af66fc99e Initial load
duke
parents:
diff changeset
134 assert(object_start(end_addr - 1) <= start_addr,
a61af66fc99e Initial load
duke
parents:
diff changeset
135 "Oops an object does start in this slice?");
a61af66fc99e Initial load
duke
parents:
diff changeset
136 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }