hotspot/src/share/vm/gc_implementation/shared/plab.hpp
changeset 30564 a37d98a1eb54
parent 30278 928bec4e217f
child 30571 9223db5721fe
equal deleted inserted replaced
30563:03c5eaa78f80 30564:a37d98a1eb54
    43   HeapWord* _end;           // Last allocatable address + 1
    43   HeapWord* _end;           // Last allocatable address + 1
    44   HeapWord* _hard_end;      // _end + AlignmentReserve
    44   HeapWord* _hard_end;      // _end + AlignmentReserve
    45   // In support of ergonomic sizing of PLAB's
    45   // In support of ergonomic sizing of PLAB's
    46   size_t    _allocated;     // in HeapWord units
    46   size_t    _allocated;     // in HeapWord units
    47   size_t    _wasted;        // in HeapWord units
    47   size_t    _wasted;        // in HeapWord units
       
    48   size_t    _undo_wasted;
    48   char      tail[32];
    49   char      tail[32];
    49   static size_t AlignmentReserve;
    50   static size_t AlignmentReserve;
    50 
    51 
    51   // Force future allocations to fail and queries for contains()
    52   // Force future allocations to fail and queries for contains()
    52   // to return false. Returns the amount of unused space in this PLAB.
    53   // to return false. Returns the amount of unused space in this PLAB.
    59   }
    60   }
    60 
    61 
    61   // Fill in remaining space with a dummy object and invalidate the PLAB. Returns
    62   // Fill in remaining space with a dummy object and invalidate the PLAB. Returns
    62   // the amount of remaining space.
    63   // the amount of remaining space.
    63   size_t retire_internal();
    64   size_t retire_internal();
       
    65 
       
    66   void add_undo_waste(HeapWord* obj, size_t word_sz);
       
    67 
       
    68   // Undo the last allocation in the buffer, which is required to be of the
       
    69   // "obj" of the given "word_sz".
       
    70   void undo_last_allocation(HeapWord* obj, size_t word_sz);
    64 
    71 
    65 public:
    72 public:
    66   // Initializes the buffer to be empty, but with the given "word_sz".
    73   // Initializes the buffer to be empty, but with the given "word_sz".
    67   // Must get initialized with "set_buf" for an allocation to succeed.
    74   // Must get initialized with "set_buf" for an allocation to succeed.
    68   PLAB(size_t word_sz);
    75   PLAB(size_t word_sz);
    88   }
    95   }
    89 
    96 
    90   // Allocate the object aligned to "alignment_in_bytes".
    97   // Allocate the object aligned to "alignment_in_bytes".
    91   HeapWord* allocate_aligned(size_t word_sz, unsigned short alignment_in_bytes);
    98   HeapWord* allocate_aligned(size_t word_sz, unsigned short alignment_in_bytes);
    92 
    99 
    93   // Undo the last allocation in the buffer, which is required to be of the
   100   // Undo any allocation in the buffer, which is required to be of the
    94   // "obj" of the given "word_sz".
   101   // "obj" of the given "word_sz".
    95   void undo_allocation(HeapWord* obj, size_t word_sz) {
   102   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 
   103 
   101   // The total (word) size of the buffer, including both allocated and
   104   // The total (word) size of the buffer, including both allocated and
   102   // unallocated space.
   105   // unallocated space.
   103   size_t word_sz() { return _word_sz; }
   106   size_t word_sz() { return _word_sz; }
       
   107 
       
   108   size_t waste() { return _wasted; }
       
   109   size_t undo_waste() { return _undo_wasted; }
   104 
   110 
   105   // Should only be done if we are about to reset with a new buffer of the
   111   // Should only be done if we are about to reset with a new buffer of the
   106   // given size.
   112   // given size.
   107   void set_word_size(size_t new_word_sz) {
   113   void set_word_size(size_t new_word_sz) {
   108     assert(new_word_sz > AlignmentReserve, "Too small");
   114     assert(new_word_sz > AlignmentReserve, "Too small");
   144 
   150 
   145 // PLAB book-keeping.
   151 // PLAB book-keeping.
   146 class PLABStats VALUE_OBJ_CLASS_SPEC {
   152 class PLABStats VALUE_OBJ_CLASS_SPEC {
   147   size_t _allocated;      // Total allocated
   153   size_t _allocated;      // Total allocated
   148   size_t _wasted;         // of which wasted (internal fragmentation)
   154   size_t _wasted;         // of which wasted (internal fragmentation)
       
   155   size_t _undo_wasted;    // of which wasted on undo (is not used for calculation of PLAB size)
   149   size_t _unused;         // Unused in last buffer
   156   size_t _unused;         // Unused in last buffer
   150   size_t _desired_plab_sz;// Output of filter (below), suitably trimmed and quantized
   157   size_t _desired_plab_sz;// Output of filter (below), suitably trimmed and quantized
   151   AdaptiveWeightedAverage
   158   AdaptiveWeightedAverage
   152          _filter;         // Integrator with decay
   159          _filter;         // Integrator with decay
   153 
   160 
   154   void reset() {
   161   void reset() {
   155     _allocated = 0;
   162     _allocated   = 0;
   156     _wasted    = 0;
   163     _wasted      = 0;
   157     _unused    = 0;
   164     _undo_wasted = 0;
       
   165     _unused      = 0;
   158   }
   166   }
   159  public:
   167  public:
   160   PLABStats(size_t desired_plab_sz_, unsigned wt) :
   168   PLABStats(size_t desired_plab_sz_, unsigned wt) :
   161     _allocated(0),
   169     _allocated(0),
   162     _wasted(0),
   170     _wasted(0),
       
   171     _undo_wasted(0),
   163     _unused(0),
   172     _unused(0),
   164     _desired_plab_sz(desired_plab_sz_),
   173     _desired_plab_sz(desired_plab_sz_),
   165     _filter(wt)
   174     _filter(wt)
   166   { }
   175   { }
   167 
   176 
   190   }
   199   }
   191 
   200 
   192   void add_wasted(size_t v) {
   201   void add_wasted(size_t v) {
   193     Atomic::add_ptr(v, &_wasted);
   202     Atomic::add_ptr(v, &_wasted);
   194   }
   203   }
       
   204 
       
   205   void add_undo_wasted(size_t v) {
       
   206     Atomic::add_ptr(v, &_undo_wasted);
       
   207   }
   195 };
   208 };
   196 
   209 
   197 #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_PLAB_HPP
   210 #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_PLAB_HPP