src/share/vm/gc_implementation/concurrentMarkSweep/promotionInfo.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 4037
da91efe96a93
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_PROMOTIONINFO_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_PROMOTIONINFO_HPP
aoqi@0 27
aoqi@0 28 #include "gc_implementation/concurrentMarkSweep/freeChunk.hpp"
aoqi@0 29 #include "memory/allocation.hpp"
aoqi@0 30
aoqi@0 31 // Forward declarations
aoqi@0 32 class CompactibleFreeListSpace;
aoqi@0 33
aoqi@0 34 class PromotedObject VALUE_OBJ_CLASS_SPEC {
aoqi@0 35 private:
aoqi@0 36 enum {
aoqi@0 37 promoted_mask = right_n_bits(2), // i.e. 0x3
aoqi@0 38 displaced_mark = nth_bit(2), // i.e. 0x4
aoqi@0 39 next_mask = ~(right_n_bits(3)) // i.e. ~(0x7)
aoqi@0 40 };
aoqi@0 41
aoqi@0 42 // Below, we want _narrow_next in the "higher" 32 bit slot,
aoqi@0 43 // whose position will depend on endian-ness of the platform.
aoqi@0 44 // This is so that there is no interference with the
aoqi@0 45 // cms_free_bit occupying bit position 7 (lsb == 0)
aoqi@0 46 // when we are using compressed oops; see FreeChunk::is_free().
aoqi@0 47 // We cannot move the cms_free_bit down because currently
aoqi@0 48 // biased locking code assumes that age bits are contiguous
aoqi@0 49 // with the lock bits. Even if that assumption were relaxed,
aoqi@0 50 // the least position we could move this bit to would be
aoqi@0 51 // to bit position 3, which would require 16 byte alignment.
aoqi@0 52 typedef struct {
aoqi@0 53 #ifdef VM_LITTLE_ENDIAN
aoqi@0 54 LP64_ONLY(narrowOop _pad;)
aoqi@0 55 narrowOop _narrow_next;
aoqi@0 56 #else
aoqi@0 57 narrowOop _narrow_next;
aoqi@0 58 LP64_ONLY(narrowOop _pad;)
aoqi@0 59 #endif
aoqi@0 60 } Data;
aoqi@0 61
aoqi@0 62 union {
aoqi@0 63 intptr_t _next;
aoqi@0 64 Data _data;
aoqi@0 65 };
aoqi@0 66 public:
aoqi@0 67 inline PromotedObject* next() const {
aoqi@0 68 assert(!((FreeChunk*)this)->is_free(), "Error");
aoqi@0 69 PromotedObject* res;
aoqi@0 70 if (UseCompressedOops) {
aoqi@0 71 // The next pointer is a compressed oop stored in the top 32 bits
aoqi@0 72 res = (PromotedObject*)oopDesc::decode_heap_oop(_data._narrow_next);
aoqi@0 73 } else {
aoqi@0 74 res = (PromotedObject*)(_next & next_mask);
aoqi@0 75 }
aoqi@0 76 assert(oop(res)->is_oop_or_null(true /* ignore mark word */), "Not an oop?");
aoqi@0 77 return res;
aoqi@0 78 }
aoqi@0 79 inline void setNext(PromotedObject* x) {
aoqi@0 80 assert(((intptr_t)x & ~next_mask) == 0, "Conflict in bit usage, "
aoqi@0 81 "or insufficient alignment of objects");
aoqi@0 82 if (UseCompressedOops) {
aoqi@0 83 assert(_data._narrow_next == 0, "Overwrite?");
aoqi@0 84 _data._narrow_next = oopDesc::encode_heap_oop(oop(x));
aoqi@0 85 } else {
aoqi@0 86 _next |= (intptr_t)x;
aoqi@0 87 }
aoqi@0 88 assert(!((FreeChunk*)this)->is_free(), "Error");
aoqi@0 89 }
aoqi@0 90 inline void setPromotedMark() {
aoqi@0 91 _next |= promoted_mask;
aoqi@0 92 assert(!((FreeChunk*)this)->is_free(), "Error");
aoqi@0 93 }
aoqi@0 94 inline bool hasPromotedMark() const {
aoqi@0 95 assert(!((FreeChunk*)this)->is_free(), "Error");
aoqi@0 96 return (_next & promoted_mask) == promoted_mask;
aoqi@0 97 }
aoqi@0 98 inline void setDisplacedMark() {
aoqi@0 99 _next |= displaced_mark;
aoqi@0 100 assert(!((FreeChunk*)this)->is_free(), "Error");
aoqi@0 101 }
aoqi@0 102 inline bool hasDisplacedMark() const {
aoqi@0 103 assert(!((FreeChunk*)this)->is_free(), "Error");
aoqi@0 104 return (_next & displaced_mark) != 0;
aoqi@0 105 }
aoqi@0 106 inline void clear_next() {
aoqi@0 107 _next = 0;
aoqi@0 108 assert(!((FreeChunk*)this)->is_free(), "Error");
aoqi@0 109 }
aoqi@0 110 debug_only(void *next_addr() { return (void *) &_next; })
aoqi@0 111 };
aoqi@0 112
aoqi@0 113 class SpoolBlock: public FreeChunk {
aoqi@0 114 friend class PromotionInfo;
aoqi@0 115 protected:
aoqi@0 116 SpoolBlock* nextSpoolBlock;
aoqi@0 117 size_t bufferSize; // number of usable words in this block
aoqi@0 118 markOop* displacedHdr; // the displaced headers start here
aoqi@0 119
aoqi@0 120 // Note about bufferSize: it denotes the number of entries available plus 1;
aoqi@0 121 // legal indices range from 1 through BufferSize - 1. See the verification
aoqi@0 122 // code verify() that counts the number of displaced headers spooled.
aoqi@0 123 size_t computeBufferSize() {
aoqi@0 124 return (size() * sizeof(HeapWord) - sizeof(*this)) / sizeof(markOop);
aoqi@0 125 }
aoqi@0 126
aoqi@0 127 public:
aoqi@0 128 void init() {
aoqi@0 129 bufferSize = computeBufferSize();
aoqi@0 130 displacedHdr = (markOop*)&displacedHdr;
aoqi@0 131 nextSpoolBlock = NULL;
aoqi@0 132 }
aoqi@0 133
aoqi@0 134 void print_on(outputStream* st) const;
aoqi@0 135 void print() const { print_on(gclog_or_tty); }
aoqi@0 136 };
aoqi@0 137
aoqi@0 138 class PromotionInfo VALUE_OBJ_CLASS_SPEC {
aoqi@0 139 bool _tracking; // set if tracking
aoqi@0 140 CompactibleFreeListSpace* _space; // the space to which this belongs
aoqi@0 141 PromotedObject* _promoHead; // head of list of promoted objects
aoqi@0 142 PromotedObject* _promoTail; // tail of list of promoted objects
aoqi@0 143 SpoolBlock* _spoolHead; // first spooling block
aoqi@0 144 SpoolBlock* _spoolTail; // last non-full spooling block or null
aoqi@0 145 SpoolBlock* _splice_point; // when _spoolTail is null, holds list tail
aoqi@0 146 SpoolBlock* _spareSpool; // free spool buffer
aoqi@0 147 size_t _firstIndex; // first active index in
aoqi@0 148 // first spooling block (_spoolHead)
aoqi@0 149 size_t _nextIndex; // last active index + 1 in last
aoqi@0 150 // spooling block (_spoolTail)
aoqi@0 151 private:
aoqi@0 152 // ensure that spooling space exists; return true if there is spooling space
aoqi@0 153 bool ensure_spooling_space_work();
aoqi@0 154
aoqi@0 155 public:
aoqi@0 156 PromotionInfo() :
aoqi@0 157 _tracking(0), _space(NULL),
aoqi@0 158 _promoHead(NULL), _promoTail(NULL),
aoqi@0 159 _spoolHead(NULL), _spoolTail(NULL),
aoqi@0 160 _spareSpool(NULL), _firstIndex(1),
aoqi@0 161 _nextIndex(1) {}
aoqi@0 162
aoqi@0 163 bool noPromotions() const {
aoqi@0 164 assert(_promoHead != NULL || _promoTail == NULL, "list inconsistency");
aoqi@0 165 return _promoHead == NULL;
aoqi@0 166 }
aoqi@0 167 void startTrackingPromotions();
aoqi@0 168 void stopTrackingPromotions(uint worker_id = 0);
aoqi@0 169 bool tracking() const { return _tracking; }
aoqi@0 170 void track(PromotedObject* trackOop); // keep track of a promoted oop
aoqi@0 171 // The following variant must be used when trackOop is not fully
aoqi@0 172 // initialized and has a NULL klass:
aoqi@0 173 void track(PromotedObject* trackOop, Klass* klassOfOop); // keep track of a promoted oop
aoqi@0 174 void setSpace(CompactibleFreeListSpace* sp) { _space = sp; }
aoqi@0 175 CompactibleFreeListSpace* space() const { return _space; }
aoqi@0 176 markOop nextDisplacedHeader(); // get next header & forward spool pointer
aoqi@0 177 void saveDisplacedHeader(markOop hdr);
aoqi@0 178 // save header and forward spool
aoqi@0 179
aoqi@0 180 inline size_t refillSize() const;
aoqi@0 181
aoqi@0 182 SpoolBlock* getSpoolBlock(); // return a free spooling block
aoqi@0 183 inline bool has_spooling_space() {
aoqi@0 184 return _spoolTail != NULL && _spoolTail->bufferSize > _nextIndex;
aoqi@0 185 }
aoqi@0 186 // ensure that spooling space exists
aoqi@0 187 bool ensure_spooling_space() {
aoqi@0 188 return has_spooling_space() || ensure_spooling_space_work();
aoqi@0 189 }
aoqi@0 190 #define PROMOTED_OOPS_ITERATE_DECL(OopClosureType, nv_suffix) \
aoqi@0 191 void promoted_oops_iterate##nv_suffix(OopClosureType* cl);
aoqi@0 192 ALL_SINCE_SAVE_MARKS_CLOSURES(PROMOTED_OOPS_ITERATE_DECL)
aoqi@0 193 #undef PROMOTED_OOPS_ITERATE_DECL
aoqi@0 194 void promoted_oops_iterate(OopsInGenClosure* cl) {
aoqi@0 195 promoted_oops_iterate_v(cl);
aoqi@0 196 }
aoqi@0 197 void verify() const;
aoqi@0 198 void reset() {
aoqi@0 199 _promoHead = NULL;
aoqi@0 200 _promoTail = NULL;
aoqi@0 201 _spoolHead = NULL;
aoqi@0 202 _spoolTail = NULL;
aoqi@0 203 _spareSpool = NULL;
aoqi@0 204 _firstIndex = 0;
aoqi@0 205 _nextIndex = 0;
aoqi@0 206
aoqi@0 207 }
aoqi@0 208
aoqi@0 209 void print_on(outputStream* st) const;
aoqi@0 210 void print_statistics(uint worker_id) const;
aoqi@0 211 };
aoqi@0 212
aoqi@0 213
aoqi@0 214 #endif // SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_PROMOTIONINFO_HPP

mercurial