hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp
changeset 613 2aa2b913106c
parent 390 2e094c1be4af
child 670 ddf3e9583f2f
child 1376 f7fc7a708b63
equal deleted inserted replaced
611:ffce0f5e4840 613:2aa2b913106c
   188   // Verify the assumption that FreeChunk::_prev and OopDesc::_klass
   188   // Verify the assumption that FreeChunk::_prev and OopDesc::_klass
   189   // offsets match. The ability to tell free chunks from objects
   189   // offsets match. The ability to tell free chunks from objects
   190   // depends on this property.
   190   // depends on this property.
   191   debug_only(
   191   debug_only(
   192     FreeChunk* junk = NULL;
   192     FreeChunk* junk = NULL;
   193     assert(junk->prev_addr() == (void*)(oop(junk)->klass_addr()),
   193     assert(UseCompressedOops ||
       
   194            junk->prev_addr() == (void*)(oop(junk)->klass_addr()),
   194            "Offset of FreeChunk::_prev within FreeChunk must match"
   195            "Offset of FreeChunk::_prev within FreeChunk must match"
   195            "  that of OopDesc::_klass within OopDesc");
   196            "  that of OopDesc::_klass within OopDesc");
   196   )
   197   )
   197   if (ParallelGCThreads > 0) {
   198   if (ParallelGCThreads > 0) {
   198     typedef CMSParGCThreadState* CMSParGCThreadStatePtr;
   199     typedef CMSParGCThreadState* CMSParGCThreadStatePtr;
  1037     _markBitMap.mark(start + 1);      // object is potentially uninitialized?
  1038     _markBitMap.mark(start + 1);      // object is potentially uninitialized?
  1038     _markBitMap.mark(start + size - 1);
  1039     _markBitMap.mark(start + size - 1);
  1039                                       // mark end of object
  1040                                       // mark end of object
  1040   }
  1041   }
  1041   // check that oop looks uninitialized
  1042   // check that oop looks uninitialized
  1042   assert(oop(start)->klass() == NULL, "_klass should be NULL");
  1043   assert(oop(start)->klass_or_null() == NULL, "_klass should be NULL");
  1043 }
  1044 }
  1044 
  1045 
  1045 void CMSCollector::promoted(bool par, HeapWord* start,
  1046 void CMSCollector::promoted(bool par, HeapWord* start,
  1046                             bool is_obj_array, size_t obj_size) {
  1047                             bool is_obj_array, size_t obj_size) {
  1047   assert(_markBitMap.covers(start), "Out of bounds");
  1048   assert(_markBitMap.covers(start), "Out of bounds");
  1307      if (obj_ptr == NULL) {
  1308      if (obj_ptr == NULL) {
  1308        return NULL;
  1309        return NULL;
  1309      }
  1310      }
  1310   }
  1311   }
  1311   oop obj = oop(obj_ptr);
  1312   oop obj = oop(obj_ptr);
  1312   assert(obj->klass() == NULL, "Object should be uninitialized here.");
  1313   assert(obj->klass_or_null() == NULL, "Object should be uninitialized here.");
  1313   // Otherwise, copy the object.  Here we must be careful to insert the
  1314   // Otherwise, copy the object.  Here we must be careful to insert the
  1314   // klass pointer last, since this marks the block as an allocated object.
  1315   // klass pointer last, since this marks the block as an allocated object.
       
  1316   // Except with compressed oops it's the mark word.
  1315   HeapWord* old_ptr = (HeapWord*)old;
  1317   HeapWord* old_ptr = (HeapWord*)old;
  1316   if (word_sz > (size_t)oopDesc::header_size()) {
  1318   if (word_sz > (size_t)oopDesc::header_size()) {
  1317     Copy::aligned_disjoint_words(old_ptr + oopDesc::header_size(),
  1319     Copy::aligned_disjoint_words(old_ptr + oopDesc::header_size(),
  1318                                  obj_ptr + oopDesc::header_size(),
  1320                                  obj_ptr + oopDesc::header_size(),
  1319                                  word_sz - oopDesc::header_size());
  1321                                  word_sz - oopDesc::header_size());
  1320   }
  1322   }
       
  1323 
       
  1324   if (UseCompressedOops) {
       
  1325     // Copy gap missed by (aligned) header size calculation above
       
  1326     obj->set_klass_gap(old->klass_gap());
       
  1327   }
       
  1328 
  1321   // Restore the mark word copied above.
  1329   // Restore the mark word copied above.
  1322   obj->set_mark(m);
  1330   obj->set_mark(m);
       
  1331 
  1323   // Now we can track the promoted object, if necessary.  We take care
  1332   // Now we can track the promoted object, if necessary.  We take care
  1324   // To delay the transition from uninitialized to full object
  1333   // To delay the transition from uninitialized to full object
  1325   // (i.e., insertion of klass pointer) until after, so that it
  1334   // (i.e., insertion of klass pointer) until after, so that it
  1326   // atomically becomes a promoted object.
  1335   // atomically becomes a promoted object.
  1327   if (promoInfo->tracking()) {
  1336   if (promoInfo->tracking()) {
  1328     promoInfo->track((PromotedObject*)obj, old->klass());
  1337     promoInfo->track((PromotedObject*)obj, old->klass());
  1329   }
  1338   }
  1330   // Finally, install the klass pointer.
  1339 
       
  1340   // Finally, install the klass pointer (this should be volatile).
  1331   obj->set_klass(old->klass());
  1341   obj->set_klass(old->klass());
  1332 
  1342 
  1333   assert(old->is_oop(), "Will dereference klass ptr below");
  1343   assert(old->is_oop(), "Will dereference klass ptr below");
  1334   collector()->promoted(true,          // parallel
  1344   collector()->promoted(true,          // parallel
  1335                         obj_ptr, old->is_objArray(), word_sz);
  1345                         obj_ptr, old->is_objArray(), word_sz);
  6163 }
  6173 }
  6164 
  6174 
  6165 HeapWord* CMSCollector::next_card_start_after_block(HeapWord* addr) const {
  6175 HeapWord* CMSCollector::next_card_start_after_block(HeapWord* addr) const {
  6166   size_t sz = 0;
  6176   size_t sz = 0;
  6167   oop p = (oop)addr;
  6177   oop p = (oop)addr;
  6168   if (p->klass() != NULL && p->is_parsable()) {
  6178   if (p->klass_or_null() != NULL && p->is_parsable()) {
  6169     sz = CompactibleFreeListSpace::adjustObjectSize(p->size());
  6179     sz = CompactibleFreeListSpace::adjustObjectSize(p->size());
  6170   } else {
  6180   } else {
  6171     sz = block_size_using_printezis_bits(addr);
  6181     sz = block_size_using_printezis_bits(addr);
  6172   }
  6182   }
  6173   assert(sz > 0, "size must be nonzero");
  6183   assert(sz > 0, "size must be nonzero");
  6600     // and we have been asked to abort this ongoing preclean cycle.
  6610     // and we have been asked to abort this ongoing preclean cycle.
  6601     return 0;
  6611     return 0;
  6602   }
  6612   }
  6603   if (_bitMap->isMarked(addr)) {
  6613   if (_bitMap->isMarked(addr)) {
  6604     // it's marked; is it potentially uninitialized?
  6614     // it's marked; is it potentially uninitialized?
  6605     if (p->klass() != NULL) {
  6615     if (p->klass_or_null() != NULL) {
  6606       if (CMSPermGenPrecleaningEnabled && !p->is_parsable()) {
  6616       if (CMSPermGenPrecleaningEnabled && !p->is_parsable()) {
  6607         // Signal precleaning to redirty the card since
  6617         // Signal precleaning to redirty the card since
  6608         // the klass pointer is already installed.
  6618         // the klass pointer is already installed.
  6609         assert(size == 0, "Initial value");
  6619         assert(size == 0, "Initial value");
  6610       } else {
  6620       } else {
  6613         // since we are running concurrent with mutators
  6623         // since we are running concurrent with mutators
  6614         assert(p->is_oop(true), "should be an oop");
  6624         assert(p->is_oop(true), "should be an oop");
  6615         if (p->is_objArray()) {
  6625         if (p->is_objArray()) {
  6616           // objArrays are precisely marked; restrict scanning
  6626           // objArrays are precisely marked; restrict scanning
  6617           // to dirty cards only.
  6627           // to dirty cards only.
  6618           size = p->oop_iterate(_scanningClosure, mr);
  6628           size = CompactibleFreeListSpace::adjustObjectSize(
  6619           assert(size == CompactibleFreeListSpace::adjustObjectSize(size),
  6629                    p->oop_iterate(_scanningClosure, mr));
  6620                  "adjustObjectSize should be the identity for array sizes, "
       
  6621                  "which are necessarily larger than minimum object size of "
       
  6622                  "two heap words");
       
  6623         } else {
  6630         } else {
  6624           // A non-array may have been imprecisely marked; we need
  6631           // A non-array may have been imprecisely marked; we need
  6625           // to scan object in its entirety.
  6632           // to scan object in its entirety.
  6626           size = CompactibleFreeListSpace::adjustObjectSize(
  6633           size = CompactibleFreeListSpace::adjustObjectSize(
  6627                    p->oop_iterate(_scanningClosure));
  6634                    p->oop_iterate(_scanningClosure));
  6651       // will dirty the card when the klass pointer is installed in the
  6658       // will dirty the card when the klass pointer is installed in the
  6652       // object (signalling the completion of initialization).
  6659       // object (signalling the completion of initialization).
  6653     }
  6660     }
  6654   } else {
  6661   } else {
  6655     // Either a not yet marked object or an uninitialized object
  6662     // Either a not yet marked object or an uninitialized object
  6656     if (p->klass() == NULL || !p->is_parsable()) {
  6663     if (p->klass_or_null() == NULL || !p->is_parsable()) {
  6657       // An uninitialized object, skip to the next card, since
  6664       // An uninitialized object, skip to the next card, since
  6658       // we may not be able to read its P-bits yet.
  6665       // we may not be able to read its P-bits yet.
  6659       assert(size == 0, "Initial value");
  6666       assert(size == 0, "Initial value");
  6660     } else {
  6667     } else {
  6661       // An object not (yet) reached by marking: we merely need to
  6668       // An object not (yet) reached by marking: we merely need to
  6708 size_t SurvivorSpacePrecleanClosure::do_object_careful(oop p) {
  6715 size_t SurvivorSpacePrecleanClosure::do_object_careful(oop p) {
  6709 
  6716 
  6710   HeapWord* addr = (HeapWord*)p;
  6717   HeapWord* addr = (HeapWord*)p;
  6711   DEBUG_ONLY(_collector->verify_work_stacks_empty();)
  6718   DEBUG_ONLY(_collector->verify_work_stacks_empty();)
  6712   assert(!_span.contains(addr), "we are scanning the survivor spaces");
  6719   assert(!_span.contains(addr), "we are scanning the survivor spaces");
  6713   assert(p->klass() != NULL, "object should be initializd");
  6720   assert(p->klass_or_null() != NULL, "object should be initializd");
  6714   assert(p->is_parsable(), "must be parsable.");
  6721   assert(p->is_parsable(), "must be parsable.");
  6715   // an initialized object; ignore mark word in verification below
  6722   // an initialized object; ignore mark word in verification below
  6716   // since we are running concurrent with mutators
  6723   // since we are running concurrent with mutators
  6717   assert(p->is_oop(true), "should be an oop");
  6724   assert(p->is_oop(true), "should be an oop");
  6718   // Note that we do not yield while we iterate over
  6725   // Note that we do not yield while we iterate over
  6866   if (_bitMap->isMarked(addr+1)) {
  6873   if (_bitMap->isMarked(addr+1)) {
  6867     // this is an allocated but not yet initialized object
  6874     // this is an allocated but not yet initialized object
  6868     assert(_skipBits == 0, "tautology");
  6875     assert(_skipBits == 0, "tautology");
  6869     _skipBits = 2;  // skip next two marked bits ("Printezis-marks")
  6876     _skipBits = 2;  // skip next two marked bits ("Printezis-marks")
  6870     oop p = oop(addr);
  6877     oop p = oop(addr);
  6871     if (p->klass() == NULL || !p->is_parsable()) {
  6878     if (p->klass_or_null() == NULL || !p->is_parsable()) {
  6872       DEBUG_ONLY(if (!_verifying) {)
  6879       DEBUG_ONLY(if (!_verifying) {)
  6873         // We re-dirty the cards on which this object lies and increase
  6880         // We re-dirty the cards on which this object lies and increase
  6874         // the _threshold so that we'll come back to scan this object
  6881         // the _threshold so that we'll come back to scan this object
  6875         // during the preclean or remark phase. (CMSCleanOnEnter)
  6882         // during the preclean or remark phase. (CMSCleanOnEnter)
  6876         if (CMSCleanOnEnter) {
  6883         if (CMSCleanOnEnter) {
  6888           assert(_threshold <= end_card_addr,
  6895           assert(_threshold <= end_card_addr,
  6889                  "Because we are just scanning into this object");
  6896                  "Because we are just scanning into this object");
  6890           if (_threshold < end_card_addr) {
  6897           if (_threshold < end_card_addr) {
  6891             _threshold = end_card_addr;
  6898             _threshold = end_card_addr;
  6892           }
  6899           }
  6893           if (p->klass() != NULL) {
  6900           if (p->klass_or_null() != NULL) {
  6894             // Redirty the range of cards...
  6901             // Redirty the range of cards...
  6895             _mut->mark_range(redirty_range);
  6902             _mut->mark_range(redirty_range);
  6896           } // ...else the setting of klass will dirty the card anyway.
  6903           } // ...else the setting of klass will dirty the card anyway.
  6897         }
  6904         }
  6898       DEBUG_ONLY(})
  6905       DEBUG_ONLY(})
  7046   if (_bit_map->isMarked(addr+1)) {
  7053   if (_bit_map->isMarked(addr+1)) {
  7047     // this is an allocated object that might not yet be initialized
  7054     // this is an allocated object that might not yet be initialized
  7048     assert(_skip_bits == 0, "tautology");
  7055     assert(_skip_bits == 0, "tautology");
  7049     _skip_bits = 2;  // skip next two marked bits ("Printezis-marks")
  7056     _skip_bits = 2;  // skip next two marked bits ("Printezis-marks")
  7050     oop p = oop(addr);
  7057     oop p = oop(addr);
  7051     if (p->klass() == NULL || !p->is_parsable()) {
  7058     if (p->klass_or_null() == NULL || !p->is_parsable()) {
  7052       // in the case of Clean-on-Enter optimization, redirty card
  7059       // in the case of Clean-on-Enter optimization, redirty card
  7053       // and avoid clearing card by increasing  the threshold.
  7060       // and avoid clearing card by increasing  the threshold.
  7054       return;
  7061       return;
  7055     }
  7062     }
  7056   }
  7063   }
  8021     size = pointer_delta(nextOneAddr + 1, addr);
  8028     size = pointer_delta(nextOneAddr + 1, addr);
  8022     assert(size == CompactibleFreeListSpace::adjustObjectSize(size),
  8029     assert(size == CompactibleFreeListSpace::adjustObjectSize(size),
  8023            "alignment problem");
  8030            "alignment problem");
  8024 
  8031 
  8025     #ifdef DEBUG
  8032     #ifdef DEBUG
  8026       if (oop(addr)->klass() != NULL &&
  8033       if (oop(addr)->klass_or_null() != NULL &&
  8027           (   !_collector->should_unload_classes()
  8034           (   !_collector->should_unload_classes()
  8028            || oop(addr)->is_parsable())) {
  8035            || oop(addr)->is_parsable())) {
  8029         // Ignore mark word because we are running concurrent with mutators
  8036         // Ignore mark word because we are running concurrent with mutators
  8030         assert(oop(addr)->is_oop(true), "live block should be an oop");
  8037         assert(oop(addr)->is_oop(true), "live block should be an oop");
  8031         assert(size ==
  8038         assert(size ==
  8034       }
  8041       }
  8035     #endif
  8042     #endif
  8036 
  8043 
  8037   } else {
  8044   } else {
  8038     // This should be an initialized object that's alive.
  8045     // This should be an initialized object that's alive.
  8039     assert(oop(addr)->klass() != NULL &&
  8046     assert(oop(addr)->klass_or_null() != NULL &&
  8040            (!_collector->should_unload_classes()
  8047            (!_collector->should_unload_classes()
  8041             || oop(addr)->is_parsable()),
  8048             || oop(addr)->is_parsable()),
  8042            "Should be an initialized object");
  8049            "Should be an initialized object");
  8043     // Ignore mark word because we are running concurrent with mutators
  8050     // Ignore mark word because we are running concurrent with mutators
  8044     assert(oop(addr)->is_oop(true), "live block should be an oop");
  8051     assert(oop(addr)->is_oop(true), "live block should be an oop");