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

Mon, 10 May 2010 12:31:52 -0700

author
ysr
date
Mon, 10 May 2010 12:31:52 -0700
changeset 1876
a8127dc669ba
child 1901
a00b51b2dda4
permissions
-rw-r--r--

6951188: CMS: move PromotionInfo into its own file
Summary: Moved PromotionInfo and friends into new files promotionInfo.{h,c}pp from their previous compactibleFreeListSpace.{h,c}pp home.
Reviewed-by: apetrusenko

     1 /*
     2  * Copyright 2001-2009 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 // Forward declarations
    26 class CompactibleFreeListSpace;
    28 class PromotedObject VALUE_OBJ_CLASS_SPEC {
    29  private:
    30   enum {
    31     promoted_mask  = right_n_bits(2),   // i.e. 0x3
    32     displaced_mark = nth_bit(2),        // i.e. 0x4
    33     next_mask      = ~(right_n_bits(3)) // i.e. ~(0x7)
    34   };
    35   intptr_t _next;
    36  public:
    37   inline PromotedObject* next() const {
    38     return (PromotedObject*)(_next & next_mask);
    39   }
    40   inline void setNext(PromotedObject* x) {
    41     assert(((intptr_t)x & ~next_mask) == 0,
    42            "Conflict in bit usage, "
    43            " or insufficient alignment of objects");
    44     _next |= (intptr_t)x;
    45   }
    46   inline void setPromotedMark() {
    47     _next |= promoted_mask;
    48   }
    49   inline bool hasPromotedMark() const {
    50     return (_next & promoted_mask) == promoted_mask;
    51   }
    52   inline void setDisplacedMark() {
    53     _next |= displaced_mark;
    54   }
    55   inline bool hasDisplacedMark() const {
    56     return (_next & displaced_mark) != 0;
    57   }
    58   inline void clearNext()        { _next = 0; }
    59   debug_only(void *next_addr() { return (void *) &_next; })
    60 };
    62 class SpoolBlock: public FreeChunk {
    63   friend class PromotionInfo;
    64  protected:
    65   SpoolBlock*  nextSpoolBlock;
    66   size_t       bufferSize;        // number of usable words in this block
    67   markOop*     displacedHdr;      // the displaced headers start here
    69   // Note about bufferSize: it denotes the number of entries available plus 1;
    70   // legal indices range from 1 through BufferSize - 1.  See the verification
    71   // code verify() that counts the number of displaced headers spooled.
    72   size_t computeBufferSize() {
    73     return (size() * sizeof(HeapWord) - sizeof(*this)) / sizeof(markOop);
    74   }
    76  public:
    77   void init() {
    78     bufferSize = computeBufferSize();
    79     displacedHdr = (markOop*)&displacedHdr;
    80     nextSpoolBlock = NULL;
    81   }
    83   void print_on(outputStream* st) const;
    84   void print() const { print_on(gclog_or_tty); }
    85 };
    87 class PromotionInfo VALUE_OBJ_CLASS_SPEC {
    88   bool            _tracking;      // set if tracking
    89   CompactibleFreeListSpace* _space; // the space to which this belongs
    90   PromotedObject* _promoHead;     // head of list of promoted objects
    91   PromotedObject* _promoTail;     // tail of list of promoted objects
    92   SpoolBlock*     _spoolHead;     // first spooling block
    93   SpoolBlock*     _spoolTail;     // last  non-full spooling block or null
    94   SpoolBlock*     _splice_point;  // when _spoolTail is null, holds list tail
    95   SpoolBlock*     _spareSpool;    // free spool buffer
    96   size_t          _firstIndex;    // first active index in
    97                                   // first spooling block (_spoolHead)
    98   size_t          _nextIndex;     // last active index + 1 in last
    99                                   // spooling block (_spoolTail)
   100  private:
   101   // ensure that spooling space exists; return true if there is spooling space
   102   bool ensure_spooling_space_work();
   104  public:
   105   PromotionInfo() :
   106     _tracking(0), _space(NULL),
   107     _promoHead(NULL), _promoTail(NULL),
   108     _spoolHead(NULL), _spoolTail(NULL),
   109     _spareSpool(NULL), _firstIndex(1),
   110     _nextIndex(1) {}
   112   bool noPromotions() const {
   113     assert(_promoHead != NULL || _promoTail == NULL, "list inconsistency");
   114     return _promoHead == NULL;
   115   }
   116   void startTrackingPromotions();
   117   void stopTrackingPromotions(uint worker_id = 0);
   118   bool tracking() const          { return _tracking;  }
   119   void track(PromotedObject* trackOop);      // keep track of a promoted oop
   120   // The following variant must be used when trackOop is not fully
   121   // initialized and has a NULL klass:
   122   void track(PromotedObject* trackOop, klassOop klassOfOop); // keep track of a promoted oop
   123   void setSpace(CompactibleFreeListSpace* sp) { _space = sp; }
   124   CompactibleFreeListSpace* space() const     { return _space; }
   125   markOop nextDisplacedHeader(); // get next header & forward spool pointer
   126   void    saveDisplacedHeader(markOop hdr);
   127                                  // save header and forward spool
   129   inline size_t refillSize() const;
   131   SpoolBlock* getSpoolBlock();   // return a free spooling block
   132   inline bool has_spooling_space() {
   133     return _spoolTail != NULL && _spoolTail->bufferSize > _nextIndex;
   134   }
   135   // ensure that spooling space exists
   136   bool ensure_spooling_space() {
   137     return has_spooling_space() || ensure_spooling_space_work();
   138   }
   139   #define PROMOTED_OOPS_ITERATE_DECL(OopClosureType, nv_suffix)  \
   140     void promoted_oops_iterate##nv_suffix(OopClosureType* cl);
   141   ALL_SINCE_SAVE_MARKS_CLOSURES(PROMOTED_OOPS_ITERATE_DECL)
   142   #undef PROMOTED_OOPS_ITERATE_DECL
   143   void promoted_oops_iterate(OopsInGenClosure* cl) {
   144     promoted_oops_iterate_v(cl);
   145   }
   146   void verify()  const;
   147   void reset() {
   148     _promoHead = NULL;
   149     _promoTail = NULL;
   150     _spoolHead = NULL;
   151     _spoolTail = NULL;
   152     _spareSpool = NULL;
   153     _firstIndex = 0;
   154     _nextIndex = 0;
   156   }
   158   void print_on(outputStream* st) const;
   159   void print_statistics(uint worker_id) const;
   160 };

mercurial