hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp
changeset 1388 3677f5f3d66b
parent 1376 f7fc7a708b63
parent 991 5b25d0a7116f
child 1392 b376216cba95
equal deleted inserted replaced
1387:580d4ae0a776 1388:3677f5f3d66b
     1 /*
     1 /*
     2  * Copyright 2001-2007 Sun Microsystems, Inc.  All Rights Reserved.
     2  * Copyright 2001-2008 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
  3194 }
  3194 }
  3195 
  3195 
  3196 // YSR: All of this generation expansion/shrinking stuff is an exact copy of
  3196 // YSR: All of this generation expansion/shrinking stuff is an exact copy of
  3197 // OneContigSpaceCardGeneration, which makes me wonder if we should move this
  3197 // OneContigSpaceCardGeneration, which makes me wonder if we should move this
  3198 // to CardGeneration and share it...
  3198 // to CardGeneration and share it...
       
  3199 bool ConcurrentMarkSweepGeneration::expand(size_t bytes, size_t expand_bytes) {
       
  3200   return CardGeneration::expand(bytes, expand_bytes);
       
  3201 }
       
  3202 
  3199 void ConcurrentMarkSweepGeneration::expand(size_t bytes, size_t expand_bytes,
  3203 void ConcurrentMarkSweepGeneration::expand(size_t bytes, size_t expand_bytes,
  3200   CMSExpansionCause::Cause cause)
  3204   CMSExpansionCause::Cause cause)
  3201 {
  3205 {
  3202   assert_locked_or_safepoint(Heap_lock);
  3206 
  3203 
  3207   bool success = expand(bytes, expand_bytes);
  3204   size_t aligned_bytes  = ReservedSpace::page_align_size_up(bytes);
  3208 
  3205   size_t aligned_expand_bytes = ReservedSpace::page_align_size_up(expand_bytes);
       
  3206   bool success = false;
       
  3207   if (aligned_expand_bytes > aligned_bytes) {
       
  3208     success = grow_by(aligned_expand_bytes);
       
  3209   }
       
  3210   if (!success) {
       
  3211     success = grow_by(aligned_bytes);
       
  3212   }
       
  3213   if (!success) {
       
  3214     size_t remaining_bytes = _virtual_space.uncommitted_size();
       
  3215     if (remaining_bytes > 0) {
       
  3216       success = grow_by(remaining_bytes);
       
  3217     }
       
  3218   }
       
  3219   if (GC_locker::is_active()) {
       
  3220     if (PrintGC && Verbose) {
       
  3221       gclog_or_tty->print_cr("Garbage collection disabled, expanded heap instead");
       
  3222     }
       
  3223   }
       
  3224   // remember why we expanded; this information is used
  3209   // remember why we expanded; this information is used
  3225   // by shouldConcurrentCollect() when making decisions on whether to start
  3210   // by shouldConcurrentCollect() when making decisions on whether to start
  3226   // a new CMS cycle.
  3211   // a new CMS cycle.
  3227   if (success) {
  3212   if (success) {
  3228     set_expansion_cause(cause);
  3213     set_expansion_cause(cause);
  6884         // We re-dirty the cards on which this object lies and increase
  6869         // We re-dirty the cards on which this object lies and increase
  6885         // the _threshold so that we'll come back to scan this object
  6870         // the _threshold so that we'll come back to scan this object
  6886         // during the preclean or remark phase. (CMSCleanOnEnter)
  6871         // during the preclean or remark phase. (CMSCleanOnEnter)
  6887         if (CMSCleanOnEnter) {
  6872         if (CMSCleanOnEnter) {
  6888           size_t sz = _collector->block_size_using_printezis_bits(addr);
  6873           size_t sz = _collector->block_size_using_printezis_bits(addr);
  6889           HeapWord* start_card_addr = (HeapWord*)round_down(
       
  6890                                          (intptr_t)addr, CardTableModRefBS::card_size);
       
  6891           HeapWord* end_card_addr   = (HeapWord*)round_to(
  6874           HeapWord* end_card_addr   = (HeapWord*)round_to(
  6892                                          (intptr_t)(addr+sz), CardTableModRefBS::card_size);
  6875                                          (intptr_t)(addr+sz), CardTableModRefBS::card_size);
  6893           MemRegion redirty_range = MemRegion(start_card_addr, end_card_addr);
  6876           MemRegion redirty_range = MemRegion(addr, end_card_addr);
  6894           assert(!redirty_range.is_empty(), "Arithmetical tautology");
  6877           assert(!redirty_range.is_empty(), "Arithmetical tautology");
  6895           // Bump _threshold to end_card_addr; note that
  6878           // Bump _threshold to end_card_addr; note that
  6896           // _threshold cannot possibly exceed end_card_addr, anyhow.
  6879           // _threshold cannot possibly exceed end_card_addr, anyhow.
  6897           // This prevents future clearing of the card as the scan proceeds
  6880           // This prevents future clearing of the card as the scan proceeds
  6898           // to the right.
  6881           // to the right.
  7484         simulate_overflow = true;
  7467         simulate_overflow = true;
  7485       }
  7468       }
  7486     )
  7469     )
  7487     if (simulate_overflow || !_mark_stack->push(obj)) {
  7470     if (simulate_overflow || !_mark_stack->push(obj)) {
  7488       if (_concurrent_precleaning) {
  7471       if (_concurrent_precleaning) {
  7489          // During precleaning we can just dirty the appropriate card
  7472          // During precleaning we can just dirty the appropriate card(s)
  7490          // in the mod union table, thus ensuring that the object remains
  7473          // in the mod union table, thus ensuring that the object remains
  7491          // in the grey set  and continue. Note that no one can be intefering
  7474          // in the grey set  and continue. In the case of object arrays
  7492          // with us in this action of dirtying the mod union table, so
  7475          // we need to dirty all of the cards that the object spans,
  7493          // no locking is required.
  7476          // since the rescan of object arrays will be limited to the
  7494          _mod_union_table->mark(addr);
  7477          // dirty cards.
       
  7478          // Note that no one can be intefering with us in this action
       
  7479          // of dirtying the mod union table, so no locking or atomics
       
  7480          // are required.
       
  7481          if (obj->is_objArray()) {
       
  7482            size_t sz = obj->size();
       
  7483            HeapWord* end_card_addr = (HeapWord*)round_to(
       
  7484                                         (intptr_t)(addr+sz), CardTableModRefBS::card_size);
       
  7485            MemRegion redirty_range = MemRegion(addr, end_card_addr);
       
  7486            assert(!redirty_range.is_empty(), "Arithmetical tautology");
       
  7487            _mod_union_table->mark_range(redirty_range);
       
  7488          } else {
       
  7489            _mod_union_table->mark(addr);
       
  7490          }
  7495          _collector->_ser_pmc_preclean_ovflw++;
  7491          _collector->_ser_pmc_preclean_ovflw++;
  7496       } else {
  7492       } else {
  7497          // During the remark phase, we need to remember this oop
  7493          // During the remark phase, we need to remember this oop
  7498          // in the overflow list.
  7494          // in the overflow list.
  7499          _collector->push_on_overflow_list(obj);
  7495          _collector->push_on_overflow_list(obj);