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

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/promotionInfo.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,214 @@
     1.4 +/*
     1.5 + * Copyright (c) 2010, 2012, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_PROMOTIONINFO_HPP
    1.29 +#define SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_PROMOTIONINFO_HPP
    1.30 +
    1.31 +#include "gc_implementation/concurrentMarkSweep/freeChunk.hpp"
    1.32 +#include "memory/allocation.hpp"
    1.33 +
    1.34 +// Forward declarations
    1.35 +class CompactibleFreeListSpace;
    1.36 +
    1.37 +class PromotedObject VALUE_OBJ_CLASS_SPEC {
    1.38 + private:
    1.39 +  enum {
    1.40 +    promoted_mask  = right_n_bits(2),   // i.e. 0x3
    1.41 +    displaced_mark = nth_bit(2),        // i.e. 0x4
    1.42 +    next_mask      = ~(right_n_bits(3)) // i.e. ~(0x7)
    1.43 +  };
    1.44 +
    1.45 +  // Below, we want _narrow_next in the "higher" 32 bit slot,
    1.46 +  // whose position will depend on endian-ness of the platform.
    1.47 +  // This is so that there is no interference with the
    1.48 +  // cms_free_bit occupying bit position 7 (lsb == 0)
    1.49 +  // when we are using compressed oops; see FreeChunk::is_free().
    1.50 +  // We cannot move the cms_free_bit down because currently
    1.51 +  // biased locking code assumes that age bits are contiguous
    1.52 +  // with the lock bits. Even if that assumption were relaxed,
    1.53 +  // the least position we could move this bit to would be
    1.54 +  // to bit position 3, which would require 16 byte alignment.
    1.55 +  typedef struct {
    1.56 +#ifdef VM_LITTLE_ENDIAN
    1.57 +    LP64_ONLY(narrowOop _pad;)
    1.58 +              narrowOop _narrow_next;
    1.59 +#else
    1.60 +              narrowOop _narrow_next;
    1.61 +    LP64_ONLY(narrowOop _pad;)
    1.62 +#endif
    1.63 +  } Data;
    1.64 +
    1.65 +  union {
    1.66 +    intptr_t _next;
    1.67 +    Data     _data;
    1.68 +  };
    1.69 + public:
    1.70 +  inline PromotedObject* next() const {
    1.71 +    assert(!((FreeChunk*)this)->is_free(), "Error");
    1.72 +    PromotedObject* res;
    1.73 +    if (UseCompressedOops) {
    1.74 +      // The next pointer is a compressed oop stored in the top 32 bits
    1.75 +      res = (PromotedObject*)oopDesc::decode_heap_oop(_data._narrow_next);
    1.76 +    } else {
    1.77 +      res = (PromotedObject*)(_next & next_mask);
    1.78 +    }
    1.79 +    assert(oop(res)->is_oop_or_null(true /* ignore mark word */), "Not an oop?");
    1.80 +    return res;
    1.81 +  }
    1.82 +  inline void setNext(PromotedObject* x) {
    1.83 +    assert(((intptr_t)x & ~next_mask) == 0, "Conflict in bit usage, "
    1.84 +           "or insufficient alignment of objects");
    1.85 +    if (UseCompressedOops) {
    1.86 +      assert(_data._narrow_next == 0, "Overwrite?");
    1.87 +      _data._narrow_next = oopDesc::encode_heap_oop(oop(x));
    1.88 +    } else {
    1.89 +      _next |= (intptr_t)x;
    1.90 +    }
    1.91 +    assert(!((FreeChunk*)this)->is_free(), "Error");
    1.92 +  }
    1.93 +  inline void setPromotedMark() {
    1.94 +    _next |= promoted_mask;
    1.95 +    assert(!((FreeChunk*)this)->is_free(), "Error");
    1.96 +  }
    1.97 +  inline bool hasPromotedMark() const {
    1.98 +    assert(!((FreeChunk*)this)->is_free(), "Error");
    1.99 +    return (_next & promoted_mask) == promoted_mask;
   1.100 +  }
   1.101 +  inline void setDisplacedMark() {
   1.102 +    _next |= displaced_mark;
   1.103 +    assert(!((FreeChunk*)this)->is_free(), "Error");
   1.104 +  }
   1.105 +  inline bool hasDisplacedMark() const {
   1.106 +    assert(!((FreeChunk*)this)->is_free(), "Error");
   1.107 +    return (_next & displaced_mark) != 0;
   1.108 +  }
   1.109 +  inline void clear_next()        {
   1.110 +    _next = 0;
   1.111 +    assert(!((FreeChunk*)this)->is_free(), "Error");
   1.112 +  }
   1.113 +  debug_only(void *next_addr() { return (void *) &_next; })
   1.114 +};
   1.115 +
   1.116 +class SpoolBlock: public FreeChunk {
   1.117 +  friend class PromotionInfo;
   1.118 + protected:
   1.119 +  SpoolBlock*  nextSpoolBlock;
   1.120 +  size_t       bufferSize;        // number of usable words in this block
   1.121 +  markOop*     displacedHdr;      // the displaced headers start here
   1.122 +
   1.123 +  // Note about bufferSize: it denotes the number of entries available plus 1;
   1.124 +  // legal indices range from 1 through BufferSize - 1.  See the verification
   1.125 +  // code verify() that counts the number of displaced headers spooled.
   1.126 +  size_t computeBufferSize() {
   1.127 +    return (size() * sizeof(HeapWord) - sizeof(*this)) / sizeof(markOop);
   1.128 +  }
   1.129 +
   1.130 + public:
   1.131 +  void init() {
   1.132 +    bufferSize = computeBufferSize();
   1.133 +    displacedHdr = (markOop*)&displacedHdr;
   1.134 +    nextSpoolBlock = NULL;
   1.135 +  }
   1.136 +
   1.137 +  void print_on(outputStream* st) const;
   1.138 +  void print() const { print_on(gclog_or_tty); }
   1.139 +};
   1.140 +
   1.141 +class PromotionInfo VALUE_OBJ_CLASS_SPEC {
   1.142 +  bool            _tracking;      // set if tracking
   1.143 +  CompactibleFreeListSpace* _space; // the space to which this belongs
   1.144 +  PromotedObject* _promoHead;     // head of list of promoted objects
   1.145 +  PromotedObject* _promoTail;     // tail of list of promoted objects
   1.146 +  SpoolBlock*     _spoolHead;     // first spooling block
   1.147 +  SpoolBlock*     _spoolTail;     // last  non-full spooling block or null
   1.148 +  SpoolBlock*     _splice_point;  // when _spoolTail is null, holds list tail
   1.149 +  SpoolBlock*     _spareSpool;    // free spool buffer
   1.150 +  size_t          _firstIndex;    // first active index in
   1.151 +                                  // first spooling block (_spoolHead)
   1.152 +  size_t          _nextIndex;     // last active index + 1 in last
   1.153 +                                  // spooling block (_spoolTail)
   1.154 + private:
   1.155 +  // ensure that spooling space exists; return true if there is spooling space
   1.156 +  bool ensure_spooling_space_work();
   1.157 +
   1.158 + public:
   1.159 +  PromotionInfo() :
   1.160 +    _tracking(0), _space(NULL),
   1.161 +    _promoHead(NULL), _promoTail(NULL),
   1.162 +    _spoolHead(NULL), _spoolTail(NULL),
   1.163 +    _spareSpool(NULL), _firstIndex(1),
   1.164 +    _nextIndex(1) {}
   1.165 +
   1.166 +  bool noPromotions() const {
   1.167 +    assert(_promoHead != NULL || _promoTail == NULL, "list inconsistency");
   1.168 +    return _promoHead == NULL;
   1.169 +  }
   1.170 +  void startTrackingPromotions();
   1.171 +  void stopTrackingPromotions(uint worker_id = 0);
   1.172 +  bool tracking() const          { return _tracking;  }
   1.173 +  void track(PromotedObject* trackOop);      // keep track of a promoted oop
   1.174 +  // The following variant must be used when trackOop is not fully
   1.175 +  // initialized and has a NULL klass:
   1.176 +  void track(PromotedObject* trackOop, Klass* klassOfOop); // keep track of a promoted oop
   1.177 +  void setSpace(CompactibleFreeListSpace* sp) { _space = sp; }
   1.178 +  CompactibleFreeListSpace* space() const     { return _space; }
   1.179 +  markOop nextDisplacedHeader(); // get next header & forward spool pointer
   1.180 +  void    saveDisplacedHeader(markOop hdr);
   1.181 +                                 // save header and forward spool
   1.182 +
   1.183 +  inline size_t refillSize() const;
   1.184 +
   1.185 +  SpoolBlock* getSpoolBlock();   // return a free spooling block
   1.186 +  inline bool has_spooling_space() {
   1.187 +    return _spoolTail != NULL && _spoolTail->bufferSize > _nextIndex;
   1.188 +  }
   1.189 +  // ensure that spooling space exists
   1.190 +  bool ensure_spooling_space() {
   1.191 +    return has_spooling_space() || ensure_spooling_space_work();
   1.192 +  }
   1.193 +  #define PROMOTED_OOPS_ITERATE_DECL(OopClosureType, nv_suffix)  \
   1.194 +    void promoted_oops_iterate##nv_suffix(OopClosureType* cl);
   1.195 +  ALL_SINCE_SAVE_MARKS_CLOSURES(PROMOTED_OOPS_ITERATE_DECL)
   1.196 +  #undef PROMOTED_OOPS_ITERATE_DECL
   1.197 +  void promoted_oops_iterate(OopsInGenClosure* cl) {
   1.198 +    promoted_oops_iterate_v(cl);
   1.199 +  }
   1.200 +  void verify()  const;
   1.201 +  void reset() {
   1.202 +    _promoHead = NULL;
   1.203 +    _promoTail = NULL;
   1.204 +    _spoolHead = NULL;
   1.205 +    _spoolTail = NULL;
   1.206 +    _spareSpool = NULL;
   1.207 +    _firstIndex = 0;
   1.208 +    _nextIndex = 0;
   1.209 +
   1.210 +  }
   1.211 +
   1.212 +  void print_on(outputStream* st) const;
   1.213 +  void print_statistics(uint worker_id) const;
   1.214 +};
   1.215 +
   1.216 +
   1.217 +#endif // SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_PROMOTIONINFO_HPP

mercurial