Mercurial > hg > graal-compiler
annotate src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp @ 517:e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
Summary: Added safe_object_iterate() for use by JMapPerm.
Reviewed-by: tonyp
author | jmasa |
---|---|
date | Tue, 06 Jan 2009 07:05:05 -0800 |
parents | 5d254928c888 |
children | 0af8b0718fc9 |
rev | line source |
---|---|
0 | 1 /* |
196 | 2 * Copyright 2001-2008 Sun Microsystems, Inc. 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 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_compactibleFreeListSpace.cpp.incl" | |
27 | |
28 ///////////////////////////////////////////////////////////////////////// | |
29 //// CompactibleFreeListSpace | |
30 ///////////////////////////////////////////////////////////////////////// | |
31 | |
32 // highest ranked free list lock rank | |
33 int CompactibleFreeListSpace::_lockRank = Mutex::leaf + 3; | |
34 | |
35 // Constructor | |
36 CompactibleFreeListSpace::CompactibleFreeListSpace(BlockOffsetSharedArray* bs, | |
37 MemRegion mr, bool use_adaptive_freelists, | |
38 FreeBlockDictionary::DictionaryChoice dictionaryChoice) : | |
39 _dictionaryChoice(dictionaryChoice), | |
40 _adaptive_freelists(use_adaptive_freelists), | |
41 _bt(bs, mr), | |
42 // free list locks are in the range of values taken by _lockRank | |
43 // This range currently is [_leaf+2, _leaf+3] | |
44 // Note: this requires that CFLspace c'tors | |
45 // are called serially in the order in which the locks are | |
46 // are acquired in the program text. This is true today. | |
47 _freelistLock(_lockRank--, "CompactibleFreeListSpace._lock", true), | |
48 _parDictionaryAllocLock(Mutex::leaf - 1, // == rank(ExpandHeap_lock) - 1 | |
49 "CompactibleFreeListSpace._dict_par_lock", true), | |
50 _rescan_task_size(CardTableModRefBS::card_size_in_words * BitsPerWord * | |
51 CMSRescanMultiple), | |
52 _marking_task_size(CardTableModRefBS::card_size_in_words * BitsPerWord * | |
53 CMSConcMarkMultiple), | |
54 _collector(NULL) | |
55 { | |
56 _bt.set_space(this); | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
187
diff
changeset
|
57 initialize(mr, SpaceDecorator::Clear, SpaceDecorator::Mangle); |
0 | 58 // We have all of "mr", all of which we place in the dictionary |
59 // as one big chunk. We'll need to decide here which of several | |
60 // possible alternative dictionary implementations to use. For | |
61 // now the choice is easy, since we have only one working | |
62 // implementation, namely, the simple binary tree (splaying | |
63 // temporarily disabled). | |
64 switch (dictionaryChoice) { | |
65 case FreeBlockDictionary::dictionaryBinaryTree: | |
66 _dictionary = new BinaryTreeDictionary(mr); | |
67 break; | |
68 case FreeBlockDictionary::dictionarySplayTree: | |
69 case FreeBlockDictionary::dictionarySkipList: | |
70 default: | |
71 warning("dictionaryChoice: selected option not understood; using" | |
72 " default BinaryTreeDictionary implementation instead."); | |
73 _dictionary = new BinaryTreeDictionary(mr); | |
74 break; | |
75 } | |
76 splitBirth(mr.word_size()); | |
77 assert(_dictionary != NULL, "CMS dictionary initialization"); | |
78 // The indexed free lists are initially all empty and are lazily | |
79 // filled in on demand. Initialize the array elements to NULL. | |
80 initializeIndexedFreeListArray(); | |
81 | |
82 // Not using adaptive free lists assumes that allocation is first | |
83 // from the linAB's. Also a cms perm gen which can be compacted | |
84 // has to have the klass's klassKlass allocated at a lower | |
85 // address in the heap than the klass so that the klassKlass is | |
86 // moved to its new location before the klass is moved. | |
87 // Set the _refillSize for the linear allocation blocks | |
88 if (!use_adaptive_freelists) { | |
89 FreeChunk* fc = _dictionary->getChunk(mr.word_size()); | |
90 // The small linAB initially has all the space and will allocate | |
91 // a chunk of any size. | |
92 HeapWord* addr = (HeapWord*) fc; | |
93 _smallLinearAllocBlock.set(addr, fc->size() , | |
94 1024*SmallForLinearAlloc, fc->size()); | |
95 // Note that _unallocated_block is not updated here. | |
96 // Allocations from the linear allocation block should | |
97 // update it. | |
98 } else { | |
99 _smallLinearAllocBlock.set(0, 0, 1024*SmallForLinearAlloc, | |
100 SmallForLinearAlloc); | |
101 } | |
102 // CMSIndexedFreeListReplenish should be at least 1 | |
103 CMSIndexedFreeListReplenish = MAX2((uintx)1, CMSIndexedFreeListReplenish); | |
104 _promoInfo.setSpace(this); | |
105 if (UseCMSBestFit) { | |
106 _fitStrategy = FreeBlockBestFitFirst; | |
107 } else { | |
108 _fitStrategy = FreeBlockStrategyNone; | |
109 } | |
110 checkFreeListConsistency(); | |
111 | |
112 // Initialize locks for parallel case. | |
113 if (ParallelGCThreads > 0) { | |
114 for (size_t i = IndexSetStart; i < IndexSetSize; i += IndexSetStride) { | |
115 _indexedFreeListParLocks[i] = new Mutex(Mutex::leaf - 1, // == ExpandHeap_lock - 1 | |
116 "a freelist par lock", | |
117 true); | |
118 if (_indexedFreeListParLocks[i] == NULL) | |
119 vm_exit_during_initialization("Could not allocate a par lock"); | |
120 DEBUG_ONLY( | |
121 _indexedFreeList[i].set_protecting_lock(_indexedFreeListParLocks[i]); | |
122 ) | |
123 } | |
124 _dictionary->set_par_lock(&_parDictionaryAllocLock); | |
125 } | |
126 } | |
127 | |
128 // Like CompactibleSpace forward() but always calls cross_threshold() to | |
129 // update the block offset table. Removed initialize_threshold call because | |
130 // CFLS does not use a block offset array for contiguous spaces. | |
131 HeapWord* CompactibleFreeListSpace::forward(oop q, size_t size, | |
132 CompactPoint* cp, HeapWord* compact_top) { | |
133 // q is alive | |
134 // First check if we should switch compaction space | |
135 assert(this == cp->space, "'this' should be current compaction space."); | |
136 size_t compaction_max_size = pointer_delta(end(), compact_top); | |
137 assert(adjustObjectSize(size) == cp->space->adjust_object_size_v(size), | |
138 "virtual adjustObjectSize_v() method is not correct"); | |
139 size_t adjusted_size = adjustObjectSize(size); | |
140 assert(compaction_max_size >= MinChunkSize || compaction_max_size == 0, | |
141 "no small fragments allowed"); | |
142 assert(minimum_free_block_size() == MinChunkSize, | |
143 "for de-virtualized reference below"); | |
144 // Can't leave a nonzero size, residual fragment smaller than MinChunkSize | |
145 if (adjusted_size + MinChunkSize > compaction_max_size && | |
146 adjusted_size != compaction_max_size) { | |
147 do { | |
148 // switch to next compaction space | |
149 cp->space->set_compaction_top(compact_top); | |
150 cp->space = cp->space->next_compaction_space(); | |
151 if (cp->space == NULL) { | |
152 cp->gen = GenCollectedHeap::heap()->prev_gen(cp->gen); | |
153 assert(cp->gen != NULL, "compaction must succeed"); | |
154 cp->space = cp->gen->first_compaction_space(); | |
155 assert(cp->space != NULL, "generation must have a first compaction space"); | |
156 } | |
157 compact_top = cp->space->bottom(); | |
158 cp->space->set_compaction_top(compact_top); | |
159 // The correct adjusted_size may not be the same as that for this method | |
160 // (i.e., cp->space may no longer be "this" so adjust the size again. | |
161 // Use the virtual method which is not used above to save the virtual | |
162 // dispatch. | |
163 adjusted_size = cp->space->adjust_object_size_v(size); | |
164 compaction_max_size = pointer_delta(cp->space->end(), compact_top); | |
165 assert(cp->space->minimum_free_block_size() == 0, "just checking"); | |
166 } while (adjusted_size > compaction_max_size); | |
167 } | |
168 | |
169 // store the forwarding pointer into the mark word | |
170 if ((HeapWord*)q != compact_top) { | |
171 q->forward_to(oop(compact_top)); | |
172 assert(q->is_gc_marked(), "encoding the pointer should preserve the mark"); | |
173 } else { | |
174 // if the object isn't moving we can just set the mark to the default | |
175 // mark and handle it specially later on. | |
176 q->init_mark(); | |
177 assert(q->forwardee() == NULL, "should be forwarded to NULL"); | |
178 } | |
179 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
180 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::register_live_oop(q, adjusted_size)); |
0 | 181 compact_top += adjusted_size; |
182 | |
183 // we need to update the offset table so that the beginnings of objects can be | |
184 // found during scavenge. Note that we are updating the offset table based on | |
185 // where the object will be once the compaction phase finishes. | |
186 | |
187 // Always call cross_threshold(). A contiguous space can only call it when | |
188 // the compaction_top exceeds the current threshold but not for an | |
189 // non-contiguous space. | |
190 cp->threshold = | |
191 cp->space->cross_threshold(compact_top - adjusted_size, compact_top); | |
192 return compact_top; | |
193 } | |
194 | |
195 // A modified copy of OffsetTableContigSpace::cross_threshold() with _offsets -> _bt | |
196 // and use of single_block instead of alloc_block. The name here is not really | |
197 // appropriate - maybe a more general name could be invented for both the | |
198 // contiguous and noncontiguous spaces. | |
199 | |
200 HeapWord* CompactibleFreeListSpace::cross_threshold(HeapWord* start, HeapWord* the_end) { | |
201 _bt.single_block(start, the_end); | |
202 return end(); | |
203 } | |
204 | |
205 // Initialize them to NULL. | |
206 void CompactibleFreeListSpace::initializeIndexedFreeListArray() { | |
207 for (size_t i = 0; i < IndexSetSize; i++) { | |
208 // Note that on platforms where objects are double word aligned, | |
209 // the odd array elements are not used. It is convenient, however, | |
210 // to map directly from the object size to the array element. | |
211 _indexedFreeList[i].reset(IndexSetSize); | |
212 _indexedFreeList[i].set_size(i); | |
213 assert(_indexedFreeList[i].count() == 0, "reset check failed"); | |
214 assert(_indexedFreeList[i].head() == NULL, "reset check failed"); | |
215 assert(_indexedFreeList[i].tail() == NULL, "reset check failed"); | |
216 assert(_indexedFreeList[i].hint() == IndexSetSize, "reset check failed"); | |
217 } | |
218 } | |
219 | |
220 void CompactibleFreeListSpace::resetIndexedFreeListArray() { | |
221 for (int i = 1; i < IndexSetSize; i++) { | |
222 assert(_indexedFreeList[i].size() == (size_t) i, | |
223 "Indexed free list sizes are incorrect"); | |
224 _indexedFreeList[i].reset(IndexSetSize); | |
225 assert(_indexedFreeList[i].count() == 0, "reset check failed"); | |
226 assert(_indexedFreeList[i].head() == NULL, "reset check failed"); | |
227 assert(_indexedFreeList[i].tail() == NULL, "reset check failed"); | |
228 assert(_indexedFreeList[i].hint() == IndexSetSize, "reset check failed"); | |
229 } | |
230 } | |
231 | |
232 void CompactibleFreeListSpace::reset(MemRegion mr) { | |
233 resetIndexedFreeListArray(); | |
234 dictionary()->reset(); | |
235 if (BlockOffsetArrayUseUnallocatedBlock) { | |
236 assert(end() == mr.end(), "We are compacting to the bottom of CMS gen"); | |
237 // Everything's allocated until proven otherwise. | |
238 _bt.set_unallocated_block(end()); | |
239 } | |
240 if (!mr.is_empty()) { | |
241 assert(mr.word_size() >= MinChunkSize, "Chunk size is too small"); | |
242 _bt.single_block(mr.start(), mr.word_size()); | |
243 FreeChunk* fc = (FreeChunk*) mr.start(); | |
244 fc->setSize(mr.word_size()); | |
245 if (mr.word_size() >= IndexSetSize ) { | |
246 returnChunkToDictionary(fc); | |
247 } else { | |
248 _bt.verify_not_unallocated((HeapWord*)fc, fc->size()); | |
249 _indexedFreeList[mr.word_size()].returnChunkAtHead(fc); | |
250 } | |
251 } | |
252 _promoInfo.reset(); | |
253 _smallLinearAllocBlock._ptr = NULL; | |
254 _smallLinearAllocBlock._word_size = 0; | |
255 } | |
256 | |
257 void CompactibleFreeListSpace::reset_after_compaction() { | |
258 // Reset the space to the new reality - one free chunk. | |
259 MemRegion mr(compaction_top(), end()); | |
260 reset(mr); | |
261 // Now refill the linear allocation block(s) if possible. | |
262 if (_adaptive_freelists) { | |
263 refillLinearAllocBlocksIfNeeded(); | |
264 } else { | |
265 // Place as much of mr in the linAB as we can get, | |
266 // provided it was big enough to go into the dictionary. | |
267 FreeChunk* fc = dictionary()->findLargestDict(); | |
268 if (fc != NULL) { | |
269 assert(fc->size() == mr.word_size(), | |
270 "Why was the chunk broken up?"); | |
271 removeChunkFromDictionary(fc); | |
272 HeapWord* addr = (HeapWord*) fc; | |
273 _smallLinearAllocBlock.set(addr, fc->size() , | |
274 1024*SmallForLinearAlloc, fc->size()); | |
275 // Note that _unallocated_block is not updated here. | |
276 } | |
277 } | |
278 } | |
279 | |
280 // Walks the entire dictionary, returning a coterminal | |
281 // chunk, if it exists. Use with caution since it involves | |
282 // a potentially complete walk of a potentially large tree. | |
283 FreeChunk* CompactibleFreeListSpace::find_chunk_at_end() { | |
284 | |
285 assert_lock_strong(&_freelistLock); | |
286 | |
287 return dictionary()->find_chunk_ends_at(end()); | |
288 } | |
289 | |
290 | |
291 #ifndef PRODUCT | |
292 void CompactibleFreeListSpace::initializeIndexedFreeListArrayReturnedBytes() { | |
293 for (size_t i = IndexSetStart; i < IndexSetSize; i += IndexSetStride) { | |
294 _indexedFreeList[i].allocation_stats()->set_returnedBytes(0); | |
295 } | |
296 } | |
297 | |
298 size_t CompactibleFreeListSpace::sumIndexedFreeListArrayReturnedBytes() { | |
299 size_t sum = 0; | |
300 for (size_t i = IndexSetStart; i < IndexSetSize; i += IndexSetStride) { | |
301 sum += _indexedFreeList[i].allocation_stats()->returnedBytes(); | |
302 } | |
303 return sum; | |
304 } | |
305 | |
306 size_t CompactibleFreeListSpace::totalCountInIndexedFreeLists() const { | |
307 size_t count = 0; | |
308 for (int i = MinChunkSize; i < IndexSetSize; i++) { | |
309 debug_only( | |
310 ssize_t total_list_count = 0; | |
311 for (FreeChunk* fc = _indexedFreeList[i].head(); fc != NULL; | |
312 fc = fc->next()) { | |
313 total_list_count++; | |
314 } | |
315 assert(total_list_count == _indexedFreeList[i].count(), | |
316 "Count in list is incorrect"); | |
317 ) | |
318 count += _indexedFreeList[i].count(); | |
319 } | |
320 return count; | |
321 } | |
322 | |
323 size_t CompactibleFreeListSpace::totalCount() { | |
324 size_t num = totalCountInIndexedFreeLists(); | |
325 num += dictionary()->totalCount(); | |
326 if (_smallLinearAllocBlock._word_size != 0) { | |
327 num++; | |
328 } | |
329 return num; | |
330 } | |
331 #endif | |
332 | |
333 bool CompactibleFreeListSpace::is_free_block(const HeapWord* p) const { | |
334 FreeChunk* fc = (FreeChunk*) p; | |
335 return fc->isFree(); | |
336 } | |
337 | |
338 size_t CompactibleFreeListSpace::used() const { | |
339 return capacity() - free(); | |
340 } | |
341 | |
342 size_t CompactibleFreeListSpace::free() const { | |
343 // "MT-safe, but not MT-precise"(TM), if you will: i.e. | |
344 // if you do this while the structures are in flux you | |
345 // may get an approximate answer only; for instance | |
346 // because there is concurrent allocation either | |
347 // directly by mutators or for promotion during a GC. | |
348 // It's "MT-safe", however, in the sense that you are guaranteed | |
349 // not to crash and burn, for instance, because of walking | |
350 // pointers that could disappear as you were walking them. | |
351 // The approximation is because the various components | |
352 // that are read below are not read atomically (and | |
353 // further the computation of totalSizeInIndexedFreeLists() | |
354 // is itself a non-atomic computation. The normal use of | |
355 // this is during a resize operation at the end of GC | |
356 // and at that time you are guaranteed to get the | |
357 // correct actual value. However, for instance, this is | |
358 // also read completely asynchronously by the "perf-sampler" | |
359 // that supports jvmstat, and you are apt to see the values | |
360 // flicker in such cases. | |
361 assert(_dictionary != NULL, "No _dictionary?"); | |
362 return (_dictionary->totalChunkSize(DEBUG_ONLY(freelistLock())) + | |
363 totalSizeInIndexedFreeLists() + | |
364 _smallLinearAllocBlock._word_size) * HeapWordSize; | |
365 } | |
366 | |
367 size_t CompactibleFreeListSpace::max_alloc_in_words() const { | |
368 assert(_dictionary != NULL, "No _dictionary?"); | |
369 assert_locked(); | |
370 size_t res = _dictionary->maxChunkSize(); | |
371 res = MAX2(res, MIN2(_smallLinearAllocBlock._word_size, | |
372 (size_t) SmallForLinearAlloc - 1)); | |
373 // XXX the following could potentially be pretty slow; | |
374 // should one, pesimally for the rare cases when res | |
375 // caclulated above is less than IndexSetSize, | |
376 // just return res calculated above? My reasoning was that | |
377 // those cases will be so rare that the extra time spent doesn't | |
378 // really matter.... | |
379 // Note: do not change the loop test i >= res + IndexSetStride | |
380 // to i > res below, because i is unsigned and res may be zero. | |
381 for (size_t i = IndexSetSize - 1; i >= res + IndexSetStride; | |
382 i -= IndexSetStride) { | |
383 if (_indexedFreeList[i].head() != NULL) { | |
384 assert(_indexedFreeList[i].count() != 0, "Inconsistent FreeList"); | |
385 return i; | |
386 } | |
387 } | |
388 return res; | |
389 } | |
390 | |
391 void CompactibleFreeListSpace::reportFreeListStatistics() const { | |
392 assert_lock_strong(&_freelistLock); | |
393 assert(PrintFLSStatistics != 0, "Reporting error"); | |
394 _dictionary->reportStatistics(); | |
395 if (PrintFLSStatistics > 1) { | |
396 reportIndexedFreeListStatistics(); | |
397 size_t totalSize = totalSizeInIndexedFreeLists() + | |
398 _dictionary->totalChunkSize(DEBUG_ONLY(freelistLock())); | |
399 gclog_or_tty->print(" free=%ld frag=%1.4f\n", totalSize, flsFrag()); | |
400 } | |
401 } | |
402 | |
403 void CompactibleFreeListSpace::reportIndexedFreeListStatistics() const { | |
404 assert_lock_strong(&_freelistLock); | |
405 gclog_or_tty->print("Statistics for IndexedFreeLists:\n" | |
406 "--------------------------------\n"); | |
407 size_t totalSize = totalSizeInIndexedFreeLists(); | |
408 size_t freeBlocks = numFreeBlocksInIndexedFreeLists(); | |
409 gclog_or_tty->print("Total Free Space: %d\n", totalSize); | |
410 gclog_or_tty->print("Max Chunk Size: %d\n", maxChunkSizeInIndexedFreeLists()); | |
411 gclog_or_tty->print("Number of Blocks: %d\n", freeBlocks); | |
412 if (freeBlocks != 0) { | |
413 gclog_or_tty->print("Av. Block Size: %d\n", totalSize/freeBlocks); | |
414 } | |
415 } | |
416 | |
417 size_t CompactibleFreeListSpace::numFreeBlocksInIndexedFreeLists() const { | |
418 size_t res = 0; | |
419 for (size_t i = IndexSetStart; i < IndexSetSize; i += IndexSetStride) { | |
420 debug_only( | |
421 ssize_t recount = 0; | |
422 for (FreeChunk* fc = _indexedFreeList[i].head(); fc != NULL; | |
423 fc = fc->next()) { | |
424 recount += 1; | |
425 } | |
426 assert(recount == _indexedFreeList[i].count(), | |
427 "Incorrect count in list"); | |
428 ) | |
429 res += _indexedFreeList[i].count(); | |
430 } | |
431 return res; | |
432 } | |
433 | |
434 size_t CompactibleFreeListSpace::maxChunkSizeInIndexedFreeLists() const { | |
435 for (size_t i = IndexSetSize - 1; i != 0; i -= IndexSetStride) { | |
436 if (_indexedFreeList[i].head() != NULL) { | |
437 assert(_indexedFreeList[i].count() != 0, "Inconsistent FreeList"); | |
438 return (size_t)i; | |
439 } | |
440 } | |
441 return 0; | |
442 } | |
443 | |
444 void CompactibleFreeListSpace::set_end(HeapWord* value) { | |
445 HeapWord* prevEnd = end(); | |
446 assert(prevEnd != value, "unnecessary set_end call"); | |
447 assert(prevEnd == NULL || value >= unallocated_block(), "New end is below unallocated block"); | |
448 _end = value; | |
449 if (prevEnd != NULL) { | |
450 // Resize the underlying block offset table. | |
451 _bt.resize(pointer_delta(value, bottom())); | |
452 if (value <= prevEnd) { | |
453 assert(value >= unallocated_block(), "New end is below unallocated block"); | |
454 } else { | |
455 // Now, take this new chunk and add it to the free blocks. | |
456 // Note that the BOT has not yet been updated for this block. | |
457 size_t newFcSize = pointer_delta(value, prevEnd); | |
458 // XXX This is REALLY UGLY and should be fixed up. XXX | |
459 if (!_adaptive_freelists && _smallLinearAllocBlock._ptr == NULL) { | |
460 // Mark the boundary of the new block in BOT | |
461 _bt.mark_block(prevEnd, value); | |
462 // put it all in the linAB | |
463 if (ParallelGCThreads == 0) { | |
464 _smallLinearAllocBlock._ptr = prevEnd; | |
465 _smallLinearAllocBlock._word_size = newFcSize; | |
466 repairLinearAllocBlock(&_smallLinearAllocBlock); | |
467 } else { // ParallelGCThreads > 0 | |
468 MutexLockerEx x(parDictionaryAllocLock(), | |
469 Mutex::_no_safepoint_check_flag); | |
470 _smallLinearAllocBlock._ptr = prevEnd; | |
471 _smallLinearAllocBlock._word_size = newFcSize; | |
472 repairLinearAllocBlock(&_smallLinearAllocBlock); | |
473 } | |
474 // Births of chunks put into a LinAB are not recorded. Births | |
475 // of chunks as they are allocated out of a LinAB are. | |
476 } else { | |
477 // Add the block to the free lists, if possible coalescing it | |
478 // with the last free block, and update the BOT and census data. | |
479 addChunkToFreeListsAtEndRecordingStats(prevEnd, newFcSize); | |
480 } | |
481 } | |
482 } | |
483 } | |
484 | |
485 class FreeListSpace_DCTOC : public Filtering_DCTOC { | |
486 CompactibleFreeListSpace* _cfls; | |
487 CMSCollector* _collector; | |
488 protected: | |
489 // Override. | |
490 #define walk_mem_region_with_cl_DECL(ClosureType) \ | |
491 virtual void walk_mem_region_with_cl(MemRegion mr, \ | |
492 HeapWord* bottom, HeapWord* top, \ | |
493 ClosureType* cl); \ | |
494 void walk_mem_region_with_cl_par(MemRegion mr, \ | |
495 HeapWord* bottom, HeapWord* top, \ | |
496 ClosureType* cl); \ | |
497 void walk_mem_region_with_cl_nopar(MemRegion mr, \ | |
498 HeapWord* bottom, HeapWord* top, \ | |
499 ClosureType* cl) | |
500 walk_mem_region_with_cl_DECL(OopClosure); | |
501 walk_mem_region_with_cl_DECL(FilteringClosure); | |
502 | |
503 public: | |
504 FreeListSpace_DCTOC(CompactibleFreeListSpace* sp, | |
505 CMSCollector* collector, | |
506 OopClosure* cl, | |
507 CardTableModRefBS::PrecisionStyle precision, | |
508 HeapWord* boundary) : | |
509 Filtering_DCTOC(sp, cl, precision, boundary), | |
510 _cfls(sp), _collector(collector) {} | |
511 }; | |
512 | |
513 // We de-virtualize the block-related calls below, since we know that our | |
514 // space is a CompactibleFreeListSpace. | |
515 #define FreeListSpace_DCTOC__walk_mem_region_with_cl_DEFN(ClosureType) \ | |
516 void FreeListSpace_DCTOC::walk_mem_region_with_cl(MemRegion mr, \ | |
517 HeapWord* bottom, \ | |
518 HeapWord* top, \ | |
519 ClosureType* cl) { \ | |
520 if (SharedHeap::heap()->n_par_threads() > 0) { \ | |
521 walk_mem_region_with_cl_par(mr, bottom, top, cl); \ | |
522 } else { \ | |
523 walk_mem_region_with_cl_nopar(mr, bottom, top, cl); \ | |
524 } \ | |
525 } \ | |
526 void FreeListSpace_DCTOC::walk_mem_region_with_cl_par(MemRegion mr, \ | |
527 HeapWord* bottom, \ | |
528 HeapWord* top, \ | |
529 ClosureType* cl) { \ | |
530 /* Skip parts that are before "mr", in case "block_start" sent us \ | |
531 back too far. */ \ | |
532 HeapWord* mr_start = mr.start(); \ | |
533 size_t bot_size = _cfls->CompactibleFreeListSpace::block_size(bottom); \ | |
534 HeapWord* next = bottom + bot_size; \ | |
535 while (next < mr_start) { \ | |
536 bottom = next; \ | |
537 bot_size = _cfls->CompactibleFreeListSpace::block_size(bottom); \ | |
538 next = bottom + bot_size; \ | |
539 } \ | |
540 \ | |
541 while (bottom < top) { \ | |
542 if (_cfls->CompactibleFreeListSpace::block_is_obj(bottom) && \ | |
543 !_cfls->CompactibleFreeListSpace::obj_allocated_since_save_marks( \ | |
544 oop(bottom)) && \ | |
545 !_collector->CMSCollector::is_dead_obj(oop(bottom))) { \ | |
546 size_t word_sz = oop(bottom)->oop_iterate(cl, mr); \ | |
547 bottom += _cfls->adjustObjectSize(word_sz); \ | |
548 } else { \ | |
549 bottom += _cfls->CompactibleFreeListSpace::block_size(bottom); \ | |
550 } \ | |
551 } \ | |
552 } \ | |
553 void FreeListSpace_DCTOC::walk_mem_region_with_cl_nopar(MemRegion mr, \ | |
554 HeapWord* bottom, \ | |
555 HeapWord* top, \ | |
556 ClosureType* cl) { \ | |
557 /* Skip parts that are before "mr", in case "block_start" sent us \ | |
558 back too far. */ \ | |
559 HeapWord* mr_start = mr.start(); \ | |
560 size_t bot_size = _cfls->CompactibleFreeListSpace::block_size_nopar(bottom); \ | |
561 HeapWord* next = bottom + bot_size; \ | |
562 while (next < mr_start) { \ | |
563 bottom = next; \ | |
564 bot_size = _cfls->CompactibleFreeListSpace::block_size_nopar(bottom); \ | |
565 next = bottom + bot_size; \ | |
566 } \ | |
567 \ | |
568 while (bottom < top) { \ | |
569 if (_cfls->CompactibleFreeListSpace::block_is_obj_nopar(bottom) && \ | |
570 !_cfls->CompactibleFreeListSpace::obj_allocated_since_save_marks( \ | |
571 oop(bottom)) && \ | |
572 !_collector->CMSCollector::is_dead_obj(oop(bottom))) { \ | |
573 size_t word_sz = oop(bottom)->oop_iterate(cl, mr); \ | |
574 bottom += _cfls->adjustObjectSize(word_sz); \ | |
575 } else { \ | |
576 bottom += _cfls->CompactibleFreeListSpace::block_size_nopar(bottom); \ | |
577 } \ | |
578 } \ | |
579 } | |
580 | |
581 // (There are only two of these, rather than N, because the split is due | |
582 // only to the introduction of the FilteringClosure, a local part of the | |
583 // impl of this abstraction.) | |
584 FreeListSpace_DCTOC__walk_mem_region_with_cl_DEFN(OopClosure) | |
585 FreeListSpace_DCTOC__walk_mem_region_with_cl_DEFN(FilteringClosure) | |
586 | |
587 DirtyCardToOopClosure* | |
588 CompactibleFreeListSpace::new_dcto_cl(OopClosure* cl, | |
589 CardTableModRefBS::PrecisionStyle precision, | |
590 HeapWord* boundary) { | |
591 return new FreeListSpace_DCTOC(this, _collector, cl, precision, boundary); | |
592 } | |
593 | |
594 | |
595 // Note on locking for the space iteration functions: | |
596 // since the collector's iteration activities are concurrent with | |
597 // allocation activities by mutators, absent a suitable mutual exclusion | |
598 // mechanism the iterators may go awry. For instace a block being iterated | |
599 // may suddenly be allocated or divided up and part of it allocated and | |
600 // so on. | |
601 | |
602 // Apply the given closure to each block in the space. | |
603 void CompactibleFreeListSpace::blk_iterate_careful(BlkClosureCareful* cl) { | |
604 assert_lock_strong(freelistLock()); | |
605 HeapWord *cur, *limit; | |
606 for (cur = bottom(), limit = end(); cur < limit; | |
607 cur += cl->do_blk_careful(cur)); | |
608 } | |
609 | |
610 // Apply the given closure to each block in the space. | |
611 void CompactibleFreeListSpace::blk_iterate(BlkClosure* cl) { | |
612 assert_lock_strong(freelistLock()); | |
613 HeapWord *cur, *limit; | |
614 for (cur = bottom(), limit = end(); cur < limit; | |
615 cur += cl->do_blk(cur)); | |
616 } | |
617 | |
618 // Apply the given closure to each oop in the space. | |
619 void CompactibleFreeListSpace::oop_iterate(OopClosure* cl) { | |
620 assert_lock_strong(freelistLock()); | |
621 HeapWord *cur, *limit; | |
622 size_t curSize; | |
623 for (cur = bottom(), limit = end(); cur < limit; | |
624 cur += curSize) { | |
625 curSize = block_size(cur); | |
626 if (block_is_obj(cur)) { | |
627 oop(cur)->oop_iterate(cl); | |
628 } | |
629 } | |
630 } | |
631 | |
632 // Apply the given closure to each oop in the space \intersect memory region. | |
633 void CompactibleFreeListSpace::oop_iterate(MemRegion mr, OopClosure* cl) { | |
634 assert_lock_strong(freelistLock()); | |
635 if (is_empty()) { | |
636 return; | |
637 } | |
638 MemRegion cur = MemRegion(bottom(), end()); | |
639 mr = mr.intersection(cur); | |
640 if (mr.is_empty()) { | |
641 return; | |
642 } | |
643 if (mr.equals(cur)) { | |
644 oop_iterate(cl); | |
645 return; | |
646 } | |
647 assert(mr.end() <= end(), "just took an intersection above"); | |
648 HeapWord* obj_addr = block_start(mr.start()); | |
649 HeapWord* t = mr.end(); | |
650 | |
651 SpaceMemRegionOopsIterClosure smr_blk(cl, mr); | |
652 if (block_is_obj(obj_addr)) { | |
653 // Handle first object specially. | |
654 oop obj = oop(obj_addr); | |
655 obj_addr += adjustObjectSize(obj->oop_iterate(&smr_blk)); | |
656 } else { | |
657 FreeChunk* fc = (FreeChunk*)obj_addr; | |
658 obj_addr += fc->size(); | |
659 } | |
660 while (obj_addr < t) { | |
661 HeapWord* obj = obj_addr; | |
662 obj_addr += block_size(obj_addr); | |
663 // If "obj_addr" is not greater than top, then the | |
664 // entire object "obj" is within the region. | |
665 if (obj_addr <= t) { | |
666 if (block_is_obj(obj)) { | |
667 oop(obj)->oop_iterate(cl); | |
668 } | |
669 } else { | |
670 // "obj" extends beyond end of region | |
671 if (block_is_obj(obj)) { | |
672 oop(obj)->oop_iterate(&smr_blk); | |
673 } | |
674 break; | |
675 } | |
676 } | |
677 } | |
678 | |
679 // NOTE: In the following methods, in order to safely be able to | |
680 // apply the closure to an object, we need to be sure that the | |
681 // object has been initialized. We are guaranteed that an object | |
682 // is initialized if we are holding the Heap_lock with the | |
683 // world stopped. | |
684 void CompactibleFreeListSpace::verify_objects_initialized() const { | |
685 if (is_init_completed()) { | |
686 assert_locked_or_safepoint(Heap_lock); | |
687 if (Universe::is_fully_initialized()) { | |
688 guarantee(SafepointSynchronize::is_at_safepoint(), | |
689 "Required for objects to be initialized"); | |
690 } | |
691 } // else make a concession at vm start-up | |
692 } | |
693 | |
694 // Apply the given closure to each object in the space | |
695 void CompactibleFreeListSpace::object_iterate(ObjectClosure* blk) { | |
696 assert_lock_strong(freelistLock()); | |
697 NOT_PRODUCT(verify_objects_initialized()); | |
698 HeapWord *cur, *limit; | |
699 size_t curSize; | |
700 for (cur = bottom(), limit = end(); cur < limit; | |
701 cur += curSize) { | |
702 curSize = block_size(cur); | |
703 if (block_is_obj(cur)) { | |
704 blk->do_object(oop(cur)); | |
705 } | |
706 } | |
707 } | |
708 | |
517
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
709 // Apply the given closure to each live object in the space |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
710 // The usage of CompactibleFreeListSpace |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
711 // by the ConcurrentMarkSweepGeneration for concurrent GC's allows |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
712 // objects in the space with references to objects that are no longer |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
713 // valid. For example, an object may reference another object |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
714 // that has already been sweep up (collected). This method uses |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
715 // obj_is_alive() to determine whether it is safe to apply the closure to |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
716 // an object. See obj_is_alive() for details on how liveness of an |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
717 // object is decided. |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
718 |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
719 void CompactibleFreeListSpace::safe_object_iterate(ObjectClosure* blk) { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
720 assert_lock_strong(freelistLock()); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
721 NOT_PRODUCT(verify_objects_initialized()); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
722 HeapWord *cur, *limit; |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
723 size_t curSize; |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
724 for (cur = bottom(), limit = end(); cur < limit; |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
725 cur += curSize) { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
726 curSize = block_size(cur); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
727 if (block_is_obj(cur) && obj_is_alive(cur)) { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
728 blk->do_object(oop(cur)); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
729 } |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
730 } |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
731 } |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
360
diff
changeset
|
732 |
0 | 733 void CompactibleFreeListSpace::object_iterate_mem(MemRegion mr, |
734 UpwardsObjectClosure* cl) { | |
735 assert_locked(); | |
736 NOT_PRODUCT(verify_objects_initialized()); | |
737 Space::object_iterate_mem(mr, cl); | |
738 } | |
739 | |
740 // Callers of this iterator beware: The closure application should | |
741 // be robust in the face of uninitialized objects and should (always) | |
742 // return a correct size so that the next addr + size below gives us a | |
743 // valid block boundary. [See for instance, | |
744 // ScanMarkedObjectsAgainCarefullyClosure::do_object_careful() | |
745 // in ConcurrentMarkSweepGeneration.cpp.] | |
746 HeapWord* | |
747 CompactibleFreeListSpace::object_iterate_careful(ObjectClosureCareful* cl) { | |
748 assert_lock_strong(freelistLock()); | |
749 HeapWord *addr, *last; | |
750 size_t size; | |
751 for (addr = bottom(), last = end(); | |
752 addr < last; addr += size) { | |
753 FreeChunk* fc = (FreeChunk*)addr; | |
754 if (fc->isFree()) { | |
755 // Since we hold the free list lock, which protects direct | |
756 // allocation in this generation by mutators, a free object | |
757 // will remain free throughout this iteration code. | |
758 size = fc->size(); | |
759 } else { | |
760 // Note that the object need not necessarily be initialized, | |
761 // because (for instance) the free list lock does NOT protect | |
762 // object initialization. The closure application below must | |
763 // therefore be correct in the face of uninitialized objects. | |
764 size = cl->do_object_careful(oop(addr)); | |
765 if (size == 0) { | |
766 // An unparsable object found. Signal early termination. | |
767 return addr; | |
768 } | |
769 } | |
770 } | |
771 return NULL; | |
772 } | |
773 | |
774 // Callers of this iterator beware: The closure application should | |
775 // be robust in the face of uninitialized objects and should (always) | |
776 // return a correct size so that the next addr + size below gives us a | |
777 // valid block boundary. [See for instance, | |
778 // ScanMarkedObjectsAgainCarefullyClosure::do_object_careful() | |
779 // in ConcurrentMarkSweepGeneration.cpp.] | |
780 HeapWord* | |
781 CompactibleFreeListSpace::object_iterate_careful_m(MemRegion mr, | |
782 ObjectClosureCareful* cl) { | |
783 assert_lock_strong(freelistLock()); | |
784 // Can't use used_region() below because it may not necessarily | |
785 // be the same as [bottom(),end()); although we could | |
786 // use [used_region().start(),round_to(used_region().end(),CardSize)), | |
787 // that appears too cumbersome, so we just do the simpler check | |
788 // in the assertion below. | |
789 assert(!mr.is_empty() && MemRegion(bottom(),end()).contains(mr), | |
790 "mr should be non-empty and within used space"); | |
791 HeapWord *addr, *end; | |
792 size_t size; | |
793 for (addr = block_start_careful(mr.start()), end = mr.end(); | |
794 addr < end; addr += size) { | |
795 FreeChunk* fc = (FreeChunk*)addr; | |
796 if (fc->isFree()) { | |
797 // Since we hold the free list lock, which protects direct | |
798 // allocation in this generation by mutators, a free object | |
799 // will remain free throughout this iteration code. | |
800 size = fc->size(); | |
801 } else { | |
802 // Note that the object need not necessarily be initialized, | |
803 // because (for instance) the free list lock does NOT protect | |
804 // object initialization. The closure application below must | |
805 // therefore be correct in the face of uninitialized objects. | |
806 size = cl->do_object_careful_m(oop(addr), mr); | |
807 if (size == 0) { | |
808 // An unparsable object found. Signal early termination. | |
809 return addr; | |
810 } | |
811 } | |
812 } | |
813 return NULL; | |
814 } | |
815 | |
816 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
817 HeapWord* CompactibleFreeListSpace::block_start_const(const void* p) const { |
0 | 818 NOT_PRODUCT(verify_objects_initialized()); |
819 return _bt.block_start(p); | |
820 } | |
821 | |
822 HeapWord* CompactibleFreeListSpace::block_start_careful(const void* p) const { | |
823 return _bt.block_start_careful(p); | |
824 } | |
825 | |
826 size_t CompactibleFreeListSpace::block_size(const HeapWord* p) const { | |
827 NOT_PRODUCT(verify_objects_initialized()); | |
828 assert(MemRegion(bottom(), end()).contains(p), "p not in space"); | |
829 // This must be volatile, or else there is a danger that the compiler | |
830 // will compile the code below into a sometimes-infinite loop, by keeping | |
831 // the value read the first time in a register. | |
832 while (true) { | |
833 // We must do this until we get a consistent view of the object. | |
187 | 834 if (FreeChunk::indicatesFreeChunk(p)) { |
835 volatile FreeChunk* fc = (volatile FreeChunk*)p; | |
836 size_t res = fc->size(); | |
837 // If the object is still a free chunk, return the size, else it | |
838 // has been allocated so try again. | |
839 if (FreeChunk::indicatesFreeChunk(p)) { | |
0 | 840 assert(res != 0, "Block size should not be 0"); |
841 return res; | |
842 } | |
187 | 843 } else { |
844 // must read from what 'p' points to in each loop. | |
845 klassOop k = ((volatile oopDesc*)p)->klass_or_null(); | |
846 if (k != NULL) { | |
847 assert(k->is_oop(true /* ignore mark word */), "Should really be klass oop."); | |
848 oop o = (oop)p; | |
849 assert(o->is_parsable(), "Should be parsable"); | |
850 assert(o->is_oop(true /* ignore mark word */), "Should be an oop."); | |
851 size_t res = o->size_given_klass(k->klass_part()); | |
852 res = adjustObjectSize(res); | |
853 assert(res != 0, "Block size should not be 0"); | |
854 return res; | |
855 } | |
0 | 856 } |
857 } | |
858 } | |
859 | |
860 // A variant of the above that uses the Printezis bits for | |
861 // unparsable but allocated objects. This avoids any possible | |
862 // stalls waiting for mutators to initialize objects, and is | |
863 // thus potentially faster than the variant above. However, | |
864 // this variant may return a zero size for a block that is | |
865 // under mutation and for which a consistent size cannot be | |
866 // inferred without stalling; see CMSCollector::block_size_if_printezis_bits(). | |
867 size_t CompactibleFreeListSpace::block_size_no_stall(HeapWord* p, | |
868 const CMSCollector* c) | |
869 const { | |
870 assert(MemRegion(bottom(), end()).contains(p), "p not in space"); | |
871 // This must be volatile, or else there is a danger that the compiler | |
872 // will compile the code below into a sometimes-infinite loop, by keeping | |
873 // the value read the first time in a register. | |
874 DEBUG_ONLY(uint loops = 0;) | |
875 while (true) { | |
876 // We must do this until we get a consistent view of the object. | |
187 | 877 if (FreeChunk::indicatesFreeChunk(p)) { |
878 volatile FreeChunk* fc = (volatile FreeChunk*)p; | |
879 size_t res = fc->size(); | |
880 if (FreeChunk::indicatesFreeChunk(p)) { | |
0 | 881 assert(res != 0, "Block size should not be 0"); |
882 assert(loops == 0, "Should be 0"); | |
883 return res; | |
884 } | |
885 } else { | |
187 | 886 // must read from what 'p' points to in each loop. |
887 klassOop k = ((volatile oopDesc*)p)->klass_or_null(); | |
888 if (k != NULL && ((oopDesc*)p)->is_parsable()) { | |
889 assert(k->is_oop(), "Should really be klass oop."); | |
890 oop o = (oop)p; | |
891 assert(o->is_oop(), "Should be an oop"); | |
892 size_t res = o->size_given_klass(k->klass_part()); | |
893 res = adjustObjectSize(res); | |
894 assert(res != 0, "Block size should not be 0"); | |
895 return res; | |
896 } else { | |
897 return c->block_size_if_printezis_bits(p); | |
898 } | |
0 | 899 } |
900 assert(loops == 0, "Can loop at most once"); | |
901 DEBUG_ONLY(loops++;) | |
902 } | |
903 } | |
904 | |
905 size_t CompactibleFreeListSpace::block_size_nopar(const HeapWord* p) const { | |
906 NOT_PRODUCT(verify_objects_initialized()); | |
907 assert(MemRegion(bottom(), end()).contains(p), "p not in space"); | |
908 FreeChunk* fc = (FreeChunk*)p; | |
909 if (fc->isFree()) { | |
910 return fc->size(); | |
911 } else { | |
912 // Ignore mark word because this may be a recently promoted | |
913 // object whose mark word is used to chain together grey | |
914 // objects (the last one would have a null value). | |
915 assert(oop(p)->is_oop(true), "Should be an oop"); | |
916 return adjustObjectSize(oop(p)->size()); | |
917 } | |
918 } | |
919 | |
920 // This implementation assumes that the property of "being an object" is | |
921 // stable. But being a free chunk may not be (because of parallel | |
922 // promotion.) | |
923 bool CompactibleFreeListSpace::block_is_obj(const HeapWord* p) const { | |
924 FreeChunk* fc = (FreeChunk*)p; | |
925 assert(is_in_reserved(p), "Should be in space"); | |
926 // When doing a mark-sweep-compact of the CMS generation, this | |
927 // assertion may fail because prepare_for_compaction() uses | |
928 // space that is garbage to maintain information on ranges of | |
929 // live objects so that these live ranges can be moved as a whole. | |
930 // Comment out this assertion until that problem can be solved | |
931 // (i.e., that the block start calculation may look at objects | |
932 // at address below "p" in finding the object that contains "p" | |
933 // and those objects (if garbage) may have been modified to hold | |
934 // live range information. | |
935 // assert(ParallelGCThreads > 0 || _bt.block_start(p) == p, "Should be a block boundary"); | |
187 | 936 if (FreeChunk::indicatesFreeChunk(p)) return false; |
937 klassOop k = oop(p)->klass_or_null(); | |
0 | 938 if (k != NULL) { |
939 // Ignore mark word because it may have been used to | |
940 // chain together promoted objects (the last one | |
941 // would have a null value). | |
942 assert(oop(p)->is_oop(true), "Should be an oop"); | |
943 return true; | |
944 } else { | |
945 return false; // Was not an object at the start of collection. | |
946 } | |
947 } | |
948 | |
949 // Check if the object is alive. This fact is checked either by consulting | |
950 // the main marking bitmap in the sweeping phase or, if it's a permanent | |
951 // generation and we're not in the sweeping phase, by checking the | |
952 // perm_gen_verify_bit_map where we store the "deadness" information if | |
953 // we did not sweep the perm gen in the most recent previous GC cycle. | |
954 bool CompactibleFreeListSpace::obj_is_alive(const HeapWord* p) const { | |
955 assert (block_is_obj(p), "The address should point to an object"); | |
956 | |
957 // If we're sweeping, we use object liveness information from the main bit map | |
958 // for both perm gen and old gen. | |
959 // We don't need to lock the bitmap (live_map or dead_map below), because | |
960 // EITHER we are in the middle of the sweeping phase, and the | |
961 // main marking bit map (live_map below) is locked, | |
962 // OR we're in other phases and perm_gen_verify_bit_map (dead_map below) | |
963 // is stable, because it's mutated only in the sweeping phase. | |
964 if (_collector->abstract_state() == CMSCollector::Sweeping) { | |
965 CMSBitMap* live_map = _collector->markBitMap(); | |
966 return live_map->isMarked((HeapWord*) p); | |
967 } else { | |
968 // If we're not currently sweeping and we haven't swept the perm gen in | |
969 // the previous concurrent cycle then we may have dead but unswept objects | |
970 // in the perm gen. In this case, we use the "deadness" information | |
971 // that we had saved in perm_gen_verify_bit_map at the last sweep. | |
972 if (!CMSClassUnloadingEnabled && _collector->_permGen->reserved().contains(p)) { | |
973 if (_collector->verifying()) { | |
974 CMSBitMap* dead_map = _collector->perm_gen_verify_bit_map(); | |
975 // Object is marked in the dead_map bitmap at the previous sweep | |
976 // when we know that it's dead; if the bitmap is not allocated then | |
977 // the object is alive. | |
978 return (dead_map->sizeInBits() == 0) // bit_map has been allocated | |
979 || !dead_map->par_isMarked((HeapWord*) p); | |
980 } else { | |
981 return false; // We can't say for sure if it's live, so we say that it's dead. | |
982 } | |
983 } | |
984 } | |
985 return true; | |
986 } | |
987 | |
988 bool CompactibleFreeListSpace::block_is_obj_nopar(const HeapWord* p) const { | |
989 FreeChunk* fc = (FreeChunk*)p; | |
990 assert(is_in_reserved(p), "Should be in space"); | |
991 assert(_bt.block_start(p) == p, "Should be a block boundary"); | |
992 if (!fc->isFree()) { | |
993 // Ignore mark word because it may have been used to | |
994 // chain together promoted objects (the last one | |
995 // would have a null value). | |
996 assert(oop(p)->is_oop(true), "Should be an oop"); | |
997 return true; | |
998 } | |
999 return false; | |
1000 } | |
1001 | |
1002 // "MT-safe but not guaranteed MT-precise" (TM); you may get an | |
1003 // approximate answer if you don't hold the freelistlock when you call this. | |
1004 size_t CompactibleFreeListSpace::totalSizeInIndexedFreeLists() const { | |
1005 size_t size = 0; | |
1006 for (size_t i = IndexSetStart; i < IndexSetSize; i += IndexSetStride) { | |
1007 debug_only( | |
1008 // We may be calling here without the lock in which case we | |
1009 // won't do this modest sanity check. | |
1010 if (freelistLock()->owned_by_self()) { | |
1011 size_t total_list_size = 0; | |
1012 for (FreeChunk* fc = _indexedFreeList[i].head(); fc != NULL; | |
1013 fc = fc->next()) { | |
1014 total_list_size += i; | |
1015 } | |
1016 assert(total_list_size == i * _indexedFreeList[i].count(), | |
1017 "Count in list is incorrect"); | |
1018 } | |
1019 ) | |
1020 size += i * _indexedFreeList[i].count(); | |
1021 } | |
1022 return size; | |
1023 } | |
1024 | |
1025 HeapWord* CompactibleFreeListSpace::par_allocate(size_t size) { | |
1026 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); | |
1027 return allocate(size); | |
1028 } | |
1029 | |
1030 HeapWord* | |
1031 CompactibleFreeListSpace::getChunkFromSmallLinearAllocBlockRemainder(size_t size) { | |
1032 return getChunkFromLinearAllocBlockRemainder(&_smallLinearAllocBlock, size); | |
1033 } | |
1034 | |
1035 HeapWord* CompactibleFreeListSpace::allocate(size_t size) { | |
1036 assert_lock_strong(freelistLock()); | |
1037 HeapWord* res = NULL; | |
1038 assert(size == adjustObjectSize(size), | |
1039 "use adjustObjectSize() before calling into allocate()"); | |
1040 | |
1041 if (_adaptive_freelists) { | |
1042 res = allocate_adaptive_freelists(size); | |
1043 } else { // non-adaptive free lists | |
1044 res = allocate_non_adaptive_freelists(size); | |
1045 } | |
1046 | |
1047 if (res != NULL) { | |
1048 // check that res does lie in this space! | |
1049 assert(is_in_reserved(res), "Not in this space!"); | |
1050 assert(is_aligned((void*)res), "alignment check"); | |
1051 | |
1052 FreeChunk* fc = (FreeChunk*)res; | |
1053 fc->markNotFree(); | |
1054 assert(!fc->isFree(), "shouldn't be marked free"); | |
187 | 1055 assert(oop(fc)->klass_or_null() == NULL, "should look uninitialized"); |
0 | 1056 // Verify that the block offset table shows this to |
1057 // be a single block, but not one which is unallocated. | |
1058 _bt.verify_single_block(res, size); | |
1059 _bt.verify_not_unallocated(res, size); | |
1060 // mangle a just allocated object with a distinct pattern. | |
1061 debug_only(fc->mangleAllocated(size)); | |
1062 } | |
1063 | |
1064 return res; | |
1065 } | |
1066 | |
1067 HeapWord* CompactibleFreeListSpace::allocate_non_adaptive_freelists(size_t size) { | |
1068 HeapWord* res = NULL; | |
1069 // try and use linear allocation for smaller blocks | |
1070 if (size < _smallLinearAllocBlock._allocation_size_limit) { | |
1071 // if successful, the following also adjusts block offset table | |
1072 res = getChunkFromSmallLinearAllocBlock(size); | |
1073 } | |
1074 // Else triage to indexed lists for smaller sizes | |
1075 if (res == NULL) { | |
1076 if (size < SmallForDictionary) { | |
1077 res = (HeapWord*) getChunkFromIndexedFreeList(size); | |
1078 } else { | |
1079 // else get it from the big dictionary; if even this doesn't | |
1080 // work we are out of luck. | |
1081 res = (HeapWord*)getChunkFromDictionaryExact(size); | |
1082 } | |
1083 } | |
1084 | |
1085 return res; | |
1086 } | |
1087 | |
1088 HeapWord* CompactibleFreeListSpace::allocate_adaptive_freelists(size_t size) { | |
1089 assert_lock_strong(freelistLock()); | |
1090 HeapWord* res = NULL; | |
1091 assert(size == adjustObjectSize(size), | |
1092 "use adjustObjectSize() before calling into allocate()"); | |
1093 | |
1094 // Strategy | |
1095 // if small | |
1096 // exact size from small object indexed list if small | |
1097 // small or large linear allocation block (linAB) as appropriate | |
1098 // take from lists of greater sized chunks | |
1099 // else | |
1100 // dictionary | |
1101 // small or large linear allocation block if it has the space | |
1102 // Try allocating exact size from indexTable first | |
1103 if (size < IndexSetSize) { | |
1104 res = (HeapWord*) getChunkFromIndexedFreeList(size); | |
1105 if(res != NULL) { | |
1106 assert(res != (HeapWord*)_indexedFreeList[size].head(), | |
1107 "Not removed from free list"); | |
1108 // no block offset table adjustment is necessary on blocks in | |
1109 // the indexed lists. | |
1110 | |
1111 // Try allocating from the small LinAB | |
1112 } else if (size < _smallLinearAllocBlock._allocation_size_limit && | |
1113 (res = getChunkFromSmallLinearAllocBlock(size)) != NULL) { | |
1114 // if successful, the above also adjusts block offset table | |
1115 // Note that this call will refill the LinAB to | |
1116 // satisfy the request. This is different that | |
1117 // evm. | |
1118 // Don't record chunk off a LinAB? smallSplitBirth(size); | |
1119 | |
1120 } else { | |
1121 // Raid the exact free lists larger than size, even if they are not | |
1122 // overpopulated. | |
1123 res = (HeapWord*) getChunkFromGreater(size); | |
1124 } | |
1125 } else { | |
1126 // Big objects get allocated directly from the dictionary. | |
1127 res = (HeapWord*) getChunkFromDictionaryExact(size); | |
1128 if (res == NULL) { | |
1129 // Try hard not to fail since an allocation failure will likely | |
1130 // trigger a synchronous GC. Try to get the space from the | |
1131 // allocation blocks. | |
1132 res = getChunkFromSmallLinearAllocBlockRemainder(size); | |
1133 } | |
1134 } | |
1135 | |
1136 return res; | |
1137 } | |
1138 | |
1139 // A worst-case estimate of the space required (in HeapWords) to expand the heap | |
1140 // when promoting obj. | |
1141 size_t CompactibleFreeListSpace::expansionSpaceRequired(size_t obj_size) const { | |
1142 // Depending on the object size, expansion may require refilling either a | |
1143 // bigLAB or a smallLAB plus refilling a PromotionInfo object. MinChunkSize | |
1144 // is added because the dictionary may over-allocate to avoid fragmentation. | |
1145 size_t space = obj_size; | |
1146 if (!_adaptive_freelists) { | |
1147 space = MAX2(space, _smallLinearAllocBlock._refillSize); | |
1148 } | |
1149 space += _promoInfo.refillSize() + 2 * MinChunkSize; | |
1150 return space; | |
1151 } | |
1152 | |
1153 FreeChunk* CompactibleFreeListSpace::getChunkFromGreater(size_t numWords) { | |
1154 FreeChunk* ret; | |
1155 | |
1156 assert(numWords >= MinChunkSize, "Size is less than minimum"); | |
1157 assert(linearAllocationWouldFail() || bestFitFirst(), | |
1158 "Should not be here"); | |
1159 | |
1160 size_t i; | |
1161 size_t currSize = numWords + MinChunkSize; | |
1162 assert(currSize % MinObjAlignment == 0, "currSize should be aligned"); | |
1163 for (i = currSize; i < IndexSetSize; i += IndexSetStride) { | |
1164 FreeList* fl = &_indexedFreeList[i]; | |
1165 if (fl->head()) { | |
1166 ret = getFromListGreater(fl, numWords); | |
1167 assert(ret == NULL || ret->isFree(), "Should be returning a free chunk"); | |
1168 return ret; | |
1169 } | |
1170 } | |
1171 | |
1172 currSize = MAX2((size_t)SmallForDictionary, | |
1173 (size_t)(numWords + MinChunkSize)); | |
1174 | |
1175 /* Try to get a chunk that satisfies request, while avoiding | |
1176 fragmentation that can't be handled. */ | |
1177 { | |
1178 ret = dictionary()->getChunk(currSize); | |
1179 if (ret != NULL) { | |
1180 assert(ret->size() - numWords >= MinChunkSize, | |
1181 "Chunk is too small"); | |
1182 _bt.allocated((HeapWord*)ret, ret->size()); | |
1183 /* Carve returned chunk. */ | |
1184 (void) splitChunkAndReturnRemainder(ret, numWords); | |
1185 /* Label this as no longer a free chunk. */ | |
1186 assert(ret->isFree(), "This chunk should be free"); | |
1187 ret->linkPrev(NULL); | |
1188 } | |
1189 assert(ret == NULL || ret->isFree(), "Should be returning a free chunk"); | |
1190 return ret; | |
1191 } | |
1192 ShouldNotReachHere(); | |
1193 } | |
1194 | |
1195 bool CompactibleFreeListSpace::verifyChunkInIndexedFreeLists(FreeChunk* fc) | |
1196 const { | |
1197 assert(fc->size() < IndexSetSize, "Size of chunk is too large"); | |
1198 return _indexedFreeList[fc->size()].verifyChunkInFreeLists(fc); | |
1199 } | |
1200 | |
1201 bool CompactibleFreeListSpace::verifyChunkInFreeLists(FreeChunk* fc) const { | |
1202 if (fc->size() >= IndexSetSize) { | |
1203 return dictionary()->verifyChunkInFreeLists(fc); | |
1204 } else { | |
1205 return verifyChunkInIndexedFreeLists(fc); | |
1206 } | |
1207 } | |
1208 | |
1209 #ifndef PRODUCT | |
1210 void CompactibleFreeListSpace::assert_locked() const { | |
1211 CMSLockVerifier::assert_locked(freelistLock(), parDictionaryAllocLock()); | |
1212 } | |
1213 #endif | |
1214 | |
1215 FreeChunk* CompactibleFreeListSpace::allocateScratch(size_t size) { | |
1216 // In the parallel case, the main thread holds the free list lock | |
1217 // on behalf the parallel threads. | |
1218 assert_locked(); | |
1219 FreeChunk* fc; | |
1220 { | |
1221 // If GC is parallel, this might be called by several threads. | |
1222 // This should be rare enough that the locking overhead won't affect | |
1223 // the sequential code. | |
1224 MutexLockerEx x(parDictionaryAllocLock(), | |
1225 Mutex::_no_safepoint_check_flag); | |
1226 fc = getChunkFromDictionary(size); | |
1227 } | |
1228 if (fc != NULL) { | |
1229 fc->dontCoalesce(); | |
1230 assert(fc->isFree(), "Should be free, but not coalescable"); | |
1231 // Verify that the block offset table shows this to | |
1232 // be a single block, but not one which is unallocated. | |
1233 _bt.verify_single_block((HeapWord*)fc, fc->size()); | |
1234 _bt.verify_not_unallocated((HeapWord*)fc, fc->size()); | |
1235 } | |
1236 return fc; | |
1237 } | |
1238 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
1239 oop CompactibleFreeListSpace::promote(oop obj, size_t obj_size) { |
0 | 1240 assert(obj_size == (size_t)obj->size(), "bad obj_size passed in"); |
1241 assert_locked(); | |
1242 | |
1243 // if we are tracking promotions, then first ensure space for | |
1244 // promotion (including spooling space for saving header if necessary). | |
1245 // then allocate and copy, then track promoted info if needed. | |
1246 // When tracking (see PromotionInfo::track()), the mark word may | |
1247 // be displaced and in this case restoration of the mark word | |
1248 // occurs in the (oop_since_save_marks_)iterate phase. | |
1249 if (_promoInfo.tracking() && !_promoInfo.ensure_spooling_space()) { | |
1250 return NULL; | |
1251 } | |
1252 // Call the allocate(size_t, bool) form directly to avoid the | |
1253 // additional call through the allocate(size_t) form. Having | |
1254 // the compile inline the call is problematic because allocate(size_t) | |
1255 // is a virtual method. | |
1256 HeapWord* res = allocate(adjustObjectSize(obj_size)); | |
1257 if (res != NULL) { | |
1258 Copy::aligned_disjoint_words((HeapWord*)obj, res, obj_size); | |
1259 // if we should be tracking promotions, do so. | |
1260 if (_promoInfo.tracking()) { | |
1261 _promoInfo.track((PromotedObject*)res); | |
1262 } | |
1263 } | |
1264 return oop(res); | |
1265 } | |
1266 | |
1267 HeapWord* | |
1268 CompactibleFreeListSpace::getChunkFromSmallLinearAllocBlock(size_t size) { | |
1269 assert_locked(); | |
1270 assert(size >= MinChunkSize, "minimum chunk size"); | |
1271 assert(size < _smallLinearAllocBlock._allocation_size_limit, | |
1272 "maximum from smallLinearAllocBlock"); | |
1273 return getChunkFromLinearAllocBlock(&_smallLinearAllocBlock, size); | |
1274 } | |
1275 | |
1276 HeapWord* | |
1277 CompactibleFreeListSpace::getChunkFromLinearAllocBlock(LinearAllocBlock *blk, | |
1278 size_t size) { | |
1279 assert_locked(); | |
1280 assert(size >= MinChunkSize, "too small"); | |
1281 HeapWord* res = NULL; | |
1282 // Try to do linear allocation from blk, making sure that | |
1283 if (blk->_word_size == 0) { | |
1284 // We have probably been unable to fill this either in the prologue or | |
1285 // when it was exhausted at the last linear allocation. Bail out until | |
1286 // next time. | |
1287 assert(blk->_ptr == NULL, "consistency check"); | |
1288 return NULL; | |
1289 } | |
1290 assert(blk->_word_size != 0 && blk->_ptr != NULL, "consistency check"); | |
1291 res = getChunkFromLinearAllocBlockRemainder(blk, size); | |
1292 if (res != NULL) return res; | |
1293 | |
1294 // about to exhaust this linear allocation block | |
1295 if (blk->_word_size == size) { // exactly satisfied | |
1296 res = blk->_ptr; | |
1297 _bt.allocated(res, blk->_word_size); | |
1298 } else if (size + MinChunkSize <= blk->_refillSize) { | |
1299 // Update _unallocated_block if the size is such that chunk would be | |
1300 // returned to the indexed free list. All other chunks in the indexed | |
1301 // free lists are allocated from the dictionary so that _unallocated_block | |
1302 // has already been adjusted for them. Do it here so that the cost | |
1303 // for all chunks added back to the indexed free lists. | |
1304 if (blk->_word_size < SmallForDictionary) { | |
1305 _bt.allocated(blk->_ptr, blk->_word_size); | |
1306 } | |
1307 // Return the chunk that isn't big enough, and then refill below. | |
1308 addChunkToFreeLists(blk->_ptr, blk->_word_size); | |
1309 _bt.verify_single_block(blk->_ptr, (blk->_ptr + blk->_word_size)); | |
1310 // Don't keep statistics on adding back chunk from a LinAB. | |
1311 } else { | |
1312 // A refilled block would not satisfy the request. | |
1313 return NULL; | |
1314 } | |
1315 | |
1316 blk->_ptr = NULL; blk->_word_size = 0; | |
1317 refillLinearAllocBlock(blk); | |
1318 assert(blk->_ptr == NULL || blk->_word_size >= size + MinChunkSize, | |
1319 "block was replenished"); | |
1320 if (res != NULL) { | |
1321 splitBirth(size); | |
1322 repairLinearAllocBlock(blk); | |
1323 } else if (blk->_ptr != NULL) { | |
1324 res = blk->_ptr; | |
1325 size_t blk_size = blk->_word_size; | |
1326 blk->_word_size -= size; | |
1327 blk->_ptr += size; | |
1328 splitBirth(size); | |
1329 repairLinearAllocBlock(blk); | |
1330 // Update BOT last so that other (parallel) GC threads see a consistent | |
1331 // view of the BOT and free blocks. | |
1332 // Above must occur before BOT is updated below. | |
1333 _bt.split_block(res, blk_size, size); // adjust block offset table | |
1334 } | |
1335 return res; | |
1336 } | |
1337 | |
1338 HeapWord* CompactibleFreeListSpace::getChunkFromLinearAllocBlockRemainder( | |
1339 LinearAllocBlock* blk, | |
1340 size_t size) { | |
1341 assert_locked(); | |
1342 assert(size >= MinChunkSize, "too small"); | |
1343 | |
1344 HeapWord* res = NULL; | |
1345 // This is the common case. Keep it simple. | |
1346 if (blk->_word_size >= size + MinChunkSize) { | |
1347 assert(blk->_ptr != NULL, "consistency check"); | |
1348 res = blk->_ptr; | |
1349 // Note that the BOT is up-to-date for the linAB before allocation. It | |
1350 // indicates the start of the linAB. The split_block() updates the | |
1351 // BOT for the linAB after the allocation (indicates the start of the | |
1352 // next chunk to be allocated). | |
1353 size_t blk_size = blk->_word_size; | |
1354 blk->_word_size -= size; | |
1355 blk->_ptr += size; | |
1356 splitBirth(size); | |
1357 repairLinearAllocBlock(blk); | |
1358 // Update BOT last so that other (parallel) GC threads see a consistent | |
1359 // view of the BOT and free blocks. | |
1360 // Above must occur before BOT is updated below. | |
1361 _bt.split_block(res, blk_size, size); // adjust block offset table | |
1362 _bt.allocated(res, size); | |
1363 } | |
1364 return res; | |
1365 } | |
1366 | |
1367 FreeChunk* | |
1368 CompactibleFreeListSpace::getChunkFromIndexedFreeList(size_t size) { | |
1369 assert_locked(); | |
1370 assert(size < SmallForDictionary, "just checking"); | |
1371 FreeChunk* res; | |
1372 res = _indexedFreeList[size].getChunkAtHead(); | |
1373 if (res == NULL) { | |
1374 res = getChunkFromIndexedFreeListHelper(size); | |
1375 } | |
1376 _bt.verify_not_unallocated((HeapWord*) res, size); | |
1377 return res; | |
1378 } | |
1379 | |
1380 FreeChunk* | |
1381 CompactibleFreeListSpace::getChunkFromIndexedFreeListHelper(size_t size) { | |
1382 assert_locked(); | |
1383 FreeChunk* fc = NULL; | |
1384 if (size < SmallForDictionary) { | |
1385 assert(_indexedFreeList[size].head() == NULL || | |
1386 _indexedFreeList[size].surplus() <= 0, | |
1387 "List for this size should be empty or under populated"); | |
1388 // Try best fit in exact lists before replenishing the list | |
1389 if (!bestFitFirst() || (fc = bestFitSmall(size)) == NULL) { | |
1390 // Replenish list. | |
1391 // | |
1392 // Things tried that failed. | |
1393 // Tried allocating out of the two LinAB's first before | |
1394 // replenishing lists. | |
1395 // Tried small linAB of size 256 (size in indexed list) | |
1396 // and replenishing indexed lists from the small linAB. | |
1397 // | |
1398 FreeChunk* newFc = NULL; | |
1399 size_t replenish_size = CMSIndexedFreeListReplenish * size; | |
1400 if (replenish_size < SmallForDictionary) { | |
1401 // Do not replenish from an underpopulated size. | |
1402 if (_indexedFreeList[replenish_size].surplus() > 0 && | |
1403 _indexedFreeList[replenish_size].head() != NULL) { | |
1404 newFc = | |
1405 _indexedFreeList[replenish_size].getChunkAtHead(); | |
1406 } else { | |
1407 newFc = bestFitSmall(replenish_size); | |
1408 } | |
1409 } | |
1410 if (newFc != NULL) { | |
1411 splitDeath(replenish_size); | |
1412 } else if (replenish_size > size) { | |
1413 assert(CMSIndexedFreeListReplenish > 1, "ctl pt invariant"); | |
1414 newFc = | |
1415 getChunkFromIndexedFreeListHelper(replenish_size); | |
1416 } | |
1417 if (newFc != NULL) { | |
1418 assert(newFc->size() == replenish_size, "Got wrong size"); | |
1419 size_t i; | |
1420 FreeChunk *curFc, *nextFc; | |
1421 // carve up and link blocks 0, ..., CMSIndexedFreeListReplenish - 2 | |
1422 // The last chunk is not added to the lists but is returned as the | |
1423 // free chunk. | |
1424 for (curFc = newFc, nextFc = (FreeChunk*)((HeapWord*)curFc + size), | |
1425 i = 0; | |
1426 i < (CMSIndexedFreeListReplenish - 1); | |
1427 curFc = nextFc, nextFc = (FreeChunk*)((HeapWord*)nextFc + size), | |
1428 i++) { | |
1429 curFc->setSize(size); | |
1430 // Don't record this as a return in order to try and | |
1431 // determine the "returns" from a GC. | |
1432 _bt.verify_not_unallocated((HeapWord*) fc, size); | |
1433 _indexedFreeList[size].returnChunkAtTail(curFc, false); | |
1434 _bt.mark_block((HeapWord*)curFc, size); | |
1435 splitBirth(size); | |
1436 // Don't record the initial population of the indexed list | |
1437 // as a split birth. | |
1438 } | |
1439 | |
1440 // check that the arithmetic was OK above | |
1441 assert((HeapWord*)nextFc == (HeapWord*)newFc + replenish_size, | |
1442 "inconsistency in carving newFc"); | |
1443 curFc->setSize(size); | |
1444 _bt.mark_block((HeapWord*)curFc, size); | |
1445 splitBirth(size); | |
1446 return curFc; | |
1447 } | |
1448 } | |
1449 } else { | |
1450 // Get a free chunk from the free chunk dictionary to be returned to | |
1451 // replenish the indexed free list. | |
1452 fc = getChunkFromDictionaryExact(size); | |
1453 } | |
1454 assert(fc == NULL || fc->isFree(), "Should be returning a free chunk"); | |
1455 return fc; | |
1456 } | |
1457 | |
1458 FreeChunk* | |
1459 CompactibleFreeListSpace::getChunkFromDictionary(size_t size) { | |
1460 assert_locked(); | |
1461 FreeChunk* fc = _dictionary->getChunk(size); | |
1462 if (fc == NULL) { | |
1463 return NULL; | |
1464 } | |
1465 _bt.allocated((HeapWord*)fc, fc->size()); | |
1466 if (fc->size() >= size + MinChunkSize) { | |
1467 fc = splitChunkAndReturnRemainder(fc, size); | |
1468 } | |
1469 assert(fc->size() >= size, "chunk too small"); | |
1470 assert(fc->size() < size + MinChunkSize, "chunk too big"); | |
1471 _bt.verify_single_block((HeapWord*)fc, fc->size()); | |
1472 return fc; | |
1473 } | |
1474 | |
1475 FreeChunk* | |
1476 CompactibleFreeListSpace::getChunkFromDictionaryExact(size_t size) { | |
1477 assert_locked(); | |
1478 FreeChunk* fc = _dictionary->getChunk(size); | |
1479 if (fc == NULL) { | |
1480 return fc; | |
1481 } | |
1482 _bt.allocated((HeapWord*)fc, fc->size()); | |
1483 if (fc->size() == size) { | |
1484 _bt.verify_single_block((HeapWord*)fc, size); | |
1485 return fc; | |
1486 } | |
1487 assert(fc->size() > size, "getChunk() guarantee"); | |
1488 if (fc->size() < size + MinChunkSize) { | |
1489 // Return the chunk to the dictionary and go get a bigger one. | |
1490 returnChunkToDictionary(fc); | |
1491 fc = _dictionary->getChunk(size + MinChunkSize); | |
1492 if (fc == NULL) { | |
1493 return NULL; | |
1494 } | |
1495 _bt.allocated((HeapWord*)fc, fc->size()); | |
1496 } | |
1497 assert(fc->size() >= size + MinChunkSize, "tautology"); | |
1498 fc = splitChunkAndReturnRemainder(fc, size); | |
1499 assert(fc->size() == size, "chunk is wrong size"); | |
1500 _bt.verify_single_block((HeapWord*)fc, size); | |
1501 return fc; | |
1502 } | |
1503 | |
1504 void | |
1505 CompactibleFreeListSpace::returnChunkToDictionary(FreeChunk* chunk) { | |
1506 assert_locked(); | |
1507 | |
1508 size_t size = chunk->size(); | |
1509 _bt.verify_single_block((HeapWord*)chunk, size); | |
1510 // adjust _unallocated_block downward, as necessary | |
1511 _bt.freed((HeapWord*)chunk, size); | |
1512 _dictionary->returnChunk(chunk); | |
1513 } | |
1514 | |
1515 void | |
1516 CompactibleFreeListSpace::returnChunkToFreeList(FreeChunk* fc) { | |
1517 assert_locked(); | |
1518 size_t size = fc->size(); | |
1519 _bt.verify_single_block((HeapWord*) fc, size); | |
1520 _bt.verify_not_unallocated((HeapWord*) fc, size); | |
1521 if (_adaptive_freelists) { | |
1522 _indexedFreeList[size].returnChunkAtTail(fc); | |
1523 } else { | |
1524 _indexedFreeList[size].returnChunkAtHead(fc); | |
1525 } | |
1526 } | |
1527 | |
1528 // Add chunk to end of last block -- if it's the largest | |
1529 // block -- and update BOT and census data. We would | |
1530 // of course have preferred to coalesce it with the | |
1531 // last block, but it's currently less expensive to find the | |
1532 // largest block than it is to find the last. | |
1533 void | |
1534 CompactibleFreeListSpace::addChunkToFreeListsAtEndRecordingStats( | |
1535 HeapWord* chunk, size_t size) { | |
1536 // check that the chunk does lie in this space! | |
1537 assert(chunk != NULL && is_in_reserved(chunk), "Not in this space!"); | |
1538 assert_locked(); | |
1539 // One of the parallel gc task threads may be here | |
1540 // whilst others are allocating. | |
1541 Mutex* lock = NULL; | |
1542 if (ParallelGCThreads != 0) { | |
1543 lock = &_parDictionaryAllocLock; | |
1544 } | |
1545 FreeChunk* ec; | |
1546 { | |
1547 MutexLockerEx x(lock, Mutex::_no_safepoint_check_flag); | |
1548 ec = dictionary()->findLargestDict(); // get largest block | |
1549 if (ec != NULL && ec->end() == chunk) { | |
1550 // It's a coterminal block - we can coalesce. | |
1551 size_t old_size = ec->size(); | |
1552 coalDeath(old_size); | |
1553 removeChunkFromDictionary(ec); | |
1554 size += old_size; | |
1555 } else { | |
1556 ec = (FreeChunk*)chunk; | |
1557 } | |
1558 } | |
1559 ec->setSize(size); | |
1560 debug_only(ec->mangleFreed(size)); | |
1561 if (size < SmallForDictionary) { | |
1562 lock = _indexedFreeListParLocks[size]; | |
1563 } | |
1564 MutexLockerEx x(lock, Mutex::_no_safepoint_check_flag); | |
1565 addChunkAndRepairOffsetTable((HeapWord*)ec, size, true); | |
1566 // record the birth under the lock since the recording involves | |
1567 // manipulation of the list on which the chunk lives and | |
1568 // if the chunk is allocated and is the last on the list, | |
1569 // the list can go away. | |
1570 coalBirth(size); | |
1571 } | |
1572 | |
1573 void | |
1574 CompactibleFreeListSpace::addChunkToFreeLists(HeapWord* chunk, | |
1575 size_t size) { | |
1576 // check that the chunk does lie in this space! | |
1577 assert(chunk != NULL && is_in_reserved(chunk), "Not in this space!"); | |
1578 assert_locked(); | |
1579 _bt.verify_single_block(chunk, size); | |
1580 | |
1581 FreeChunk* fc = (FreeChunk*) chunk; | |
1582 fc->setSize(size); | |
1583 debug_only(fc->mangleFreed(size)); | |
1584 if (size < SmallForDictionary) { | |
1585 returnChunkToFreeList(fc); | |
1586 } else { | |
1587 returnChunkToDictionary(fc); | |
1588 } | |
1589 } | |
1590 | |
1591 void | |
1592 CompactibleFreeListSpace::addChunkAndRepairOffsetTable(HeapWord* chunk, | |
1593 size_t size, bool coalesced) { | |
1594 assert_locked(); | |
1595 assert(chunk != NULL, "null chunk"); | |
1596 if (coalesced) { | |
1597 // repair BOT | |
1598 _bt.single_block(chunk, size); | |
1599 } | |
1600 addChunkToFreeLists(chunk, size); | |
1601 } | |
1602 | |
1603 // We _must_ find the purported chunk on our free lists; | |
1604 // we assert if we don't. | |
1605 void | |
1606 CompactibleFreeListSpace::removeFreeChunkFromFreeLists(FreeChunk* fc) { | |
1607 size_t size = fc->size(); | |
1608 assert_locked(); | |
1609 debug_only(verifyFreeLists()); | |
1610 if (size < SmallForDictionary) { | |
1611 removeChunkFromIndexedFreeList(fc); | |
1612 } else { | |
1613 removeChunkFromDictionary(fc); | |
1614 } | |
1615 _bt.verify_single_block((HeapWord*)fc, size); | |
1616 debug_only(verifyFreeLists()); | |
1617 } | |
1618 | |
1619 void | |
1620 CompactibleFreeListSpace::removeChunkFromDictionary(FreeChunk* fc) { | |
1621 size_t size = fc->size(); | |
1622 assert_locked(); | |
1623 assert(fc != NULL, "null chunk"); | |
1624 _bt.verify_single_block((HeapWord*)fc, size); | |
1625 _dictionary->removeChunk(fc); | |
1626 // adjust _unallocated_block upward, as necessary | |
1627 _bt.allocated((HeapWord*)fc, size); | |
1628 } | |
1629 | |
1630 void | |
1631 CompactibleFreeListSpace::removeChunkFromIndexedFreeList(FreeChunk* fc) { | |
1632 assert_locked(); | |
1633 size_t size = fc->size(); | |
1634 _bt.verify_single_block((HeapWord*)fc, size); | |
1635 NOT_PRODUCT( | |
1636 if (FLSVerifyIndexTable) { | |
1637 verifyIndexedFreeList(size); | |
1638 } | |
1639 ) | |
1640 _indexedFreeList[size].removeChunk(fc); | |
1641 debug_only(fc->clearNext()); | |
1642 debug_only(fc->clearPrev()); | |
1643 NOT_PRODUCT( | |
1644 if (FLSVerifyIndexTable) { | |
1645 verifyIndexedFreeList(size); | |
1646 } | |
1647 ) | |
1648 } | |
1649 | |
1650 FreeChunk* CompactibleFreeListSpace::bestFitSmall(size_t numWords) { | |
1651 /* A hint is the next larger size that has a surplus. | |
1652 Start search at a size large enough to guarantee that | |
1653 the excess is >= MIN_CHUNK. */ | |
1654 size_t start = align_object_size(numWords + MinChunkSize); | |
1655 if (start < IndexSetSize) { | |
1656 FreeList* it = _indexedFreeList; | |
1657 size_t hint = _indexedFreeList[start].hint(); | |
1658 while (hint < IndexSetSize) { | |
1659 assert(hint % MinObjAlignment == 0, "hint should be aligned"); | |
1660 FreeList *fl = &_indexedFreeList[hint]; | |
1661 if (fl->surplus() > 0 && fl->head() != NULL) { | |
1662 // Found a list with surplus, reset original hint | |
1663 // and split out a free chunk which is returned. | |
1664 _indexedFreeList[start].set_hint(hint); | |
1665 FreeChunk* res = getFromListGreater(fl, numWords); | |
1666 assert(res == NULL || res->isFree(), | |
1667 "Should be returning a free chunk"); | |
1668 return res; | |
1669 } | |
1670 hint = fl->hint(); /* keep looking */ | |
1671 } | |
1672 /* None found. */ | |
1673 it[start].set_hint(IndexSetSize); | |
1674 } | |
1675 return NULL; | |
1676 } | |
1677 | |
1678 /* Requires fl->size >= numWords + MinChunkSize */ | |
1679 FreeChunk* CompactibleFreeListSpace::getFromListGreater(FreeList* fl, | |
1680 size_t numWords) { | |
1681 FreeChunk *curr = fl->head(); | |
1682 size_t oldNumWords = curr->size(); | |
1683 assert(numWords >= MinChunkSize, "Word size is too small"); | |
1684 assert(curr != NULL, "List is empty"); | |
1685 assert(oldNumWords >= numWords + MinChunkSize, | |
1686 "Size of chunks in the list is too small"); | |
1687 | |
1688 fl->removeChunk(curr); | |
1689 // recorded indirectly by splitChunkAndReturnRemainder - | |
1690 // smallSplit(oldNumWords, numWords); | |
1691 FreeChunk* new_chunk = splitChunkAndReturnRemainder(curr, numWords); | |
1692 // Does anything have to be done for the remainder in terms of | |
1693 // fixing the card table? | |
1694 assert(new_chunk == NULL || new_chunk->isFree(), | |
1695 "Should be returning a free chunk"); | |
1696 return new_chunk; | |
1697 } | |
1698 | |
1699 FreeChunk* | |
1700 CompactibleFreeListSpace::splitChunkAndReturnRemainder(FreeChunk* chunk, | |
1701 size_t new_size) { | |
1702 assert_locked(); | |
1703 size_t size = chunk->size(); | |
1704 assert(size > new_size, "Split from a smaller block?"); | |
1705 assert(is_aligned(chunk), "alignment problem"); | |
1706 assert(size == adjustObjectSize(size), "alignment problem"); | |
1707 size_t rem_size = size - new_size; | |
1708 assert(rem_size == adjustObjectSize(rem_size), "alignment problem"); | |
1709 assert(rem_size >= MinChunkSize, "Free chunk smaller than minimum"); | |
1710 FreeChunk* ffc = (FreeChunk*)((HeapWord*)chunk + new_size); | |
1711 assert(is_aligned(ffc), "alignment problem"); | |
1712 ffc->setSize(rem_size); | |
1713 ffc->linkNext(NULL); | |
1714 ffc->linkPrev(NULL); // Mark as a free block for other (parallel) GC threads. | |
1715 // Above must occur before BOT is updated below. | |
1716 // adjust block offset table | |
1717 _bt.split_block((HeapWord*)chunk, chunk->size(), new_size); | |
1718 if (rem_size < SmallForDictionary) { | |
1719 bool is_par = (SharedHeap::heap()->n_par_threads() > 0); | |
1720 if (is_par) _indexedFreeListParLocks[rem_size]->lock(); | |
1721 returnChunkToFreeList(ffc); | |
1722 split(size, rem_size); | |
1723 if (is_par) _indexedFreeListParLocks[rem_size]->unlock(); | |
1724 } else { | |
1725 returnChunkToDictionary(ffc); | |
1726 split(size ,rem_size); | |
1727 } | |
1728 chunk->setSize(new_size); | |
1729 return chunk; | |
1730 } | |
1731 | |
1732 void | |
1733 CompactibleFreeListSpace::sweep_completed() { | |
1734 // Now that space is probably plentiful, refill linear | |
1735 // allocation blocks as needed. | |
1736 refillLinearAllocBlocksIfNeeded(); | |
1737 } | |
1738 | |
1739 void | |
1740 CompactibleFreeListSpace::gc_prologue() { | |
1741 assert_locked(); | |
1742 if (PrintFLSStatistics != 0) { | |
1743 gclog_or_tty->print("Before GC:\n"); | |
1744 reportFreeListStatistics(); | |
1745 } | |
1746 refillLinearAllocBlocksIfNeeded(); | |
1747 } | |
1748 | |
1749 void | |
1750 CompactibleFreeListSpace::gc_epilogue() { | |
1751 assert_locked(); | |
1752 if (PrintGCDetails && Verbose && !_adaptive_freelists) { | |
1753 if (_smallLinearAllocBlock._word_size == 0) | |
1754 warning("CompactibleFreeListSpace(epilogue):: Linear allocation failure"); | |
1755 } | |
1756 assert(_promoInfo.noPromotions(), "_promoInfo inconsistency"); | |
1757 _promoInfo.stopTrackingPromotions(); | |
1758 repairLinearAllocationBlocks(); | |
1759 // Print Space's stats | |
1760 if (PrintFLSStatistics != 0) { | |
1761 gclog_or_tty->print("After GC:\n"); | |
1762 reportFreeListStatistics(); | |
1763 } | |
1764 } | |
1765 | |
1766 // Iteration support, mostly delegated from a CMS generation | |
1767 | |
1768 void CompactibleFreeListSpace::save_marks() { | |
1769 // mark the "end" of the used space at the time of this call; | |
1770 // note, however, that promoted objects from this point | |
1771 // on are tracked in the _promoInfo below. | |
1772 set_saved_mark_word(BlockOffsetArrayUseUnallocatedBlock ? | |
1773 unallocated_block() : end()); | |
1774 // inform allocator that promotions should be tracked. | |
1775 assert(_promoInfo.noPromotions(), "_promoInfo inconsistency"); | |
1776 _promoInfo.startTrackingPromotions(); | |
1777 } | |
1778 | |
1779 bool CompactibleFreeListSpace::no_allocs_since_save_marks() { | |
1780 assert(_promoInfo.tracking(), "No preceding save_marks?"); | |
1781 guarantee(SharedHeap::heap()->n_par_threads() == 0, | |
1782 "Shouldn't be called (yet) during parallel part of gc."); | |
1783 return _promoInfo.noPromotions(); | |
1784 } | |
1785 | |
1786 #define CFLS_OOP_SINCE_SAVE_MARKS_DEFN(OopClosureType, nv_suffix) \ | |
1787 \ | |
1788 void CompactibleFreeListSpace:: \ | |
1789 oop_since_save_marks_iterate##nv_suffix(OopClosureType* blk) { \ | |
1790 assert(SharedHeap::heap()->n_par_threads() == 0, \ | |
1791 "Shouldn't be called (yet) during parallel part of gc."); \ | |
1792 _promoInfo.promoted_oops_iterate##nv_suffix(blk); \ | |
1793 /* \ | |
1794 * This also restores any displaced headers and removes the elements from \ | |
1795 * the iteration set as they are processed, so that we have a clean slate \ | |
1796 * at the end of the iteration. Note, thus, that if new objects are \ | |
1797 * promoted as a result of the iteration they are iterated over as well. \ | |
1798 */ \ | |
1799 assert(_promoInfo.noPromotions(), "_promoInfo inconsistency"); \ | |
1800 } | |
1801 | |
1802 ALL_SINCE_SAVE_MARKS_CLOSURES(CFLS_OOP_SINCE_SAVE_MARKS_DEFN) | |
1803 | |
1804 ////////////////////////////////////////////////////////////////////////////// | |
1805 // We go over the list of promoted objects, removing each from the list, | |
1806 // and applying the closure (this may, in turn, add more elements to | |
1807 // the tail of the promoted list, and these newly added objects will | |
1808 // also be processed) until the list is empty. | |
1809 // To aid verification and debugging, in the non-product builds | |
1810 // we actually forward _promoHead each time we process a promoted oop. | |
1811 // Note that this is not necessary in general (i.e. when we don't need to | |
1812 // call PromotionInfo::verify()) because oop_iterate can only add to the | |
1813 // end of _promoTail, and never needs to look at _promoHead. | |
1814 | |
1815 #define PROMOTED_OOPS_ITERATE_DEFN(OopClosureType, nv_suffix) \ | |
1816 \ | |
1817 void PromotionInfo::promoted_oops_iterate##nv_suffix(OopClosureType* cl) { \ | |
1818 NOT_PRODUCT(verify()); \ | |
1819 PromotedObject *curObj, *nextObj; \ | |
1820 for (curObj = _promoHead; curObj != NULL; curObj = nextObj) { \ | |
1821 if ((nextObj = curObj->next()) == NULL) { \ | |
1822 /* protect ourselves against additions due to closure application \ | |
1823 below by resetting the list. */ \ | |
1824 assert(_promoTail == curObj, "Should have been the tail"); \ | |
1825 _promoHead = _promoTail = NULL; \ | |
1826 } \ | |
1827 if (curObj->hasDisplacedMark()) { \ | |
1828 /* restore displaced header */ \ | |
1829 oop(curObj)->set_mark(nextDisplacedHeader()); \ | |
1830 } else { \ | |
1831 /* restore prototypical header */ \ | |
1832 oop(curObj)->init_mark(); \ | |
1833 } \ | |
1834 /* The "promoted_mark" should now not be set */ \ | |
1835 assert(!curObj->hasPromotedMark(), \ | |
1836 "Should have been cleared by restoring displaced mark-word"); \ | |
1837 NOT_PRODUCT(_promoHead = nextObj); \ | |
1838 if (cl != NULL) oop(curObj)->oop_iterate(cl); \ | |
1839 if (nextObj == NULL) { /* start at head of list reset above */ \ | |
1840 nextObj = _promoHead; \ | |
1841 } \ | |
1842 } \ | |
1843 assert(noPromotions(), "post-condition violation"); \ | |
1844 assert(_promoHead == NULL && _promoTail == NULL, "emptied promoted list");\ | |
1845 assert(_spoolHead == _spoolTail, "emptied spooling buffers"); \ | |
1846 assert(_firstIndex == _nextIndex, "empty buffer"); \ | |
1847 } | |
1848 | |
1849 // This should have been ALL_SINCE_...() just like the others, | |
1850 // but, because the body of the method above is somehwat longer, | |
1851 // the MSVC compiler cannot cope; as a workaround, we split the | |
1852 // macro into its 3 constituent parts below (see original macro | |
1853 // definition in specializedOopClosures.hpp). | |
1854 SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG(PROMOTED_OOPS_ITERATE_DEFN) | |
1855 PROMOTED_OOPS_ITERATE_DEFN(OopsInGenClosure,_v) | |
1856 | |
1857 | |
1858 void CompactibleFreeListSpace::object_iterate_since_last_GC(ObjectClosure* cl) { | |
1859 // ugghh... how would one do this efficiently for a non-contiguous space? | |
1860 guarantee(false, "NYI"); | |
1861 } | |
1862 | |
12
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
1863 bool CompactibleFreeListSpace::linearAllocationWouldFail() const { |
0 | 1864 return _smallLinearAllocBlock._word_size == 0; |
1865 } | |
1866 | |
1867 void CompactibleFreeListSpace::repairLinearAllocationBlocks() { | |
1868 // Fix up linear allocation blocks to look like free blocks | |
1869 repairLinearAllocBlock(&_smallLinearAllocBlock); | |
1870 } | |
1871 | |
1872 void CompactibleFreeListSpace::repairLinearAllocBlock(LinearAllocBlock* blk) { | |
1873 assert_locked(); | |
1874 if (blk->_ptr != NULL) { | |
1875 assert(blk->_word_size != 0 && blk->_word_size >= MinChunkSize, | |
1876 "Minimum block size requirement"); | |
1877 FreeChunk* fc = (FreeChunk*)(blk->_ptr); | |
1878 fc->setSize(blk->_word_size); | |
1879 fc->linkPrev(NULL); // mark as free | |
1880 fc->dontCoalesce(); | |
1881 assert(fc->isFree(), "just marked it free"); | |
1882 assert(fc->cantCoalesce(), "just marked it uncoalescable"); | |
1883 } | |
1884 } | |
1885 | |
1886 void CompactibleFreeListSpace::refillLinearAllocBlocksIfNeeded() { | |
1887 assert_locked(); | |
1888 if (_smallLinearAllocBlock._ptr == NULL) { | |
1889 assert(_smallLinearAllocBlock._word_size == 0, | |
1890 "Size of linAB should be zero if the ptr is NULL"); | |
1891 // Reset the linAB refill and allocation size limit. | |
1892 _smallLinearAllocBlock.set(0, 0, 1024*SmallForLinearAlloc, SmallForLinearAlloc); | |
1893 } | |
1894 refillLinearAllocBlockIfNeeded(&_smallLinearAllocBlock); | |
1895 } | |
1896 | |
1897 void | |
1898 CompactibleFreeListSpace::refillLinearAllocBlockIfNeeded(LinearAllocBlock* blk) { | |
1899 assert_locked(); | |
1900 assert((blk->_ptr == NULL && blk->_word_size == 0) || | |
1901 (blk->_ptr != NULL && blk->_word_size >= MinChunkSize), | |
1902 "blk invariant"); | |
1903 if (blk->_ptr == NULL) { | |
1904 refillLinearAllocBlock(blk); | |
1905 } | |
1906 if (PrintMiscellaneous && Verbose) { | |
1907 if (blk->_word_size == 0) { | |
1908 warning("CompactibleFreeListSpace(prologue):: Linear allocation failure"); | |
1909 } | |
1910 } | |
1911 } | |
1912 | |
1913 void | |
1914 CompactibleFreeListSpace::refillLinearAllocBlock(LinearAllocBlock* blk) { | |
1915 assert_locked(); | |
1916 assert(blk->_word_size == 0 && blk->_ptr == NULL, | |
1917 "linear allocation block should be empty"); | |
1918 FreeChunk* fc; | |
1919 if (blk->_refillSize < SmallForDictionary && | |
1920 (fc = getChunkFromIndexedFreeList(blk->_refillSize)) != NULL) { | |
1921 // A linAB's strategy might be to use small sizes to reduce | |
1922 // fragmentation but still get the benefits of allocation from a | |
1923 // linAB. | |
1924 } else { | |
1925 fc = getChunkFromDictionary(blk->_refillSize); | |
1926 } | |
1927 if (fc != NULL) { | |
1928 blk->_ptr = (HeapWord*)fc; | |
1929 blk->_word_size = fc->size(); | |
1930 fc->dontCoalesce(); // to prevent sweeper from sweeping us up | |
1931 } | |
1932 } | |
1933 | |
12
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
1934 // Support for concurrent collection policy decisions. |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
1935 bool CompactibleFreeListSpace::should_concurrent_collect() const { |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
1936 // In the future we might want to add in frgamentation stats -- |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
1937 // including erosion of the "mountain" into this decision as well. |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
1938 return !adaptive_freelists() && linearAllocationWouldFail(); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
1939 } |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
1940 |
0 | 1941 // Support for compaction |
1942 | |
1943 void CompactibleFreeListSpace::prepare_for_compaction(CompactPoint* cp) { | |
1944 SCAN_AND_FORWARD(cp,end,block_is_obj,block_size); | |
1945 // prepare_for_compaction() uses the space between live objects | |
1946 // so that later phase can skip dead space quickly. So verification | |
1947 // of the free lists doesn't work after. | |
1948 } | |
1949 | |
1950 #define obj_size(q) adjustObjectSize(oop(q)->size()) | |
1951 #define adjust_obj_size(s) adjustObjectSize(s) | |
1952 | |
1953 void CompactibleFreeListSpace::adjust_pointers() { | |
1954 // In other versions of adjust_pointers(), a bail out | |
1955 // based on the amount of live data in the generation | |
1956 // (i.e., if 0, bail out) may be used. | |
1957 // Cannot test used() == 0 here because the free lists have already | |
1958 // been mangled by the compaction. | |
1959 | |
1960 SCAN_AND_ADJUST_POINTERS(adjust_obj_size); | |
1961 // See note about verification in prepare_for_compaction(). | |
1962 } | |
1963 | |
1964 void CompactibleFreeListSpace::compact() { | |
1965 SCAN_AND_COMPACT(obj_size); | |
1966 } | |
1967 | |
1968 // fragmentation_metric = 1 - [sum of (fbs**2) / (sum of fbs)**2] | |
1969 // where fbs is free block sizes | |
1970 double CompactibleFreeListSpace::flsFrag() const { | |
1971 size_t itabFree = totalSizeInIndexedFreeLists(); | |
1972 double frag = 0.0; | |
1973 size_t i; | |
1974 | |
1975 for (i = IndexSetStart; i < IndexSetSize; i += IndexSetStride) { | |
1976 double sz = i; | |
1977 frag += _indexedFreeList[i].count() * (sz * sz); | |
1978 } | |
1979 | |
1980 double totFree = itabFree + | |
1981 _dictionary->totalChunkSize(DEBUG_ONLY(freelistLock())); | |
1982 if (totFree > 0) { | |
1983 frag = ((frag + _dictionary->sum_of_squared_block_sizes()) / | |
1984 (totFree * totFree)); | |
1985 frag = (double)1.0 - frag; | |
1986 } else { | |
1987 assert(frag == 0.0, "Follows from totFree == 0"); | |
1988 } | |
1989 return frag; | |
1990 } | |
1991 | |
1992 #define CoalSurplusPercent 1.05 | |
1993 #define SplitSurplusPercent 1.10 | |
1994 | |
1995 void CompactibleFreeListSpace::beginSweepFLCensus( | |
1996 float inter_sweep_current, | |
1997 float inter_sweep_estimate) { | |
1998 assert_locked(); | |
1999 size_t i; | |
2000 for (i = IndexSetStart; i < IndexSetSize; i += IndexSetStride) { | |
2001 FreeList* fl = &_indexedFreeList[i]; | |
2002 fl->compute_desired(inter_sweep_current, inter_sweep_estimate); | |
2003 fl->set_coalDesired((ssize_t)((double)fl->desired() * CoalSurplusPercent)); | |
2004 fl->set_beforeSweep(fl->count()); | |
2005 fl->set_bfrSurp(fl->surplus()); | |
2006 } | |
2007 _dictionary->beginSweepDictCensus(CoalSurplusPercent, | |
2008 inter_sweep_current, | |
2009 inter_sweep_estimate); | |
2010 } | |
2011 | |
2012 void CompactibleFreeListSpace::setFLSurplus() { | |
2013 assert_locked(); | |
2014 size_t i; | |
2015 for (i = IndexSetStart; i < IndexSetSize; i += IndexSetStride) { | |
2016 FreeList *fl = &_indexedFreeList[i]; | |
2017 fl->set_surplus(fl->count() - | |
2018 (ssize_t)((double)fl->desired() * SplitSurplusPercent)); | |
2019 } | |
2020 } | |
2021 | |
2022 void CompactibleFreeListSpace::setFLHints() { | |
2023 assert_locked(); | |
2024 size_t i; | |
2025 size_t h = IndexSetSize; | |
2026 for (i = IndexSetSize - 1; i != 0; i -= IndexSetStride) { | |
2027 FreeList *fl = &_indexedFreeList[i]; | |
2028 fl->set_hint(h); | |
2029 if (fl->surplus() > 0) { | |
2030 h = i; | |
2031 } | |
2032 } | |
2033 } | |
2034 | |
2035 void CompactibleFreeListSpace::clearFLCensus() { | |
2036 assert_locked(); | |
2037 int i; | |
2038 for (i = IndexSetStart; i < IndexSetSize; i += IndexSetStride) { | |
2039 FreeList *fl = &_indexedFreeList[i]; | |
2040 fl->set_prevSweep(fl->count()); | |
2041 fl->set_coalBirths(0); | |
2042 fl->set_coalDeaths(0); | |
2043 fl->set_splitBirths(0); | |
2044 fl->set_splitDeaths(0); | |
2045 } | |
2046 } | |
2047 | |
12
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2048 void CompactibleFreeListSpace::endSweepFLCensus(size_t sweep_count) { |
0 | 2049 setFLSurplus(); |
2050 setFLHints(); | |
2051 if (PrintGC && PrintFLSCensus > 0) { | |
12
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2052 printFLCensus(sweep_count); |
0 | 2053 } |
2054 clearFLCensus(); | |
2055 assert_locked(); | |
2056 _dictionary->endSweepDictCensus(SplitSurplusPercent); | |
2057 } | |
2058 | |
2059 bool CompactibleFreeListSpace::coalOverPopulated(size_t size) { | |
2060 if (size < SmallForDictionary) { | |
2061 FreeList *fl = &_indexedFreeList[size]; | |
2062 return (fl->coalDesired() < 0) || | |
2063 ((int)fl->count() > fl->coalDesired()); | |
2064 } else { | |
2065 return dictionary()->coalDictOverPopulated(size); | |
2066 } | |
2067 } | |
2068 | |
2069 void CompactibleFreeListSpace::smallCoalBirth(size_t size) { | |
2070 assert(size < SmallForDictionary, "Size too large for indexed list"); | |
2071 FreeList *fl = &_indexedFreeList[size]; | |
2072 fl->increment_coalBirths(); | |
2073 fl->increment_surplus(); | |
2074 } | |
2075 | |
2076 void CompactibleFreeListSpace::smallCoalDeath(size_t size) { | |
2077 assert(size < SmallForDictionary, "Size too large for indexed list"); | |
2078 FreeList *fl = &_indexedFreeList[size]; | |
2079 fl->increment_coalDeaths(); | |
2080 fl->decrement_surplus(); | |
2081 } | |
2082 | |
2083 void CompactibleFreeListSpace::coalBirth(size_t size) { | |
2084 if (size < SmallForDictionary) { | |
2085 smallCoalBirth(size); | |
2086 } else { | |
2087 dictionary()->dictCensusUpdate(size, | |
2088 false /* split */, | |
2089 true /* birth */); | |
2090 } | |
2091 } | |
2092 | |
2093 void CompactibleFreeListSpace::coalDeath(size_t size) { | |
2094 if(size < SmallForDictionary) { | |
2095 smallCoalDeath(size); | |
2096 } else { | |
2097 dictionary()->dictCensusUpdate(size, | |
2098 false /* split */, | |
2099 false /* birth */); | |
2100 } | |
2101 } | |
2102 | |
2103 void CompactibleFreeListSpace::smallSplitBirth(size_t size) { | |
2104 assert(size < SmallForDictionary, "Size too large for indexed list"); | |
2105 FreeList *fl = &_indexedFreeList[size]; | |
2106 fl->increment_splitBirths(); | |
2107 fl->increment_surplus(); | |
2108 } | |
2109 | |
2110 void CompactibleFreeListSpace::smallSplitDeath(size_t size) { | |
2111 assert(size < SmallForDictionary, "Size too large for indexed list"); | |
2112 FreeList *fl = &_indexedFreeList[size]; | |
2113 fl->increment_splitDeaths(); | |
2114 fl->decrement_surplus(); | |
2115 } | |
2116 | |
2117 void CompactibleFreeListSpace::splitBirth(size_t size) { | |
2118 if (size < SmallForDictionary) { | |
2119 smallSplitBirth(size); | |
2120 } else { | |
2121 dictionary()->dictCensusUpdate(size, | |
2122 true /* split */, | |
2123 true /* birth */); | |
2124 } | |
2125 } | |
2126 | |
2127 void CompactibleFreeListSpace::splitDeath(size_t size) { | |
2128 if (size < SmallForDictionary) { | |
2129 smallSplitDeath(size); | |
2130 } else { | |
2131 dictionary()->dictCensusUpdate(size, | |
2132 true /* split */, | |
2133 false /* birth */); | |
2134 } | |
2135 } | |
2136 | |
2137 void CompactibleFreeListSpace::split(size_t from, size_t to1) { | |
2138 size_t to2 = from - to1; | |
2139 splitDeath(from); | |
2140 splitBirth(to1); | |
2141 splitBirth(to2); | |
2142 } | |
2143 | |
2144 void CompactibleFreeListSpace::print() const { | |
2145 tty->print(" CompactibleFreeListSpace"); | |
2146 Space::print(); | |
2147 } | |
2148 | |
2149 void CompactibleFreeListSpace::prepare_for_verify() { | |
2150 assert_locked(); | |
2151 repairLinearAllocationBlocks(); | |
2152 // Verify that the SpoolBlocks look like free blocks of | |
2153 // appropriate sizes... To be done ... | |
2154 } | |
2155 | |
2156 class VerifyAllBlksClosure: public BlkClosure { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2157 private: |
0 | 2158 const CompactibleFreeListSpace* _sp; |
2159 const MemRegion _span; | |
2160 | |
2161 public: | |
2162 VerifyAllBlksClosure(const CompactibleFreeListSpace* sp, | |
2163 MemRegion span) : _sp(sp), _span(span) { } | |
2164 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2165 virtual size_t do_blk(HeapWord* addr) { |
0 | 2166 size_t res; |
2167 if (_sp->block_is_obj(addr)) { | |
2168 oop p = oop(addr); | |
2169 guarantee(p->is_oop(), "Should be an oop"); | |
2170 res = _sp->adjustObjectSize(p->size()); | |
2171 if (_sp->obj_is_alive(addr)) { | |
2172 p->verify(); | |
2173 } | |
2174 } else { | |
2175 FreeChunk* fc = (FreeChunk*)addr; | |
2176 res = fc->size(); | |
2177 if (FLSVerifyLists && !fc->cantCoalesce()) { | |
2178 guarantee(_sp->verifyChunkInFreeLists(fc), | |
2179 "Chunk should be on a free list"); | |
2180 } | |
2181 } | |
2182 guarantee(res != 0, "Livelock: no rank reduction!"); | |
2183 return res; | |
2184 } | |
2185 }; | |
2186 | |
2187 class VerifyAllOopsClosure: public OopClosure { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2188 private: |
0 | 2189 const CMSCollector* _collector; |
2190 const CompactibleFreeListSpace* _sp; | |
2191 const MemRegion _span; | |
2192 const bool _past_remark; | |
2193 const CMSBitMap* _bit_map; | |
2194 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2195 protected: |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2196 void do_oop(void* p, oop obj) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2197 if (_span.contains(obj)) { // the interior oop points into CMS heap |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2198 if (!_span.contains(p)) { // reference from outside CMS heap |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2199 // Should be a valid object; the first disjunct below allows |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2200 // us to sidestep an assertion in block_is_obj() that insists |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2201 // that p be in _sp. Note that several generations (and spaces) |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2202 // are spanned by _span (CMS heap) above. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2203 guarantee(!_sp->is_in_reserved(obj) || |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2204 _sp->block_is_obj((HeapWord*)obj), |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2205 "Should be an object"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2206 guarantee(obj->is_oop(), "Should be an oop"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2207 obj->verify(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2208 if (_past_remark) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2209 // Remark has been completed, the object should be marked |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2210 _bit_map->isMarked((HeapWord*)obj); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2211 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2212 } else { // reference within CMS heap |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2213 if (_past_remark) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2214 // Remark has been completed -- so the referent should have |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2215 // been marked, if referring object is. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2216 if (_bit_map->isMarked(_collector->block_start(p))) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2217 guarantee(_bit_map->isMarked((HeapWord*)obj), "Marking error?"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2218 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2219 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2220 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2221 } else if (_sp->is_in_reserved(p)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2222 // the reference is from FLS, and points out of FLS |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2223 guarantee(obj->is_oop(), "Should be an oop"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2224 obj->verify(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2225 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2226 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2227 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2228 template <class T> void do_oop_work(T* p) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2229 T heap_oop = oopDesc::load_heap_oop(p); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2230 if (!oopDesc::is_null(heap_oop)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2231 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2232 do_oop(p, obj); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2233 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2234 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2235 |
0 | 2236 public: |
2237 VerifyAllOopsClosure(const CMSCollector* collector, | |
2238 const CompactibleFreeListSpace* sp, MemRegion span, | |
2239 bool past_remark, CMSBitMap* bit_map) : | |
2240 OopClosure(), _collector(collector), _sp(sp), _span(span), | |
2241 _past_remark(past_remark), _bit_map(bit_map) { } | |
2242 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2243 virtual void do_oop(oop* p) { VerifyAllOopsClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
12
diff
changeset
|
2244 virtual void do_oop(narrowOop* p) { VerifyAllOopsClosure::do_oop_work(p); } |
0 | 2245 }; |
2246 | |
2247 void CompactibleFreeListSpace::verify(bool ignored) const { | |
2248 assert_lock_strong(&_freelistLock); | |
2249 verify_objects_initialized(); | |
2250 MemRegion span = _collector->_span; | |
2251 bool past_remark = (_collector->abstract_state() == | |
2252 CMSCollector::Sweeping); | |
2253 | |
2254 ResourceMark rm; | |
2255 HandleMark hm; | |
2256 | |
2257 // Check integrity of CFL data structures | |
2258 _promoInfo.verify(); | |
2259 _dictionary->verify(); | |
2260 if (FLSVerifyIndexTable) { | |
2261 verifyIndexedFreeLists(); | |
2262 } | |
2263 // Check integrity of all objects and free blocks in space | |
2264 { | |
2265 VerifyAllBlksClosure cl(this, span); | |
2266 ((CompactibleFreeListSpace*)this)->blk_iterate(&cl); // cast off const | |
2267 } | |
2268 // Check that all references in the heap to FLS | |
2269 // are to valid objects in FLS or that references in | |
2270 // FLS are to valid objects elsewhere in the heap | |
2271 if (FLSVerifyAllHeapReferences) | |
2272 { | |
2273 VerifyAllOopsClosure cl(_collector, this, span, past_remark, | |
2274 _collector->markBitMap()); | |
2275 CollectedHeap* ch = Universe::heap(); | |
2276 ch->oop_iterate(&cl); // all oops in generations | |
2277 ch->permanent_oop_iterate(&cl); // all oops in perm gen | |
2278 } | |
2279 | |
2280 if (VerifyObjectStartArray) { | |
2281 // Verify the block offset table | |
2282 _bt.verify(); | |
2283 } | |
2284 } | |
2285 | |
2286 #ifndef PRODUCT | |
2287 void CompactibleFreeListSpace::verifyFreeLists() const { | |
2288 if (FLSVerifyLists) { | |
2289 _dictionary->verify(); | |
2290 verifyIndexedFreeLists(); | |
2291 } else { | |
2292 if (FLSVerifyDictionary) { | |
2293 _dictionary->verify(); | |
2294 } | |
2295 if (FLSVerifyIndexTable) { | |
2296 verifyIndexedFreeLists(); | |
2297 } | |
2298 } | |
2299 } | |
2300 #endif | |
2301 | |
2302 void CompactibleFreeListSpace::verifyIndexedFreeLists() const { | |
2303 size_t i = 0; | |
2304 for (; i < MinChunkSize; i++) { | |
2305 guarantee(_indexedFreeList[i].head() == NULL, "should be NULL"); | |
2306 } | |
2307 for (; i < IndexSetSize; i++) { | |
2308 verifyIndexedFreeList(i); | |
2309 } | |
2310 } | |
2311 | |
2312 void CompactibleFreeListSpace::verifyIndexedFreeList(size_t size) const { | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
2313 FreeChunk* fc = _indexedFreeList[size].head(); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
2314 guarantee((size % 2 == 0) || fc == NULL, "Odd slots should be empty"); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
2315 for (; fc != NULL; fc = fc->next()) { |
0 | 2316 guarantee(fc->size() == size, "Size inconsistency"); |
2317 guarantee(fc->isFree(), "!free?"); | |
2318 guarantee(fc->next() == NULL || fc->next()->prev() == fc, "Broken list"); | |
2319 } | |
2320 } | |
2321 | |
2322 #ifndef PRODUCT | |
2323 void CompactibleFreeListSpace::checkFreeListConsistency() const { | |
2324 assert(_dictionary->minSize() <= IndexSetSize, | |
2325 "Some sizes can't be allocated without recourse to" | |
2326 " linear allocation buffers"); | |
2327 assert(MIN_TREE_CHUNK_SIZE*HeapWordSize == sizeof(TreeChunk), | |
2328 "else MIN_TREE_CHUNK_SIZE is wrong"); | |
2329 assert((IndexSetStride == 2 && IndexSetStart == 2) || | |
2330 (IndexSetStride == 1 && IndexSetStart == 1), "just checking"); | |
2331 assert((IndexSetStride != 2) || (MinChunkSize % 2 == 0), | |
2332 "Some for-loops may be incorrectly initialized"); | |
2333 assert((IndexSetStride != 2) || (IndexSetSize % 2 == 1), | |
2334 "For-loops that iterate over IndexSet with stride 2 may be wrong"); | |
2335 } | |
2336 #endif | |
2337 | |
12
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2338 void CompactibleFreeListSpace::printFLCensus(size_t sweep_count) const { |
0 | 2339 assert_lock_strong(&_freelistLock); |
12
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2340 FreeList total; |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2341 gclog_or_tty->print("end sweep# " SIZE_FORMAT "\n", sweep_count); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2342 FreeList::print_labels_on(gclog_or_tty, "size"); |
0 | 2343 size_t totalFree = 0; |
2344 for (size_t i = IndexSetStart; i < IndexSetSize; i += IndexSetStride) { | |
2345 const FreeList *fl = &_indexedFreeList[i]; | |
12
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2346 totalFree += fl->count() * fl->size(); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2347 if (i % (40*IndexSetStride) == 0) { |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2348 FreeList::print_labels_on(gclog_or_tty, "size"); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2349 } |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2350 fl->print_on(gclog_or_tty); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2351 total.set_bfrSurp( total.bfrSurp() + fl->bfrSurp() ); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2352 total.set_surplus( total.surplus() + fl->surplus() ); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2353 total.set_desired( total.desired() + fl->desired() ); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2354 total.set_prevSweep( total.prevSweep() + fl->prevSweep() ); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2355 total.set_beforeSweep(total.beforeSweep() + fl->beforeSweep()); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2356 total.set_count( total.count() + fl->count() ); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2357 total.set_coalBirths( total.coalBirths() + fl->coalBirths() ); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2358 total.set_coalDeaths( total.coalDeaths() + fl->coalDeaths() ); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2359 total.set_splitBirths(total.splitBirths() + fl->splitBirths()); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2360 total.set_splitDeaths(total.splitDeaths() + fl->splitDeaths()); |
0 | 2361 } |
12
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2362 total.print_on(gclog_or_tty, "TOTAL"); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2363 gclog_or_tty->print_cr("Total free in indexed lists " |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2364 SIZE_FORMAT " words", totalFree); |
0 | 2365 gclog_or_tty->print("growth: %8.5f deficit: %8.5f\n", |
12
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2366 (double)(total.splitBirths()+total.coalBirths()-total.splitDeaths()-total.coalDeaths())/ |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2367 (total.prevSweep() != 0 ? (double)total.prevSweep() : 1.0), |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
2368 (double)(total.desired() - total.count())/(total.desired() != 0 ? (double)total.desired() : 1.0)); |
0 | 2369 _dictionary->printDictCensus(); |
2370 } | |
2371 | |
2372 // Return the next displaced header, incrementing the pointer and | |
2373 // recycling spool area as necessary. | |
2374 markOop PromotionInfo::nextDisplacedHeader() { | |
2375 assert(_spoolHead != NULL, "promotionInfo inconsistency"); | |
2376 assert(_spoolHead != _spoolTail || _firstIndex < _nextIndex, | |
2377 "Empty spool space: no displaced header can be fetched"); | |
2378 assert(_spoolHead->bufferSize > _firstIndex, "Off by one error at head?"); | |
2379 markOop hdr = _spoolHead->displacedHdr[_firstIndex]; | |
2380 // Spool forward | |
2381 if (++_firstIndex == _spoolHead->bufferSize) { // last location in this block | |
2382 // forward to next block, recycling this block into spare spool buffer | |
2383 SpoolBlock* tmp = _spoolHead->nextSpoolBlock; | |
2384 assert(_spoolHead != _spoolTail, "Spooling storage mix-up"); | |
2385 _spoolHead->nextSpoolBlock = _spareSpool; | |
2386 _spareSpool = _spoolHead; | |
2387 _spoolHead = tmp; | |
2388 _firstIndex = 1; | |
2389 NOT_PRODUCT( | |
2390 if (_spoolHead == NULL) { // all buffers fully consumed | |
2391 assert(_spoolTail == NULL && _nextIndex == 1, | |
2392 "spool buffers processing inconsistency"); | |
2393 } | |
2394 ) | |
2395 } | |
2396 return hdr; | |
2397 } | |
2398 | |
2399 void PromotionInfo::track(PromotedObject* trackOop) { | |
2400 track(trackOop, oop(trackOop)->klass()); | |
2401 } | |
2402 | |
2403 void PromotionInfo::track(PromotedObject* trackOop, klassOop klassOfOop) { | |
2404 // make a copy of header as it may need to be spooled | |
2405 markOop mark = oop(trackOop)->mark(); | |
2406 trackOop->clearNext(); | |
2407 if (mark->must_be_preserved_for_cms_scavenge(klassOfOop)) { | |
2408 // save non-prototypical header, and mark oop | |
2409 saveDisplacedHeader(mark); | |
2410 trackOop->setDisplacedMark(); | |
2411 } else { | |
2412 // we'd like to assert something like the following: | |
2413 // assert(mark == markOopDesc::prototype(), "consistency check"); | |
2414 // ... but the above won't work because the age bits have not (yet) been | |
2415 // cleared. The remainder of the check would be identical to the | |
2416 // condition checked in must_be_preserved() above, so we don't really | |
2417 // have anything useful to check here! | |
2418 } | |
2419 if (_promoTail != NULL) { | |
2420 assert(_promoHead != NULL, "List consistency"); | |
2421 _promoTail->setNext(trackOop); | |
2422 _promoTail = trackOop; | |
2423 } else { | |
2424 assert(_promoHead == NULL, "List consistency"); | |
2425 _promoHead = _promoTail = trackOop; | |
2426 } | |
2427 // Mask as newly promoted, so we can skip over such objects | |
2428 // when scanning dirty cards | |
2429 assert(!trackOop->hasPromotedMark(), "Should not have been marked"); | |
2430 trackOop->setPromotedMark(); | |
2431 } | |
2432 | |
2433 // Save the given displaced header, incrementing the pointer and | |
2434 // obtaining more spool area as necessary. | |
2435 void PromotionInfo::saveDisplacedHeader(markOop hdr) { | |
2436 assert(_spoolHead != NULL && _spoolTail != NULL, | |
2437 "promotionInfo inconsistency"); | |
2438 assert(_spoolTail->bufferSize > _nextIndex, "Off by one error at tail?"); | |
2439 _spoolTail->displacedHdr[_nextIndex] = hdr; | |
2440 // Spool forward | |
2441 if (++_nextIndex == _spoolTail->bufferSize) { // last location in this block | |
2442 // get a new spooling block | |
2443 assert(_spoolTail->nextSpoolBlock == NULL, "tail should terminate spool list"); | |
2444 _splice_point = _spoolTail; // save for splicing | |
2445 _spoolTail->nextSpoolBlock = getSpoolBlock(); // might fail | |
2446 _spoolTail = _spoolTail->nextSpoolBlock; // might become NULL ... | |
2447 // ... but will attempt filling before next promotion attempt | |
2448 _nextIndex = 1; | |
2449 } | |
2450 } | |
2451 | |
2452 // Ensure that spooling space exists. Return false if spooling space | |
2453 // could not be obtained. | |
2454 bool PromotionInfo::ensure_spooling_space_work() { | |
2455 assert(!has_spooling_space(), "Only call when there is no spooling space"); | |
2456 // Try and obtain more spooling space | |
2457 SpoolBlock* newSpool = getSpoolBlock(); | |
2458 assert(newSpool == NULL || | |
2459 (newSpool->bufferSize != 0 && newSpool->nextSpoolBlock == NULL), | |
2460 "getSpoolBlock() sanity check"); | |
2461 if (newSpool == NULL) { | |
2462 return false; | |
2463 } | |
2464 _nextIndex = 1; | |
2465 if (_spoolTail == NULL) { | |
2466 _spoolTail = newSpool; | |
2467 if (_spoolHead == NULL) { | |
2468 _spoolHead = newSpool; | |
2469 _firstIndex = 1; | |
2470 } else { | |
2471 assert(_splice_point != NULL && _splice_point->nextSpoolBlock == NULL, | |
2472 "Splice point invariant"); | |
2473 // Extra check that _splice_point is connected to list | |
2474 #ifdef ASSERT | |
2475 { | |
2476 SpoolBlock* blk = _spoolHead; | |
2477 for (; blk->nextSpoolBlock != NULL; | |
2478 blk = blk->nextSpoolBlock); | |
2479 assert(blk != NULL && blk == _splice_point, | |
2480 "Splice point incorrect"); | |
2481 } | |
2482 #endif // ASSERT | |
2483 _splice_point->nextSpoolBlock = newSpool; | |
2484 } | |
2485 } else { | |
2486 assert(_spoolHead != NULL, "spool list consistency"); | |
2487 _spoolTail->nextSpoolBlock = newSpool; | |
2488 _spoolTail = newSpool; | |
2489 } | |
2490 return true; | |
2491 } | |
2492 | |
2493 // Get a free spool buffer from the free pool, getting a new block | |
2494 // from the heap if necessary. | |
2495 SpoolBlock* PromotionInfo::getSpoolBlock() { | |
2496 SpoolBlock* res; | |
2497 if ((res = _spareSpool) != NULL) { | |
2498 _spareSpool = _spareSpool->nextSpoolBlock; | |
2499 res->nextSpoolBlock = NULL; | |
2500 } else { // spare spool exhausted, get some from heap | |
2501 res = (SpoolBlock*)(space()->allocateScratch(refillSize())); | |
2502 if (res != NULL) { | |
2503 res->init(); | |
2504 } | |
2505 } | |
2506 assert(res == NULL || res->nextSpoolBlock == NULL, "postcondition"); | |
2507 return res; | |
2508 } | |
2509 | |
2510 void PromotionInfo::startTrackingPromotions() { | |
2511 assert(_spoolHead == _spoolTail && _firstIndex == _nextIndex, | |
2512 "spooling inconsistency?"); | |
2513 _firstIndex = _nextIndex = 1; | |
2514 _tracking = true; | |
2515 } | |
2516 | |
2517 void PromotionInfo::stopTrackingPromotions() { | |
2518 assert(_spoolHead == _spoolTail && _firstIndex == _nextIndex, | |
2519 "spooling inconsistency?"); | |
2520 _firstIndex = _nextIndex = 1; | |
2521 _tracking = false; | |
2522 } | |
2523 | |
2524 // When _spoolTail is not NULL, then the slot <_spoolTail, _nextIndex> | |
2525 // points to the next slot available for filling. | |
2526 // The set of slots holding displaced headers are then all those in the | |
2527 // right-open interval denoted by: | |
2528 // | |
2529 // [ <_spoolHead, _firstIndex>, <_spoolTail, _nextIndex> ) | |
2530 // | |
2531 // When _spoolTail is NULL, then the set of slots with displaced headers | |
2532 // is all those starting at the slot <_spoolHead, _firstIndex> and | |
2533 // going up to the last slot of last block in the linked list. | |
2534 // In this lartter case, _splice_point points to the tail block of | |
2535 // this linked list of blocks holding displaced headers. | |
2536 void PromotionInfo::verify() const { | |
2537 // Verify the following: | |
2538 // 1. the number of displaced headers matches the number of promoted | |
2539 // objects that have displaced headers | |
2540 // 2. each promoted object lies in this space | |
2541 debug_only( | |
2542 PromotedObject* junk = NULL; | |
2543 assert(junk->next_addr() == (void*)(oop(junk)->mark_addr()), | |
2544 "Offset of PromotedObject::_next is expected to align with " | |
2545 " the OopDesc::_mark within OopDesc"); | |
2546 ) | |
2547 // FIXME: guarantee???? | |
2548 guarantee(_spoolHead == NULL || _spoolTail != NULL || | |
2549 _splice_point != NULL, "list consistency"); | |
2550 guarantee(_promoHead == NULL || _promoTail != NULL, "list consistency"); | |
2551 // count the number of objects with displaced headers | |
2552 size_t numObjsWithDisplacedHdrs = 0; | |
2553 for (PromotedObject* curObj = _promoHead; curObj != NULL; curObj = curObj->next()) { | |
2554 guarantee(space()->is_in_reserved((HeapWord*)curObj), "Containment"); | |
2555 // the last promoted object may fail the mark() != NULL test of is_oop(). | |
2556 guarantee(curObj->next() == NULL || oop(curObj)->is_oop(), "must be an oop"); | |
2557 if (curObj->hasDisplacedMark()) { | |
2558 numObjsWithDisplacedHdrs++; | |
2559 } | |
2560 } | |
2561 // Count the number of displaced headers | |
2562 size_t numDisplacedHdrs = 0; | |
2563 for (SpoolBlock* curSpool = _spoolHead; | |
2564 curSpool != _spoolTail && curSpool != NULL; | |
2565 curSpool = curSpool->nextSpoolBlock) { | |
2566 // the first entry is just a self-pointer; indices 1 through | |
2567 // bufferSize - 1 are occupied (thus, bufferSize - 1 slots). | |
2568 guarantee((void*)curSpool->displacedHdr == (void*)&curSpool->displacedHdr, | |
2569 "first entry of displacedHdr should be self-referential"); | |
2570 numDisplacedHdrs += curSpool->bufferSize - 1; | |
2571 } | |
2572 guarantee((_spoolHead == _spoolTail) == (numDisplacedHdrs == 0), | |
2573 "internal consistency"); | |
2574 guarantee(_spoolTail != NULL || _nextIndex == 1, | |
2575 "Inconsistency between _spoolTail and _nextIndex"); | |
2576 // We overcounted (_firstIndex-1) worth of slots in block | |
2577 // _spoolHead and we undercounted (_nextIndex-1) worth of | |
2578 // slots in block _spoolTail. We make an appropriate | |
2579 // adjustment by subtracting the first and adding the | |
2580 // second: - (_firstIndex - 1) + (_nextIndex - 1) | |
2581 numDisplacedHdrs += (_nextIndex - _firstIndex); | |
2582 guarantee(numDisplacedHdrs == numObjsWithDisplacedHdrs, "Displaced hdr count"); | |
2583 } | |
2584 | |
2585 | |
2586 CFLS_LAB::CFLS_LAB(CompactibleFreeListSpace* cfls) : | |
2587 _cfls(cfls) | |
2588 { | |
2589 _blocks_to_claim = CMSParPromoteBlocksToClaim; | |
2590 for (size_t i = CompactibleFreeListSpace::IndexSetStart; | |
2591 i < CompactibleFreeListSpace::IndexSetSize; | |
2592 i += CompactibleFreeListSpace::IndexSetStride) { | |
2593 _indexedFreeList[i].set_size(i); | |
2594 } | |
2595 } | |
2596 | |
2597 HeapWord* CFLS_LAB::alloc(size_t word_sz) { | |
2598 FreeChunk* res; | |
2599 word_sz = _cfls->adjustObjectSize(word_sz); | |
2600 if (word_sz >= CompactibleFreeListSpace::IndexSetSize) { | |
2601 // This locking manages sync with other large object allocations. | |
2602 MutexLockerEx x(_cfls->parDictionaryAllocLock(), | |
2603 Mutex::_no_safepoint_check_flag); | |
2604 res = _cfls->getChunkFromDictionaryExact(word_sz); | |
2605 if (res == NULL) return NULL; | |
2606 } else { | |
2607 FreeList* fl = &_indexedFreeList[word_sz]; | |
2608 bool filled = false; //TRAP | |
2609 if (fl->count() == 0) { | |
2610 bool filled = true; //TRAP | |
2611 // Attempt to refill this local free list. | |
2612 _cfls->par_get_chunk_of_blocks(word_sz, _blocks_to_claim, fl); | |
2613 // If it didn't work, give up. | |
2614 if (fl->count() == 0) return NULL; | |
2615 } | |
2616 res = fl->getChunkAtHead(); | |
2617 assert(res != NULL, "Why was count non-zero?"); | |
2618 } | |
2619 res->markNotFree(); | |
2620 assert(!res->isFree(), "shouldn't be marked free"); | |
187 | 2621 assert(oop(res)->klass_or_null() == NULL, "should look uninitialized"); |
0 | 2622 // mangle a just allocated object with a distinct pattern. |
2623 debug_only(res->mangleAllocated(word_sz)); | |
2624 return (HeapWord*)res; | |
2625 } | |
2626 | |
2627 void CFLS_LAB::retire() { | |
2628 for (size_t i = CompactibleFreeListSpace::IndexSetStart; | |
2629 i < CompactibleFreeListSpace::IndexSetSize; | |
2630 i += CompactibleFreeListSpace::IndexSetStride) { | |
2631 if (_indexedFreeList[i].count() > 0) { | |
2632 MutexLockerEx x(_cfls->_indexedFreeListParLocks[i], | |
2633 Mutex::_no_safepoint_check_flag); | |
2634 _cfls->_indexedFreeList[i].prepend(&_indexedFreeList[i]); | |
2635 // Reset this list. | |
2636 _indexedFreeList[i] = FreeList(); | |
2637 _indexedFreeList[i].set_size(i); | |
2638 } | |
2639 } | |
2640 } | |
2641 | |
2642 void | |
2643 CompactibleFreeListSpace:: | |
2644 par_get_chunk_of_blocks(size_t word_sz, size_t n, FreeList* fl) { | |
2645 assert(fl->count() == 0, "Precondition."); | |
2646 assert(word_sz < CompactibleFreeListSpace::IndexSetSize, | |
2647 "Precondition"); | |
2648 | |
2649 // We'll try all multiples of word_sz in the indexed set (starting with | |
2650 // word_sz itself), then try getting a big chunk and splitting it. | |
2651 int k = 1; | |
2652 size_t cur_sz = k * word_sz; | |
2653 bool found = false; | |
2654 while (cur_sz < CompactibleFreeListSpace::IndexSetSize && k == 1) { | |
2655 FreeList* gfl = &_indexedFreeList[cur_sz]; | |
2656 FreeList fl_for_cur_sz; // Empty. | |
2657 fl_for_cur_sz.set_size(cur_sz); | |
2658 { | |
2659 MutexLockerEx x(_indexedFreeListParLocks[cur_sz], | |
2660 Mutex::_no_safepoint_check_flag); | |
2661 if (gfl->count() != 0) { | |
2662 size_t nn = MAX2(n/k, (size_t)1); | |
2663 gfl->getFirstNChunksFromList(nn, &fl_for_cur_sz); | |
2664 found = true; | |
2665 } | |
2666 } | |
2667 // Now transfer fl_for_cur_sz to fl. Common case, we hope, is k = 1. | |
2668 if (found) { | |
2669 if (k == 1) { | |
2670 fl->prepend(&fl_for_cur_sz); | |
2671 } else { | |
2672 // Divide each block on fl_for_cur_sz up k ways. | |
2673 FreeChunk* fc; | |
2674 while ((fc = fl_for_cur_sz.getChunkAtHead()) != NULL) { | |
2675 // Must do this in reverse order, so that anybody attempting to | |
2676 // access the main chunk sees it as a single free block until we | |
2677 // change it. | |
2678 size_t fc_size = fc->size(); | |
2679 for (int i = k-1; i >= 0; i--) { | |
2680 FreeChunk* ffc = (FreeChunk*)((HeapWord*)fc + i * word_sz); | |
2681 ffc->setSize(word_sz); | |
2682 ffc->linkNext(NULL); | |
2683 ffc->linkPrev(NULL); // Mark as a free block for other (parallel) GC threads. | |
2684 // Above must occur before BOT is updated below. | |
2685 // splitting from the right, fc_size == (k - i + 1) * wordsize | |
2686 _bt.mark_block((HeapWord*)ffc, word_sz); | |
2687 fc_size -= word_sz; | |
2688 _bt.verify_not_unallocated((HeapWord*)ffc, ffc->size()); | |
2689 _bt.verify_single_block((HeapWord*)fc, fc_size); | |
2690 _bt.verify_single_block((HeapWord*)ffc, ffc->size()); | |
2691 // Push this on "fl". | |
2692 fl->returnChunkAtHead(ffc); | |
2693 } | |
2694 // TRAP | |
2695 assert(fl->tail()->next() == NULL, "List invariant."); | |
2696 } | |
2697 } | |
2698 return; | |
2699 } | |
2700 k++; cur_sz = k * word_sz; | |
2701 } | |
2702 // Otherwise, we'll split a block from the dictionary. | |
2703 FreeChunk* fc = NULL; | |
2704 FreeChunk* rem_fc = NULL; | |
2705 size_t rem; | |
2706 { | |
2707 MutexLockerEx x(parDictionaryAllocLock(), | |
2708 Mutex::_no_safepoint_check_flag); | |
2709 while (n > 0) { | |
2710 fc = dictionary()->getChunk(MAX2(n * word_sz, | |
2711 _dictionary->minSize()), | |
2712 FreeBlockDictionary::atLeast); | |
2713 if (fc != NULL) { | |
2714 _bt.allocated((HeapWord*)fc, fc->size()); // update _unallocated_blk | |
2715 dictionary()->dictCensusUpdate(fc->size(), | |
2716 true /*split*/, | |
2717 false /*birth*/); | |
2718 break; | |
2719 } else { | |
2720 n--; | |
2721 } | |
2722 } | |
2723 if (fc == NULL) return; | |
2724 // Otherwise, split up that block. | |
2725 size_t nn = fc->size() / word_sz; | |
2726 n = MIN2(nn, n); | |
2727 rem = fc->size() - n * word_sz; | |
2728 // If there is a remainder, and it's too small, allocate one fewer. | |
2729 if (rem > 0 && rem < MinChunkSize) { | |
2730 n--; rem += word_sz; | |
2731 } | |
2732 // First return the remainder, if any. | |
2733 // Note that we hold the lock until we decide if we're going to give | |
2734 // back the remainder to the dictionary, since a contending allocator | |
2735 // may otherwise see the heap as empty. (We're willing to take that | |
2736 // hit if the block is a small block.) | |
2737 if (rem > 0) { | |
2738 size_t prefix_size = n * word_sz; | |
2739 rem_fc = (FreeChunk*)((HeapWord*)fc + prefix_size); | |
2740 rem_fc->setSize(rem); | |
2741 rem_fc->linkNext(NULL); | |
2742 rem_fc->linkPrev(NULL); // Mark as a free block for other (parallel) GC threads. | |
2743 // Above must occur before BOT is updated below. | |
2744 _bt.split_block((HeapWord*)fc, fc->size(), prefix_size); | |
2745 if (rem >= IndexSetSize) { | |
2746 returnChunkToDictionary(rem_fc); | |
2747 dictionary()->dictCensusUpdate(fc->size(), | |
2748 true /*split*/, | |
2749 true /*birth*/); | |
2750 rem_fc = NULL; | |
2751 } | |
2752 // Otherwise, return it to the small list below. | |
2753 } | |
2754 } | |
2755 // | |
2756 if (rem_fc != NULL) { | |
2757 MutexLockerEx x(_indexedFreeListParLocks[rem], | |
2758 Mutex::_no_safepoint_check_flag); | |
2759 _bt.verify_not_unallocated((HeapWord*)rem_fc, rem_fc->size()); | |
2760 _indexedFreeList[rem].returnChunkAtHead(rem_fc); | |
2761 smallSplitBirth(rem); | |
2762 } | |
2763 | |
2764 // Now do the splitting up. | |
2765 // Must do this in reverse order, so that anybody attempting to | |
2766 // access the main chunk sees it as a single free block until we | |
2767 // change it. | |
2768 size_t fc_size = n * word_sz; | |
2769 // All but first chunk in this loop | |
2770 for (ssize_t i = n-1; i > 0; i--) { | |
2771 FreeChunk* ffc = (FreeChunk*)((HeapWord*)fc + i * word_sz); | |
2772 ffc->setSize(word_sz); | |
2773 ffc->linkNext(NULL); | |
2774 ffc->linkPrev(NULL); // Mark as a free block for other (parallel) GC threads. | |
2775 // Above must occur before BOT is updated below. | |
2776 // splitting from the right, fc_size == (n - i + 1) * wordsize | |
2777 _bt.mark_block((HeapWord*)ffc, word_sz); | |
2778 fc_size -= word_sz; | |
2779 _bt.verify_not_unallocated((HeapWord*)ffc, ffc->size()); | |
2780 _bt.verify_single_block((HeapWord*)ffc, ffc->size()); | |
2781 _bt.verify_single_block((HeapWord*)fc, fc_size); | |
2782 // Push this on "fl". | |
2783 fl->returnChunkAtHead(ffc); | |
2784 } | |
2785 // First chunk | |
2786 fc->setSize(word_sz); | |
2787 fc->linkNext(NULL); | |
2788 fc->linkPrev(NULL); | |
2789 _bt.verify_not_unallocated((HeapWord*)fc, fc->size()); | |
2790 _bt.verify_single_block((HeapWord*)fc, fc->size()); | |
2791 fl->returnChunkAtHead(fc); | |
2792 | |
2793 { | |
2794 MutexLockerEx x(_indexedFreeListParLocks[word_sz], | |
2795 Mutex::_no_safepoint_check_flag); | |
2796 ssize_t new_births = _indexedFreeList[word_sz].splitBirths() + n; | |
2797 _indexedFreeList[word_sz].set_splitBirths(new_births); | |
2798 ssize_t new_surplus = _indexedFreeList[word_sz].surplus() + n; | |
2799 _indexedFreeList[word_sz].set_surplus(new_surplus); | |
2800 } | |
2801 | |
2802 // TRAP | |
2803 assert(fl->tail()->next() == NULL, "List invariant."); | |
2804 } | |
2805 | |
2806 // Set up the space's par_seq_tasks structure for work claiming | |
2807 // for parallel rescan. See CMSParRemarkTask where this is currently used. | |
2808 // XXX Need to suitably abstract and generalize this and the next | |
2809 // method into one. | |
2810 void | |
2811 CompactibleFreeListSpace:: | |
2812 initialize_sequential_subtasks_for_rescan(int n_threads) { | |
2813 // The "size" of each task is fixed according to rescan_task_size. | |
2814 assert(n_threads > 0, "Unexpected n_threads argument"); | |
2815 const size_t task_size = rescan_task_size(); | |
2816 size_t n_tasks = (used_region().word_size() + task_size - 1)/task_size; | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
269
diff
changeset
|
2817 assert((n_tasks == 0) == used_region().is_empty(), "n_tasks incorrect"); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
269
diff
changeset
|
2818 assert(n_tasks == 0 || |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
269
diff
changeset
|
2819 ((used_region().start() + (n_tasks - 1)*task_size < used_region().end()) && |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
269
diff
changeset
|
2820 (used_region().start() + n_tasks*task_size >= used_region().end())), |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
269
diff
changeset
|
2821 "n_tasks calculation incorrect"); |
0 | 2822 SequentialSubTasksDone* pst = conc_par_seq_tasks(); |
2823 assert(!pst->valid(), "Clobbering existing data?"); | |
2824 pst->set_par_threads(n_threads); | |
2825 pst->set_n_tasks((int)n_tasks); | |
2826 } | |
2827 | |
2828 // Set up the space's par_seq_tasks structure for work claiming | |
2829 // for parallel concurrent marking. See CMSConcMarkTask where this is currently used. | |
2830 void | |
2831 CompactibleFreeListSpace:: | |
2832 initialize_sequential_subtasks_for_marking(int n_threads, | |
2833 HeapWord* low) { | |
2834 // The "size" of each task is fixed according to rescan_task_size. | |
2835 assert(n_threads > 0, "Unexpected n_threads argument"); | |
2836 const size_t task_size = marking_task_size(); | |
2837 assert(task_size > CardTableModRefBS::card_size_in_words && | |
2838 (task_size % CardTableModRefBS::card_size_in_words == 0), | |
2839 "Otherwise arithmetic below would be incorrect"); | |
2840 MemRegion span = _gen->reserved(); | |
2841 if (low != NULL) { | |
2842 if (span.contains(low)) { | |
2843 // Align low down to a card boundary so that | |
2844 // we can use block_offset_careful() on span boundaries. | |
2845 HeapWord* aligned_low = (HeapWord*)align_size_down((uintptr_t)low, | |
2846 CardTableModRefBS::card_size); | |
2847 // Clip span prefix at aligned_low | |
2848 span = span.intersection(MemRegion(aligned_low, span.end())); | |
2849 } else if (low > span.end()) { | |
2850 span = MemRegion(low, low); // Null region | |
2851 } // else use entire span | |
2852 } | |
2853 assert(span.is_empty() || | |
2854 ((uintptr_t)span.start() % CardTableModRefBS::card_size == 0), | |
2855 "span should start at a card boundary"); | |
2856 size_t n_tasks = (span.word_size() + task_size - 1)/task_size; | |
2857 assert((n_tasks == 0) == span.is_empty(), "Inconsistency"); | |
2858 assert(n_tasks == 0 || | |
2859 ((span.start() + (n_tasks - 1)*task_size < span.end()) && | |
2860 (span.start() + n_tasks*task_size >= span.end())), | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
269
diff
changeset
|
2861 "n_tasks calculation incorrect"); |
0 | 2862 SequentialSubTasksDone* pst = conc_par_seq_tasks(); |
2863 assert(!pst->valid(), "Clobbering existing data?"); | |
2864 pst->set_par_threads(n_threads); | |
2865 pst->set_n_tasks((int)n_tasks); | |
2866 } |