< prev index next >

src/share/vm/gc_implementation/shared/parGCAllocBuffer.hpp

Print this page




  28 #include "gc_implementation/shared/gcUtil.hpp"
  29 #include "memory/allocation.hpp"
  30 #include "runtime/atomic.hpp"
  31 #include "utilities/globalDefinitions.hpp"
  32 
  33 // Forward declarations.
  34 class PLABStats;
  35 
  36 // A per-thread allocation buffer used during GC.
  37 class ParGCAllocBuffer: public CHeapObj<mtGC> {
  38 protected:
  39   char      head[32];
  40   size_t    _word_sz;          // In HeapWord units
  41   HeapWord* _bottom;
  42   HeapWord* _top;
  43   HeapWord* _end;           // Last allocatable address + 1
  44   HeapWord* _hard_end;      // _end + AlignmentReserve
  45   // In support of ergonomic sizing of PLAB's
  46   size_t    _allocated;     // in HeapWord units
  47   size_t    _wasted;        // in HeapWord units

  48   char      tail[32];
  49   static size_t AlignmentReserve;
  50 
  51   // Force future allocations to fail and queries for contains()
  52   // to return false. Returns the amount of unused space in this PLAB.
  53   size_t invalidate() {
  54     _end    = _hard_end;
  55     size_t remaining = pointer_delta(_end, _top);  // Calculate remaining space.
  56     _top    = _end;      // Force future allocations to fail.
  57     _bottom = _end;      // Force future contains() queries to return false.
  58     return remaining;
  59   }
  60 
  61   // Fill in remaining space with a dummy object and invalidate the PLAB. Returns
  62   // the amount of remaining space.
  63   size_t retire_internal();
  64 
  65 public:
  66   // Initializes the buffer to be empty, but with the given "word_sz".
  67   // Must get initialized with "set_buf" for an allocation to succeed.


  81     HeapWord* res = _top;
  82     if (pointer_delta(_end, _top) >= word_sz) {
  83       _top = _top + word_sz;
  84       return res;
  85     } else {
  86       return NULL;
  87     }
  88   }
  89 
  90   // Allocate the object aligned to "alignment_in_bytes".
  91   HeapWord* allocate_aligned(size_t word_sz, unsigned short alignment_in_bytes);
  92 
  93   // Undo the last allocation in the buffer, which is required to be of the
  94   // "obj" of the given "word_sz".
  95   void undo_allocation(HeapWord* obj, size_t word_sz) {
  96     assert(pointer_delta(_top, _bottom) >= word_sz, "Bad undo");
  97     assert(pointer_delta(_top, obj)     == word_sz, "Bad undo");
  98     _top = obj;
  99   }
 100 




 101   // The total (word) size of the buffer, including both allocated and
 102   // unallocated space.
 103   size_t word_sz() { return _word_sz; }



 104 
 105   // Should only be done if we are about to reset with a new buffer of the
 106   // given size.
 107   void set_word_size(size_t new_word_sz) {
 108     assert(new_word_sz > AlignmentReserve, "Too small");
 109     _word_sz = new_word_sz;
 110   }
 111 
 112   // The number of words of unallocated space remaining in the buffer.
 113   size_t words_remaining() {
 114     assert(_end >= _top, "Negative buffer");
 115     return pointer_delta(_end, _top, HeapWordSize);
 116   }
 117 
 118   bool contains(void* addr) {
 119     return (void*)_bottom <= addr && addr < (void*)_hard_end;
 120   }
 121 
 122   // Sets the space of the buffer to be [buf, space+word_sz()).
 123   virtual void set_buf(HeapWord* buf) {




  28 #include "gc_implementation/shared/gcUtil.hpp"
  29 #include "memory/allocation.hpp"
  30 #include "runtime/atomic.hpp"
  31 #include "utilities/globalDefinitions.hpp"
  32 
  33 // Forward declarations.
  34 class PLABStats;
  35 
  36 // A per-thread allocation buffer used during GC.
  37 class ParGCAllocBuffer: public CHeapObj<mtGC> {
  38 protected:
  39   char      head[32];
  40   size_t    _word_sz;          // In HeapWord units
  41   HeapWord* _bottom;
  42   HeapWord* _top;
  43   HeapWord* _end;           // Last allocatable address + 1
  44   HeapWord* _hard_end;      // _end + AlignmentReserve
  45   // In support of ergonomic sizing of PLAB's
  46   size_t    _allocated;     // in HeapWord units
  47   size_t    _wasted;        // in HeapWord units
  48   size_t    _undo_wasted;
  49   char      tail[32];
  50   static size_t AlignmentReserve;
  51 
  52   // Force future allocations to fail and queries for contains()
  53   // to return false. Returns the amount of unused space in this PLAB.
  54   size_t invalidate() {
  55     _end    = _hard_end;
  56     size_t remaining = pointer_delta(_end, _top);  // Calculate remaining space.
  57     _top    = _end;      // Force future allocations to fail.
  58     _bottom = _end;      // Force future contains() queries to return false.
  59     return remaining;
  60   }
  61 
  62   // Fill in remaining space with a dummy object and invalidate the PLAB. Returns
  63   // the amount of remaining space.
  64   size_t retire_internal();
  65 
  66 public:
  67   // Initializes the buffer to be empty, but with the given "word_sz".
  68   // Must get initialized with "set_buf" for an allocation to succeed.


  82     HeapWord* res = _top;
  83     if (pointer_delta(_end, _top) >= word_sz) {
  84       _top = _top + word_sz;
  85       return res;
  86     } else {
  87       return NULL;
  88     }
  89   }
  90 
  91   // Allocate the object aligned to "alignment_in_bytes".
  92   HeapWord* allocate_aligned(size_t word_sz, unsigned short alignment_in_bytes);
  93 
  94   // Undo the last allocation in the buffer, which is required to be of the
  95   // "obj" of the given "word_sz".
  96   void undo_allocation(HeapWord* obj, size_t word_sz) {
  97     assert(pointer_delta(_top, _bottom) >= word_sz, "Bad undo");
  98     assert(pointer_delta(_top, obj)     == word_sz, "Bad undo");
  99     _top = obj;
 100   }
 101   
 102   void add_undo_waste(size_t word_sz) {
 103     _undo_wasted += word_sz;
 104   }
 105 
 106   // The total (word) size of the buffer, including both allocated and
 107   // unallocated space.
 108   size_t word_sz() { return _word_sz; }
 109 
 110   size_t wasted() { return _wasted; }
 111   size_t undo_wasted() { return _undo_wasted; }
 112 
 113   // Should only be done if we are about to reset with a new buffer of the
 114   // given size.
 115   void set_word_size(size_t new_word_sz) {
 116     assert(new_word_sz > AlignmentReserve, "Too small");
 117     _word_sz = new_word_sz;
 118   }
 119 
 120   // The number of words of unallocated space remaining in the buffer.
 121   size_t words_remaining() {
 122     assert(_end >= _top, "Negative buffer");
 123     return pointer_delta(_end, _top, HeapWordSize);
 124   }
 125 
 126   bool contains(void* addr) {
 127     return (void*)_bottom <= addr && addr < (void*)_hard_end;
 128   }
 129 
 130   // Sets the space of the buffer to be [buf, space+word_sz()).
 131   virtual void set_buf(HeapWord* buf) {


< prev index next >