hotspot/src/share/vm/gc_implementation/shared/parGCAllocBuffer.cpp
author drchase
Fri, 09 May 2014 16:50:54 -0400
changeset 24424 2658d7834c6e
parent 24098 48f07e2c74de
child 27899 17754211a7ab
permissions -rw-r--r--
8037816: Fix for 8036122 breaks build with Xcode5/clang Summary: Repaired or selectively disabled offending formats; future-proofed with additional checking Reviewed-by: kvn, jrose, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24098
diff changeset
     2
 * Copyright (c) 2001, 2014, 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: 2105
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
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: 2105
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
#include "precompiled.hpp"
13466
9fdf353d5f4c 6818524: G1: use ergonomic resizing of PLABs
johnc
parents: 7397
diff changeset
    26
#include "gc_implementation/shared/parGCAllocBuffer.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "memory/sharedHeap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "oops/arrayOop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "oops/oop.inline.hpp"
24098
48f07e2c74de 8039957: Replace the last few %p usages with PTR_FORMAT in the GC code
stefank
parents: 24092
diff changeset
    30
#include "utilities/globalDefinitions.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24098
diff changeset
    32
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24098
diff changeset
    33
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
ParGCAllocBuffer::ParGCAllocBuffer(size_t desired_plab_sz_) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  _word_sz(desired_plab_sz_), _bottom(NULL), _top(NULL),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  _end(NULL), _hard_end(NULL),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  _retained(false), _retained_filler(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  _allocated(0), _wasted(0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  assert (min_size() > AlignmentReserve, "Inconsistency!");
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    41
  // arrayOopDesc::header_size depends on command line initialization.
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    42
  FillerHeaderSize = align_object_size(arrayOopDesc::header_size(T_INT));
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    43
  AlignmentReserve = oopDesc::header_size() > MinObjAlignment ? FillerHeaderSize : 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    46
size_t ParGCAllocBuffer::FillerHeaderSize;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// If the minimum object size is greater than MinObjAlignment, we can
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// end up with a shard at the end of the buffer that's smaller than
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// the smallest object.  We can't allow that because the buffer must
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
// look like it's full of objects when we retire it, so we make
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// sure we have enough space for a filler int array object.
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    53
size_t ParGCAllocBuffer::AlignmentReserve;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
void ParGCAllocBuffer::retire(bool end_of_gc, bool retain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  assert(!retain || end_of_gc, "Can only retain at GC end.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  if (_retained) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    // If the buffer had been retained shorten the previous filler object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    assert(_retained_filler.end() <= _top, "INVARIANT");
1668
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1063
diff changeset
    60
    CollectedHeap::fill_with_object(_retained_filler);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    // Wasted space book-keeping, otherwise (normally) done in invalidate()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    _wasted += _retained_filler.word_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    _retained = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  assert(!end_of_gc || !_retained, "At this point, end_of_gc ==> !_retained.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  if (_top < _hard_end) {
1668
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1063
diff changeset
    67
    CollectedHeap::fill_with_object(_top, _hard_end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    if (!retain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
      invalidate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
      // Is there wasted space we'd like to retain for the next GC?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
      if (pointer_delta(_end, _top) > FillerHeaderSize) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
        _retained = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
        _retained_filler = MemRegion(_top, FillerHeaderSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
        _top = _top + FillerHeaderSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
        invalidate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
void ParGCAllocBuffer::flush_stats(PLABStats* stats) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  assert(ResizePLAB, "Wasted work");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  stats->add_allocated(_allocated);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  stats->add_wasted(_wasted);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  stats->add_unused(pointer_delta(_end, _top));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
// Compute desired plab size and latch result for later
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
// use. This should be called once at the end of parallel
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
// scavenge; it clears the sensor accumulators.
13926
289339903fcf 8000311: G1: ParallelGCThreads==0 broken
johnc
parents: 13758
diff changeset
    93
void PLABStats::adjust_desired_plab_sz(uint no_of_gc_workers) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  assert(ResizePLAB, "Not set");
22552
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
    95
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
    96
  assert(is_object_aligned(max_size()) && min_size() <= max_size(),
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
    97
         "PLAB clipping computation may be incorrect");
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
    98
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  if (_allocated == 0) {
13758
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   100
    assert(_unused == 0,
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   101
           err_msg("Inconsistency in PLAB stats: "
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   102
                   "_allocated: "SIZE_FORMAT", "
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   103
                   "_wasted: "SIZE_FORMAT", "
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   104
                   "_unused: "SIZE_FORMAT", "
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   105
                   "_used  : "SIZE_FORMAT,
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   106
                   _allocated, _wasted, _unused, _used));
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   107
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    _allocated = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  double wasted_frac    = (double)_unused/(double)_allocated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  size_t target_refills = (size_t)((wasted_frac*TargetSurvivorRatio)/
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
                                   TargetPLABWastePct);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  if (target_refills == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    target_refills = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  _used = _allocated - _wasted - _unused;
13926
289339903fcf 8000311: G1: ParallelGCThreads==0 broken
johnc
parents: 13758
diff changeset
   117
  size_t plab_sz = _used/(target_refills*no_of_gc_workers);
24092
e274d864545a 8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents: 22552
diff changeset
   118
  if (PrintPLAB) gclog_or_tty->print(" (plab_sz = " SIZE_FORMAT " ", plab_sz);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // Take historical weighted average
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  _filter.sample(plab_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // Clip from above and below, and align to object boundary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  plab_sz = MAX2(min_size(), (size_t)_filter.average());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  plab_sz = MIN2(max_size(), plab_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  plab_sz = align_object_size(plab_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // Latch the result
24092
e274d864545a 8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents: 22552
diff changeset
   126
  if (PrintPLAB) gclog_or_tty->print(" desired_plab_sz = " SIZE_FORMAT ") ", plab_sz);
13466
9fdf353d5f4c 6818524: G1: use ergonomic resizing of PLABs
johnc
parents: 7397
diff changeset
   127
  _desired_plab_sz = plab_sz;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // Now clear the accumulators for next round:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  // note this needs to be fixed in the case where we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // are retaining across scavenges. FIX ME !!! XXX
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  _allocated = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  _wasted    = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  _unused    = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
void ParGCAllocBuffer::print() {
24098
48f07e2c74de 8039957: Replace the last few %p usages with PTR_FORMAT in the GC code
stefank
parents: 24092
diff changeset
   138
  gclog_or_tty->print("parGCAllocBuffer: _bottom: " PTR_FORMAT "  _top: " PTR_FORMAT
48f07e2c74de 8039957: Replace the last few %p usages with PTR_FORMAT in the GC code
stefank
parents: 24092
diff changeset
   139
             "  _end: " PTR_FORMAT "  _hard_end: " PTR_FORMAT " _retained: %c"
48f07e2c74de 8039957: Replace the last few %p usages with PTR_FORMAT in the GC code
stefank
parents: 24092
diff changeset
   140
             " _retained_filler: [" PTR_FORMAT "," PTR_FORMAT ")\n",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
             _bottom, _top, _end, _hard_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
             "FT"[_retained], _retained_filler.start(), _retained_filler.end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
#endif // !PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
const size_t ParGCAllocBufferWithBOT::ChunkSizeInWords =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
MIN2(CardTableModRefBS::par_chunk_heapword_alignment(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
     ((size_t)Generation::GenGrain)/HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
const size_t ParGCAllocBufferWithBOT::ChunkSizeInBytes =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
MIN2(CardTableModRefBS::par_chunk_heapword_alignment() * HeapWordSize,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
     (size_t)Generation::GenGrain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
ParGCAllocBufferWithBOT::ParGCAllocBufferWithBOT(size_t word_sz,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
                                                 BlockOffsetSharedArray* bsa) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  ParGCAllocBuffer(word_sz),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  _bsa(bsa),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  _bt(bsa, MemRegion(_bottom, _hard_end)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  _true_end(_hard_end)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
{}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
// The buffer comes with its own BOT, with a shared (obviously) underlying
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
// BlockOffsetSharedArray. We manipulate this BOT in the normal way
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 13926
diff changeset
   163
// as we would for any contiguous space. However, on occasion we
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
// need to do some buffer surgery at the extremities before we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
// start using the body of the buffer for allocations. Such surgery
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
// (as explained elsewhere) is to prevent allocation on a card that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
// is in the process of being walked concurrently by another GC thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
// When such surgery happens at a point that is far removed (to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
// right of the current allocation point, top), we use the "contig"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
// parameter below to directly manipulate the shared array without
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
// modifying the _next_threshold state in the BOT.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
void ParGCAllocBufferWithBOT::fill_region_with_block(MemRegion mr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
                                                     bool contig) {
1668
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1063
diff changeset
   174
  CollectedHeap::fill_with_object(mr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  if (contig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    _bt.alloc_block(mr.start(), mr.end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    _bt.BlockOffsetArray::alloc_block(mr.start(), mr.end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
HeapWord* ParGCAllocBufferWithBOT::allocate_slow(size_t word_sz) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  HeapWord* res = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  if (_true_end > _hard_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    assert((HeapWord*)align_size_down(intptr_t(_hard_end),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
                                      ChunkSizeInBytes) == _hard_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
           "or else _true_end should be equal to _hard_end");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    assert(_retained, "or else _true_end should be equal to _hard_end");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    assert(_retained_filler.end() <= _top, "INVARIANT");
1668
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1063
diff changeset
   190
    CollectedHeap::fill_with_object(_retained_filler);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    if (_top < _hard_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      fill_region_with_block(MemRegion(_top, _hard_end), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    HeapWord* next_hard_end = MIN2(_true_end, _hard_end + ChunkSizeInWords);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    _retained_filler = MemRegion(_hard_end, FillerHeaderSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    _bt.alloc_block(_retained_filler.start(), _retained_filler.word_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    _top      = _retained_filler.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    _hard_end = next_hard_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    _end      = _hard_end - AlignmentReserve;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    res       = ParGCAllocBuffer::allocate(word_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    if (res != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      _bt.alloc_block(res, word_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
ParGCAllocBufferWithBOT::undo_allocation(HeapWord* obj, size_t word_sz) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  ParGCAllocBuffer::undo_allocation(obj, word_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  // This may back us up beyond the previous threshold, so reset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  _bt.set_region(MemRegion(_top, _hard_end));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  _bt.initialize_threshold();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
void ParGCAllocBufferWithBOT::retire(bool end_of_gc, bool retain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  assert(!retain || end_of_gc, "Can only retain at GC end.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  if (_retained) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    // We're about to make the retained_filler into a block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    _bt.BlockOffsetArray::alloc_block(_retained_filler.start(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
                                      _retained_filler.end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  // Reset _hard_end to _true_end (and update _end)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  if (retain && _hard_end != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    assert(_hard_end <= _true_end, "Invariant.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    _hard_end = _true_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    _end      = MAX2(_top, _hard_end - AlignmentReserve);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    assert(_end <= _hard_end, "Invariant.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  _true_end = _hard_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  HeapWord* pre_top = _top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  ParGCAllocBuffer::retire(end_of_gc, retain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  // Now any old _retained_filler is cut back to size, the free part is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  // filled with a filler object, and top is past the header of that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  // object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  if (retain && _top < _end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    assert(end_of_gc && retain, "Or else retain should be false.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    // If the lab does not start on a card boundary, we don't want to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    // allocate onto that card, since that might lead to concurrent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    // allocation and card scanning, which we don't support.  So we fill
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    // the first card with a garbage object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    size_t first_card_index = _bsa->index_for(pre_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    HeapWord* first_card_start = _bsa->address_for_index(first_card_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    if (first_card_start < pre_top) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      HeapWord* second_card_start =
1063
f666dc7f514d 6728478: Assertion at parallel promotion from young to old generation
jmasa
parents: 670
diff changeset
   248
        _bsa->inc_by_region_size(first_card_start);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      // Ensure enough room to fill with the smallest block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      second_card_start = MAX2(second_card_start, pre_top + AlignmentReserve);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      // If the end is already in the first card, don't go beyond it!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
      // Or if the remainder is too small for a filler object, gobble it up.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
      if (_hard_end < second_card_start ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
          pointer_delta(_hard_end, second_card_start) < AlignmentReserve) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
        second_card_start = _hard_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      if (pre_top < second_card_start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
        MemRegion first_card_suffix(pre_top, second_card_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
        fill_region_with_block(first_card_suffix, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
      pre_top = second_card_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
      _top = pre_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
      _end = MAX2(_top, _hard_end - AlignmentReserve);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    // If the lab does not end on a card boundary, we don't want to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    // allocate onto that card, since that might lead to concurrent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    // allocation and card scanning, which we don't support.  So we fill
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    // the last card with a garbage object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    size_t last_card_index = _bsa->index_for(_hard_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    HeapWord* last_card_start = _bsa->address_for_index(last_card_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    if (last_card_start < _hard_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
      // Ensure enough room to fill with the smallest block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
      last_card_start = MIN2(last_card_start, _hard_end - AlignmentReserve);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
      // If the top is already in the last card, don't go back beyond it!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      // Or if the remainder is too small for a filler object, gobble it up.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
      if (_top > last_card_start ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
          pointer_delta(last_card_start, _top) < AlignmentReserve) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
        last_card_start = _top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
      if (last_card_start < _hard_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
        MemRegion last_card_prefix(last_card_start, _hard_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
        fill_region_with_block(last_card_prefix, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
      _hard_end = last_card_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
      _end      = MAX2(_top, _hard_end - AlignmentReserve);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      _true_end = _hard_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
      assert(_end <= _hard_end, "Invariant.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    // At this point:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    //   1) we had a filler object from the original top to hard_end.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    //   2) We've filled in any partial cards at the front and back.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    if (pre_top < _hard_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
      // Now we can reset the _bt to do allocation in the given area.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
      MemRegion new_filler(pre_top, _hard_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
      fill_region_with_block(new_filler, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
      _top = pre_top + ParGCAllocBuffer::FillerHeaderSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
      // If there's no space left, don't retain.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
      if (_top >= _end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
        _retained = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
        invalidate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
      _retained_filler = MemRegion(pre_top, _top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
      _bt.set_region(MemRegion(_top, _hard_end));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
      _bt.initialize_threshold();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
      assert(_bt.threshold() > _top, "initialize_threshold failed!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
      // There may be other reasons for queries into the middle of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
      // filler object.  When such queries are done in parallel with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
      // allocation, bad things can happen, if the query involves object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
      // iteration.  So we ensure that such queries do not involve object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
      // iteration, by putting another filler object on the boundaries of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
      // such queries.  One such is the object spanning a parallel card
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
      // chunk boundary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
      // "chunk_boundary" is the address of the first chunk boundary less
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
      // than "hard_end".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
      HeapWord* chunk_boundary =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
        (HeapWord*)align_size_down(intptr_t(_hard_end-1), ChunkSizeInBytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
      assert(chunk_boundary < _hard_end, "Or else above did not work.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
      assert(pointer_delta(_true_end, chunk_boundary) >= AlignmentReserve,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
             "Consequence of last card handling above.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
      if (_top <= chunk_boundary) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
        assert(_true_end == _hard_end, "Invariant.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
        while (_top <= chunk_boundary) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
          assert(pointer_delta(_hard_end, chunk_boundary) >= AlignmentReserve,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
                 "Consequence of last card handling above.");
1668
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1063
diff changeset
   335
          _bt.BlockOffsetArray::alloc_block(chunk_boundary, _hard_end);
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1063
diff changeset
   336
          CollectedHeap::fill_with_object(chunk_boundary, _hard_end);
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1063
diff changeset
   337
          _hard_end = chunk_boundary;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
          chunk_boundary -= ChunkSizeInWords;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
        _end = _hard_end - AlignmentReserve;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
        assert(_top <= _end, "Invariant.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
        // Now reset the initial filler chunk so it doesn't overlap with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
        // the one(s) inserted above.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
        MemRegion new_filler(pre_top, _hard_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
        fill_region_with_block(new_filler, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
      _retained = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
      invalidate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    assert(!end_of_gc ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
           (!_retained && _true_end == _hard_end), "Checking.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  assert(_end <= _hard_end, "Invariant.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  assert(_top < _end || _top == _hard_end, "Invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
}