hotspot/src/share/vm/memory/tenuredGeneration.cpp
author sjohanss
Wed, 27 Aug 2014 09:47:06 +0200
changeset 26324 6b9c12e15535
parent 22551 9bf46d16dcc6
child 27898 813ad96387b3
permissions -rw-r--r--
8028787: tmtools/jstat/gcoldcapacity/jstat_gcoldcapacity02 fails nsk.share.Failure: OGC < OGCMN in RT_Baseline Summary: Passing the min and max size of the generation into the counter instead of using the space to estimate sizes. Reviewed-by: stefank, tschatzl
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: 16681
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: 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: 6985
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    26
#include "gc_implementation/shared/collectorCounters.hpp"
13466
9fdf353d5f4c 6818524: G1: use ergonomic resizing of PLABs
johnc
parents: 13195
diff changeset
    27
#include "gc_implementation/shared/parGCAllocBuffer.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    28
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    29
#include "memory/blockOffsetTable.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    30
#include "memory/generation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    31
#include "memory/generationSpec.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    32
#include "memory/space.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    33
#include "memory/tenuredGeneration.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    34
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    35
#include "runtime/java.hpp"
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 15091
diff changeset
    36
#include "utilities/macros.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
TenuredGeneration::TenuredGeneration(ReservedSpace rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
                                     size_t initial_byte_size, int level,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
                                     GenRemSet* remset) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  OneContigSpaceCardGeneration(rs, initial_byte_size,
16681
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 15482
diff changeset
    42
                               level, remset, NULL)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  HeapWord* bottom = (HeapWord*) _virtual_space.low();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  HeapWord* end    = (HeapWord*) _virtual_space.high();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  _the_space  = new TenuredSpace(_bts, MemRegion(bottom, end));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  _the_space->reset_saved_mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  _shrink_factor = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  _capacity_at_prologue = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  _gc_stats = new GCStats();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // initialize performance counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  const char* gen_name = "old";
26324
6b9c12e15535 8028787: tmtools/jstat/gcoldcapacity/jstat_gcoldcapacity02 fails nsk.share.Failure: OGC < OGCMN in RT_Baseline
sjohanss
parents: 22551
diff changeset
    56
  GenCollectorPolicy* gcp = (GenCollectorPolicy*) GenCollectedHeap::heap()->collector_policy();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // Generation Counters -- generation 1, 1 subspace
26324
6b9c12e15535 8028787: tmtools/jstat/gcoldcapacity/jstat_gcoldcapacity02 fails nsk.share.Failure: OGC < OGCMN in RT_Baseline
sjohanss
parents: 22551
diff changeset
    59
  _gen_counters = new GenerationCounters(gen_name, 1, 1,
6b9c12e15535 8028787: tmtools/jstat/gcoldcapacity/jstat_gcoldcapacity02 fails nsk.share.Failure: OGC < OGCMN in RT_Baseline
sjohanss
parents: 22551
diff changeset
    60
      gcp->min_old_size(), gcp->max_old_size(), &_virtual_space);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  _gc_counters = new CollectorCounters("MSC", 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  _space_counters = new CSpaceCounters(gen_name, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
                                       _virtual_space.reserved_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
                                       _the_space, _gen_counters);
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 15091
diff changeset
    67
#if INCLUDE_ALL_GCS
15091
826cff1f58f5 8005396: Use ParNew with only one thread instead of DefNew as default for CMS on single CPU machines
brutisso
parents: 13466
diff changeset
    68
  if (UseParNewGC) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    typedef ParGCAllocBufferWithBOT* ParGCAllocBufferWithBOTPtr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    _alloc_buffers = NEW_C_HEAP_ARRAY(ParGCAllocBufferWithBOTPtr,
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    71
                                      ParallelGCThreads, mtGC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    if (_alloc_buffers == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
      vm_exit_during_initialization("Could not allocate alloc_buffers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    for (uint i = 0; i < ParallelGCThreads; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      _alloc_buffers[i] =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
        new ParGCAllocBufferWithBOT(OldPLABSize, _bts);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
      if (_alloc_buffers[i] == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
        vm_exit_during_initialization("Could not allocate alloc_buffers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    _alloc_buffers = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  }
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 15091
diff changeset
    83
#endif // INCLUDE_ALL_GCS
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
const char* TenuredGeneration::name() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  return "tenured generation";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
void TenuredGeneration::gc_prologue(bool full) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  _capacity_at_prologue = capacity();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  _used_at_prologue = used();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  if (VerifyBeforeGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    verify_alloc_buffers_clean();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
void TenuredGeneration::gc_epilogue(bool full) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  if (VerifyAfterGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    verify_alloc_buffers_clean();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  OneContigSpaceCardGeneration::gc_epilogue(full);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
bool TenuredGeneration::should_collect(bool  full,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
                                       size_t size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
                                       bool   is_tlab) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // This should be one big conditional or (||), but I want to be able to tell
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // why it returns what it returns (without re-evaluating the conditionals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // in case they aren't idempotent), so I'm doing it this way.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // DeMorgan says it's okay.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  bool result = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  if (!result && full) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    result = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    if (PrintGC && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      gclog_or_tty->print_cr("TenuredGeneration::should_collect: because"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
                    " full");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  if (!result && should_allocate(size, is_tlab)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    result = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    if (PrintGC && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      gclog_or_tty->print_cr("TenuredGeneration::should_collect: because"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
                    " should_allocate(" SIZE_FORMAT ")",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
                    size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // If we don't have very much free space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // XXX: 10000 should be a percentage of the capacity!!!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  if (!result && free() < 10000) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    result = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    if (PrintGC && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      gclog_or_tty->print_cr("TenuredGeneration::should_collect: because"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
                    " free(): " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
                    free());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22234
diff changeset
   140
  // If we had to expand to accommodate promotions from younger generations
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  if (!result && _capacity_at_prologue < capacity()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    result = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    if (PrintGC && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      gclog_or_tty->print_cr("TenuredGeneration::should_collect: because"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
                    "_capacity_at_prologue: " SIZE_FORMAT " < capacity(): " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
                    _capacity_at_prologue, capacity());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
void TenuredGeneration::collect(bool   full,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
                                bool   clear_all_soft_refs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
                                size_t size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
                                bool   is_tlab) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  retire_alloc_buffers_before_full_gc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  OneContigSpaceCardGeneration::collect(full, clear_all_soft_refs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
                                        size, is_tlab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
16681
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 15482
diff changeset
   161
void TenuredGeneration::compute_new_size() {
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 15482
diff changeset
   162
  assert_locked_or_safepoint(Heap_lock);
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 15482
diff changeset
   163
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 15482
diff changeset
   164
  // Compute some numbers about the state of the heap.
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 15482
diff changeset
   165
  const size_t used_after_gc = used();
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 15482
diff changeset
   166
  const size_t capacity_after_gc = capacity();
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 15482
diff changeset
   167
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 15482
diff changeset
   168
  CardGeneration::compute_new_size();
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 15482
diff changeset
   169
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 15482
diff changeset
   170
  assert(used() == used_after_gc && used_after_gc <= capacity(),
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 15482
diff changeset
   171
         err_msg("used: " SIZE_FORMAT " used_after_gc: " SIZE_FORMAT
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 15482
diff changeset
   172
         " capacity: " SIZE_FORMAT, used(), used_after_gc, capacity()));
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 15482
diff changeset
   173
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
void TenuredGeneration::update_gc_stats(int current_level,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
                                        bool full) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  // If the next lower level(s) has been collected, gather any statistics
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  // that are of interest at this point.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  if (!full && (current_level + 1) == level()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    // Calculate size of data promoted from the younger generations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    // before doing the collection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    size_t used_before_gc = used();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    // If the younger gen collections were skipped, then the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    // number of promoted bytes will be 0 and adding it to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    // average will incorrectly lessen the average.  It is, however,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    // also possible that no promotion was needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    if (used_before_gc >= _used_at_prologue) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      size_t promoted_in_bytes = used_before_gc - _used_at_prologue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
      gc_stats()->avg_promoted()->sample(promoted_in_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
void TenuredGeneration::update_counters() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    _space_counters->update_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    _gen_counters->update_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 15091
diff changeset
   202
#if INCLUDE_ALL_GCS
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
oop TenuredGeneration::par_promote(int thread_num,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
                                   oop old, markOop m, size_t word_sz) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  ParGCAllocBufferWithBOT* buf = _alloc_buffers[thread_num];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  HeapWord* obj_ptr = buf->allocate(word_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  bool is_lab = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  if (obj_ptr == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    if (Universe::heap()->promotion_should_fail()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
#endif  // #ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    // Slow path:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    if (word_sz * 100 < ParallelGCBufferWastePct * buf->word_sz()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
      // Is small enough; abandon this buffer and start a new one.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
      size_t buf_size = buf->word_sz();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
      HeapWord* buf_space =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
        TenuredGeneration::par_allocate(buf_size, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      if (buf_space == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
        buf_space = expand_and_allocate(buf_size, false, true /* parallel*/);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      if (buf_space != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
        buf->retire(false, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
        buf->set_buf(buf_space);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
        obj_ptr = buf->allocate(word_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
        assert(obj_ptr != NULL, "Buffer was definitely big enough...");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    // Otherwise, buffer allocation failed; try allocating object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    // individually.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    if (obj_ptr == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
      obj_ptr = TenuredGeneration::par_allocate(word_sz, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
      if (obj_ptr == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
        obj_ptr = expand_and_allocate(word_sz, false, true /* parallel */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    if (obj_ptr == NULL) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  assert(obj_ptr != NULL, "program logic");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  Copy::aligned_disjoint_words((HeapWord*)old, obj_ptr, word_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  oop obj = oop(obj_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  // Restore the mark word copied above.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  obj->set_mark(m);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  return obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
void TenuredGeneration::par_promote_alloc_undo(int thread_num,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
                                               HeapWord* obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
                                               size_t word_sz) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  ParGCAllocBufferWithBOT* buf = _alloc_buffers[thread_num];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  if (buf->contains(obj)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    guarantee(buf->contains(obj + word_sz - 1),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
              "should contain whole object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    buf->undo_allocation(obj, word_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  } else {
1668
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 670
diff changeset
   259
    CollectedHeap::fill_with_object(obj, word_sz);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
void TenuredGeneration::par_promote_alloc_done(int thread_num) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  ParGCAllocBufferWithBOT* buf = _alloc_buffers[thread_num];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  buf->retire(true, ParallelGCRetainPLAB);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
void TenuredGeneration::retire_alloc_buffers_before_full_gc() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  if (UseParNewGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    for (uint i = 0; i < ParallelGCThreads; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      _alloc_buffers[i]->retire(true /*end_of_gc*/, false /*retain*/);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
// Verify that any retained parallel allocation buffers do not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
// intersect with dirty cards.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
void TenuredGeneration::verify_alloc_buffers_clean() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  if (UseParNewGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    for (uint i = 0; i < ParallelGCThreads; i++) {
179
59e3abf83f72 6624765: Guarantee failure "Unexpected dirty card found"
jmasa
parents: 1
diff changeset
   281
      _rs->verify_aligned_region_empty(_alloc_buffers[i]->range());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
}
179
59e3abf83f72 6624765: Guarantee failure "Unexpected dirty card found"
jmasa
parents: 1
diff changeset
   285
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 15091
diff changeset
   286
#else  // INCLUDE_ALL_GCS
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
void TenuredGeneration::retire_alloc_buffers_before_full_gc() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
void TenuredGeneration::verify_alloc_buffers_clean() {}
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 15091
diff changeset
   289
#endif // INCLUDE_ALL_GCS
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
6985
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   291
bool TenuredGeneration::promotion_attempt_is_safe(size_t max_promotion_in_bytes) const {
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   292
  size_t available = max_contiguous_available();
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   293
  size_t av_promo  = (size_t)gc_stats()->avg_promoted()->padded_average();
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   294
  bool   res = (available >= av_promo) || (available >= max_promotion_in_bytes);
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   295
  if (PrintGC && Verbose) {
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   296
    gclog_or_tty->print_cr(
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   297
      "Tenured: promo attempt is%s safe: available("SIZE_FORMAT") %s av_promo("SIZE_FORMAT"),"
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   298
      "max_promo("SIZE_FORMAT")",
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   299
      res? "":" not", available, res? ">=":"<",
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   300
      av_promo, max_promotion_in_bytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  }
6985
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   302
  return res;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
}