annotate src/share/vm/gc_implementation/parallelScavenge/psPromotionLAB.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 d1605aabd0a1
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
196
d1605aabd0a1 6719955: Update copyright year
xdono
parents: 113
diff changeset
2 * Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved.
0
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/_psPromotionLAB.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
28 size_t PSPromotionLAB::filler_header_size;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // This is the shared initialization code. It sets up the basic pointers,
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // and allows enough extra space for a filler object. We call a virtual
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // method, "lab_is_valid()" to handle the different asserts the old/young
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // labs require.
a61af66fc99e Initial load
duke
parents:
diff changeset
34 void PSPromotionLAB::initialize(MemRegion lab) {
a61af66fc99e Initial load
duke
parents:
diff changeset
35 assert(lab_is_valid(lab), "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 HeapWord* bottom = lab.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
38 HeapWord* end = lab.end();
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 set_bottom(bottom);
a61af66fc99e Initial load
duke
parents:
diff changeset
41 set_end(end);
a61af66fc99e Initial load
duke
parents:
diff changeset
42 set_top(bottom);
a61af66fc99e Initial load
duke
parents:
diff changeset
43
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
44 // Initialize after VM starts up because header_size depends on compressed
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
45 // oops.
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
46 filler_header_size = align_object_size(typeArrayOopDesc::header_size(T_INT));
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
47
0
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // We can be initialized to a zero size!
a61af66fc99e Initial load
duke
parents:
diff changeset
49 if (free() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 if (ZapUnusedHeapArea) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 debug_only(Copy::fill_to_words(top(), free()/HeapWordSize, badHeapWord));
a61af66fc99e Initial load
duke
parents:
diff changeset
52 }
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // NOTE! We need to allow space for a filler object.
a61af66fc99e Initial load
duke
parents:
diff changeset
55 assert(lab.word_size() >= filler_header_size, "lab is too small");
a61af66fc99e Initial load
duke
parents:
diff changeset
56 end = end - filler_header_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 set_end(end);
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 _state = needs_flush;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 _state = zero_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 assert(this->top() <= this->end(), "pointers out of order");
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // Fill all remaining lab space with an unreachable object.
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // The goal is to leave a contiguous parseable span of objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
69 void PSPromotionLAB::flush() {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 assert(_state != flushed, "Attempt to flush PLAB twice");
a61af66fc99e Initial load
duke
parents:
diff changeset
71 assert(top() <= end(), "pointers out of order");
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // If we were initialized to a zero sized lab, there is
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // nothing to flush
a61af66fc99e Initial load
duke
parents:
diff changeset
75 if (_state == zero_size)
a61af66fc99e Initial load
duke
parents:
diff changeset
76 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // PLAB's never allocate the last aligned_header_size
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // so they can always fill with an array.
a61af66fc99e Initial load
duke
parents:
diff changeset
80 HeapWord* tlab_end = end() + filler_header_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 typeArrayOop filler_oop = (typeArrayOop) top();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 filler_oop->set_mark(markOopDesc::prototype());
a61af66fc99e Initial load
duke
parents:
diff changeset
83 filler_oop->set_klass(Universe::intArrayKlassObj());
a61af66fc99e Initial load
duke
parents:
diff changeset
84 const size_t array_length =
a61af66fc99e Initial load
duke
parents:
diff changeset
85 pointer_delta(tlab_end, top()) - typeArrayOopDesc::header_size(T_INT);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 assert( (array_length * (HeapWordSize/sizeof(jint))) < (size_t)max_jint, "array too big in PSPromotionLAB");
a61af66fc99e Initial load
duke
parents:
diff changeset
87 filler_oop->set_length((int)(array_length * (HeapWordSize/sizeof(jint))));
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // Note that we actually DO NOT want to use the aligned header size!
a61af66fc99e Initial load
duke
parents:
diff changeset
91 HeapWord* elt_words = ((HeapWord*)filler_oop) + typeArrayOopDesc::header_size(T_INT);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 Copy::fill_to_words(elt_words, array_length, 0xDEAABABE);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 set_bottom(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
96 set_end(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 set_top(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 _state = flushed;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 bool PSPromotionLAB::unallocate_object(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 assert(Universe::heap()->is_in(obj), "Object outside heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 if (contains(obj)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 HeapWord* object_end = (HeapWord*)obj + obj->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
107 assert(object_end <= top(), "Object crosses promotion LAB boundary");
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 if (object_end == top()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 set_top((HeapWord*)obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // Fill all remaining lab space with an unreachable object.
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // The goal is to leave a contiguous parseable span of objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
120 void PSOldPromotionLAB::flush() {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 assert(_state != flushed, "Attempt to flush PLAB twice");
a61af66fc99e Initial load
duke
parents:
diff changeset
122 assert(top() <= end(), "pointers out of order");
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 if (_state == zero_size)
a61af66fc99e Initial load
duke
parents:
diff changeset
125 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 HeapWord* obj = top();
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 PSPromotionLAB::flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 assert(_start_array != NULL, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 _start_array->allocate_block(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 bool PSYoungPromotionLAB::lab_is_valid(MemRegion lab) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 MutableSpace* to_space = heap->young_gen()->to_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
143 MemRegion used = to_space->used_region();
a61af66fc99e Initial load
duke
parents:
diff changeset
144 if (used.contains(lab)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 bool PSOldPromotionLAB::lab_is_valid(MemRegion lab) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
153 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
154 assert(_start_array->covered_region().contains(lab), "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 PSOldGen* old_gen = heap->old_gen();
a61af66fc99e Initial load
duke
parents:
diff changeset
157 MemRegion used = old_gen->object_space()->used_region();
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 if (used.contains(lab)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 #endif /* ASSERT */