< prev index next >

src/hotspot/share/gc/cms/promotionInfo.cpp

Print this page




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/cms/compactibleFreeListSpace.hpp"
  27 #include "gc/cms/promotionInfo.hpp"
  28 #include "gc/shared/genOopClosures.hpp"
  29 #include "oops/compressedOops.inline.hpp"
  30 #include "oops/markWord.inline.hpp"
  31 #include "oops/oop.inline.hpp"
  32 
  33 /////////////////////////////////////////////////////////////////////////
  34 //// PromotionInfo
  35 /////////////////////////////////////////////////////////////////////////
  36 
  37 
  38 PromotedObject* PromotedObject::next() const {
  39   assert(!((FreeChunk*)this)->is_free(), "Error");
  40   PromotedObject* res;
  41   if (UseCompressedOops) {
  42     // The next pointer is a compressed oop stored in the top 32 bits
  43     res = (PromotedObject*)CompressedOops::decode(_data._narrow_next);
  44   } else {
  45     res = (PromotedObject*)(_next & next_mask);
  46   }
  47   assert(oopDesc::is_oop_or_null(oop(res), true /* ignore mark word */), "Expected an oop or NULL at " PTR_FORMAT, p2i(oop(res)));
  48   return res;
  49 }
  50 
  51 inline void PromotedObject::setNext(PromotedObject* x) {
  52   assert(((intptr_t)x & ~next_mask) == 0, "Conflict in bit usage, "
  53          "or insufficient alignment of objects");
  54   if (UseCompressedOops) {
  55     assert(_data._narrow_next == 0, "Overwrite?");
  56     _data._narrow_next = CompressedOops::encode(oop(x));
  57   } else {
  58     _next |= (intptr_t)x;
  59   }
  60   assert(!((FreeChunk*)this)->is_free(), "Error");
  61 }
  62 
  63 // Return the next displaced header, incrementing the pointer and
  64 // recycling spool area as necessary.
  65 markWord PromotionInfo::nextDisplacedHeader() {
  66   assert(_spoolHead != NULL, "promotionInfo inconsistency");
  67   assert(_spoolHead != _spoolTail || _firstIndex < _nextIndex,
  68          "Empty spool space: no displaced header can be fetched");
  69   assert(_spoolHead->bufferSize > _firstIndex, "Off by one error at head?");
  70   markWord hdr = _spoolHead->displacedHdr[_firstIndex];
  71   // Spool forward
  72   if (++_firstIndex == _spoolHead->bufferSize) { // last location in this block
  73     // forward to next block, recycling this block into spare spool buffer
  74     SpoolBlock* tmp = _spoolHead->nextSpoolBlock;
  75     assert(_spoolHead != _spoolTail, "Spooling storage mix-up");
  76     _spoolHead->nextSpoolBlock = _spareSpool;
  77     _spareSpool = _spoolHead;
  78     _spoolHead = tmp;
  79     _firstIndex = 1;
  80     NOT_PRODUCT(
  81       if (_spoolHead == NULL) {  // all buffers fully consumed
  82         assert(_spoolTail == NULL && _nextIndex == 1,
  83                "spool buffers processing inconsistency");
  84       }
  85     )
  86   }
  87   return hdr;
  88 }
  89 
  90 void PromotionInfo::track(PromotedObject* trackOop) {
  91   track(trackOop, oop(trackOop)->klass());
  92 }
  93 
  94 void PromotionInfo::track(PromotedObject* trackOop, Klass* klassOfOop) {
  95   // make a copy of header as it may need to be spooled
  96   markWord mark = oop(trackOop)->mark_raw();
  97   trackOop->clear_next();
  98   if (mark.must_be_preserved_for_cms_scavenge(klassOfOop)) {
  99     // save non-prototypical header, and mark oop
 100     saveDisplacedHeader(mark);
 101     trackOop->setDisplacedMark();
 102   } else {
 103     // we'd like to assert something like the following:
 104     // assert(mark == markWord::prototype(), "consistency check");
 105     // ... but the above won't work because the age bits have not (yet) been
 106     // cleared. The remainder of the check would be identical to the
 107     // condition checked in must_be_preserved() above, so we don't really
 108     // have anything useful to check here!
 109   }
 110   if (_promoTail != NULL) {
 111     assert(_promoHead != NULL, "List consistency");
 112     _promoTail->setNext(trackOop);
 113     _promoTail = trackOop;
 114   } else {
 115     assert(_promoHead == NULL, "List consistency");
 116     _promoHead = _promoTail = trackOop;
 117   }
 118   // Mask as newly promoted, so we can skip over such objects
 119   // when scanning dirty cards
 120   assert(!trackOop->hasPromotedMark(), "Should not have been marked");
 121   trackOop->setPromotedMark();
 122 }
 123 
 124 // Save the given displaced header, incrementing the pointer and
 125 // obtaining more spool area as necessary.
 126 void PromotionInfo::saveDisplacedHeader(markWord hdr) {
 127   assert(_spoolHead != NULL && _spoolTail != NULL,
 128          "promotionInfo inconsistency");
 129   assert(_spoolTail->bufferSize > _nextIndex, "Off by one error at tail?");
 130   _spoolTail->displacedHdr[_nextIndex] = hdr;
 131   // Spool forward
 132   if (++_nextIndex == _spoolTail->bufferSize) { // last location in this block
 133     // get a new spooling block
 134     assert(_spoolTail->nextSpoolBlock == NULL, "tail should terminate spool list");
 135     _splice_point = _spoolTail;                   // save for splicing
 136     _spoolTail->nextSpoolBlock = getSpoolBlock(); // might fail
 137     _spoolTail = _spoolTail->nextSpoolBlock;      // might become NULL ...
 138     // ... but will attempt filling before next promotion attempt
 139     _nextIndex = 1;
 140   }
 141 }
 142 
 143 // Ensure that spooling space exists. Return false if spooling space
 144 // could not be obtained.
 145 bool PromotionInfo::ensure_spooling_space_work() {
 146   assert(!has_spooling_space(), "Only call when there is no spooling space");




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/cms/compactibleFreeListSpace.hpp"
  27 #include "gc/cms/promotionInfo.hpp"
  28 #include "gc/shared/genOopClosures.hpp"
  29 #include "oops/compressedOops.inline.hpp"
  30 #include "oops/markOop.inline.hpp"
  31 #include "oops/oop.hpp"
  32 
  33 /////////////////////////////////////////////////////////////////////////
  34 //// PromotionInfo
  35 /////////////////////////////////////////////////////////////////////////
  36 
  37 
  38 PromotedObject* PromotedObject::next() const {
  39   assert(!((FreeChunk*)this)->is_free(), "Error");
  40   PromotedObject* res;
  41   if (UseCompressedOops) {
  42     // The next pointer is a compressed oop stored in the top 32 bits
  43     res = (PromotedObject*)CompressedOops::decode(_data._narrow_next);
  44   } else {
  45     res = (PromotedObject*)(_next & next_mask);
  46   }
  47   assert(oopDesc::is_oop_or_null(oop(res), true /* ignore mark word */), "Expected an oop or NULL at " PTR_FORMAT, p2i(oop(res)));
  48   return res;
  49 }
  50 
  51 inline void PromotedObject::setNext(PromotedObject* x) {
  52   assert(((intptr_t)x & ~next_mask) == 0, "Conflict in bit usage, "
  53          "or insufficient alignment of objects");
  54   if (UseCompressedOops) {
  55     assert(_data._narrow_next == 0, "Overwrite?");
  56     _data._narrow_next = CompressedOops::encode(oop(x));
  57   } else {
  58     _next |= (intptr_t)x;
  59   }
  60   assert(!((FreeChunk*)this)->is_free(), "Error");
  61 }
  62 
  63 // Return the next displaced header, incrementing the pointer and
  64 // recycling spool area as necessary.
  65 markOop PromotionInfo::nextDisplacedHeader() {
  66   assert(_spoolHead != NULL, "promotionInfo inconsistency");
  67   assert(_spoolHead != _spoolTail || _firstIndex < _nextIndex,
  68          "Empty spool space: no displaced header can be fetched");
  69   assert(_spoolHead->bufferSize > _firstIndex, "Off by one error at head?");
  70   markOop hdr = _spoolHead->displacedHdr[_firstIndex];
  71   // Spool forward
  72   if (++_firstIndex == _spoolHead->bufferSize) { // last location in this block
  73     // forward to next block, recycling this block into spare spool buffer
  74     SpoolBlock* tmp = _spoolHead->nextSpoolBlock;
  75     assert(_spoolHead != _spoolTail, "Spooling storage mix-up");
  76     _spoolHead->nextSpoolBlock = _spareSpool;
  77     _spareSpool = _spoolHead;
  78     _spoolHead = tmp;
  79     _firstIndex = 1;
  80     NOT_PRODUCT(
  81       if (_spoolHead == NULL) {  // all buffers fully consumed
  82         assert(_spoolTail == NULL && _nextIndex == 1,
  83                "spool buffers processing inconsistency");
  84       }
  85     )
  86   }
  87   return hdr;
  88 }
  89 
  90 void PromotionInfo::track(PromotedObject* trackOop) {
  91   track(trackOop, oop(trackOop)->klass());
  92 }
  93 
  94 void PromotionInfo::track(PromotedObject* trackOop, Klass* klassOfOop) {
  95   // make a copy of header as it may need to be spooled
  96   markOop mark = oop(trackOop)->mark_raw();
  97   trackOop->clear_next();
  98   if (mark->must_be_preserved_for_cms_scavenge(klassOfOop)) {
  99     // save non-prototypical header, and mark oop
 100     saveDisplacedHeader(mark);
 101     trackOop->setDisplacedMark();
 102   } else {
 103     // we'd like to assert something like the following:
 104     // assert(mark == markOopDesc::prototype(), "consistency check");
 105     // ... but the above won't work because the age bits have not (yet) been
 106     // cleared. The remainder of the check would be identical to the
 107     // condition checked in must_be_preserved() above, so we don't really
 108     // have anything useful to check here!
 109   }
 110   if (_promoTail != NULL) {
 111     assert(_promoHead != NULL, "List consistency");
 112     _promoTail->setNext(trackOop);
 113     _promoTail = trackOop;
 114   } else {
 115     assert(_promoHead == NULL, "List consistency");
 116     _promoHead = _promoTail = trackOop;
 117   }
 118   // Mask as newly promoted, so we can skip over such objects
 119   // when scanning dirty cards
 120   assert(!trackOop->hasPromotedMark(), "Should not have been marked");
 121   trackOop->setPromotedMark();
 122 }
 123 
 124 // Save the given displaced header, incrementing the pointer and
 125 // obtaining more spool area as necessary.
 126 void PromotionInfo::saveDisplacedHeader(markOop hdr) {
 127   assert(_spoolHead != NULL && _spoolTail != NULL,
 128          "promotionInfo inconsistency");
 129   assert(_spoolTail->bufferSize > _nextIndex, "Off by one error at tail?");
 130   _spoolTail->displacedHdr[_nextIndex] = hdr;
 131   // Spool forward
 132   if (++_nextIndex == _spoolTail->bufferSize) { // last location in this block
 133     // get a new spooling block
 134     assert(_spoolTail->nextSpoolBlock == NULL, "tail should terminate spool list");
 135     _splice_point = _spoolTail;                   // save for splicing
 136     _spoolTail->nextSpoolBlock = getSpoolBlock(); // might fail
 137     _spoolTail = _spoolTail->nextSpoolBlock;      // might become NULL ...
 138     // ... but will attempt filling before next promotion attempt
 139     _nextIndex = 1;
 140   }
 141 }
 142 
 143 // Ensure that spooling space exists. Return false if spooling space
 144 // could not be obtained.
 145 bool PromotionInfo::ensure_spooling_space_work() {
 146   assert(!has_spooling_space(), "Only call when there is no spooling space");


< prev index next >