hotspot/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp
changeset 46968 9119841280f4
parent 46795 623a5e42deb6
equal deleted inserted replaced
46953:39063b484ec2 46968:9119841280f4
   938     res = _cmsSpace->promote(obj, obj_size);
   938     res = _cmsSpace->promote(obj, obj_size);
   939   }
   939   }
   940   if (res != NULL) {
   940   if (res != NULL) {
   941     // See comment in allocate() about when objects should
   941     // See comment in allocate() about when objects should
   942     // be allocated live.
   942     // be allocated live.
   943     assert(obj->is_oop(), "Will dereference klass pointer below");
   943     assert(oopDesc::is_oop(obj), "Will dereference klass pointer below");
   944     collector()->promoted(false,           // Not parallel
   944     collector()->promoted(false,           // Not parallel
   945                           (HeapWord*)res, obj->is_objArray(), obj_size);
   945                           (HeapWord*)res, obj->is_objArray(), obj_size);
   946     // promotion counters
   946     // promotion counters
   947     NOT_PRODUCT(
   947     NOT_PRODUCT(
   948       _numObjectsPromoted++;
   948       _numObjectsPromoted++;
  1061   if (promoInfo->tracking()) {
  1061   if (promoInfo->tracking()) {
  1062     promoInfo->track((PromotedObject*)obj, old->klass());
  1062     promoInfo->track((PromotedObject*)obj, old->klass());
  1063   }
  1063   }
  1064   assert(obj->klass_or_null() == NULL, "Object should be uninitialized here.");
  1064   assert(obj->klass_or_null() == NULL, "Object should be uninitialized here.");
  1065   assert(!((FreeChunk*)obj_ptr)->is_free(), "Error, block will look free but show wrong size");
  1065   assert(!((FreeChunk*)obj_ptr)->is_free(), "Error, block will look free but show wrong size");
  1066   assert(old->is_oop(), "Will use and dereference old klass ptr below");
  1066   assert(oopDesc::is_oop(old), "Will use and dereference old klass ptr below");
  1067 
  1067 
  1068   // Finally, install the klass pointer (this should be volatile).
  1068   // Finally, install the klass pointer (this should be volatile).
  1069   OrderAccess::storestore();
  1069   OrderAccess::storestore();
  1070   obj->set_klass(old->klass());
  1070   obj->set_klass(old->klass());
  1071   // We should now be able to calculate the right size for this object
  1071   // We should now be able to calculate the right size for this object
  1072   assert(obj->is_oop() && obj->size() == (int)word_sz, "Error, incorrect size computed for promoted object");
  1072   assert(oopDesc::is_oop(obj) && obj->size() == (int)word_sz, "Error, incorrect size computed for promoted object");
  1073 
  1073 
  1074   collector()->promoted(true,          // parallel
  1074   collector()->promoted(true,          // parallel
  1075                         obj_ptr, old->is_objArray(), word_sz);
  1075                         obj_ptr, old->is_objArray(), word_sz);
  1076 
  1076 
  1077   NOT_PRODUCT(
  1077   NOT_PRODUCT(
  3346 // that are in these stolen objects being scanned must
  3346 // that are in these stolen objects being scanned must
  3347 // already have been initialized (else they would not have
  3347 // already have been initialized (else they would not have
  3348 // been published), so we do not need to check for
  3348 // been published), so we do not need to check for
  3349 // uninitialized objects before pushing here.
  3349 // uninitialized objects before pushing here.
  3350 void ParConcMarkingClosure::do_oop(oop obj) {
  3350 void ParConcMarkingClosure::do_oop(oop obj) {
  3351   assert(obj->is_oop_or_null(true), "Expected an oop or NULL at " PTR_FORMAT, p2i(obj));
  3351   assert(oopDesc::is_oop_or_null(obj, true), "Expected an oop or NULL at " PTR_FORMAT, p2i(obj));
  3352   HeapWord* addr = (HeapWord*)obj;
  3352   HeapWord* addr = (HeapWord*)obj;
  3353   // Check if oop points into the CMS generation
  3353   // Check if oop points into the CMS generation
  3354   // and is not marked
  3354   // and is not marked
  3355   if (_span.contains(addr) && !_bit_map->isMarked(addr)) {
  3355   if (_span.contains(addr) && !_bit_map->isMarked(addr)) {
  3356     // a white object ...
  3356     // a white object ...
  3388 
  3388 
  3389 void ParConcMarkingClosure::trim_queue(size_t max) {
  3389 void ParConcMarkingClosure::trim_queue(size_t max) {
  3390   while (_work_queue->size() > max) {
  3390   while (_work_queue->size() > max) {
  3391     oop new_oop;
  3391     oop new_oop;
  3392     if (_work_queue->pop_local(new_oop)) {
  3392     if (_work_queue->pop_local(new_oop)) {
  3393       assert(new_oop->is_oop(), "Should be an oop");
  3393       assert(oopDesc::is_oop(new_oop), "Should be an oop");
  3394       assert(_bit_map->isMarked((HeapWord*)new_oop), "Grey object");
  3394       assert(_bit_map->isMarked((HeapWord*)new_oop), "Grey object");
  3395       assert(_span.contains((HeapWord*)new_oop), "Not in span");
  3395       assert(_span.contains((HeapWord*)new_oop), "Not in span");
  3396       new_oop->oop_iterate(this);  // do_oop() above
  3396       new_oop->oop_iterate(this);  // do_oop() above
  3397       do_yield_check();
  3397       do_yield_check();
  3398     }
  3398     }
  3429       // Can't assert below because the work obtained from the
  3429       // Can't assert below because the work obtained from the
  3430       // overflow stack may already have been stolen from us.
  3430       // overflow stack may already have been stolen from us.
  3431       // assert(work_q->size() > 0, "Work from overflow stack");
  3431       // assert(work_q->size() > 0, "Work from overflow stack");
  3432       continue;
  3432       continue;
  3433     } else if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) {
  3433     } else if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) {
  3434       assert(obj_to_scan->is_oop(), "Should be an oop");
  3434       assert(oopDesc::is_oop(obj_to_scan), "Should be an oop");
  3435       assert(bm->isMarked((HeapWord*)obj_to_scan), "Grey object");
  3435       assert(bm->isMarked((HeapWord*)obj_to_scan), "Grey object");
  3436       obj_to_scan->oop_iterate(&cl);
  3436       obj_to_scan->oop_iterate(&cl);
  3437     } else if (terminator()->offer_termination(&_term_term)) {
  3437     } else if (terminator()->offer_termination(&_term_term)) {
  3438       assert(work_q->size() == 0, "Impossible!");
  3438       assert(work_q->size() == 0, "Impossible!");
  3439       break;
  3439       break;
  4520       MemRegion mr(start, end);
  4520       MemRegion mr(start, end);
  4521       // Verify that mr is in space
  4521       // Verify that mr is in space
  4522       assert(mr.is_empty() || space->used_region().contains(mr),
  4522       assert(mr.is_empty() || space->used_region().contains(mr),
  4523              "Should be in space");
  4523              "Should be in space");
  4524       // Verify that "start" is an object boundary
  4524       // Verify that "start" is an object boundary
  4525       assert(mr.is_empty() || oop(mr.start())->is_oop(),
  4525       assert(mr.is_empty() || oopDesc::is_oop(oop(mr.start())),
  4526              "Should be an oop");
  4526              "Should be an oop");
  4527       space->par_oop_iterate(mr, cl);
  4527       space->par_oop_iterate(mr, cl);
  4528     }
  4528     }
  4529     pst->all_tasks_completed();
  4529     pst->all_tasks_completed();
  4530   }
  4530   }
  4654     // Verify that we have no work before we resort to stealing
  4654     // Verify that we have no work before we resort to stealing
  4655     assert(work_q->size() == 0, "Have work, shouldn't steal");
  4655     assert(work_q->size() == 0, "Have work, shouldn't steal");
  4656     // Try to steal from other queues that have work
  4656     // Try to steal from other queues that have work
  4657     if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) {
  4657     if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) {
  4658       NOT_PRODUCT(num_steals++;)
  4658       NOT_PRODUCT(num_steals++;)
  4659       assert(obj_to_scan->is_oop(), "Oops, not an oop!");
  4659       assert(oopDesc::is_oop(obj_to_scan), "Oops, not an oop!");
  4660       assert(bm->isMarked((HeapWord*)obj_to_scan), "Stole an unmarked oop?");
  4660       assert(bm->isMarked((HeapWord*)obj_to_scan), "Stole an unmarked oop?");
  4661       // Do scanning work
  4661       // Do scanning work
  4662       obj_to_scan->oop_iterate(cl);
  4662       obj_to_scan->oop_iterate(cl);
  4663       // Loop around, finish this work, and try to steal some more
  4663       // Loop around, finish this work, and try to steal some more
  4664     } else if (terminator()->offer_termination()) {
  4664     } else if (terminator()->offer_termination()) {
  5133     // Verify that we have no work before we resort to stealing
  5133     // Verify that we have no work before we resort to stealing
  5134     assert(work_q->size() == 0, "Have work, shouldn't steal");
  5134     assert(work_q->size() == 0, "Have work, shouldn't steal");
  5135     // Try to steal from other queues that have work
  5135     // Try to steal from other queues that have work
  5136     if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) {
  5136     if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) {
  5137       NOT_PRODUCT(num_steals++;)
  5137       NOT_PRODUCT(num_steals++;)
  5138       assert(obj_to_scan->is_oop(), "Oops, not an oop!");
  5138       assert(oopDesc::is_oop(obj_to_scan), "Oops, not an oop!");
  5139       assert(_mark_bit_map->isMarked((HeapWord*)obj_to_scan), "Stole an unmarked oop?");
  5139       assert(_mark_bit_map->isMarked((HeapWord*)obj_to_scan), "Stole an unmarked oop?");
  5140       // Do scanning work
  5140       // Do scanning work
  5141       obj_to_scan->oop_iterate(keep_alive);
  5141       obj_to_scan->oop_iterate(keep_alive);
  5142       // Loop around, finish this work, and try to steal some more
  5142       // Loop around, finish this work, and try to steal some more
  5143     } else if (terminator()->offer_termination()) {
  5143     } else if (terminator()->offer_termination()) {
  5823   assert(_bitMap->covers(_span), "_bitMap/_span mismatch");
  5823   assert(_bitMap->covers(_span), "_bitMap/_span mismatch");
  5824 }
  5824 }
  5825 
  5825 
  5826 void MarkRefsIntoClosure::do_oop(oop obj) {
  5826 void MarkRefsIntoClosure::do_oop(oop obj) {
  5827   // if p points into _span, then mark corresponding bit in _markBitMap
  5827   // if p points into _span, then mark corresponding bit in _markBitMap
  5828   assert(obj->is_oop(), "expected an oop");
  5828   assert(oopDesc::is_oop(obj), "expected an oop");
  5829   HeapWord* addr = (HeapWord*)obj;
  5829   HeapWord* addr = (HeapWord*)obj;
  5830   if (_span.contains(addr)) {
  5830   if (_span.contains(addr)) {
  5831     // this should be made more efficient
  5831     // this should be made more efficient
  5832     _bitMap->mark(addr);
  5832     _bitMap->mark(addr);
  5833   }
  5833   }
  5845   assert(_bitMap->covers(_span), "_bitMap/_span mismatch");
  5845   assert(_bitMap->covers(_span), "_bitMap/_span mismatch");
  5846 }
  5846 }
  5847 
  5847 
  5848 void ParMarkRefsIntoClosure::do_oop(oop obj) {
  5848 void ParMarkRefsIntoClosure::do_oop(oop obj) {
  5849   // if p points into _span, then mark corresponding bit in _markBitMap
  5849   // if p points into _span, then mark corresponding bit in _markBitMap
  5850   assert(obj->is_oop(), "expected an oop");
  5850   assert(oopDesc::is_oop(obj), "expected an oop");
  5851   HeapWord* addr = (HeapWord*)obj;
  5851   HeapWord* addr = (HeapWord*)obj;
  5852   if (_span.contains(addr)) {
  5852   if (_span.contains(addr)) {
  5853     // this should be made more efficient
  5853     // this should be made more efficient
  5854     _bitMap->par_mark(addr);
  5854     _bitMap->par_mark(addr);
  5855   }
  5855   }
  5869   assert(_verification_bm->covers(_span), "_verification_bm/_span mismatch");
  5869   assert(_verification_bm->covers(_span), "_verification_bm/_span mismatch");
  5870 }
  5870 }
  5871 
  5871 
  5872 void MarkRefsIntoVerifyClosure::do_oop(oop obj) {
  5872 void MarkRefsIntoVerifyClosure::do_oop(oop obj) {
  5873   // if p points into _span, then mark corresponding bit in _markBitMap
  5873   // if p points into _span, then mark corresponding bit in _markBitMap
  5874   assert(obj->is_oop(), "expected an oop");
  5874   assert(oopDesc::is_oop(obj), "expected an oop");
  5875   HeapWord* addr = (HeapWord*)obj;
  5875   HeapWord* addr = (HeapWord*)obj;
  5876   if (_span.contains(addr)) {
  5876   if (_span.contains(addr)) {
  5877     _verification_bm->mark(addr);
  5877     _verification_bm->mark(addr);
  5878     if (!_cms_bm->isMarked(addr)) {
  5878     if (!_cms_bm->isMarked(addr)) {
  5879       Log(gc, verify) log;
  5879       Log(gc, verify) log;
  5923 // The marks are made in the marking bit map and the marking stack is
  5923 // The marks are made in the marking bit map and the marking stack is
  5924 // used for keeping the (newly) grey objects during the scan.
  5924 // used for keeping the (newly) grey objects during the scan.
  5925 // The parallel version (Par_...) appears further below.
  5925 // The parallel version (Par_...) appears further below.
  5926 void MarkRefsIntoAndScanClosure::do_oop(oop obj) {
  5926 void MarkRefsIntoAndScanClosure::do_oop(oop obj) {
  5927   if (obj != NULL) {
  5927   if (obj != NULL) {
  5928     assert(obj->is_oop(), "expected an oop");
  5928     assert(oopDesc::is_oop(obj), "expected an oop");
  5929     HeapWord* addr = (HeapWord*)obj;
  5929     HeapWord* addr = (HeapWord*)obj;
  5930     assert(_mark_stack->isEmpty(), "pre-condition (eager drainage)");
  5930     assert(_mark_stack->isEmpty(), "pre-condition (eager drainage)");
  5931     assert(_collector->overflow_list_is_empty(),
  5931     assert(_collector->overflow_list_is_empty(),
  5932            "overflow list should be empty");
  5932            "overflow list should be empty");
  5933     if (_span.contains(addr) &&
  5933     if (_span.contains(addr) &&
  5939       // from the stack (i.e. blacken the grey objects)
  5939       // from the stack (i.e. blacken the grey objects)
  5940       bool res = _mark_stack->push(obj);
  5940       bool res = _mark_stack->push(obj);
  5941       assert(res, "Should have space to push on empty stack");
  5941       assert(res, "Should have space to push on empty stack");
  5942       do {
  5942       do {
  5943         oop new_oop = _mark_stack->pop();
  5943         oop new_oop = _mark_stack->pop();
  5944         assert(new_oop != NULL && new_oop->is_oop(), "Expected an oop");
  5944         assert(new_oop != NULL && oopDesc::is_oop(new_oop), "Expected an oop");
  5945         assert(_bit_map->isMarked((HeapWord*)new_oop),
  5945         assert(_bit_map->isMarked((HeapWord*)new_oop),
  5946                "only grey objects on this stack");
  5946                "only grey objects on this stack");
  5947         // iterate over the oops in this oop, marking and pushing
  5947         // iterate over the oops in this oop, marking and pushing
  5948         // the ones in CMS heap (i.e. in _span).
  5948         // the ones in CMS heap (i.e. in _span).
  5949         new_oop->oop_iterate(&_pushAndMarkClosure);
  5949         new_oop->oop_iterate(&_pushAndMarkClosure);
  6021 // synchronized (via CAS).
  6021 // synchronized (via CAS).
  6022 void ParMarkRefsIntoAndScanClosure::do_oop(oop obj) {
  6022 void ParMarkRefsIntoAndScanClosure::do_oop(oop obj) {
  6023   if (obj != NULL) {
  6023   if (obj != NULL) {
  6024     // Ignore mark word because this could be an already marked oop
  6024     // Ignore mark word because this could be an already marked oop
  6025     // that may be chained at the end of the overflow list.
  6025     // that may be chained at the end of the overflow list.
  6026     assert(obj->is_oop(true), "expected an oop");
  6026     assert(oopDesc::is_oop(obj, true), "expected an oop");
  6027     HeapWord* addr = (HeapWord*)obj;
  6027     HeapWord* addr = (HeapWord*)obj;
  6028     if (_span.contains(addr) &&
  6028     if (_span.contains(addr) &&
  6029         !_bit_map->isMarked(addr)) {
  6029         !_bit_map->isMarked(addr)) {
  6030       // mark bit map (object will become grey):
  6030       // mark bit map (object will become grey):
  6031       // It is possible for several threads to be
  6031       // It is possible for several threads to be
  6067   if (_bitMap->isMarked(addr)) {
  6067   if (_bitMap->isMarked(addr)) {
  6068     // it's marked; is it potentially uninitialized?
  6068     // it's marked; is it potentially uninitialized?
  6069     if (p->klass_or_null_acquire() != NULL) {
  6069     if (p->klass_or_null_acquire() != NULL) {
  6070         // an initialized object; ignore mark word in verification below
  6070         // an initialized object; ignore mark word in verification below
  6071         // since we are running concurrent with mutators
  6071         // since we are running concurrent with mutators
  6072         assert(p->is_oop(true), "should be an oop");
  6072         assert(oopDesc::is_oop(p, true), "should be an oop");
  6073         if (p->is_objArray()) {
  6073         if (p->is_objArray()) {
  6074           // objArrays are precisely marked; restrict scanning
  6074           // objArrays are precisely marked; restrict scanning
  6075           // to dirty cards only.
  6075           // to dirty cards only.
  6076           size = CompactibleFreeListSpace::adjustObjectSize(
  6076           size = CompactibleFreeListSpace::adjustObjectSize(
  6077                    p->oop_iterate_size(_scanningClosure, mr));
  6077                    p->oop_iterate_size(_scanningClosure, mr));
  6116       // we may not be able to read its P-bits yet.
  6116       // we may not be able to read its P-bits yet.
  6117       assert(size == 0, "Initial value");
  6117       assert(size == 0, "Initial value");
  6118     } else {
  6118     } else {
  6119       // An object not (yet) reached by marking: we merely need to
  6119       // An object not (yet) reached by marking: we merely need to
  6120       // compute its size so as to go look at the next block.
  6120       // compute its size so as to go look at the next block.
  6121       assert(p->is_oop(true), "should be an oop");
  6121       assert(oopDesc::is_oop(p, true), "should be an oop");
  6122       size = CompactibleFreeListSpace::adjustObjectSize(p->size());
  6122       size = CompactibleFreeListSpace::adjustObjectSize(p->size());
  6123     }
  6123     }
  6124   }
  6124   }
  6125   DEBUG_ONLY(_collector->verify_work_stacks_empty();)
  6125   DEBUG_ONLY(_collector->verify_work_stacks_empty();)
  6126   return size;
  6126   return size;
  6163   DEBUG_ONLY(_collector->verify_work_stacks_empty();)
  6163   DEBUG_ONLY(_collector->verify_work_stacks_empty();)
  6164   assert(!_span.contains(addr), "we are scanning the survivor spaces");
  6164   assert(!_span.contains(addr), "we are scanning the survivor spaces");
  6165   assert(p->klass_or_null() != NULL, "object should be initialized");
  6165   assert(p->klass_or_null() != NULL, "object should be initialized");
  6166   // an initialized object; ignore mark word in verification below
  6166   // an initialized object; ignore mark word in verification below
  6167   // since we are running concurrent with mutators
  6167   // since we are running concurrent with mutators
  6168   assert(p->is_oop(true), "should be an oop");
  6168   assert(oopDesc::is_oop(p, true), "should be an oop");
  6169   // Note that we do not yield while we iterate over
  6169   // Note that we do not yield while we iterate over
  6170   // the interior oops of p, pushing the relevant ones
  6170   // the interior oops of p, pushing the relevant ones
  6171   // on our marking stack.
  6171   // on our marking stack.
  6172   size_t size = p->oop_iterate_size(_scanning_closure);
  6172   size_t size = p->oop_iterate_size(_scanning_closure);
  6173   do_yield_check();
  6173   do_yield_check();
  6177   // some existing assertions. In general, it may be a
  6177   // some existing assertions. In general, it may be a
  6178   // good idea to abort immediately and complete the marking
  6178   // good idea to abort immediately and complete the marking
  6179   // from the grey objects at a later time.
  6179   // from the grey objects at a later time.
  6180   while (!_mark_stack->isEmpty()) {
  6180   while (!_mark_stack->isEmpty()) {
  6181     oop new_oop = _mark_stack->pop();
  6181     oop new_oop = _mark_stack->pop();
  6182     assert(new_oop != NULL && new_oop->is_oop(), "Expected an oop");
  6182     assert(new_oop != NULL && oopDesc::is_oop(new_oop), "Expected an oop");
  6183     assert(_bit_map->isMarked((HeapWord*)new_oop),
  6183     assert(_bit_map->isMarked((HeapWord*)new_oop),
  6184            "only grey objects on this stack");
  6184            "only grey objects on this stack");
  6185     // iterate over the oops in this oop, marking and pushing
  6185     // iterate over the oops in this oop, marking and pushing
  6186     // the ones in CMS heap (i.e. in _span).
  6186     // the ones in CMS heap (i.e. in _span).
  6187     new_oop->oop_iterate(_scanning_closure);
  6187     new_oop->oop_iterate(_scanning_closure);
  6221 // in the mod union table and the card table proper. In the parallel
  6221 // in the mod union table and the card table proper. In the parallel
  6222 // case, although the bitMap is shared, we do a single read so the
  6222 // case, although the bitMap is shared, we do a single read so the
  6223 // isMarked() query is "safe".
  6223 // isMarked() query is "safe".
  6224 bool ScanMarkedObjectsAgainClosure::do_object_bm(oop p, MemRegion mr) {
  6224 bool ScanMarkedObjectsAgainClosure::do_object_bm(oop p, MemRegion mr) {
  6225   // Ignore mark word because we are running concurrent with mutators
  6225   // Ignore mark word because we are running concurrent with mutators
  6226   assert(p->is_oop_or_null(true), "Expected an oop or NULL at " PTR_FORMAT, p2i(p));
  6226   assert(oopDesc::is_oop_or_null(p, true), "Expected an oop or NULL at " PTR_FORMAT, p2i(p));
  6227   HeapWord* addr = (HeapWord*)p;
  6227   HeapWord* addr = (HeapWord*)p;
  6228   assert(_span.contains(addr), "we are scanning the CMS generation");
  6228   assert(_span.contains(addr), "we are scanning the CMS generation");
  6229   bool is_obj_array = false;
  6229   bool is_obj_array = false;
  6230   #ifdef ASSERT
  6230   #ifdef ASSERT
  6231     if (!_parallel) {
  6231     if (!_parallel) {
  6374          "should drain stack to limit stack usage");
  6374          "should drain stack to limit stack usage");
  6375   // convert ptr to an oop preparatory to scanning
  6375   // convert ptr to an oop preparatory to scanning
  6376   oop obj = oop(ptr);
  6376   oop obj = oop(ptr);
  6377   // Ignore mark word in verification below, since we
  6377   // Ignore mark word in verification below, since we
  6378   // may be running concurrent with mutators.
  6378   // may be running concurrent with mutators.
  6379   assert(obj->is_oop(true), "should be an oop");
  6379   assert(oopDesc::is_oop(obj, true), "should be an oop");
  6380   assert(_finger <= ptr, "_finger runneth ahead");
  6380   assert(_finger <= ptr, "_finger runneth ahead");
  6381   // advance the finger to right end of this object
  6381   // advance the finger to right end of this object
  6382   _finger = ptr + obj->size();
  6382   _finger = ptr + obj->size();
  6383   assert(_finger > ptr, "we just incremented it above");
  6383   assert(_finger > ptr, "we just incremented it above");
  6384   // On large heaps, it may take us some time to get through
  6384   // On large heaps, it may take us some time to get through
  6421   assert(res, "Empty non-zero size stack should have space for single push");
  6421   assert(res, "Empty non-zero size stack should have space for single push");
  6422   while (!_markStack->isEmpty()) {
  6422   while (!_markStack->isEmpty()) {
  6423     oop new_oop = _markStack->pop();
  6423     oop new_oop = _markStack->pop();
  6424     // Skip verifying header mark word below because we are
  6424     // Skip verifying header mark word below because we are
  6425     // running concurrent with mutators.
  6425     // running concurrent with mutators.
  6426     assert(new_oop->is_oop(true), "Oops! expected to pop an oop");
  6426     assert(oopDesc::is_oop(new_oop, true), "Oops! expected to pop an oop");
  6427     // now scan this oop's oops
  6427     // now scan this oop's oops
  6428     new_oop->oop_iterate(&pushOrMarkClosure);
  6428     new_oop->oop_iterate(&pushOrMarkClosure);
  6429     do_yield_check();
  6429     do_yield_check();
  6430   }
  6430   }
  6431   assert(_markStack->isEmpty(), "tautology, emphasizing post-condition");
  6431   assert(_markStack->isEmpty(), "tautology, emphasizing post-condition");
  6487          "should drain stack to limit stack usage");
  6487          "should drain stack to limit stack usage");
  6488   // convert ptr to an oop preparatory to scanning
  6488   // convert ptr to an oop preparatory to scanning
  6489   oop obj = oop(ptr);
  6489   oop obj = oop(ptr);
  6490   // Ignore mark word in verification below, since we
  6490   // Ignore mark word in verification below, since we
  6491   // may be running concurrent with mutators.
  6491   // may be running concurrent with mutators.
  6492   assert(obj->is_oop(true), "should be an oop");
  6492   assert(oopDesc::is_oop(obj, true), "should be an oop");
  6493   assert(_finger <= ptr, "_finger runneth ahead");
  6493   assert(_finger <= ptr, "_finger runneth ahead");
  6494   // advance the finger to right end of this object
  6494   // advance the finger to right end of this object
  6495   _finger = ptr + obj->size();
  6495   _finger = ptr + obj->size();
  6496   assert(_finger > ptr, "we just incremented it above");
  6496   assert(_finger > ptr, "we just incremented it above");
  6497   // On large heaps, it may take us some time to get through
  6497   // On large heaps, it may take us some time to get through
  6548         break;
  6548         break;
  6549       }
  6549       }
  6550     }
  6550     }
  6551     // Skip verifying header mark word below because we are
  6551     // Skip verifying header mark word below because we are
  6552     // running concurrent with mutators.
  6552     // running concurrent with mutators.
  6553     assert(new_oop->is_oop(true), "Oops! expected to pop an oop");
  6553     assert(oopDesc::is_oop(new_oop, true), "Oops! expected to pop an oop");
  6554     // now scan this oop's oops
  6554     // now scan this oop's oops
  6555     new_oop->oop_iterate(&pushOrMarkClosure);
  6555     new_oop->oop_iterate(&pushOrMarkClosure);
  6556     do_yield_check();
  6556     do_yield_check();
  6557   }
  6557   }
  6558   assert(_work_queue->size() == 0, "tautology, emphasizing post-condition");
  6558   assert(_work_queue->size() == 0, "tautology, emphasizing post-condition");
  6602 
  6602 
  6603   assert(_mark_stack->isEmpty(),
  6603   assert(_mark_stack->isEmpty(),
  6604          "should drain stack to limit stack usage");
  6604          "should drain stack to limit stack usage");
  6605   // convert addr to an oop preparatory to scanning
  6605   // convert addr to an oop preparatory to scanning
  6606   oop obj = oop(addr);
  6606   oop obj = oop(addr);
  6607   assert(obj->is_oop(), "should be an oop");
  6607   assert(oopDesc::is_oop(obj), "should be an oop");
  6608   assert(_finger <= addr, "_finger runneth ahead");
  6608   assert(_finger <= addr, "_finger runneth ahead");
  6609   // advance the finger to right end of this object
  6609   // advance the finger to right end of this object
  6610   _finger = addr + obj->size();
  6610   _finger = addr + obj->size();
  6611   assert(_finger > addr, "we just incremented it above");
  6611   assert(_finger > addr, "we just incremented it above");
  6612   // Note: the finger doesn't advance while we drain
  6612   // Note: the finger doesn't advance while we drain
  6613   // the stack below.
  6613   // the stack below.
  6614   bool res = _mark_stack->push(obj);
  6614   bool res = _mark_stack->push(obj);
  6615   assert(res, "Empty non-zero size stack should have space for single push");
  6615   assert(res, "Empty non-zero size stack should have space for single push");
  6616   while (!_mark_stack->isEmpty()) {
  6616   while (!_mark_stack->isEmpty()) {
  6617     oop new_oop = _mark_stack->pop();
  6617     oop new_oop = _mark_stack->pop();
  6618     assert(new_oop->is_oop(), "Oops! expected to pop an oop");
  6618     assert(oopDesc::is_oop(new_oop), "Oops! expected to pop an oop");
  6619     // now scan this oop's oops
  6619     // now scan this oop's oops
  6620     new_oop->oop_iterate(&_pam_verify_closure);
  6620     new_oop->oop_iterate(&_pam_verify_closure);
  6621   }
  6621   }
  6622   assert(_mark_stack->isEmpty(), "tautology, emphasizing post-condition");
  6622   assert(_mark_stack->isEmpty(), "tautology, emphasizing post-condition");
  6623   return true;
  6623   return true;
  6648   _mark_stack->reset();  // discard stack contents
  6648   _mark_stack->reset();  // discard stack contents
  6649   _mark_stack->expand(); // expand the stack if possible
  6649   _mark_stack->expand(); // expand the stack if possible
  6650 }
  6650 }
  6651 
  6651 
  6652 void PushAndMarkVerifyClosure::do_oop(oop obj) {
  6652 void PushAndMarkVerifyClosure::do_oop(oop obj) {
  6653   assert(obj->is_oop_or_null(), "Expected an oop or NULL at " PTR_FORMAT, p2i(obj));
  6653   assert(oopDesc::is_oop_or_null(obj), "Expected an oop or NULL at " PTR_FORMAT, p2i(obj));
  6654   HeapWord* addr = (HeapWord*)obj;
  6654   HeapWord* addr = (HeapWord*)obj;
  6655   if (_span.contains(addr) && !_verification_bm->isMarked(addr)) {
  6655   if (_span.contains(addr) && !_verification_bm->isMarked(addr)) {
  6656     // Oop lies in _span and isn't yet grey or black
  6656     // Oop lies in _span and isn't yet grey or black
  6657     _verification_bm->mark(addr);            // now grey
  6657     _verification_bm->mark(addr);            // now grey
  6658     if (!_cms_bm->isMarked(addr)) {
  6658     if (!_cms_bm->isMarked(addr)) {
  6745   _overflow_stack->expand(); // expand the stack if possible
  6745   _overflow_stack->expand(); // expand the stack if possible
  6746 }
  6746 }
  6747 
  6747 
  6748 void PushOrMarkClosure::do_oop(oop obj) {
  6748 void PushOrMarkClosure::do_oop(oop obj) {
  6749   // Ignore mark word because we are running concurrent with mutators.
  6749   // Ignore mark word because we are running concurrent with mutators.
  6750   assert(obj->is_oop_or_null(true), "Expected an oop or NULL at " PTR_FORMAT, p2i(obj));
  6750   assert(oopDesc::is_oop_or_null(obj, true), "Expected an oop or NULL at " PTR_FORMAT, p2i(obj));
  6751   HeapWord* addr = (HeapWord*)obj;
  6751   HeapWord* addr = (HeapWord*)obj;
  6752   if (_span.contains(addr) && !_bitMap->isMarked(addr)) {
  6752   if (_span.contains(addr) && !_bitMap->isMarked(addr)) {
  6753     // Oop lies in _span and isn't yet grey or black
  6753     // Oop lies in _span and isn't yet grey or black
  6754     _bitMap->mark(addr);            // now grey
  6754     _bitMap->mark(addr);            // now grey
  6755     if (addr < _finger) {
  6755     if (addr < _finger) {
  6780 void PushOrMarkClosure::do_oop(oop* p)       { PushOrMarkClosure::do_oop_work(p); }
  6780 void PushOrMarkClosure::do_oop(oop* p)       { PushOrMarkClosure::do_oop_work(p); }
  6781 void PushOrMarkClosure::do_oop(narrowOop* p) { PushOrMarkClosure::do_oop_work(p); }
  6781 void PushOrMarkClosure::do_oop(narrowOop* p) { PushOrMarkClosure::do_oop_work(p); }
  6782 
  6782 
  6783 void ParPushOrMarkClosure::do_oop(oop obj) {
  6783 void ParPushOrMarkClosure::do_oop(oop obj) {
  6784   // Ignore mark word because we are running concurrent with mutators.
  6784   // Ignore mark word because we are running concurrent with mutators.
  6785   assert(obj->is_oop_or_null(true), "Expected an oop or NULL at " PTR_FORMAT, p2i(obj));
  6785   assert(oopDesc::is_oop_or_null(obj, true), "Expected an oop or NULL at " PTR_FORMAT, p2i(obj));
  6786   HeapWord* addr = (HeapWord*)obj;
  6786   HeapWord* addr = (HeapWord*)obj;
  6787   if (_whole_span.contains(addr) && !_bit_map->isMarked(addr)) {
  6787   if (_whole_span.contains(addr) && !_bit_map->isMarked(addr)) {
  6788     // Oop lies in _span and isn't yet grey or black
  6788     // Oop lies in _span and isn't yet grey or black
  6789     // We read the global_finger (volatile read) strictly after marking oop
  6789     // We read the global_finger (volatile read) strictly after marking oop
  6790     bool res = _bit_map->par_mark(addr);    // now grey
  6790     bool res = _bit_map->par_mark(addr);    // now grey
  6853   // Ignore mark word verification. If during concurrent precleaning,
  6853   // Ignore mark word verification. If during concurrent precleaning,
  6854   // the object monitor may be locked. If during the checkpoint
  6854   // the object monitor may be locked. If during the checkpoint
  6855   // phases, the object may already have been reached by a  different
  6855   // phases, the object may already have been reached by a  different
  6856   // path and may be at the end of the global overflow list (so
  6856   // path and may be at the end of the global overflow list (so
  6857   // the mark word may be NULL).
  6857   // the mark word may be NULL).
  6858   assert(obj->is_oop_or_null(true /* ignore mark word */),
  6858   assert(oopDesc::is_oop_or_null(obj, true /* ignore mark word */),
  6859          "Expected an oop or NULL at " PTR_FORMAT, p2i(obj));
  6859          "Expected an oop or NULL at " PTR_FORMAT, p2i(obj));
  6860   HeapWord* addr = (HeapWord*)obj;
  6860   HeapWord* addr = (HeapWord*)obj;
  6861   // Check if oop points into the CMS generation
  6861   // Check if oop points into the CMS generation
  6862   // and is not marked
  6862   // and is not marked
  6863   if (_span.contains(addr) && !_bit_map->isMarked(addr)) {
  6863   if (_span.contains(addr) && !_bit_map->isMarked(addr)) {
  6932   // have been subsequently popped off the global overflow
  6932   // have been subsequently popped off the global overflow
  6933   // stack, and the mark word possibly restored to the prototypical
  6933   // stack, and the mark word possibly restored to the prototypical
  6934   // value, by the time we get to examined this failing assert in
  6934   // value, by the time we get to examined this failing assert in
  6935   // the debugger, is_oop_or_null(false) may subsequently start
  6935   // the debugger, is_oop_or_null(false) may subsequently start
  6936   // to hold.
  6936   // to hold.
  6937   assert(obj->is_oop_or_null(true),
  6937   assert(oopDesc::is_oop_or_null(obj, true),
  6938          "Expected an oop or NULL at " PTR_FORMAT, p2i(obj));
  6938          "Expected an oop or NULL at " PTR_FORMAT, p2i(obj));
  6939   HeapWord* addr = (HeapWord*)obj;
  6939   HeapWord* addr = (HeapWord*)obj;
  6940   // Check if oop points into the CMS generation
  6940   // Check if oop points into the CMS generation
  6941   // and is not marked
  6941   // and is not marked
  6942   if (_span.contains(addr) && !_bit_map->isMarked(addr)) {
  6942   if (_span.contains(addr) && !_bit_map->isMarked(addr)) {
  7323     flush_cur_free_chunk(freeFinger(), pointer_delta(addr, freeFinger()));
  7323     flush_cur_free_chunk(freeFinger(), pointer_delta(addr, freeFinger()));
  7324   }
  7324   }
  7325 
  7325 
  7326   // This object is live: we'd normally expect this to be
  7326   // This object is live: we'd normally expect this to be
  7327   // an oop, and like to assert the following:
  7327   // an oop, and like to assert the following:
  7328   // assert(oop(addr)->is_oop(), "live block should be an oop");
  7328   // assert(oopDesc::is_oop(oop(addr)), "live block should be an oop");
  7329   // However, as we commented above, this may be an object whose
  7329   // However, as we commented above, this may be an object whose
  7330   // header hasn't yet been initialized.
  7330   // header hasn't yet been initialized.
  7331   size_t size;
  7331   size_t size;
  7332   assert(_bitMap->isMarked(addr), "Tautology for this control point");
  7332   assert(_bitMap->isMarked(addr), "Tautology for this control point");
  7333   if (_bitMap->isMarked(addr + 1)) {
  7333   if (_bitMap->isMarked(addr + 1)) {
  7339            "alignment problem");
  7339            "alignment problem");
  7340 
  7340 
  7341 #ifdef ASSERT
  7341 #ifdef ASSERT
  7342       if (oop(addr)->klass_or_null_acquire() != NULL) {
  7342       if (oop(addr)->klass_or_null_acquire() != NULL) {
  7343         // Ignore mark word because we are running concurrent with mutators
  7343         // Ignore mark word because we are running concurrent with mutators
  7344         assert(oop(addr)->is_oop(true), "live block should be an oop");
  7344         assert(oopDesc::is_oop(oop(addr), true), "live block should be an oop");
  7345         assert(size ==
  7345         assert(size ==
  7346                CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size()),
  7346                CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size()),
  7347                "P-mark and computed size do not agree");
  7347                "P-mark and computed size do not agree");
  7348       }
  7348       }
  7349 #endif
  7349 #endif
  7351   } else {
  7351   } else {
  7352     // This should be an initialized object that's alive.
  7352     // This should be an initialized object that's alive.
  7353     assert(oop(addr)->klass_or_null_acquire() != NULL,
  7353     assert(oop(addr)->klass_or_null_acquire() != NULL,
  7354            "Should be an initialized object");
  7354            "Should be an initialized object");
  7355     // Ignore mark word because we are running concurrent with mutators
  7355     // Ignore mark word because we are running concurrent with mutators
  7356     assert(oop(addr)->is_oop(true), "live block should be an oop");
  7356     assert(oopDesc::is_oop(oop(addr), true), "live block should be an oop");
  7357     // Verify that the bit map has no bits marked between
  7357     // Verify that the bit map has no bits marked between
  7358     // addr and purported end of this block.
  7358     // addr and purported end of this block.
  7359     size = CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size());
  7359     size = CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size());
  7360     assert(size >= 3, "Necessary for Printezis marks to work");
  7360     assert(size >= 3, "Necessary for Printezis marks to work");
  7361     assert(!_bitMap->isMarked(addr+1), "Tautology for this control point");
  7361     assert(!_bitMap->isMarked(addr+1), "Tautology for this control point");
  7659 
  7659 
  7660 void CMSParKeepAliveClosure::trim_queue(uint max) {
  7660 void CMSParKeepAliveClosure::trim_queue(uint max) {
  7661   while (_work_queue->size() > max) {
  7661   while (_work_queue->size() > max) {
  7662     oop new_oop;
  7662     oop new_oop;
  7663     if (_work_queue->pop_local(new_oop)) {
  7663     if (_work_queue->pop_local(new_oop)) {
  7664       assert(new_oop != NULL && new_oop->is_oop(), "Expected an oop");
  7664       assert(new_oop != NULL && oopDesc::is_oop(new_oop), "Expected an oop");
  7665       assert(_bit_map->isMarked((HeapWord*)new_oop),
  7665       assert(_bit_map->isMarked((HeapWord*)new_oop),
  7666              "no white objects on this stack!");
  7666              "no white objects on this stack!");
  7667       assert(_span.contains((HeapWord*)new_oop), "Out of bounds oop");
  7667       assert(_span.contains((HeapWord*)new_oop), "Out of bounds oop");
  7668       // iterate over the oops in this oop, marking and pushing
  7668       // iterate over the oops in this oop, marking and pushing
  7669       // the ones in CMS heap (i.e. in _span).
  7669       // the ones in CMS heap (i.e. in _span).
  7739          _collector->take_from_overflow_list(num, _mark_stack)) {
  7739          _collector->take_from_overflow_list(num, _mark_stack)) {
  7740     oop obj = _mark_stack->pop();
  7740     oop obj = _mark_stack->pop();
  7741     HeapWord* addr = (HeapWord*)obj;
  7741     HeapWord* addr = (HeapWord*)obj;
  7742     assert(_span.contains(addr), "Should be within span");
  7742     assert(_span.contains(addr), "Should be within span");
  7743     assert(_bit_map->isMarked(addr), "Should be marked");
  7743     assert(_bit_map->isMarked(addr), "Should be marked");
  7744     assert(obj->is_oop(), "Should be an oop");
  7744     assert(oopDesc::is_oop(obj), "Should be an oop");
  7745     obj->oop_iterate(_keep_alive);
  7745     obj->oop_iterate(_keep_alive);
  7746   }
  7746   }
  7747 }
  7747 }
  7748 
  7748 
  7749 void CMSParDrainMarkingStackClosure::do_void() {
  7749 void CMSParDrainMarkingStackClosure::do_void() {
  7754 // Trim our work_queue so its length is below max at return
  7754 // Trim our work_queue so its length is below max at return
  7755 void CMSParDrainMarkingStackClosure::trim_queue(uint max) {
  7755 void CMSParDrainMarkingStackClosure::trim_queue(uint max) {
  7756   while (_work_queue->size() > max) {
  7756   while (_work_queue->size() > max) {
  7757     oop new_oop;
  7757     oop new_oop;
  7758     if (_work_queue->pop_local(new_oop)) {
  7758     if (_work_queue->pop_local(new_oop)) {
  7759       assert(new_oop->is_oop(), "Expected an oop");
  7759       assert(oopDesc::is_oop(new_oop), "Expected an oop");
  7760       assert(_bit_map->isMarked((HeapWord*)new_oop),
  7760       assert(_bit_map->isMarked((HeapWord*)new_oop),
  7761              "no white objects on this stack!");
  7761              "no white objects on this stack!");
  7762       assert(_span.contains((HeapWord*)new_oop), "Out of bounds oop");
  7762       assert(_span.contains((HeapWord*)new_oop), "Out of bounds oop");
  7763       // iterate over the oops in this oop, marking and pushing
  7763       // iterate over the oops in this oop, marking and pushing
  7764       // the ones in CMS heap (i.e. in _span).
  7764       // the ones in CMS heap (i.e. in _span).
  7805   const markOop proto = markOopDesc::prototype();
  7805   const markOop proto = markOopDesc::prototype();
  7806   NOT_PRODUCT(ssize_t n = 0;)
  7806   NOT_PRODUCT(ssize_t n = 0;)
  7807   for (oop next; i > 0 && cur != NULL; cur = next, i--) {
  7807   for (oop next; i > 0 && cur != NULL; cur = next, i--) {
  7808     next = oop(cur->mark());
  7808     next = oop(cur->mark());
  7809     cur->set_mark(proto);   // until proven otherwise
  7809     cur->set_mark(proto);   // until proven otherwise
  7810     assert(cur->is_oop(), "Should be an oop");
  7810     assert(oopDesc::is_oop(cur), "Should be an oop");
  7811     bool res = stack->push(cur);
  7811     bool res = stack->push(cur);
  7812     assert(res, "Bit off more than can chew?");
  7812     assert(res, "Bit off more than can chew?");
  7813     NOT_PRODUCT(n++;)
  7813     NOT_PRODUCT(n++;)
  7814   }
  7814   }
  7815   _overflow_list = cur;
  7815   _overflow_list = cur;
  7949   oop next;
  7949   oop next;
  7950   NOT_PRODUCT(ssize_t n = 0;)
  7950   NOT_PRODUCT(ssize_t n = 0;)
  7951   for (cur = prefix; cur != NULL; cur = next) {
  7951   for (cur = prefix; cur != NULL; cur = next) {
  7952     next = oop(cur->mark());
  7952     next = oop(cur->mark());
  7953     cur->set_mark(proto);   // until proven otherwise
  7953     cur->set_mark(proto);   // until proven otherwise
  7954     assert(cur->is_oop(), "Should be an oop");
  7954     assert(oopDesc::is_oop(cur), "Should be an oop");
  7955     bool res = work_q->push(cur);
  7955     bool res = work_q->push(cur);
  7956     assert(res, "Bit off more than we can chew?");
  7956     assert(res, "Bit off more than we can chew?");
  7957     NOT_PRODUCT(n++;)
  7957     NOT_PRODUCT(n++;)
  7958   }
  7958   }
  7959 #ifndef PRODUCT
  7959 #ifndef PRODUCT
  7964 }
  7964 }
  7965 
  7965 
  7966 // Single-threaded
  7966 // Single-threaded
  7967 void CMSCollector::push_on_overflow_list(oop p) {
  7967 void CMSCollector::push_on_overflow_list(oop p) {
  7968   NOT_PRODUCT(_num_par_pushes++;)
  7968   NOT_PRODUCT(_num_par_pushes++;)
  7969   assert(p->is_oop(), "Not an oop");
  7969   assert(oopDesc::is_oop(p), "Not an oop");
  7970   preserve_mark_if_necessary(p);
  7970   preserve_mark_if_necessary(p);
  7971   p->set_mark((markOop)_overflow_list);
  7971   p->set_mark((markOop)_overflow_list);
  7972   _overflow_list = p;
  7972   _overflow_list = p;
  7973 }
  7973 }
  7974 
  7974 
  7975 // Multi-threaded; use CAS to prepend to overflow list
  7975 // Multi-threaded; use CAS to prepend to overflow list
  7976 void CMSCollector::par_push_on_overflow_list(oop p) {
  7976 void CMSCollector::par_push_on_overflow_list(oop p) {
  7977   NOT_PRODUCT(Atomic::inc_ptr(&_num_par_pushes);)
  7977   NOT_PRODUCT(Atomic::inc_ptr(&_num_par_pushes);)
  7978   assert(p->is_oop(), "Not an oop");
  7978   assert(oopDesc::is_oop(p), "Not an oop");
  7979   par_preserve_mark_if_necessary(p);
  7979   par_preserve_mark_if_necessary(p);
  7980   oop observed_overflow_list = _overflow_list;
  7980   oop observed_overflow_list = _overflow_list;
  7981   oop cur_overflow_list;
  7981   oop cur_overflow_list;
  7982   do {
  7982   do {
  7983     cur_overflow_list = observed_overflow_list;
  7983     cur_overflow_list = observed_overflow_list;
  8060   assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(),
  8060   assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(),
  8061          "bijection");
  8061          "bijection");
  8062 
  8062 
  8063   while (!_preserved_oop_stack.is_empty()) {
  8063   while (!_preserved_oop_stack.is_empty()) {
  8064     oop p = _preserved_oop_stack.pop();
  8064     oop p = _preserved_oop_stack.pop();
  8065     assert(p->is_oop(), "Should be an oop");
  8065     assert(oopDesc::is_oop(p), "Should be an oop");
  8066     assert(_span.contains(p), "oop should be in _span");
  8066     assert(_span.contains(p), "oop should be in _span");
  8067     assert(p->mark() == markOopDesc::prototype(),
  8067     assert(p->mark() == markOopDesc::prototype(),
  8068            "Set when taken from overflow list");
  8068            "Set when taken from overflow list");
  8069     markOop m = _preserved_mark_stack.pop();
  8069     markOop m = _preserved_mark_stack.pop();
  8070     p->set_mark(m);
  8070     p->set_mark(m);