src/hotspot/share/gc/shared/plab.hpp
author tschatzl
Tue, 13 Feb 2018 16:13:20 +0100
changeset 48963 7e09b699f7b6
parent 47216 71c04702a3d5
child 53244 9807daeb47c4
permissions -rw-r--r--
7127700: G1: Replace G1PLAB with PLAB Reviewed-by: sjohanss, kbarrett
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
/*
48963
7e09b699f7b6 7127700: G1: Replace G1PLAB with PLAB
tschatzl
parents: 47216
diff changeset
     2
 * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
30275
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
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    25
#ifndef SHARE_VM_GC_SHARED_PLAB_HPP
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    26
#define SHARE_VM_GC_SHARED_PLAB_HPP
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    27
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    28
#include "gc/shared/gcUtil.hpp"
30275
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 "utilities/globalDefinitions.hpp"
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    31
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    32
// Forward declarations.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    33
class PLABStats;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    34
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    35
// A per-thread allocation buffer used during GC.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    36
class PLAB: public CHeapObj<mtGC> {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    37
protected:
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    38
  char      head[32];
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    39
  size_t    _word_sz;          // In HeapWord units
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    40
  HeapWord* _bottom;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    41
  HeapWord* _top;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    42
  HeapWord* _end;           // Last allocatable address + 1
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    43
  HeapWord* _hard_end;      // _end + AlignmentReserve
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    44
  // In support of ergonomic sizing of PLAB's
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    45
  size_t    _allocated;     // in HeapWord units
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    46
  size_t    _wasted;        // in HeapWord units
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
    47
  size_t    _undo_wasted;
30275
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
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
    65
  void add_undo_waste(HeapWord* obj, size_t word_sz);
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
    66
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
    67
  // Undo the last allocation in the buffer, which is required to be of the
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
    68
  // "obj" of the given "word_sz".
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
    69
  void undo_last_allocation(HeapWord* obj, size_t word_sz);
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
    70
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    71
public:
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    72
  // 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
    73
  // Must get initialized with "set_buf" for an allocation to succeed.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    74
  PLAB(size_t word_sz);
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    75
32383
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
    76
  static size_t size_required_for_allocation(size_t word_size) { return word_size + AlignmentReserve; }
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
    77
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    78
  // Minimum PLAB size.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    79
  static size_t min_size();
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    80
  // Maximum PLAB size.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    81
  static size_t max_size();
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    82
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    83
  // 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
    84
  // 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
    85
  // allocated block.  If the allocation request cannot be satisfied,
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
  HeapWord* allocate(size_t word_sz) {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    88
    HeapWord* res = _top;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    89
    if (pointer_delta(_end, _top) >= word_sz) {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    90
      _top = _top + word_sz;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    91
      return res;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    92
    } else {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    93
      return NULL;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    94
    }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    95
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    96
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    97
  // Allocate the object aligned to "alignment_in_bytes".
32378
8dd0e7359751 8133470: Uses of Atomic methods in plab.hpp should be moved to .inline.hpp file
tschatzl
parents: 31632
diff changeset
    98
  inline HeapWord* allocate_aligned(size_t word_sz, unsigned short alignment_in_bytes);
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    99
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
   100
  // Undo any allocation in the buffer, which is required to be of the
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   101
  // "obj" of the given "word_sz".
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
   102
  void undo_allocation(HeapWord* obj, size_t word_sz);
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   103
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   104
  // The total (word) size of the buffer, including both allocated and
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   105
  // unallocated space.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   106
  size_t word_sz() { return _word_sz; }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   107
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
   108
  size_t waste() { return _wasted; }
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
   109
  size_t undo_waste() { return _undo_wasted; }
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
   110
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   111
  // The number of words of unallocated space remaining in the buffer.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   112
  size_t words_remaining() {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   113
    assert(_end >= _top, "Negative buffer");
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   114
    return pointer_delta(_end, _top, HeapWordSize);
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   115
  }
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
  bool contains(void* addr) {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   118
    return (void*)_bottom <= addr && addr < (void*)_hard_end;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   119
  }
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
  // Sets the space of the buffer to be [buf, space+word_sz()).
48963
7e09b699f7b6 7127700: G1: Replace G1PLAB with PLAB
tschatzl
parents: 47216
diff changeset
   122
  void set_buf(HeapWord* buf, size_t new_word_sz) {
32383
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
   123
    assert(new_word_sz > AlignmentReserve, "Too small");
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
   124
    _word_sz = new_word_sz;
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
   125
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   126
    _bottom   = buf;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   127
    _top      = _bottom;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   128
    _hard_end = _bottom + word_sz();
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   129
    _end      = _hard_end - AlignmentReserve;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   130
    assert(_end >= _top, "Negative buffer");
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   131
    // In support of ergonomic sizing
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   132
    _allocated += word_sz();
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   133
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   134
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   135
  // Flush allocation statistics into the given PLABStats supporting ergonomic
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   136
  // 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
   137
  // GC.
48963
7e09b699f7b6 7127700: G1: Replace G1PLAB with PLAB
tschatzl
parents: 47216
diff changeset
   138
  void flush_and_retire_stats(PLABStats* stats);
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   139
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   140
  // 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
   141
  // statistics. To be called during GC.
48963
7e09b699f7b6 7127700: G1: Replace G1PLAB with PLAB
tschatzl
parents: 47216
diff changeset
   142
  void retire();
30275
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.
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32378
diff changeset
   146
class PLABStats : public CHeapObj<mtGC> {
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32378
diff changeset
   147
 protected:
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   148
  const char* _description;   // Identifying string.
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   149
31632
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 30764
diff changeset
   150
  size_t _allocated;          // Total allocated
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 30764
diff changeset
   151
  size_t _wasted;             // of which wasted (internal fragmentation)
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 30764
diff changeset
   152
  size_t _undo_wasted;        // of which wasted on undo (is not used for calculation of PLAB size)
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 30764
diff changeset
   153
  size_t _unused;             // Unused in last buffer
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 30764
diff changeset
   154
  size_t _desired_net_plab_sz;// Output of filter (below), suitably trimmed and quantized
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   155
  AdaptiveWeightedAverage
31632
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 30764
diff changeset
   156
         _filter;             // Integrator with decay
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   157
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32378
diff changeset
   158
  virtual void reset() {
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
   159
    _allocated   = 0;
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
   160
    _wasted      = 0;
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
   161
    _undo_wasted = 0;
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
   162
    _unused      = 0;
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   163
  }
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   164
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   165
  virtual void log_plab_allocation();
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   166
  virtual void log_sizing(size_t calculated, size_t net_desired);
46290
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 36390
diff changeset
   167
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 36390
diff changeset
   168
  // helper for adjust_desired_plab_sz().
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 36390
diff changeset
   169
  virtual size_t compute_desired_plab_sz();
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 36390
diff changeset
   170
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   171
 public:
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   172
  PLABStats(const char* description, size_t desired_net_plab_sz_, unsigned wt) :
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   173
    _description(description),
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   174
    _allocated(0),
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   175
    _wasted(0),
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
   176
    _undo_wasted(0),
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   177
    _unused(0),
31632
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 30764
diff changeset
   178
    _desired_net_plab_sz(desired_net_plab_sz_),
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   179
    _filter(wt)
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   180
  { }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   181
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32378
diff changeset
   182
  virtual ~PLABStats() { }
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32378
diff changeset
   183
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   184
  size_t allocated() const { return _allocated; }
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   185
  size_t wasted() const { return _wasted; }
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   186
  size_t unused() const { return _unused; }
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   187
  size_t used() const { return allocated() - (wasted() + unused()); }
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   188
  size_t undo_wasted() const { return _undo_wasted; }
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   189
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   190
  static const size_t min_size() {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   191
    return PLAB::min_size();
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   192
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   193
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   194
  static const size_t max_size() {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   195
    return PLAB::max_size();
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
31632
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 30764
diff changeset
   198
  // Calculates plab size for current number of gc worker threads.
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 30764
diff changeset
   199
  size_t desired_plab_sz(uint no_of_gc_workers);
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   200
31632
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 30764
diff changeset
   201
  // Updates the current desired PLAB size. Computes the new desired PLAB size with one gc worker thread,
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   202
  // updates _desired_plab_sz and clears sensor accumulators.
46290
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 36390
diff changeset
   203
  void adjust_desired_plab_sz();
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   204
32378
8dd0e7359751 8133470: Uses of Atomic methods in plab.hpp should be moved to .inline.hpp file
tschatzl
parents: 31632
diff changeset
   205
  inline void add_allocated(size_t v);
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   206
32378
8dd0e7359751 8133470: Uses of Atomic methods in plab.hpp should be moved to .inline.hpp file
tschatzl
parents: 31632
diff changeset
   207
  inline void add_unused(size_t v);
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   208
32378
8dd0e7359751 8133470: Uses of Atomic methods in plab.hpp should be moved to .inline.hpp file
tschatzl
parents: 31632
diff changeset
   209
  inline void add_wasted(size_t v);
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
   210
32378
8dd0e7359751 8133470: Uses of Atomic methods in plab.hpp should be moved to .inline.hpp file
tschatzl
parents: 31632
diff changeset
   211
  inline void add_undo_wasted(size_t v);
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   212
};
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   213
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
   214
#endif // SHARE_VM_GC_SHARED_PLAB_HPP