aoqi@0: /* aoqi@0: * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_PROMOTIONINFO_HPP aoqi@0: #define SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_PROMOTIONINFO_HPP aoqi@0: aoqi@0: #include "gc_implementation/concurrentMarkSweep/freeChunk.hpp" aoqi@0: #include "memory/allocation.hpp" aoqi@0: aoqi@0: // Forward declarations aoqi@0: class CompactibleFreeListSpace; aoqi@0: aoqi@0: class PromotedObject VALUE_OBJ_CLASS_SPEC { aoqi@0: private: aoqi@0: enum { aoqi@0: promoted_mask = right_n_bits(2), // i.e. 0x3 aoqi@0: displaced_mark = nth_bit(2), // i.e. 0x4 aoqi@0: next_mask = ~(right_n_bits(3)) // i.e. ~(0x7) aoqi@0: }; aoqi@0: aoqi@0: // Below, we want _narrow_next in the "higher" 32 bit slot, aoqi@0: // whose position will depend on endian-ness of the platform. aoqi@0: // This is so that there is no interference with the aoqi@0: // cms_free_bit occupying bit position 7 (lsb == 0) aoqi@0: // when we are using compressed oops; see FreeChunk::is_free(). aoqi@0: // We cannot move the cms_free_bit down because currently aoqi@0: // biased locking code assumes that age bits are contiguous aoqi@0: // with the lock bits. Even if that assumption were relaxed, aoqi@0: // the least position we could move this bit to would be aoqi@0: // to bit position 3, which would require 16 byte alignment. aoqi@0: typedef struct { aoqi@0: #ifdef VM_LITTLE_ENDIAN aoqi@0: LP64_ONLY(narrowOop _pad;) aoqi@0: narrowOop _narrow_next; aoqi@0: #else aoqi@0: narrowOop _narrow_next; aoqi@0: LP64_ONLY(narrowOop _pad;) aoqi@0: #endif aoqi@0: } Data; aoqi@0: aoqi@0: union { aoqi@0: intptr_t _next; aoqi@0: Data _data; aoqi@0: }; aoqi@0: public: aoqi@0: inline PromotedObject* next() const { aoqi@0: assert(!((FreeChunk*)this)->is_free(), "Error"); aoqi@0: PromotedObject* res; aoqi@0: if (UseCompressedOops) { aoqi@0: // The next pointer is a compressed oop stored in the top 32 bits aoqi@0: res = (PromotedObject*)oopDesc::decode_heap_oop(_data._narrow_next); aoqi@0: } else { aoqi@0: res = (PromotedObject*)(_next & next_mask); aoqi@0: } aoqi@0: assert(oop(res)->is_oop_or_null(true /* ignore mark word */), "Not an oop?"); aoqi@0: return res; aoqi@0: } aoqi@0: inline void setNext(PromotedObject* x) { aoqi@0: assert(((intptr_t)x & ~next_mask) == 0, "Conflict in bit usage, " aoqi@0: "or insufficient alignment of objects"); aoqi@0: if (UseCompressedOops) { aoqi@0: assert(_data._narrow_next == 0, "Overwrite?"); aoqi@0: _data._narrow_next = oopDesc::encode_heap_oop(oop(x)); aoqi@0: } else { aoqi@0: _next |= (intptr_t)x; aoqi@0: } aoqi@0: assert(!((FreeChunk*)this)->is_free(), "Error"); aoqi@0: } aoqi@0: inline void setPromotedMark() { aoqi@0: _next |= promoted_mask; aoqi@0: assert(!((FreeChunk*)this)->is_free(), "Error"); aoqi@0: } aoqi@0: inline bool hasPromotedMark() const { aoqi@0: assert(!((FreeChunk*)this)->is_free(), "Error"); aoqi@0: return (_next & promoted_mask) == promoted_mask; aoqi@0: } aoqi@0: inline void setDisplacedMark() { aoqi@0: _next |= displaced_mark; aoqi@0: assert(!((FreeChunk*)this)->is_free(), "Error"); aoqi@0: } aoqi@0: inline bool hasDisplacedMark() const { aoqi@0: assert(!((FreeChunk*)this)->is_free(), "Error"); aoqi@0: return (_next & displaced_mark) != 0; aoqi@0: } aoqi@0: inline void clear_next() { aoqi@0: _next = 0; aoqi@0: assert(!((FreeChunk*)this)->is_free(), "Error"); aoqi@0: } aoqi@0: debug_only(void *next_addr() { return (void *) &_next; }) aoqi@0: }; aoqi@0: aoqi@0: class SpoolBlock: public FreeChunk { aoqi@0: friend class PromotionInfo; aoqi@0: protected: aoqi@0: SpoolBlock* nextSpoolBlock; aoqi@0: size_t bufferSize; // number of usable words in this block aoqi@0: markOop* displacedHdr; // the displaced headers start here aoqi@0: aoqi@0: // Note about bufferSize: it denotes the number of entries available plus 1; aoqi@0: // legal indices range from 1 through BufferSize - 1. See the verification aoqi@0: // code verify() that counts the number of displaced headers spooled. aoqi@0: size_t computeBufferSize() { aoqi@0: return (size() * sizeof(HeapWord) - sizeof(*this)) / sizeof(markOop); aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: void init() { aoqi@0: bufferSize = computeBufferSize(); aoqi@0: displacedHdr = (markOop*)&displacedHdr; aoqi@0: nextSpoolBlock = NULL; aoqi@0: } aoqi@0: aoqi@0: void print_on(outputStream* st) const; aoqi@0: void print() const { print_on(gclog_or_tty); } aoqi@0: }; aoqi@0: aoqi@0: class PromotionInfo VALUE_OBJ_CLASS_SPEC { aoqi@0: bool _tracking; // set if tracking aoqi@0: CompactibleFreeListSpace* _space; // the space to which this belongs aoqi@0: PromotedObject* _promoHead; // head of list of promoted objects aoqi@0: PromotedObject* _promoTail; // tail of list of promoted objects aoqi@0: SpoolBlock* _spoolHead; // first spooling block aoqi@0: SpoolBlock* _spoolTail; // last non-full spooling block or null aoqi@0: SpoolBlock* _splice_point; // when _spoolTail is null, holds list tail aoqi@0: SpoolBlock* _spareSpool; // free spool buffer aoqi@0: size_t _firstIndex; // first active index in aoqi@0: // first spooling block (_spoolHead) aoqi@0: size_t _nextIndex; // last active index + 1 in last aoqi@0: // spooling block (_spoolTail) aoqi@0: private: aoqi@0: // ensure that spooling space exists; return true if there is spooling space aoqi@0: bool ensure_spooling_space_work(); aoqi@0: aoqi@0: public: aoqi@0: PromotionInfo() : aoqi@0: _tracking(0), _space(NULL), aoqi@0: _promoHead(NULL), _promoTail(NULL), aoqi@0: _spoolHead(NULL), _spoolTail(NULL), aoqi@0: _spareSpool(NULL), _firstIndex(1), aoqi@0: _nextIndex(1) {} aoqi@0: aoqi@0: bool noPromotions() const { aoqi@0: assert(_promoHead != NULL || _promoTail == NULL, "list inconsistency"); aoqi@0: return _promoHead == NULL; aoqi@0: } aoqi@0: void startTrackingPromotions(); aoqi@0: void stopTrackingPromotions(uint worker_id = 0); aoqi@0: bool tracking() const { return _tracking; } aoqi@0: void track(PromotedObject* trackOop); // keep track of a promoted oop aoqi@0: // The following variant must be used when trackOop is not fully aoqi@0: // initialized and has a NULL klass: aoqi@0: void track(PromotedObject* trackOop, Klass* klassOfOop); // keep track of a promoted oop aoqi@0: void setSpace(CompactibleFreeListSpace* sp) { _space = sp; } aoqi@0: CompactibleFreeListSpace* space() const { return _space; } aoqi@0: markOop nextDisplacedHeader(); // get next header & forward spool pointer aoqi@0: void saveDisplacedHeader(markOop hdr); aoqi@0: // save header and forward spool aoqi@0: aoqi@0: inline size_t refillSize() const; aoqi@0: aoqi@0: SpoolBlock* getSpoolBlock(); // return a free spooling block aoqi@0: inline bool has_spooling_space() { aoqi@0: return _spoolTail != NULL && _spoolTail->bufferSize > _nextIndex; aoqi@0: } aoqi@0: // ensure that spooling space exists aoqi@0: bool ensure_spooling_space() { aoqi@0: return has_spooling_space() || ensure_spooling_space_work(); aoqi@0: } aoqi@0: #define PROMOTED_OOPS_ITERATE_DECL(OopClosureType, nv_suffix) \ aoqi@0: void promoted_oops_iterate##nv_suffix(OopClosureType* cl); aoqi@0: ALL_SINCE_SAVE_MARKS_CLOSURES(PROMOTED_OOPS_ITERATE_DECL) aoqi@0: #undef PROMOTED_OOPS_ITERATE_DECL aoqi@0: void promoted_oops_iterate(OopsInGenClosure* cl) { aoqi@0: promoted_oops_iterate_v(cl); aoqi@0: } aoqi@0: void verify() const; aoqi@0: void reset() { aoqi@0: _promoHead = NULL; aoqi@0: _promoTail = NULL; aoqi@0: _spoolHead = NULL; aoqi@0: _spoolTail = NULL; aoqi@0: _spareSpool = NULL; aoqi@0: _firstIndex = 0; aoqi@0: _nextIndex = 0; aoqi@0: aoqi@0: } aoqi@0: aoqi@0: void print_on(outputStream* st) const; aoqi@0: void print_statistics(uint worker_id) const; aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: #endif // SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_PROMOTIONINFO_HPP