< prev index next >

src/share/vm/gc/shared/plab.hpp

Print this page
rev 8852 : [mq]: 8133470-fix-plab-inline
rev 8853 : imported patch mikael-erik-suggestions
rev 8854 : imported patch 8073013-add-detailed-information-about-plab-memory-usage
rev 8857 : imported patch mikael-comments
rev 8866 : imported patch 8067339-PLAB-reallocation-might-result-in-failure-to-allocate
rev 8867 : [mq]: bengt-refactoring


  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   void add_undo_waste(HeapWord* obj, size_t word_sz);
  66 
  67   // Undo the last allocation in the buffer, which is required to be of the
  68   // "obj" of the given "word_sz".
  69   void undo_last_allocation(HeapWord* obj, size_t word_sz);
  70 
  71 public:
  72   // Initializes the buffer to be empty, but with the given "word_sz".
  73   // Must get initialized with "set_buf" for an allocation to succeed.
  74   PLAB(size_t word_sz);
  75   virtual ~PLAB() {}
  76 
  77   static size_t alignment_reserve() { return AlignmentReserve; }
  78 
  79   // Minimum PLAB size.
  80   static size_t min_size();
  81   // Maximum PLAB size.
  82   static size_t max_size();
  83 
  84   // If an allocation of the given "word_sz" can be satisfied within the
  85   // buffer, do the allocation, returning a pointer to the start of the
  86   // allocated block.  If the allocation request cannot be satisfied,
  87   // return NULL.
  88   HeapWord* allocate(size_t word_sz) {
  89     HeapWord* res = _top;
  90     if (pointer_delta(_end, _top) >= word_sz) {
  91       _top = _top + word_sz;
  92       return res;
  93     } else {
  94       return NULL;
  95     }
  96   }
  97 
  98   // Allocate the object aligned to "alignment_in_bytes".
  99   inline HeapWord* allocate_aligned(size_t word_sz, unsigned short alignment_in_bytes);
 100 
 101   // Undo any allocation in the buffer, which is required to be of the
 102   // "obj" of the given "word_sz".
 103   void undo_allocation(HeapWord* obj, size_t word_sz);
 104 
 105   // The total (word) size of the buffer, including both allocated and
 106   // unallocated space.
 107   size_t word_sz() { return _word_sz; }
 108 
 109   size_t waste() { return _wasted; }
 110   size_t undo_waste() { return _undo_wasted; }
 111 
 112   // Should only be done if we are about to reset with a new buffer of the
 113   // given size.
 114   void set_word_size(size_t new_word_sz) {
 115     assert(new_word_sz > AlignmentReserve, "Too small");
 116     _word_sz = new_word_sz;
 117   }
 118 
 119   // The number of words of unallocated space remaining in the buffer.
 120   size_t words_remaining() {
 121     assert(_end >= _top, "Negative buffer");
 122     return pointer_delta(_end, _top, HeapWordSize);
 123   }
 124 
 125   bool contains(void* addr) {
 126     return (void*)_bottom <= addr && addr < (void*)_hard_end;
 127   }
 128 
 129   // Sets the space of the buffer to be [buf, space+word_sz()).
 130   virtual void set_buf(HeapWord* buf) {



 131     _bottom   = buf;
 132     _top      = _bottom;
 133     _hard_end = _bottom + word_sz();
 134     _end      = _hard_end - AlignmentReserve;
 135     assert(_end >= _top, "Negative buffer");
 136     // In support of ergonomic sizing
 137     _allocated += word_sz();
 138   }
 139 
 140   // Flush allocation statistics into the given PLABStats supporting ergonomic
 141   // sizing of PLAB's and retire the current buffer. To be called at the end of
 142   // GC.
 143   virtual void flush_and_retire_stats(PLABStats* stats);
 144 
 145   // Fills in the unallocated portion of the buffer with a garbage object and updates
 146   // statistics. To be called during GC.
 147   virtual void retire();
 148 
 149   void print() PRODUCT_RETURN;
 150 };




  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   void add_undo_waste(HeapWord* obj, size_t word_sz);
  66 
  67   // Undo the last allocation in the buffer, which is required to be of the
  68   // "obj" of the given "word_sz".
  69   void undo_last_allocation(HeapWord* obj, size_t word_sz);
  70 
  71 public:
  72   // Initializes the buffer to be empty, but with the given "word_sz".
  73   // Must get initialized with "set_buf" for an allocation to succeed.
  74   PLAB(size_t word_sz);
  75   virtual ~PLAB() {}
  76 
  77   static size_t size_required_for_allocation(size_t word_size) { return word_size + AlignmentReserve; }
  78 
  79   // Minimum PLAB size.
  80   static size_t min_size();
  81   // Maximum PLAB size.
  82   static size_t max_size();
  83 
  84   // If an allocation of the given "word_sz" can be satisfied within the
  85   // buffer, do the allocation, returning a pointer to the start of the
  86   // allocated block.  If the allocation request cannot be satisfied,
  87   // return NULL.
  88   HeapWord* allocate(size_t word_sz) {
  89     HeapWord* res = _top;
  90     if (pointer_delta(_end, _top) >= word_sz) {
  91       _top = _top + word_sz;
  92       return res;
  93     } else {
  94       return NULL;
  95     }
  96   }
  97 
  98   // Allocate the object aligned to "alignment_in_bytes".
  99   inline HeapWord* allocate_aligned(size_t word_sz, unsigned short alignment_in_bytes);
 100 
 101   // Undo any allocation in the buffer, which is required to be of the
 102   // "obj" of the given "word_sz".
 103   void undo_allocation(HeapWord* obj, size_t word_sz);
 104 
 105   // The total (word) size of the buffer, including both allocated and
 106   // unallocated space.
 107   size_t word_sz() { return _word_sz; }
 108 
 109   size_t waste() { return _wasted; }
 110   size_t undo_waste() { return _undo_wasted; }
 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, size_t new_word_sz) {
 124     assert(new_word_sz > AlignmentReserve, "Too small");
 125     _word_sz = new_word_sz;
 126 
 127     _bottom   = buf;
 128     _top      = _bottom;
 129     _hard_end = _bottom + word_sz();
 130     _end      = _hard_end - AlignmentReserve;
 131     assert(_end >= _top, "Negative buffer");
 132     // In support of ergonomic sizing
 133     _allocated += word_sz();
 134   }
 135 
 136   // Flush allocation statistics into the given PLABStats supporting ergonomic
 137   // sizing of PLAB's and retire the current buffer. To be called at the end of
 138   // GC.
 139   virtual void flush_and_retire_stats(PLABStats* stats);
 140 
 141   // Fills in the unallocated portion of the buffer with a garbage object and updates
 142   // statistics. To be called during GC.
 143   virtual void retire();
 144 
 145   void print() PRODUCT_RETURN;
 146 };


< prev index next >