hotspot/src/share/vm/gc_implementation/shared/parGCAllocBuffer.hpp
author mikael
Tue, 24 Dec 2013 11:48:39 -0800
changeset 22234 da823d78ad65
parent 17856 8871abcf70fa
child 22551 9bf46d16dcc6
permissions -rw-r--r--
8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013 Summary: Copyright year updated for files modified during 2013 Reviewed-by: twisti, iveresov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
22234
da823d78ad65 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 17856
diff changeset
     2
 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARGCALLOCBUFFER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARGCALLOCBUFFER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/allocation.hpp"
7408
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
    29
#include "memory/blockOffsetTable.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "memory/threadLocalAllocBuffer.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "utilities/globalDefinitions.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// Forward decl.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
class PLABStats;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// A per-thread allocation buffer used during GC.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7408
diff changeset
    38
class ParGCAllocBuffer: public CHeapObj<mtGC> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  char head[32];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  size_t _word_sz;          // in HeapWord units
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  HeapWord* _bottom;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  HeapWord* _top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  HeapWord* _end;       // last allocatable address + 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  HeapWord* _hard_end;  // _end + AlignmentReserve
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  bool      _retained;  // whether we hold a _retained_filler
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  MemRegion _retained_filler;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // In support of ergonomic sizing of PLAB's
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  size_t    _allocated;     // in HeapWord units
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  size_t    _wasted;        // in HeapWord units
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  char tail[32];
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    52
  static size_t FillerHeaderSize;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    53
  static size_t AlignmentReserve;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
13758
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
    55
  // Flush the stats supporting ergonomic sizing of PLAB's
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
    56
  // Should not be called directly
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
    57
  void flush_stats(PLABStats* stats);
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
    58
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // Initializes the buffer to be empty, but with the given "word_sz".
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // Must get initialized with "set_buf" for an allocation to succeed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  ParGCAllocBuffer(size_t word_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  static const size_t min_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    return ThreadLocalAllocBuffer::min_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  static const size_t max_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    return ThreadLocalAllocBuffer::max_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // If an allocation of the given "word_sz" can be satisfied within the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // buffer, do the allocation, returning a pointer to the start of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // allocated block.  If the allocation request cannot be satisfied,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  // return NULL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  HeapWord* allocate(size_t word_sz) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    HeapWord* res = _top;
2246
3c71d9b4b8e6 6808322: ParNew, CMS, G1: ParGCAllocBuffer overflow
ysr
parents: 670
diff changeset
    78
    if (pointer_delta(_end, _top) >= word_sz) {
3c71d9b4b8e6 6808322: ParNew, CMS, G1: ParGCAllocBuffer overflow
ysr
parents: 670
diff changeset
    79
      _top = _top + word_sz;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
      return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  // Undo the last allocation in the buffer, which is required to be of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // "obj" of the given "word_sz".
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  void undo_allocation(HeapWord* obj, size_t word_sz) {
2246
3c71d9b4b8e6 6808322: ParNew, CMS, G1: ParGCAllocBuffer overflow
ysr
parents: 670
diff changeset
    89
    assert(pointer_delta(_top, _bottom) >= word_sz, "Bad undo");
3c71d9b4b8e6 6808322: ParNew, CMS, G1: ParGCAllocBuffer overflow
ysr
parents: 670
diff changeset
    90
    assert(pointer_delta(_top, obj)     == word_sz, "Bad undo");
3c71d9b4b8e6 6808322: ParNew, CMS, G1: ParGCAllocBuffer overflow
ysr
parents: 670
diff changeset
    91
    _top = obj;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // The total (word) size of the buffer, including both allocated and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // unallocted space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  size_t word_sz() { return _word_sz; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // Should only be done if we are about to reset with a new buffer of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // given size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  void set_word_size(size_t new_word_sz) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    assert(new_word_sz > AlignmentReserve, "Too small");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    _word_sz = new_word_sz;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // The number of words of unallocated space remaining in the buffer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  size_t words_remaining() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    assert(_end >= _top, "Negative buffer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    return pointer_delta(_end, _top, HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  bool contains(void* addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    return (void*)_bottom <= addr && addr < (void*)_hard_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  // Sets the space of the buffer to be [buf, space+word_sz()).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  void set_buf(HeapWord* buf) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    _bottom   = buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    _top      = _bottom;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    _hard_end = _bottom + word_sz();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    _end      = _hard_end - AlignmentReserve;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    assert(_end >= _top, "Negative buffer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    // In support of ergonomic sizing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    _allocated += word_sz();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // Flush the stats supporting ergonomic sizing of PLAB's
13758
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   127
  // and retire the current buffer.
13466
9fdf353d5f4c 6818524: G1: use ergonomic resizing of PLABs
johnc
parents: 13195
diff changeset
   128
  void flush_stats_and_retire(PLABStats* stats, bool end_of_gc, bool retain) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    // We flush the stats first in order to get a reading of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    // unused space in the last buffer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    if (ResizePLAB) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      flush_stats(stats);
13758
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   133
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   134
      // Since we have flushed the stats we need to clear
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   135
      // the _allocated and _wasted fields. Not doing so
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   136
      // will artifically inflate the values in the stats
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   137
      // to which we add them.
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   138
      // The next time we flush these values, we will add
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   139
      // what we have just flushed in addition to the size
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   140
      // of the buffers allocated between now and then.
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   141
      _allocated = 0;
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   142
      _wasted = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    // Retire the last allocation buffer.
13466
9fdf353d5f4c 6818524: G1: use ergonomic resizing of PLABs
johnc
parents: 13195
diff changeset
   145
    retire(end_of_gc, retain);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // Force future allocations to fail and queries for contains()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  // to return false
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  void invalidate() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    assert(!_retained, "Shouldn't retain an invalidated buffer.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    _end    = _hard_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    _wasted += pointer_delta(_end, _top);  // unused  space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    _top    = _end;      // force future allocations to fail
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    _bottom = _end;      // force future contains() queries to return false
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // Fills in the unallocated portion of the buffer with a garbage object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // If "end_of_gc" is TRUE, is after the last use in the GC.  IF "retain"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  // is true, attempt to re-use the unused portion in the next GC.
17856
8871abcf70fa 6976350: G1: deal with fragmentation while copying objects during GC
tamao
parents: 13926
diff changeset
   161
  virtual void retire(bool end_of_gc, bool retain);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  void print() PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
// PLAB stats book-keeping
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
class PLABStats VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  size_t _allocated;      // total allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  size_t _wasted;         // of which wasted (internal fragmentation)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  size_t _unused;         // Unused in last buffer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  size_t _used;           // derived = allocated - wasted - unused
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  size_t _desired_plab_sz;// output of filter (below), suitably trimmed and quantized
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  AdaptiveWeightedAverage
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
         _filter;         // integrator with decay
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  PLABStats(size_t desired_plab_sz_, unsigned wt) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    _allocated(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    _wasted(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    _unused(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    _used(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    _desired_plab_sz(desired_plab_sz_),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    _filter(wt)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    size_t min_sz = min_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    size_t max_sz = max_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    size_t aligned_min_sz = align_object_size(min_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    size_t aligned_max_sz = align_object_size(max_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    assert(min_sz <= aligned_min_sz && max_sz >= aligned_max_sz &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
           min_sz <= max_sz,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
           "PLAB clipping computation in adjust_desired_plab_sz()"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
           " may be incorrect");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  static const size_t min_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    return ParGCAllocBuffer::min_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  static const size_t max_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    return ParGCAllocBuffer::max_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  size_t desired_plab_sz() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    return _desired_plab_sz;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
13926
289339903fcf 8000311: G1: ParallelGCThreads==0 broken
johnc
parents: 13758
diff changeset
   207
  void adjust_desired_plab_sz(uint no_of_gc_workers);
289339903fcf 8000311: G1: ParallelGCThreads==0 broken
johnc
parents: 13758
diff changeset
   208
                                 // filter computation, latches output to
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
                                 // _desired_plab_sz, clears sensor accumulators
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  void add_allocated(size_t v) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    Atomic::add_ptr(v, &_allocated);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  void add_unused(size_t v) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    Atomic::add_ptr(v, &_unused);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  void add_wasted(size_t v) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    Atomic::add_ptr(v, &_wasted);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
class ParGCAllocBufferWithBOT: public ParGCAllocBuffer {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  BlockOffsetArrayContigSpace _bt;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  BlockOffsetSharedArray*     _bsa;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  HeapWord*                   _true_end;  // end of the whole ParGCAllocBuffer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  static const size_t ChunkSizeInWords;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  static const size_t ChunkSizeInBytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  HeapWord* allocate_slow(size_t word_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  void fill_region_with_block(MemRegion mr, bool contig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  ParGCAllocBufferWithBOT(size_t word_sz, BlockOffsetSharedArray* bsa);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  HeapWord* allocate(size_t word_sz) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    HeapWord* res = ParGCAllocBuffer::allocate(word_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    if (res != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      _bt.alloc_block(res, word_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      res = allocate_slow(word_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  void undo_allocation(HeapWord* obj, size_t word_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  void set_buf(HeapWord* buf_start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    ParGCAllocBuffer::set_buf(buf_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    _true_end = _hard_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    _bt.set_region(MemRegion(buf_start, word_sz()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    _bt.initialize_threshold();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  void retire(bool end_of_gc, bool retain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  MemRegion range() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    return MemRegion(_top, _true_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   263
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   264
#endif // SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARGCALLOCBUFFER_HPP