1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/promotionInfo.hpp Mon May 10 12:31:52 2010 -0700 1.3 @@ -0,0 +1,161 @@ 1.4 +/* 1.5 + * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// Forward declarations 1.29 +class CompactibleFreeListSpace; 1.30 + 1.31 +class PromotedObject VALUE_OBJ_CLASS_SPEC { 1.32 + private: 1.33 + enum { 1.34 + promoted_mask = right_n_bits(2), // i.e. 0x3 1.35 + displaced_mark = nth_bit(2), // i.e. 0x4 1.36 + next_mask = ~(right_n_bits(3)) // i.e. ~(0x7) 1.37 + }; 1.38 + intptr_t _next; 1.39 + public: 1.40 + inline PromotedObject* next() const { 1.41 + return (PromotedObject*)(_next & next_mask); 1.42 + } 1.43 + inline void setNext(PromotedObject* x) { 1.44 + assert(((intptr_t)x & ~next_mask) == 0, 1.45 + "Conflict in bit usage, " 1.46 + " or insufficient alignment of objects"); 1.47 + _next |= (intptr_t)x; 1.48 + } 1.49 + inline void setPromotedMark() { 1.50 + _next |= promoted_mask; 1.51 + } 1.52 + inline bool hasPromotedMark() const { 1.53 + return (_next & promoted_mask) == promoted_mask; 1.54 + } 1.55 + inline void setDisplacedMark() { 1.56 + _next |= displaced_mark; 1.57 + } 1.58 + inline bool hasDisplacedMark() const { 1.59 + return (_next & displaced_mark) != 0; 1.60 + } 1.61 + inline void clearNext() { _next = 0; } 1.62 + debug_only(void *next_addr() { return (void *) &_next; }) 1.63 +}; 1.64 + 1.65 +class SpoolBlock: public FreeChunk { 1.66 + friend class PromotionInfo; 1.67 + protected: 1.68 + SpoolBlock* nextSpoolBlock; 1.69 + size_t bufferSize; // number of usable words in this block 1.70 + markOop* displacedHdr; // the displaced headers start here 1.71 + 1.72 + // Note about bufferSize: it denotes the number of entries available plus 1; 1.73 + // legal indices range from 1 through BufferSize - 1. See the verification 1.74 + // code verify() that counts the number of displaced headers spooled. 1.75 + size_t computeBufferSize() { 1.76 + return (size() * sizeof(HeapWord) - sizeof(*this)) / sizeof(markOop); 1.77 + } 1.78 + 1.79 + public: 1.80 + void init() { 1.81 + bufferSize = computeBufferSize(); 1.82 + displacedHdr = (markOop*)&displacedHdr; 1.83 + nextSpoolBlock = NULL; 1.84 + } 1.85 + 1.86 + void print_on(outputStream* st) const; 1.87 + void print() const { print_on(gclog_or_tty); } 1.88 +}; 1.89 + 1.90 +class PromotionInfo VALUE_OBJ_CLASS_SPEC { 1.91 + bool _tracking; // set if tracking 1.92 + CompactibleFreeListSpace* _space; // the space to which this belongs 1.93 + PromotedObject* _promoHead; // head of list of promoted objects 1.94 + PromotedObject* _promoTail; // tail of list of promoted objects 1.95 + SpoolBlock* _spoolHead; // first spooling block 1.96 + SpoolBlock* _spoolTail; // last non-full spooling block or null 1.97 + SpoolBlock* _splice_point; // when _spoolTail is null, holds list tail 1.98 + SpoolBlock* _spareSpool; // free spool buffer 1.99 + size_t _firstIndex; // first active index in 1.100 + // first spooling block (_spoolHead) 1.101 + size_t _nextIndex; // last active index + 1 in last 1.102 + // spooling block (_spoolTail) 1.103 + private: 1.104 + // ensure that spooling space exists; return true if there is spooling space 1.105 + bool ensure_spooling_space_work(); 1.106 + 1.107 + public: 1.108 + PromotionInfo() : 1.109 + _tracking(0), _space(NULL), 1.110 + _promoHead(NULL), _promoTail(NULL), 1.111 + _spoolHead(NULL), _spoolTail(NULL), 1.112 + _spareSpool(NULL), _firstIndex(1), 1.113 + _nextIndex(1) {} 1.114 + 1.115 + bool noPromotions() const { 1.116 + assert(_promoHead != NULL || _promoTail == NULL, "list inconsistency"); 1.117 + return _promoHead == NULL; 1.118 + } 1.119 + void startTrackingPromotions(); 1.120 + void stopTrackingPromotions(uint worker_id = 0); 1.121 + bool tracking() const { return _tracking; } 1.122 + void track(PromotedObject* trackOop); // keep track of a promoted oop 1.123 + // The following variant must be used when trackOop is not fully 1.124 + // initialized and has a NULL klass: 1.125 + void track(PromotedObject* trackOop, klassOop klassOfOop); // keep track of a promoted oop 1.126 + void setSpace(CompactibleFreeListSpace* sp) { _space = sp; } 1.127 + CompactibleFreeListSpace* space() const { return _space; } 1.128 + markOop nextDisplacedHeader(); // get next header & forward spool pointer 1.129 + void saveDisplacedHeader(markOop hdr); 1.130 + // save header and forward spool 1.131 + 1.132 + inline size_t refillSize() const; 1.133 + 1.134 + SpoolBlock* getSpoolBlock(); // return a free spooling block 1.135 + inline bool has_spooling_space() { 1.136 + return _spoolTail != NULL && _spoolTail->bufferSize > _nextIndex; 1.137 + } 1.138 + // ensure that spooling space exists 1.139 + bool ensure_spooling_space() { 1.140 + return has_spooling_space() || ensure_spooling_space_work(); 1.141 + } 1.142 + #define PROMOTED_OOPS_ITERATE_DECL(OopClosureType, nv_suffix) \ 1.143 + void promoted_oops_iterate##nv_suffix(OopClosureType* cl); 1.144 + ALL_SINCE_SAVE_MARKS_CLOSURES(PROMOTED_OOPS_ITERATE_DECL) 1.145 + #undef PROMOTED_OOPS_ITERATE_DECL 1.146 + void promoted_oops_iterate(OopsInGenClosure* cl) { 1.147 + promoted_oops_iterate_v(cl); 1.148 + } 1.149 + void verify() const; 1.150 + void reset() { 1.151 + _promoHead = NULL; 1.152 + _promoTail = NULL; 1.153 + _spoolHead = NULL; 1.154 + _spoolTail = NULL; 1.155 + _spareSpool = NULL; 1.156 + _firstIndex = 0; 1.157 + _nextIndex = 0; 1.158 + 1.159 + } 1.160 + 1.161 + void print_on(outputStream* st) const; 1.162 + void print_statistics(uint worker_id) const; 1.163 +}; 1.164 +