hotspot/src/share/vm/gc_implementation/shared/plab.hpp
author kbarrett
Tue, 21 Apr 2015 16:49:39 +0000
changeset 30276 1b77a431c374
parent 30261 faa43d41b739
parent 30275 41fef3a62cc8
child 30278 928bec4e217f
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
     1
/*
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
     2
 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
     4
 *
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
     7
 * published by the Free Software Foundation.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
     8
 *
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    13
 * accompanied this code).
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    14
 *
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    18
 *
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    21
 * questions.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    22
 *
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    23
 */
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    24
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    25
#ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_PLAB_HPP
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    26
#define SHARE_VM_GC_IMPLEMENTATION_SHARED_PLAB_HPP
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    27
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    28
#include "gc_implementation/shared/gcUtil.hpp"
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    29
#include "memory/allocation.hpp"
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    30
#include "runtime/atomic.hpp"
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    31
#include "utilities/globalDefinitions.hpp"
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    32
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    33
// Forward declarations.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    34
class PLABStats;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    35
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    36
// A per-thread allocation buffer used during GC.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    37
class PLAB: public CHeapObj<mtGC> {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    38
protected:
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    39
  char      head[32];
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    40
  size_t    _word_sz;          // In HeapWord units
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    41
  HeapWord* _bottom;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    42
  HeapWord* _top;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    43
  HeapWord* _end;           // Last allocatable address + 1
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    44
  HeapWord* _hard_end;      // _end + AlignmentReserve
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    45
  // In support of ergonomic sizing of PLAB's
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    46
  size_t    _allocated;     // in HeapWord units
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    47
  size_t    _wasted;        // in HeapWord units
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    48
  char      tail[32];
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    49
  static size_t AlignmentReserve;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    50
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    51
  // Force future allocations to fail and queries for contains()
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    52
  // to return false. Returns the amount of unused space in this PLAB.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    53
  size_t invalidate() {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    54
    _end    = _hard_end;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    55
    size_t remaining = pointer_delta(_end, _top);  // Calculate remaining space.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    56
    _top    = _end;      // Force future allocations to fail.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    57
    _bottom = _end;      // Force future contains() queries to return false.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    58
    return remaining;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    59
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    60
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    61
  // Fill in remaining space with a dummy object and invalidate the PLAB. Returns
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    62
  // the amount of remaining space.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    63
  size_t retire_internal();
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    64
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    65
public:
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    66
  // Initializes the buffer to be empty, but with the given "word_sz".
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    67
  // Must get initialized with "set_buf" for an allocation to succeed.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    68
  PLAB(size_t word_sz);
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    69
  virtual ~PLAB() {}
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    70
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    71
  // Minimum PLAB size.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    72
  static size_t min_size();
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    73
  // Maximum PLAB size.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    74
  static size_t max_size();
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    75
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    76
  // If an allocation of the given "word_sz" can be satisfied within the
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    77
  // buffer, do the allocation, returning a pointer to the start of the
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    78
  // allocated block.  If the allocation request cannot be satisfied,
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    79
  // return NULL.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    80
  HeapWord* allocate(size_t word_sz) {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    81
    HeapWord* res = _top;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    82
    if (pointer_delta(_end, _top) >= word_sz) {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    83
      _top = _top + word_sz;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    84
      return res;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    85
    } else {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    86
      return NULL;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    87
    }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    88
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    89
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    90
  // Allocate the object aligned to "alignment_in_bytes".
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    91
  HeapWord* allocate_aligned(size_t word_sz, unsigned short alignment_in_bytes);
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    92
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    93
  // Undo the last allocation in the buffer, which is required to be of the
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    94
  // "obj" of the given "word_sz".
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    95
  void undo_allocation(HeapWord* obj, size_t word_sz) {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    96
    assert(pointer_delta(_top, _bottom) >= word_sz, "Bad undo");
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    97
    assert(pointer_delta(_top, obj)     == word_sz, "Bad undo");
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    98
    _top = obj;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    99
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   100
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   101
  // The total (word) size of the buffer, including both allocated and
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   102
  // unallocated space.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   103
  size_t word_sz() { return _word_sz; }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   104
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   105
  // Should only be done if we are about to reset with a new buffer of the
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   106
  // given size.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   107
  void set_word_size(size_t new_word_sz) {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   108
    assert(new_word_sz > AlignmentReserve, "Too small");
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   109
    _word_sz = new_word_sz;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   110
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   111
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   112
  // The number of words of unallocated space remaining in the buffer.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   113
  size_t words_remaining() {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   114
    assert(_end >= _top, "Negative buffer");
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   115
    return pointer_delta(_end, _top, HeapWordSize);
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   116
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   117
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   118
  bool contains(void* addr) {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   119
    return (void*)_bottom <= addr && addr < (void*)_hard_end;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   120
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   121
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   122
  // Sets the space of the buffer to be [buf, space+word_sz()).
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   123
  virtual void set_buf(HeapWord* buf) {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   124
    _bottom   = buf;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   125
    _top      = _bottom;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   126
    _hard_end = _bottom + word_sz();
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   127
    _end      = _hard_end - AlignmentReserve;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   128
    assert(_end >= _top, "Negative buffer");
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   129
    // In support of ergonomic sizing
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   130
    _allocated += word_sz();
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   131
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   132
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   133
  // Flush allocation statistics into the given PLABStats supporting ergonomic
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   134
  // sizing of PLAB's and retire the current buffer. To be called at the end of
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   135
  // GC.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   136
  void flush_and_retire_stats(PLABStats* stats);
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   137
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   138
  // Fills in the unallocated portion of the buffer with a garbage object and updates
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   139
  // statistics. To be called during GC.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   140
  virtual void retire();
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   141
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   142
  void print() PRODUCT_RETURN;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   143
};
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   144
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   145
// PLAB book-keeping.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   146
class PLABStats VALUE_OBJ_CLASS_SPEC {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   147
  size_t _allocated;      // Total allocated
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   148
  size_t _wasted;         // of which wasted (internal fragmentation)
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   149
  size_t _unused;         // Unused in last buffer
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   150
  size_t _desired_plab_sz;// Output of filter (below), suitably trimmed and quantized
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   151
  AdaptiveWeightedAverage
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   152
         _filter;         // Integrator with decay
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   153
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   154
  void reset() {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   155
    _allocated = 0;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   156
    _wasted    = 0;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   157
    _unused    = 0;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   158
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   159
 public:
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   160
  PLABStats(size_t desired_plab_sz_, unsigned wt) :
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   161
    _allocated(0),
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   162
    _wasted(0),
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   163
    _unused(0),
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   164
    _desired_plab_sz(desired_plab_sz_),
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   165
    _filter(wt)
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   166
  { }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   167
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   168
  static const size_t min_size() {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   169
    return PLAB::min_size();
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   170
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   171
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   172
  static const size_t max_size() {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   173
    return PLAB::max_size();
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   174
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   175
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   176
  size_t desired_plab_sz() {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   177
    return _desired_plab_sz;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   178
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   179
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   180
  // Updates the current desired PLAB size. Computes the new desired PLAB size,
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   181
  // updates _desired_plab_sz and clears sensor accumulators.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   182
  void adjust_desired_plab_sz(uint no_of_gc_workers);
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   183
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   184
  void add_allocated(size_t v) {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   185
    Atomic::add_ptr(v, &_allocated);
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   186
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   187
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   188
  void add_unused(size_t v) {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   189
    Atomic::add_ptr(v, &_unused);
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   190
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   191
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   192
  void add_wasted(size_t v) {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   193
    Atomic::add_ptr(v, &_wasted);
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   194
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   195
};
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   196
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   197
#endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_PLAB_HPP