Mercurial > hg > graal-compiler
annotate src/share/vm/gc_implementation/shared/parGCAllocBuffer.hpp @ 20501:c204e2044c29
8038624: interpretedVFrame::expressions() must respect InterpreterOopMap for liveness
Reviewed-by: coleenp, minqi
author | mgronlun |
---|---|
date | Mon, 29 Sep 2014 13:12:48 +0200 |
parents | ee019285a52c |
children | c2844108a708 |
rev | line source |
---|---|
0 | 1 /* |
17467
55fb97c4c58d
8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents:
10374
diff
changeset
|
2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARGCALLOCBUFFER_HPP |
26 #define SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARGCALLOCBUFFER_HPP | |
20317
ee019285a52c
8031323: Optionally align objects copied to survivor spaces
jmasa
parents:
20215
diff
changeset
|
27 #include "gc_interface/collectedHeap.hpp" |
1972 | 28 #include "memory/allocation.hpp" |
1983
c760f78e0a53
7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents:
1972
diff
changeset
|
29 #include "memory/blockOffsetTable.hpp" |
1972 | 30 #include "memory/threadLocalAllocBuffer.hpp" |
31 #include "utilities/globalDefinitions.hpp" | |
32 | |
0 | 33 // Forward decl. |
34 | |
35 class PLABStats; | |
36 | |
37 // A per-thread allocation buffer used during GC. | |
6197 | 38 class ParGCAllocBuffer: public CHeapObj<mtGC> { |
0 | 39 protected: |
40 char head[32]; | |
41 size_t _word_sz; // in HeapWord units | |
42 HeapWord* _bottom; | |
43 HeapWord* _top; | |
44 HeapWord* _end; // last allocatable address + 1 | |
45 HeapWord* _hard_end; // _end + AlignmentReserve | |
46 bool _retained; // whether we hold a _retained_filler | |
47 MemRegion _retained_filler; | |
48 // In support of ergonomic sizing of PLAB's | |
49 size_t _allocated; // in HeapWord units | |
50 size_t _wasted; // in HeapWord units | |
51 char tail[32]; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
52 static size_t FillerHeaderSize; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
53 static size_t AlignmentReserve; |
0 | 54 |
6756
b2ef234911c9
7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents:
6595
diff
changeset
|
55 // Flush the stats supporting ergonomic sizing of PLAB's |
b2ef234911c9
7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents:
6595
diff
changeset
|
56 // Should not be called directly |
b2ef234911c9
7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents:
6595
diff
changeset
|
57 void flush_stats(PLABStats* stats); |
b2ef234911c9
7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents:
6595
diff
changeset
|
58 |
0 | 59 public: |
60 // Initializes the buffer to be empty, but with the given "word_sz". | |
61 // Must get initialized with "set_buf" for an allocation to succeed. | |
62 ParGCAllocBuffer(size_t word_sz); | |
20215
983092f35ff7
8028710: G1 does not retire allocation buffers after reference processing work
tschatzl
parents:
17727
diff
changeset
|
63 virtual ~ParGCAllocBuffer() {} |
0 | 64 |
65 static const size_t min_size() { | |
66 return ThreadLocalAllocBuffer::min_size(); | |
67 } | |
68 | |
69 static const size_t max_size() { | |
70 return ThreadLocalAllocBuffer::max_size(); | |
71 } | |
72 | |
73 // If an allocation of the given "word_sz" can be satisfied within the | |
74 // buffer, do the allocation, returning a pointer to the start of the | |
75 // allocated block. If the allocation request cannot be satisfied, | |
76 // return NULL. | |
77 HeapWord* allocate(size_t word_sz) { | |
78 HeapWord* res = _top; | |
634 | 79 if (pointer_delta(_end, _top) >= word_sz) { |
80 _top = _top + word_sz; | |
0 | 81 return res; |
82 } else { | |
83 return NULL; | |
84 } | |
85 } | |
86 | |
20317
ee019285a52c
8031323: Optionally align objects copied to survivor spaces
jmasa
parents:
20215
diff
changeset
|
87 // Allocate the object aligned to "alignment_in_bytes". |
ee019285a52c
8031323: Optionally align objects copied to survivor spaces
jmasa
parents:
20215
diff
changeset
|
88 HeapWord* allocate_aligned(size_t word_sz, unsigned short alignment_in_bytes); |
ee019285a52c
8031323: Optionally align objects copied to survivor spaces
jmasa
parents:
20215
diff
changeset
|
89 |
0 | 90 // Undo the last allocation in the buffer, which is required to be of the |
91 // "obj" of the given "word_sz". | |
92 void undo_allocation(HeapWord* obj, size_t word_sz) { | |
634 | 93 assert(pointer_delta(_top, _bottom) >= word_sz, "Bad undo"); |
94 assert(pointer_delta(_top, obj) == word_sz, "Bad undo"); | |
95 _top = obj; | |
0 | 96 } |
97 | |
98 // The total (word) size of the buffer, including both allocated and | |
99 // unallocted space. | |
100 size_t word_sz() { return _word_sz; } | |
101 | |
102 // Should only be done if we are about to reset with a new buffer of the | |
103 // given size. | |
104 void set_word_size(size_t new_word_sz) { | |
105 assert(new_word_sz > AlignmentReserve, "Too small"); | |
106 _word_sz = new_word_sz; | |
107 } | |
108 | |
109 // The number of words of unallocated space remaining in the buffer. | |
110 size_t words_remaining() { | |
111 assert(_end >= _top, "Negative buffer"); | |
112 return pointer_delta(_end, _top, HeapWordSize); | |
113 } | |
114 | |
115 bool contains(void* addr) { | |
116 return (void*)_bottom <= addr && addr < (void*)_hard_end; | |
117 } | |
118 | |
119 // Sets the space of the buffer to be [buf, space+word_sz()). | |
20215
983092f35ff7
8028710: G1 does not retire allocation buffers after reference processing work
tschatzl
parents:
17727
diff
changeset
|
120 virtual void set_buf(HeapWord* buf) { |
0 | 121 _bottom = buf; |
122 _top = _bottom; | |
123 _hard_end = _bottom + word_sz(); | |
124 _end = _hard_end - AlignmentReserve; | |
125 assert(_end >= _top, "Negative buffer"); | |
126 // In support of ergonomic sizing | |
127 _allocated += word_sz(); | |
128 } | |
129 | |
130 // Flush the stats supporting ergonomic sizing of PLAB's | |
6756
b2ef234911c9
7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents:
6595
diff
changeset
|
131 // and retire the current buffer. |
6595 | 132 void flush_stats_and_retire(PLABStats* stats, bool end_of_gc, bool retain) { |
0 | 133 // We flush the stats first in order to get a reading of |
134 // unused space in the last buffer. | |
135 if (ResizePLAB) { | |
136 flush_stats(stats); | |
6756
b2ef234911c9
7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents:
6595
diff
changeset
|
137 |
b2ef234911c9
7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents:
6595
diff
changeset
|
138 // Since we have flushed the stats we need to clear |
b2ef234911c9
7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents:
6595
diff
changeset
|
139 // the _allocated and _wasted fields. Not doing so |
b2ef234911c9
7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents:
6595
diff
changeset
|
140 // will artifically inflate the values in the stats |
b2ef234911c9
7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents:
6595
diff
changeset
|
141 // to which we add them. |
b2ef234911c9
7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents:
6595
diff
changeset
|
142 // The next time we flush these values, we will add |
b2ef234911c9
7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents:
6595
diff
changeset
|
143 // what we have just flushed in addition to the size |
b2ef234911c9
7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents:
6595
diff
changeset
|
144 // of the buffers allocated between now and then. |
b2ef234911c9
7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents:
6595
diff
changeset
|
145 _allocated = 0; |
b2ef234911c9
7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents:
6595
diff
changeset
|
146 _wasted = 0; |
0 | 147 } |
148 // Retire the last allocation buffer. | |
6595 | 149 retire(end_of_gc, retain); |
0 | 150 } |
151 | |
152 // Force future allocations to fail and queries for contains() | |
153 // to return false | |
154 void invalidate() { | |
155 assert(!_retained, "Shouldn't retain an invalidated buffer."); | |
156 _end = _hard_end; | |
157 _wasted += pointer_delta(_end, _top); // unused space | |
158 _top = _end; // force future allocations to fail | |
159 _bottom = _end; // force future contains() queries to return false | |
160 } | |
161 | |
162 // Fills in the unallocated portion of the buffer with a garbage object. | |
163 // If "end_of_gc" is TRUE, is after the last use in the GC. IF "retain" | |
164 // is true, attempt to re-use the unused portion in the next GC. | |
20215
983092f35ff7
8028710: G1 does not retire allocation buffers after reference processing work
tschatzl
parents:
17727
diff
changeset
|
165 virtual void retire(bool end_of_gc, bool retain); |
0 | 166 |
167 void print() PRODUCT_RETURN; | |
168 }; | |
169 | |
170 // PLAB stats book-keeping | |
171 class PLABStats VALUE_OBJ_CLASS_SPEC { | |
172 size_t _allocated; // total allocated | |
173 size_t _wasted; // of which wasted (internal fragmentation) | |
174 size_t _unused; // Unused in last buffer | |
175 size_t _used; // derived = allocated - wasted - unused | |
176 size_t _desired_plab_sz;// output of filter (below), suitably trimmed and quantized | |
177 AdaptiveWeightedAverage | |
178 _filter; // integrator with decay | |
179 | |
180 public: | |
181 PLABStats(size_t desired_plab_sz_, unsigned wt) : | |
182 _allocated(0), | |
183 _wasted(0), | |
184 _unused(0), | |
185 _used(0), | |
186 _desired_plab_sz(desired_plab_sz_), | |
187 _filter(wt) | |
17727 | 188 { } |
0 | 189 |
190 static const size_t min_size() { | |
191 return ParGCAllocBuffer::min_size(); | |
192 } | |
193 | |
194 static const size_t max_size() { | |
195 return ParGCAllocBuffer::max_size(); | |
196 } | |
197 | |
198 size_t desired_plab_sz() { | |
199 return _desired_plab_sz; | |
200 } | |
201 | |
6819 | 202 void adjust_desired_plab_sz(uint no_of_gc_workers); |
203 // filter computation, latches output to | |
0 | 204 // _desired_plab_sz, clears sensor accumulators |
205 | |
206 void add_allocated(size_t v) { | |
207 Atomic::add_ptr(v, &_allocated); | |
208 } | |
209 | |
210 void add_unused(size_t v) { | |
211 Atomic::add_ptr(v, &_unused); | |
212 } | |
213 | |
214 void add_wasted(size_t v) { | |
215 Atomic::add_ptr(v, &_wasted); | |
216 } | |
217 }; | |
218 | |
219 class ParGCAllocBufferWithBOT: public ParGCAllocBuffer { | |
220 BlockOffsetArrayContigSpace _bt; | |
221 BlockOffsetSharedArray* _bsa; | |
222 HeapWord* _true_end; // end of the whole ParGCAllocBuffer | |
223 | |
224 static const size_t ChunkSizeInWords; | |
225 static const size_t ChunkSizeInBytes; | |
226 HeapWord* allocate_slow(size_t word_sz); | |
227 | |
228 void fill_region_with_block(MemRegion mr, bool contig); | |
229 | |
230 public: | |
231 ParGCAllocBufferWithBOT(size_t word_sz, BlockOffsetSharedArray* bsa); | |
232 | |
233 HeapWord* allocate(size_t word_sz) { | |
234 HeapWord* res = ParGCAllocBuffer::allocate(word_sz); | |
235 if (res != NULL) { | |
236 _bt.alloc_block(res, word_sz); | |
237 } else { | |
238 res = allocate_slow(word_sz); | |
239 } | |
240 return res; | |
241 } | |
242 | |
243 void undo_allocation(HeapWord* obj, size_t word_sz); | |
244 | |
20215
983092f35ff7
8028710: G1 does not retire allocation buffers after reference processing work
tschatzl
parents:
17727
diff
changeset
|
245 virtual void set_buf(HeapWord* buf_start) { |
0 | 246 ParGCAllocBuffer::set_buf(buf_start); |
247 _true_end = _hard_end; | |
248 _bt.set_region(MemRegion(buf_start, word_sz())); | |
249 _bt.initialize_threshold(); | |
250 } | |
251 | |
20215
983092f35ff7
8028710: G1 does not retire allocation buffers after reference processing work
tschatzl
parents:
17727
diff
changeset
|
252 virtual void retire(bool end_of_gc, bool retain); |
0 | 253 |
254 MemRegion range() { | |
255 return MemRegion(_top, _true_end); | |
256 } | |
257 }; | |
1972 | 258 |
259 #endif // SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARGCALLOCBUFFER_HPP |