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