hotspot/src/share/vm/gc_implementation/parNew/parGCAllocBuffer.hpp

Print this page
rev 611 : Merge
   1 #ifdef USE_PRAGMA_IDENT_HDR
   2 #pragma ident "@(#)parGCAllocBuffer.hpp 1.30 07/05/29 09:44:13 JVM"
   3 #endif
   4 /*
   5  * Copyright 2001-2006 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  


  27 
  28 // Forward decl.
  29 
  30 class PLABStats;
  31 
  32 // A per-thread allocation buffer used during GC.
  33 class ParGCAllocBuffer: public CHeapObj {
  34 protected:
  35   char head[32];
  36   size_t _word_sz;          // in HeapWord units
  37   HeapWord* _bottom;
  38   HeapWord* _top;
  39   HeapWord* _end;       // last allocatable address + 1
  40   HeapWord* _hard_end;  // _end + AlignmentReserve
  41   bool      _retained;  // whether we hold a _retained_filler
  42   MemRegion _retained_filler;
  43   // In support of ergonomic sizing of PLAB's
  44   size_t    _allocated;     // in HeapWord units
  45   size_t    _wasted;        // in HeapWord units
  46   char tail[32];
  47   static const size_t FillerHeaderSize;
  48   static const size_t AlignmentReserve;
  49 
  50 public:
  51   // Initializes the buffer to be empty, but with the given "word_sz".
  52   // Must get initialized with "set_buf" for an allocation to succeed.
  53   ParGCAllocBuffer(size_t word_sz);
  54 
  55   static const size_t min_size() {
  56     return ThreadLocalAllocBuffer::min_size();
  57   }
  58 
  59   static const size_t max_size() {
  60     return ThreadLocalAllocBuffer::max_size();
  61   }
  62 
  63   // If an allocation of the given "word_sz" can be satisfied within the
  64   // buffer, do the allocation, returning a pointer to the start of the
  65   // allocated block.  If the allocation request cannot be satisfied,
  66   // return NULL.
  67   HeapWord* allocate(size_t word_sz) {
  68     HeapWord* res = _top;
  69     HeapWord* new_top = _top + word_sz;
  70     if (new_top <= _end) {
  71       _top = new_top;
  72       return res;
  73     } else {
  74       return NULL;
  75     }
  76   }
  77 
  78   // Undo the last allocation in the buffer, which is required to be of the 
  79   // "obj" of the given "word_sz".
  80   void undo_allocation(HeapWord* obj, size_t word_sz) {
  81     assert(_top - word_sz >= _bottom
  82            && _top - word_sz == obj,
  83            "Bad undo_allocation");
  84     _top = _top - word_sz;
  85   }
  86 
  87   // The total (word) size of the buffer, including both allocated and
  88   // unallocted space.
  89   size_t word_sz() { return _word_sz; }
  90 
  91   // Should only be done if we are about to reset with a new buffer of the
  92   // given size.
  93   void set_word_size(size_t new_word_sz) {
  94     assert(new_word_sz > AlignmentReserve, "Too small");
  95     _word_sz = new_word_sz;
  96   }
  97 
  98   // The number of words of unallocated space remaining in the buffer.
  99   size_t words_remaining() {
 100     assert(_end >= _top, "Negative buffer");
 101     return pointer_delta(_end, _top, HeapWordSize);
 102   }
 103 
 104   bool contains(void* addr) {


   1 #ifdef USE_PRAGMA_IDENT_HDR
   2 #pragma ident "@(#)parGCAllocBuffer.hpp 1.30 07/05/29 09:44:13 JVM"
   3 #endif
   4 /*
   5  * Copyright 2001-2008 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  


  27 
  28 // Forward decl.
  29 
  30 class PLABStats;
  31 
  32 // A per-thread allocation buffer used during GC.
  33 class ParGCAllocBuffer: public CHeapObj {
  34 protected:
  35   char head[32];
  36   size_t _word_sz;          // in HeapWord units
  37   HeapWord* _bottom;
  38   HeapWord* _top;
  39   HeapWord* _end;       // last allocatable address + 1
  40   HeapWord* _hard_end;  // _end + AlignmentReserve
  41   bool      _retained;  // whether we hold a _retained_filler
  42   MemRegion _retained_filler;
  43   // In support of ergonomic sizing of PLAB's
  44   size_t    _allocated;     // in HeapWord units
  45   size_t    _wasted;        // in HeapWord units
  46   char tail[32];
  47   static size_t FillerHeaderSize;
  48   static size_t AlignmentReserve;
  49 
  50 public:
  51   // Initializes the buffer to be empty, but with the given "word_sz".
  52   // Must get initialized with "set_buf" for an allocation to succeed.
  53   ParGCAllocBuffer(size_t word_sz);
  54 
  55   static const size_t min_size() {
  56     return ThreadLocalAllocBuffer::min_size();
  57   }
  58 
  59   static const size_t max_size() {
  60     return ThreadLocalAllocBuffer::max_size();
  61   }
  62 
  63   // If an allocation of the given "word_sz" can be satisfied within the
  64   // buffer, do the allocation, returning a pointer to the start of the
  65   // allocated block.  If the allocation request cannot be satisfied,
  66   // return NULL.
  67   HeapWord* allocate(size_t word_sz) {
  68     HeapWord* res = _top;
  69     if (pointer_delta(_end, _top) >= word_sz) {
  70       _top = _top + word_sz;

  71       return res;
  72     } else {
  73       return NULL;
  74     }
  75   }
  76 
  77   // Undo the last allocation in the buffer, which is required to be of the 
  78   // "obj" of the given "word_sz".
  79   void undo_allocation(HeapWord* obj, size_t word_sz) {
  80     assert(pointer_delta(_top, _bottom) >= word_sz, "Bad undo");
  81     assert(pointer_delta(_top, obj)     == word_sz, "Bad undo");
  82     _top = obj;

  83   }
  84 
  85   // The total (word) size of the buffer, including both allocated and
  86   // unallocted space.
  87   size_t word_sz() { return _word_sz; }
  88 
  89   // Should only be done if we are about to reset with a new buffer of the
  90   // given size.
  91   void set_word_size(size_t new_word_sz) {
  92     assert(new_word_sz > AlignmentReserve, "Too small");
  93     _word_sz = new_word_sz;
  94   }
  95 
  96   // The number of words of unallocated space remaining in the buffer.
  97   size_t words_remaining() {
  98     assert(_end >= _top, "Negative buffer");
  99     return pointer_delta(_end, _top, HeapWordSize);
 100   }
 101 
 102   bool contains(void* addr) {