Mercurial > hg > truffle
comparison src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp @ 3746:537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
Summary: Do a one-step look-ahead, when sweeping free or garbage blocks, to avoid overstepping sweep limit, which may become a non-block-boundary because of a heap expansion delta coalescing with a previously co-terminal free block.
Reviewed-by: brutisso, tonyp
author | ysr |
---|---|
date | Mon, 23 May 2011 16:42:14 -0700 |
parents | 78542e2b5e35 |
children | 48048b59a551 |
comparison
equal
deleted
inserted
replaced
3397:cfbca4d74a61 | 3746:537a4053b0f9 |
---|---|
7886 _sp->dictionary()->initializeDictReturnedBytes(); | 7886 _sp->dictionary()->initializeDictReturnedBytes(); |
7887 ) | 7887 ) |
7888 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), | 7888 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), |
7889 "sweep _limit out of bounds"); | 7889 "sweep _limit out of bounds"); |
7890 if (CMSTraceSweeper) { | 7890 if (CMSTraceSweeper) { |
7891 gclog_or_tty->print("\n====================\nStarting new sweep\n"); | 7891 gclog_or_tty->print_cr("\n====================\nStarting new sweep with limit " PTR_FORMAT, |
7892 } | 7892 _limit); |
7893 } | 7893 } |
7894 | 7894 } |
7895 // We need this destructor to reclaim any space at the end | 7895 |
7896 // of the space, which do_blk below may not yet have added back to | 7896 void SweepClosure::print_on(outputStream* st) const { |
7897 // the free lists. | 7897 tty->print_cr("_sp = [" PTR_FORMAT "," PTR_FORMAT ")", |
7898 _sp->bottom(), _sp->end()); | |
7899 tty->print_cr("_limit = " PTR_FORMAT, _limit); | |
7900 tty->print_cr("_freeFinger = " PTR_FORMAT, _freeFinger); | |
7901 NOT_PRODUCT(tty->print_cr("_last_fc = " PTR_FORMAT, _last_fc);) | |
7902 tty->print_cr("_inFreeRange = %d, _freeRangeInFreeLists = %d, _lastFreeRangeCoalesced = %d", | |
7903 _inFreeRange, _freeRangeInFreeLists, _lastFreeRangeCoalesced); | |
7904 } | |
7905 | |
7906 #ifndef PRODUCT | |
7907 // Assertion checking only: no useful work in product mode -- | |
7908 // however, if any of the flags below become product flags, | |
7909 // you may need to review this code to see if it needs to be | |
7910 // enabled in product mode. | |
7898 SweepClosure::~SweepClosure() { | 7911 SweepClosure::~SweepClosure() { |
7899 assert_lock_strong(_freelistLock); | 7912 assert_lock_strong(_freelistLock); |
7900 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), | 7913 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), |
7901 "sweep _limit out of bounds"); | 7914 "sweep _limit out of bounds"); |
7902 // Flush any remaining coterminal free run as a single | |
7903 // coalesced chunk to the appropriate free list. | |
7904 if (inFreeRange()) { | 7915 if (inFreeRange()) { |
7905 assert(freeFinger() < _limit, "freeFinger points too high"); | 7916 warning("inFreeRange() should have been reset; dumping state of SweepClosure"); |
7906 flush_cur_free_chunk(freeFinger(), pointer_delta(_limit, freeFinger())); | 7917 print(); |
7907 if (CMSTraceSweeper) { | 7918 ShouldNotReachHere(); |
7908 gclog_or_tty->print("Sweep: last chunk: "); | 7919 } |
7909 gclog_or_tty->print("put_free_blk 0x%x ("SIZE_FORMAT") [coalesced:"SIZE_FORMAT"]\n", | 7920 if (Verbose && PrintGC) { |
7910 freeFinger(), pointer_delta(_limit, freeFinger()), lastFreeRangeCoalesced()); | 7921 gclog_or_tty->print("Collected "SIZE_FORMAT" objects, " SIZE_FORMAT " bytes", |
7911 } | 7922 _numObjectsFreed, _numWordsFreed*sizeof(HeapWord)); |
7912 } // else nothing to flush | 7923 gclog_or_tty->print_cr("\nLive "SIZE_FORMAT" objects, " |
7913 NOT_PRODUCT( | 7924 SIZE_FORMAT" bytes " |
7914 if (Verbose && PrintGC) { | 7925 "Already free "SIZE_FORMAT" objects, "SIZE_FORMAT" bytes", |
7915 gclog_or_tty->print("Collected "SIZE_FORMAT" objects, " | 7926 _numObjectsLive, _numWordsLive*sizeof(HeapWord), |
7916 SIZE_FORMAT " bytes", | 7927 _numObjectsAlreadyFree, _numWordsAlreadyFree*sizeof(HeapWord)); |
7917 _numObjectsFreed, _numWordsFreed*sizeof(HeapWord)); | 7928 size_t totalBytes = (_numWordsFreed + _numWordsLive + _numWordsAlreadyFree) |
7918 gclog_or_tty->print_cr("\nLive "SIZE_FORMAT" objects, " | 7929 * sizeof(HeapWord); |
7919 SIZE_FORMAT" bytes " | 7930 gclog_or_tty->print_cr("Total sweep: "SIZE_FORMAT" bytes", totalBytes); |
7920 "Already free "SIZE_FORMAT" objects, "SIZE_FORMAT" bytes", | 7931 |
7921 _numObjectsLive, _numWordsLive*sizeof(HeapWord), | 7932 if (PrintCMSStatistics && CMSVerifyReturnedBytes) { |
7922 _numObjectsAlreadyFree, _numWordsAlreadyFree*sizeof(HeapWord)); | 7933 size_t indexListReturnedBytes = _sp->sumIndexedFreeListArrayReturnedBytes(); |
7923 size_t totalBytes = (_numWordsFreed + _numWordsLive + _numWordsAlreadyFree) * | 7934 size_t dictReturnedBytes = _sp->dictionary()->sumDictReturnedBytes(); |
7924 sizeof(HeapWord); | 7935 size_t returnedBytes = indexListReturnedBytes + dictReturnedBytes; |
7925 gclog_or_tty->print_cr("Total sweep: "SIZE_FORMAT" bytes", totalBytes); | 7936 gclog_or_tty->print("Returned "SIZE_FORMAT" bytes", returnedBytes); |
7926 | 7937 gclog_or_tty->print(" Indexed List Returned "SIZE_FORMAT" bytes", |
7927 if (PrintCMSStatistics && CMSVerifyReturnedBytes) { | 7938 indexListReturnedBytes); |
7928 size_t indexListReturnedBytes = _sp->sumIndexedFreeListArrayReturnedBytes(); | 7939 gclog_or_tty->print_cr(" Dictionary Returned "SIZE_FORMAT" bytes", |
7929 size_t dictReturnedBytes = _sp->dictionary()->sumDictReturnedBytes(); | 7940 dictReturnedBytes); |
7930 size_t returnedBytes = indexListReturnedBytes + dictReturnedBytes; | 7941 } |
7931 gclog_or_tty->print("Returned "SIZE_FORMAT" bytes", returnedBytes); | 7942 } |
7932 gclog_or_tty->print(" Indexed List Returned "SIZE_FORMAT" bytes", | |
7933 indexListReturnedBytes); | |
7934 gclog_or_tty->print_cr(" Dictionary Returned "SIZE_FORMAT" bytes", | |
7935 dictReturnedBytes); | |
7936 } | |
7937 } | |
7938 ) | |
7939 // Now, in debug mode, just null out the sweep_limit | |
7940 NOT_PRODUCT(_sp->clear_sweep_limit();) | |
7941 if (CMSTraceSweeper) { | 7943 if (CMSTraceSweeper) { |
7942 gclog_or_tty->print("end of sweep\n================\n"); | 7944 gclog_or_tty->print_cr("end of sweep with _limit = " PTR_FORMAT "\n================", |
7943 } | 7945 _limit); |
7944 } | 7946 } |
7947 } | |
7948 #endif // PRODUCT | |
7945 | 7949 |
7946 void SweepClosure::initialize_free_range(HeapWord* freeFinger, | 7950 void SweepClosure::initialize_free_range(HeapWord* freeFinger, |
7947 bool freeRangeInFreeLists) { | 7951 bool freeRangeInFreeLists) { |
7948 if (CMSTraceSweeper) { | 7952 if (CMSTraceSweeper) { |
7949 gclog_or_tty->print("---- Start free range at 0x%x with free block (%d)\n", | 7953 gclog_or_tty->print("---- Start free range at 0x%x with free block (%d)\n", |
7999 // Check if we are done sweeping. Below we check "addr >= _limit" rather | 8003 // Check if we are done sweeping. Below we check "addr >= _limit" rather |
8000 // than "addr == _limit" because although _limit was a block boundary when | 8004 // than "addr == _limit" because although _limit was a block boundary when |
8001 // we started the sweep, it may no longer be one because heap expansion | 8005 // we started the sweep, it may no longer be one because heap expansion |
8002 // may have caused us to coalesce the block ending at the address _limit | 8006 // may have caused us to coalesce the block ending at the address _limit |
8003 // with a newly expanded chunk (this happens when _limit was set to the | 8007 // with a newly expanded chunk (this happens when _limit was set to the |
8004 // previous _end of the space), so we may have stepped past _limit; see CR 6977970. | 8008 // previous _end of the space), so we may have stepped past _limit: |
8009 // see the following Zeno-like trail of CRs 6977970, 7008136, 7042740. | |
8005 if (addr >= _limit) { // we have swept up to or past the limit: finish up | 8010 if (addr >= _limit) { // we have swept up to or past the limit: finish up |
8006 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), | 8011 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), |
8007 "sweep _limit out of bounds"); | 8012 "sweep _limit out of bounds"); |
8008 assert(addr < _sp->end(), "addr out of bounds"); | 8013 assert(addr < _sp->end(), "addr out of bounds"); |
8009 // Flush any remaining coterminal free run as a single | 8014 // Flush any free range we might be holding as a single |
8010 // coalesced chunk to the appropriate free list. | 8015 // coalesced chunk to the appropriate free list. |
8011 if (inFreeRange()) { | 8016 if (inFreeRange()) { |
8012 assert(freeFinger() < _limit, "finger points too high"); | 8017 assert(freeFinger() >= _sp->bottom() && freeFinger() < _limit, |
8018 err_msg("freeFinger() " PTR_FORMAT" is out-of-bounds", freeFinger())); | |
8013 flush_cur_free_chunk(freeFinger(), | 8019 flush_cur_free_chunk(freeFinger(), |
8014 pointer_delta(addr, freeFinger())); | 8020 pointer_delta(addr, freeFinger())); |
8015 if (CMSTraceSweeper) { | 8021 if (CMSTraceSweeper) { |
8016 gclog_or_tty->print("Sweep: last chunk: "); | 8022 gclog_or_tty->print("Sweep: last chunk: "); |
8017 gclog_or_tty->print("put_free_blk 0x%x ("SIZE_FORMAT") " | 8023 gclog_or_tty->print("put_free_blk 0x%x ("SIZE_FORMAT") " |
8031 if (fc->isFree()) { | 8037 if (fc->isFree()) { |
8032 // Chunk that is already free | 8038 // Chunk that is already free |
8033 res = fc->size(); | 8039 res = fc->size(); |
8034 do_already_free_chunk(fc); | 8040 do_already_free_chunk(fc); |
8035 debug_only(_sp->verifyFreeLists()); | 8041 debug_only(_sp->verifyFreeLists()); |
8036 assert(res == fc->size(), "Don't expect the size to change"); | 8042 // If we flush the chunk at hand in lookahead_and_flush() |
8043 // and it's coalesced with a preceding chunk, then the | |
8044 // process of "mangling" the payload of the coalesced block | |
8045 // will cause erasure of the size information from the | |
8046 // (erstwhile) header of all the coalesced blocks but the | |
8047 // first, so the first disjunct in the assert will not hold | |
8048 // in that specific case (in which case the second disjunct | |
8049 // will hold). | |
8050 assert(res == fc->size() || ((HeapWord*)fc) + res >= _limit, | |
8051 "Otherwise the size info doesn't change at this step"); | |
8037 NOT_PRODUCT( | 8052 NOT_PRODUCT( |
8038 _numObjectsAlreadyFree++; | 8053 _numObjectsAlreadyFree++; |
8039 _numWordsAlreadyFree += res; | 8054 _numWordsAlreadyFree += res; |
8040 ) | 8055 ) |
8041 NOT_PRODUCT(_last_fc = fc;) | 8056 NOT_PRODUCT(_last_fc = fc;) |
8101 // be chosen. The "hint" associated with a free list, if non-null, points | 8116 // be chosen. The "hint" associated with a free list, if non-null, points |
8102 // to a free list which may be overpopulated. | 8117 // to a free list which may be overpopulated. |
8103 // | 8118 // |
8104 | 8119 |
8105 void SweepClosure::do_already_free_chunk(FreeChunk* fc) { | 8120 void SweepClosure::do_already_free_chunk(FreeChunk* fc) { |
8106 size_t size = fc->size(); | 8121 const size_t size = fc->size(); |
8107 // Chunks that cannot be coalesced are not in the | 8122 // Chunks that cannot be coalesced are not in the |
8108 // free lists. | 8123 // free lists. |
8109 if (CMSTestInFreeList && !fc->cantCoalesce()) { | 8124 if (CMSTestInFreeList && !fc->cantCoalesce()) { |
8110 assert(_sp->verifyChunkInFreeLists(fc), | 8125 assert(_sp->verifyChunkInFreeLists(fc), |
8111 "free chunk should be in free lists"); | 8126 "free chunk should be in free lists"); |
8112 } | 8127 } |
8113 // a chunk that is already free, should not have been | 8128 // a chunk that is already free, should not have been |
8114 // marked in the bit map | 8129 // marked in the bit map |
8115 HeapWord* addr = (HeapWord*) fc; | 8130 HeapWord* const addr = (HeapWord*) fc; |
8116 assert(!_bitMap->isMarked(addr), "free chunk should be unmarked"); | 8131 assert(!_bitMap->isMarked(addr), "free chunk should be unmarked"); |
8117 // Verify that the bit map has no bits marked between | 8132 // Verify that the bit map has no bits marked between |
8118 // addr and purported end of this block. | 8133 // addr and purported end of this block. |
8119 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); | 8134 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); |
8120 | 8135 |
8147 initialize_free_range(addr, true); | 8162 initialize_free_range(addr, true); |
8148 // end - can coalesce with next chunk | 8163 // end - can coalesce with next chunk |
8149 } | 8164 } |
8150 } else { | 8165 } else { |
8151 // the midst of a free range, we are coalescing | 8166 // the midst of a free range, we are coalescing |
8152 debug_only(record_free_block_coalesced(fc);) | 8167 print_free_block_coalesced(fc); |
8153 if (CMSTraceSweeper) { | 8168 if (CMSTraceSweeper) { |
8154 gclog_or_tty->print(" -- pick up free block 0x%x (%d)\n", fc, size); | 8169 gclog_or_tty->print(" -- pick up free block 0x%x (%d)\n", fc, size); |
8155 } | 8170 } |
8156 // remove it from the free lists | 8171 // remove it from the free lists |
8157 _sp->removeFreeChunkFromFreeLists(fc); | 8172 _sp->removeFreeChunkFromFreeLists(fc); |
8171 _sp->removeFreeChunkFromFreeLists(ffc); | 8186 _sp->removeFreeChunkFromFreeLists(ffc); |
8172 set_freeRangeInFreeLists(false); | 8187 set_freeRangeInFreeLists(false); |
8173 } | 8188 } |
8174 } | 8189 } |
8175 } | 8190 } |
8191 // Note that if the chunk is not coalescable (the else arm | |
8192 // below), we unconditionally flush, without needing to do | |
8193 // a "lookahead," as we do below. | |
8194 if (inFreeRange()) lookahead_and_flush(fc, size); | |
8176 } else { | 8195 } else { |
8177 // Code path common to both original and adaptive free lists. | 8196 // Code path common to both original and adaptive free lists. |
8178 | 8197 |
8179 // cant coalesce with previous block; this should be treated | 8198 // cant coalesce with previous block; this should be treated |
8180 // as the end of a free run if any | 8199 // as the end of a free run if any |
8189 | 8208 |
8190 size_t SweepClosure::do_garbage_chunk(FreeChunk* fc) { | 8209 size_t SweepClosure::do_garbage_chunk(FreeChunk* fc) { |
8191 // This is a chunk of garbage. It is not in any free list. | 8210 // This is a chunk of garbage. It is not in any free list. |
8192 // Add it to a free list or let it possibly be coalesced into | 8211 // Add it to a free list or let it possibly be coalesced into |
8193 // a larger chunk. | 8212 // a larger chunk. |
8194 HeapWord* addr = (HeapWord*) fc; | 8213 HeapWord* const addr = (HeapWord*) fc; |
8195 size_t size = CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size()); | 8214 const size_t size = CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size()); |
8196 | 8215 |
8197 if (_sp->adaptive_freelists()) { | 8216 if (_sp->adaptive_freelists()) { |
8198 // Verify that the bit map has no bits marked between | 8217 // Verify that the bit map has no bits marked between |
8199 // addr and purported end of just dead object. | 8218 // addr and purported end of just dead object. |
8200 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); | 8219 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); |
8203 } else { | 8222 } else { |
8204 if (!inFreeRange()) { | 8223 if (!inFreeRange()) { |
8205 // start of a new free range | 8224 // start of a new free range |
8206 assert(size > 0, "A free range should have a size"); | 8225 assert(size > 0, "A free range should have a size"); |
8207 initialize_free_range(addr, false); | 8226 initialize_free_range(addr, false); |
8208 | |
8209 } else { | 8227 } else { |
8210 // this will be swept up when we hit the end of the | 8228 // this will be swept up when we hit the end of the |
8211 // free range | 8229 // free range |
8212 if (CMSTraceSweeper) { | 8230 if (CMSTraceSweeper) { |
8213 gclog_or_tty->print(" -- pick up garbage 0x%x (%d) \n", fc, size); | 8231 gclog_or_tty->print(" -- pick up garbage 0x%x (%d) \n", fc, size); |
8233 | 8251 |
8234 // Verify that the bit map has no bits marked between | 8252 // Verify that the bit map has no bits marked between |
8235 // addr and purported end of just dead object. | 8253 // addr and purported end of just dead object. |
8236 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); | 8254 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); |
8237 } | 8255 } |
8256 assert(_limit >= addr + size, | |
8257 "A freshly garbage chunk can't possibly straddle over _limit"); | |
8258 if (inFreeRange()) lookahead_and_flush(fc, size); | |
8238 return size; | 8259 return size; |
8239 } | 8260 } |
8240 | 8261 |
8241 size_t SweepClosure::do_live_chunk(FreeChunk* fc) { | 8262 size_t SweepClosure::do_live_chunk(FreeChunk* fc) { |
8242 HeapWord* addr = (HeapWord*) fc; | 8263 HeapWord* addr = (HeapWord*) fc; |
8282 // This should be an initialized object that's alive. | 8303 // This should be an initialized object that's alive. |
8283 assert(oop(addr)->klass_or_null() != NULL && | 8304 assert(oop(addr)->klass_or_null() != NULL && |
8284 (!_collector->should_unload_classes() | 8305 (!_collector->should_unload_classes() |
8285 || oop(addr)->is_parsable()), | 8306 || oop(addr)->is_parsable()), |
8286 "Should be an initialized object"); | 8307 "Should be an initialized object"); |
8287 // Note that there are objects used during class redefinition | 8308 // Note that there are objects used during class redefinition, |
8288 // (e.g., merge_cp in VM_RedefineClasses::merge_cp_and_rewrite() | 8309 // e.g. merge_cp in VM_RedefineClasses::merge_cp_and_rewrite(), |
8289 // which are discarded with their is_conc_safe state still | 8310 // which are discarded with their is_conc_safe state still |
8290 // false. These object may be floating garbage so may be | 8311 // false. These object may be floating garbage so may be |
8291 // seen here. If they are floating garbage their size | 8312 // seen here. If they are floating garbage their size |
8292 // should be attainable from their klass. Do not that | 8313 // should be attainable from their klass. Do not that |
8293 // is_conc_safe() is true for oop(addr). | 8314 // is_conc_safe() is true for oop(addr). |
8305 | 8326 |
8306 void SweepClosure::do_post_free_or_garbage_chunk(FreeChunk* fc, | 8327 void SweepClosure::do_post_free_or_garbage_chunk(FreeChunk* fc, |
8307 size_t chunkSize) { | 8328 size_t chunkSize) { |
8308 // do_post_free_or_garbage_chunk() should only be called in the case | 8329 // do_post_free_or_garbage_chunk() should only be called in the case |
8309 // of the adaptive free list allocator. | 8330 // of the adaptive free list allocator. |
8310 bool fcInFreeLists = fc->isFree(); | 8331 const bool fcInFreeLists = fc->isFree(); |
8311 assert(_sp->adaptive_freelists(), "Should only be used in this case."); | 8332 assert(_sp->adaptive_freelists(), "Should only be used in this case."); |
8312 assert((HeapWord*)fc <= _limit, "sweep invariant"); | 8333 assert((HeapWord*)fc <= _limit, "sweep invariant"); |
8313 if (CMSTestInFreeList && fcInFreeLists) { | 8334 if (CMSTestInFreeList && fcInFreeLists) { |
8314 assert(_sp->verifyChunkInFreeLists(fc), "free chunk is not in free lists"); | 8335 assert(_sp->verifyChunkInFreeLists(fc), "free chunk is not in free lists"); |
8315 } | 8336 } |
8316 | 8337 |
8317 if (CMSTraceSweeper) { | 8338 if (CMSTraceSweeper) { |
8318 gclog_or_tty->print_cr(" -- pick up another chunk at 0x%x (%d)", fc, chunkSize); | 8339 gclog_or_tty->print_cr(" -- pick up another chunk at 0x%x (%d)", fc, chunkSize); |
8319 } | 8340 } |
8320 | 8341 |
8321 HeapWord* addr = (HeapWord*) fc; | 8342 HeapWord* const fc_addr = (HeapWord*) fc; |
8322 | 8343 |
8323 bool coalesce; | 8344 bool coalesce; |
8324 size_t left = pointer_delta(addr, freeFinger()); | 8345 const size_t left = pointer_delta(fc_addr, freeFinger()); |
8325 size_t right = chunkSize; | 8346 const size_t right = chunkSize; |
8326 switch (FLSCoalescePolicy) { | 8347 switch (FLSCoalescePolicy) { |
8327 // numeric value forms a coalition aggressiveness metric | 8348 // numeric value forms a coalition aggressiveness metric |
8328 case 0: { // never coalesce | 8349 case 0: { // never coalesce |
8329 coalesce = false; | 8350 coalesce = false; |
8330 break; | 8351 break; |
8353 | 8374 |
8354 // Should the current free range be coalesced? | 8375 // Should the current free range be coalesced? |
8355 // If the chunk is in a free range and either we decided to coalesce above | 8376 // If the chunk is in a free range and either we decided to coalesce above |
8356 // or the chunk is near the large block at the end of the heap | 8377 // or the chunk is near the large block at the end of the heap |
8357 // (isNearLargestChunk() returns true), then coalesce this chunk. | 8378 // (isNearLargestChunk() returns true), then coalesce this chunk. |
8358 bool doCoalesce = inFreeRange() && | 8379 const bool doCoalesce = inFreeRange() |
8359 (coalesce || _g->isNearLargestChunk((HeapWord*)fc)); | 8380 && (coalesce || _g->isNearLargestChunk(fc_addr)); |
8360 if (doCoalesce) { | 8381 if (doCoalesce) { |
8361 // Coalesce the current free range on the left with the new | 8382 // Coalesce the current free range on the left with the new |
8362 // chunk on the right. If either is on a free list, | 8383 // chunk on the right. If either is on a free list, |
8363 // it must be removed from the list and stashed in the closure. | 8384 // it must be removed from the list and stashed in the closure. |
8364 if (freeRangeInFreeLists()) { | 8385 if (freeRangeInFreeLists()) { |
8365 FreeChunk* ffc = (FreeChunk*)freeFinger(); | 8386 FreeChunk* const ffc = (FreeChunk*)freeFinger(); |
8366 assert(ffc->size() == pointer_delta(addr, freeFinger()), | 8387 assert(ffc->size() == pointer_delta(fc_addr, freeFinger()), |
8367 "Size of free range is inconsistent with chunk size."); | 8388 "Size of free range is inconsistent with chunk size."); |
8368 if (CMSTestInFreeList) { | 8389 if (CMSTestInFreeList) { |
8369 assert(_sp->verifyChunkInFreeLists(ffc), | 8390 assert(_sp->verifyChunkInFreeLists(ffc), |
8370 "Chunk is not in free lists"); | 8391 "Chunk is not in free lists"); |
8371 } | 8392 } |
8378 assert(fc->size() == chunkSize, | 8399 assert(fc->size() == chunkSize, |
8379 "The chunk has the wrong size or is not in the free lists"); | 8400 "The chunk has the wrong size or is not in the free lists"); |
8380 _sp->removeFreeChunkFromFreeLists(fc); | 8401 _sp->removeFreeChunkFromFreeLists(fc); |
8381 } | 8402 } |
8382 set_lastFreeRangeCoalesced(true); | 8403 set_lastFreeRangeCoalesced(true); |
8404 print_free_block_coalesced(fc); | |
8383 } else { // not in a free range and/or should not coalesce | 8405 } else { // not in a free range and/or should not coalesce |
8384 // Return the current free range and start a new one. | 8406 // Return the current free range and start a new one. |
8385 if (inFreeRange()) { | 8407 if (inFreeRange()) { |
8386 // In a free range but cannot coalesce with the right hand chunk. | 8408 // In a free range but cannot coalesce with the right hand chunk. |
8387 // Put the current free range into the free lists. | 8409 // Put the current free range into the free lists. |
8388 flush_cur_free_chunk(freeFinger(), | 8410 flush_cur_free_chunk(freeFinger(), |
8389 pointer_delta(addr, freeFinger())); | 8411 pointer_delta(fc_addr, freeFinger())); |
8390 } | 8412 } |
8391 // Set up for new free range. Pass along whether the right hand | 8413 // Set up for new free range. Pass along whether the right hand |
8392 // chunk is in the free lists. | 8414 // chunk is in the free lists. |
8393 initialize_free_range((HeapWord*)fc, fcInFreeLists); | 8415 initialize_free_range((HeapWord*)fc, fcInFreeLists); |
8416 } | |
8417 } | |
8418 | |
8419 // Lookahead flush: | |
8420 // If we are tracking a free range, and this is the last chunk that | |
8421 // we'll look at because its end crosses past _limit, we'll preemptively | |
8422 // flush it along with any free range we may be holding on to. Note that | |
8423 // this can be the case only for an already free or freshly garbage | |
8424 // chunk. If this block is an object, it can never straddle | |
8425 // over _limit. The "straddling" occurs when _limit is set at | |
8426 // the previous end of the space when this cycle started, and | |
8427 // a subsequent heap expansion caused the previously co-terminal | |
8428 // free block to be coalesced with the newly expanded portion, | |
8429 // thus rendering _limit a non-block-boundary making it dangerous | |
8430 // for the sweeper to step over and examine. | |
8431 void SweepClosure::lookahead_and_flush(FreeChunk* fc, size_t chunk_size) { | |
8432 assert(inFreeRange(), "Should only be called if currently in a free range."); | |
8433 HeapWord* const eob = ((HeapWord*)fc) + chunk_size; | |
8434 assert(_sp->used_region().contains(eob - 1), | |
8435 err_msg("eob = " PTR_FORMAT " out of bounds wrt _sp = [" PTR_FORMAT "," PTR_FORMAT ")" | |
8436 " when examining fc = " PTR_FORMAT "(" SIZE_FORMAT ")", | |
8437 _limit, _sp->bottom(), _sp->end(), fc, chunk_size)); | |
8438 if (eob >= _limit) { | |
8439 assert(eob == _limit || fc->isFree(), "Only a free chunk should allow us to cross over the limit"); | |
8440 if (CMSTraceSweeper) { | |
8441 gclog_or_tty->print_cr("_limit " PTR_FORMAT " reached or crossed by block " | |
8442 "[" PTR_FORMAT "," PTR_FORMAT ") in space " | |
8443 "[" PTR_FORMAT "," PTR_FORMAT ")", | |
8444 _limit, fc, eob, _sp->bottom(), _sp->end()); | |
8445 } | |
8446 // Return the storage we are tracking back into the free lists. | |
8447 if (CMSTraceSweeper) { | |
8448 gclog_or_tty->print_cr("Flushing ... "); | |
8449 } | |
8450 assert(freeFinger() < eob, "Error"); | |
8451 flush_cur_free_chunk( freeFinger(), pointer_delta(eob, freeFinger())); | |
8394 } | 8452 } |
8395 } | 8453 } |
8396 | 8454 |
8397 void SweepClosure::flush_cur_free_chunk(HeapWord* chunk, size_t size) { | 8455 void SweepClosure::flush_cur_free_chunk(HeapWord* chunk, size_t size) { |
8398 assert(inFreeRange(), "Should only be called if currently in a free range."); | 8456 assert(inFreeRange(), "Should only be called if currently in a free range."); |
8417 if (lastFreeRangeCoalesced()) { | 8475 if (lastFreeRangeCoalesced()) { |
8418 _sp->coalBirth(size); | 8476 _sp->coalBirth(size); |
8419 } | 8477 } |
8420 _sp->addChunkAndRepairOffsetTable(chunk, size, | 8478 _sp->addChunkAndRepairOffsetTable(chunk, size, |
8421 lastFreeRangeCoalesced()); | 8479 lastFreeRangeCoalesced()); |
8480 } else if (CMSTraceSweeper) { | |
8481 gclog_or_tty->print_cr("Already in free list: nothing to flush"); | |
8422 } | 8482 } |
8423 set_inFreeRange(false); | 8483 set_inFreeRange(false); |
8424 set_freeRangeInFreeLists(false); | 8484 set_freeRangeInFreeLists(false); |
8425 } | 8485 } |
8426 | 8486 |
8475 // be called from the debugger. Compile it into the product | 8535 // be called from the debugger. Compile it into the product |
8476 // as needed. | 8536 // as needed. |
8477 bool debug_verifyChunkInFreeLists(FreeChunk* fc) { | 8537 bool debug_verifyChunkInFreeLists(FreeChunk* fc) { |
8478 return debug_cms_space->verifyChunkInFreeLists(fc); | 8538 return debug_cms_space->verifyChunkInFreeLists(fc); |
8479 } | 8539 } |
8480 | 8540 #endif |
8481 void SweepClosure::record_free_block_coalesced(FreeChunk* fc) const { | 8541 |
8542 void SweepClosure::print_free_block_coalesced(FreeChunk* fc) const { | |
8482 if (CMSTraceSweeper) { | 8543 if (CMSTraceSweeper) { |
8483 gclog_or_tty->print("Sweep:coal_free_blk 0x%x (%d)\n", fc, fc->size()); | 8544 gclog_or_tty->print_cr("Sweep:coal_free_blk " PTR_FORMAT " (" SIZE_FORMAT ")", |
8484 } | 8545 fc, fc->size()); |
8485 } | 8546 } |
8486 #endif | 8547 } |
8487 | 8548 |
8488 // CMSIsAliveClosure | 8549 // CMSIsAliveClosure |
8489 bool CMSIsAliveClosure::do_object_b(oop obj) { | 8550 bool CMSIsAliveClosure::do_object_b(oop obj) { |
8490 HeapWord* addr = (HeapWord*)obj; | 8551 HeapWord* addr = (HeapWord*)obj; |
8491 return addr != NULL && | 8552 return addr != NULL && |