hotspot/src/share/vm/memory/generation.cpp
author mgerdin
Thu, 06 Mar 2014 09:08:18 +0100
changeset 23508 3b15250ea28f
parent 21767 41eaa9a17059
child 24092 e274d864545a
permissions -rw-r--r--
8038399: Remove dead oop_iterate MemRegion variants from SharedHeap, Generation and Space classes Reviewed-by: tschatzl, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 16681
diff changeset
     2
 * Copyright (c) 1997, 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: 4106
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4106
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: 4106
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"
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 16681
diff changeset
    26
#include "gc_implementation/shared/gcTimer.hpp"
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 16681
diff changeset
    27
#include "gc_implementation/shared/gcTrace.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    28
#include "gc_implementation/shared/spaceDecorator.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    29
#include "gc_interface/collectedHeap.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    30
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    31
#include "memory/blockOffsetTable.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    32
#include "memory/cardTableRS.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    33
#include "memory/gcLocker.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    34
#include "memory/genCollectedHeap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    35
#include "memory/genMarkSweep.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    36
#include "memory/genOopClosures.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    37
#include "memory/genOopClosures.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    38
#include "memory/generation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    39
#include "memory/generation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    40
#include "memory/space.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    41
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    42
#include "runtime/java.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    43
#include "utilities/copy.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    44
#include "utilities/events.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
Generation::Generation(ReservedSpace rs, size_t initial_size, int level) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  _level(level),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  _ref_processor(NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  if (!_virtual_space.initialize(rs, initial_size)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    vm_exit_during_initialization("Could not reserve enough space for "
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
                    "object heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  }
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
    53
  // Mangle all of the the initial generation.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
    54
  if (ZapUnusedHeapArea) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
    55
    MemRegion mangle_region((HeapWord*)_virtual_space.low(),
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
    56
      (HeapWord*)_virtual_space.high());
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
    57
    SpaceMangler::mangle_region(mangle_region);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
    58
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  _reserved = MemRegion((HeapWord*)_virtual_space.low_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
          (HeapWord*)_virtual_space.high_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
GenerationSpec* Generation::spec() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  GenCollectedHeap* gch = GenCollectedHeap::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  assert(0 <= level() && level() < gch->_n_gens, "Bad gen level");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  return gch->_gen_specs[level()];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
size_t Generation::max_capacity() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  return reserved().byte_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
void Generation::print_heap_change(size_t prev_used) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  if (PrintGCDetails && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    gclog_or_tty->print(" "  SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
                        "->" SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
                        "("  SIZE_FORMAT ")",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
                        prev_used, used(), capacity());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    gclog_or_tty->print(" "  SIZE_FORMAT "K"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
                        "->" SIZE_FORMAT "K"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
                        "("  SIZE_FORMAT "K)",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
                        prev_used / K, used() / K, capacity() / K);
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
// By default we get a single threaded default reference processor;
8688
493d12ccc6db 6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents: 7397
diff changeset
    88
// generations needing multi-threaded refs processing or discovery override this method.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
void Generation::ref_processor_init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  assert(_ref_processor == NULL, "a reference processor already exists");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  assert(!_reserved.is_empty(), "empty generation?");
8688
493d12ccc6db 6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents: 7397
diff changeset
    92
  _ref_processor = new ReferenceProcessor(_reserved);    // a vanilla reference processor
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  if (_ref_processor == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    vm_exit_during_initialization("Could not allocate ReferenceProcessor object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
void Generation::print() const { print_on(tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
void Generation::print_on(outputStream* st)  const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  st->print(" %-20s", name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
             capacity()/K, used()/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
              _virtual_space.low_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
              _virtual_space.high(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
              _virtual_space.high_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
void Generation::print_summary_info() { print_summary_info_on(tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
void Generation::print_summary_info_on(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  StatRecord* sr = stat_record();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  double time = sr->accumulated_time.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  st->print_cr("[Accumulated GC generation %d time %3.7f secs, "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
               "%d GC's, avg GC time %3.7f]",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
               level(), time, sr->invocations,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
               sr->invocations > 0 ? time / sr->invocations : 0.0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
// Utility iterator classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
class GenerationIsInReservedClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  const void* _p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  Space* sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    if (sp == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      if (s->is_in_reserved(_p)) sp = s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  GenerationIsInReservedClosure(const void* p) : _p(p), sp(NULL) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
class GenerationIsInClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  const void* _p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  Space* sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    if (sp == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
      if (s->is_in(_p)) sp = s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  GenerationIsInClosure(const void* p) : _p(p), sp(NULL) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
bool Generation::is_in(const void* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  GenerationIsInClosure blk(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  ((Generation*)this)->space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  return blk.sp != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
DefNewGeneration* Generation::as_DefNewGeneration() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  assert((kind() == Generation::DefNew) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
         (kind() == Generation::ParNew) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
         (kind() == Generation::ASParNew),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    "Wrong youngest generation type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  return (DefNewGeneration*) this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
Generation* Generation::next_gen() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  GenCollectedHeap* gch = GenCollectedHeap::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  int next = level() + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  if (next < gch->_n_gens) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    return gch->_gens[next];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
size_t Generation::max_contiguous_available() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  // The largest number of contiguous free words in this or any higher generation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  size_t max = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  for (const Generation* gen = this; gen != NULL; gen = gen->next_gen()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    size_t avail = gen->contiguous_available();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    if (avail > max) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      max = avail;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  return max;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
6985
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   183
bool Generation::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
   184
  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
   185
  bool   res = (available >= max_promotion_in_bytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  if (PrintGC && Verbose) {
6985
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   187
    gclog_or_tty->print_cr(
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   188
      "Generation: promo attempt is%s safe: available("SIZE_FORMAT") %s max_promo("SIZE_FORMAT")",
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   189
      res? "":" not", available, res? ">=":"<",
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   190
      max_promotion_in_bytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  }
6985
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   192
  return res;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
// Ignores "ref" and calls allocate().
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   196
oop Generation::promote(oop obj, size_t obj_size) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  assert(obj_size == (size_t)obj->size(), "bad obj_size passed in");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  if (Universe::heap()->promotion_should_fail()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
#endif  // #ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  HeapWord* result = allocate(obj_size, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  if (result != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    Copy::aligned_disjoint_words((HeapWord*)obj, result, obj_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    return oop(result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    GenCollectedHeap* gch = GenCollectedHeap::heap();
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   211
    return gch->handle_failed_promotion(this, obj, obj_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
oop Generation::par_promote(int thread_num,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
                            oop obj, markOop m, size_t word_sz) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // Could do a bad general impl here that gets a lock.  But no.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  ShouldNotCallThis();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
void Generation::par_promote_alloc_undo(int thread_num,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
                                        HeapWord* obj, size_t word_sz) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  // Could do a bad general impl here that gets a lock.  But no.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  guarantee(false, "No good general implementation.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
Space* Generation::space_containing(const void* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  GenerationIsInReservedClosure blk(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  // Cast away const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  ((Generation*)this)->space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  return blk.sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
// Some of these are mediocre general implementations.  Should be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
// overridden to get better performance.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
class GenerationBlockStartClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  const void* _p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  HeapWord* _start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    if (_start == NULL && s->is_in_reserved(_p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
      _start = s->block_start(_p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  GenerationBlockStartClosure(const void* p) { _p = p; _start = NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
HeapWord* Generation::block_start(const void* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  GenerationBlockStartClosure blk(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  // Cast away const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  ((Generation*)this)->space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  return blk._start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
class GenerationBlockSizeClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  const HeapWord* _p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  size_t size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    if (size == 0 && s->is_in_reserved(_p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
      size = s->block_size(_p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  GenerationBlockSizeClosure(const HeapWord* p) { _p = p; size = 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
size_t Generation::block_size(const HeapWord* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  GenerationBlockSizeClosure blk(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  // Cast away const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  ((Generation*)this)->space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  assert(blk.size > 0, "seems reasonable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  return blk.size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
class GenerationBlockIsObjClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  const HeapWord* _p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  bool is_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    if (!is_obj && s->is_in_reserved(_p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
      is_obj |= s->block_is_obj(_p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  GenerationBlockIsObjClosure(const HeapWord* p) { _p = p; is_obj = false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
bool Generation::block_is_obj(const HeapWord* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  GenerationBlockIsObjClosure blk(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  // Cast away const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  ((Generation*)this)->space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  return blk.is_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
class GenerationOopIterateClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
 public:
23508
3b15250ea28f 8038399: Remove dead oop_iterate MemRegion variants from SharedHeap, Generation and Space classes
mgerdin
parents: 21767
diff changeset
   298
  ExtendedOopClosure* _cl;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  virtual void do_space(Space* s) {
23508
3b15250ea28f 8038399: Remove dead oop_iterate MemRegion variants from SharedHeap, Generation and Space classes
mgerdin
parents: 21767
diff changeset
   300
    s->oop_iterate(_cl);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  }
23508
3b15250ea28f 8038399: Remove dead oop_iterate MemRegion variants from SharedHeap, Generation and Space classes
mgerdin
parents: 21767
diff changeset
   302
  GenerationOopIterateClosure(ExtendedOopClosure* cl) :
3b15250ea28f 8038399: Remove dead oop_iterate MemRegion variants from SharedHeap, Generation and Space classes
mgerdin
parents: 21767
diff changeset
   303
    _cl(cl) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   306
void Generation::oop_iterate(ExtendedOopClosure* cl) {
23508
3b15250ea28f 8038399: Remove dead oop_iterate MemRegion variants from SharedHeap, Generation and Space classes
mgerdin
parents: 21767
diff changeset
   307
  GenerationOopIterateClosure blk(cl);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
void Generation::younger_refs_in_space_iterate(Space* sp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
                                               OopsInGenClosure* cl) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  GenRemSet* rs = SharedHeap::heap()->rem_set();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  rs->younger_refs_in_space_iterate(sp, cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
class GenerationObjIterateClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  ObjectClosure* _cl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    s->object_iterate(_cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  GenerationObjIterateClosure(ObjectClosure* cl) : _cl(cl) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
void Generation::object_iterate(ObjectClosure* cl) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  GenerationObjIterateClosure blk(cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
1893
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   332
class GenerationSafeObjIterateClosure : public SpaceClosure {
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   333
 private:
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   334
  ObjectClosure* _cl;
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   335
 public:
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   336
  virtual void do_space(Space* s) {
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   337
    s->safe_object_iterate(_cl);
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   338
  }
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   339
  GenerationSafeObjIterateClosure(ObjectClosure* cl) : _cl(cl) {}
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   340
};
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   341
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   342
void Generation::safe_object_iterate(ObjectClosure* cl) {
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   343
  GenerationSafeObjIterateClosure blk(cl);
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   344
  space_iterate(&blk);
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   345
}
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   346
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
void Generation::prepare_for_compaction(CompactPoint* cp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  // Generic implementation, can be specialized
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  CompactibleSpace* space = first_compaction_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  while (space != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    space->prepare_for_compaction(cp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    space = space->next_compaction_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
class AdjustPointersClosure: public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  void do_space(Space* sp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    sp->adjust_pointers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
void Generation::adjust_pointers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  // Note that this is done over all spaces, not just the compactible
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  // ones.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  AdjustPointersClosure blk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  space_iterate(&blk, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
void Generation::compact() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  CompactibleSpace* sp = first_compaction_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  while (sp != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    sp->compact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    sp = sp->next_compaction_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
CardGeneration::CardGeneration(ReservedSpace rs, size_t initial_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
                               int level,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
                               GenRemSet* remset) :
16681
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   381
  Generation(rs, initial_byte_size, level), _rs(remset),
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   382
  _shrink_factor(0), _min_heap_delta_bytes(), _capacity_at_prologue(),
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   383
  _used_at_prologue()
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  HeapWord* start = (HeapWord*)rs.base();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  size_t reserved_byte_size = rs.size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  assert((uintptr_t(start) & 3) == 0, "bad alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  assert((reserved_byte_size & 3) == 0, "bad alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  MemRegion reserved_mr(start, heap_word_size(reserved_byte_size));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  _bts = new BlockOffsetSharedArray(reserved_mr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
                                    heap_word_size(initial_byte_size));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  MemRegion committed_mr(start, heap_word_size(initial_byte_size));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  _rs->resize_covered_region(committed_mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  if (_bts == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    vm_exit_during_initialization("Could not allocate a BlockOffsetArray");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  // Verify that the start and end of this generation is the start of a card.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  // If this wasn't true, a single card could span more than on generation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  // which would cause problems when we commit/uncommit memory, and when we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  // clear and dirty cards.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  guarantee(_rs->is_aligned(reserved_mr.start()), "generation must be card aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  if (reserved_mr.end() != Universe::heap()->reserved_region().end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    // Don't check at the very end of the heap as we'll assert that we're probing off
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    // the end if we try.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    guarantee(_rs->is_aligned(reserved_mr.end()), "generation must be card aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  }
16681
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   407
  _min_heap_delta_bytes = MinHeapDeltaBytes;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   408
  _capacity_at_prologue = initial_byte_size;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   409
  _used_at_prologue = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   412
bool CardGeneration::expand(size_t bytes, size_t expand_bytes) {
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   413
  assert_locked_or_safepoint(Heap_lock);
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   414
  if (bytes == 0) {
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   415
    return true;  // That's what grow_by(0) would return
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   416
  }
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   417
  size_t aligned_bytes  = ReservedSpace::page_align_size_up(bytes);
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   418
  if (aligned_bytes == 0){
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   419
    // The alignment caused the number of bytes to wrap.  An expand_by(0) will
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   420
    // return true with the implication that an expansion was done when it
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   421
    // was not.  A call to expand implies a best effort to expand by "bytes"
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   422
    // but not a guarantee.  Align down to give a best effort.  This is likely
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   423
    // the most that the generation can expand since it has some capacity to
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   424
    // start with.
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   425
    aligned_bytes = ReservedSpace::page_align_size_down(bytes);
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   426
  }
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   427
  size_t aligned_expand_bytes = ReservedSpace::page_align_size_up(expand_bytes);
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   428
  bool success = false;
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   429
  if (aligned_expand_bytes > aligned_bytes) {
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   430
    success = grow_by(aligned_expand_bytes);
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   431
  }
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   432
  if (!success) {
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   433
    success = grow_by(aligned_bytes);
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   434
  }
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   435
  if (!success) {
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   436
    success = grow_to_reserved();
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   437
  }
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   438
  if (PrintGC && Verbose) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   439
    if (success && GC_locker::is_active_and_needs_gc()) {
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   440
      gclog_or_tty->print_cr("Garbage collection disabled, expanded heap instead");
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   441
    }
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   442
  }
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   443
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   444
  return success;
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   445
}
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   446
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
// No young generation references, clear this generation's cards.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
void CardGeneration::clear_remembered_set() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  _rs->clear(reserved());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
// Objects in this generation may have moved, invalidate this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
// generation's cards.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
void CardGeneration::invalidate_remembered_set() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  _rs->invalidate(used_region());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
16681
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   461
void CardGeneration::compute_new_size() {
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   462
  assert(_shrink_factor <= 100, "invalid shrink factor");
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   463
  size_t current_shrink_factor = _shrink_factor;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   464
  _shrink_factor = 0;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   465
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   466
  // We don't have floating point command-line arguments
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   467
  // Note:  argument processing ensures that MinHeapFreeRatio < 100.
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   468
  const double minimum_free_percentage = MinHeapFreeRatio / 100.0;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   469
  const double maximum_used_percentage = 1.0 - minimum_free_percentage;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   470
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   471
  // Compute some numbers about the state of the heap.
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   472
  const size_t used_after_gc = used();
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   473
  const size_t capacity_after_gc = capacity();
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   474
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   475
  const double min_tmp = used_after_gc / maximum_used_percentage;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   476
  size_t minimum_desired_capacity = (size_t)MIN2(min_tmp, double(max_uintx));
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   477
  // Don't shrink less than the initial generation size
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   478
  minimum_desired_capacity = MAX2(minimum_desired_capacity,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   479
                                  spec()->init_size());
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   480
  assert(used_after_gc <= minimum_desired_capacity, "sanity check");
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   481
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   482
  if (PrintGC && Verbose) {
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   483
    const size_t free_after_gc = free();
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   484
    const double free_percentage = ((double)free_after_gc) / capacity_after_gc;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   485
    gclog_or_tty->print_cr("TenuredGeneration::compute_new_size: ");
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   486
    gclog_or_tty->print_cr("  "
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   487
                  "  minimum_free_percentage: %6.2f"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   488
                  "  maximum_used_percentage: %6.2f",
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   489
                  minimum_free_percentage,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   490
                  maximum_used_percentage);
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   491
    gclog_or_tty->print_cr("  "
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   492
                  "   free_after_gc   : %6.1fK"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   493
                  "   used_after_gc   : %6.1fK"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   494
                  "   capacity_after_gc   : %6.1fK",
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   495
                  free_after_gc / (double) K,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   496
                  used_after_gc / (double) K,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   497
                  capacity_after_gc / (double) K);
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   498
    gclog_or_tty->print_cr("  "
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   499
                  "   free_percentage: %6.2f",
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   500
                  free_percentage);
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   501
  }
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   502
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   503
  if (capacity_after_gc < minimum_desired_capacity) {
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   504
    // If we have less free space than we want then expand
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   505
    size_t expand_bytes = minimum_desired_capacity - capacity_after_gc;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   506
    // Don't expand unless it's significant
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   507
    if (expand_bytes >= _min_heap_delta_bytes) {
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   508
      expand(expand_bytes, 0); // safe if expansion fails
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   509
    }
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   510
    if (PrintGC && Verbose) {
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   511
      gclog_or_tty->print_cr("    expanding:"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   512
                    "  minimum_desired_capacity: %6.1fK"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   513
                    "  expand_bytes: %6.1fK"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   514
                    "  _min_heap_delta_bytes: %6.1fK",
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   515
                    minimum_desired_capacity / (double) K,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   516
                    expand_bytes / (double) K,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   517
                    _min_heap_delta_bytes / (double) K);
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   518
    }
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   519
    return;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   520
  }
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   521
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   522
  // No expansion, now see if we want to shrink
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   523
  size_t shrink_bytes = 0;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   524
  // We would never want to shrink more than this
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   525
  size_t max_shrink_bytes = capacity_after_gc - minimum_desired_capacity;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   526
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   527
  if (MaxHeapFreeRatio < 100) {
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   528
    const double maximum_free_percentage = MaxHeapFreeRatio / 100.0;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   529
    const double minimum_used_percentage = 1.0 - maximum_free_percentage;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   530
    const double max_tmp = used_after_gc / minimum_used_percentage;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   531
    size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx));
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   532
    maximum_desired_capacity = MAX2(maximum_desired_capacity,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   533
                                    spec()->init_size());
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   534
    if (PrintGC && Verbose) {
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   535
      gclog_or_tty->print_cr("  "
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   536
                             "  maximum_free_percentage: %6.2f"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   537
                             "  minimum_used_percentage: %6.2f",
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   538
                             maximum_free_percentage,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   539
                             minimum_used_percentage);
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   540
      gclog_or_tty->print_cr("  "
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   541
                             "  _capacity_at_prologue: %6.1fK"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   542
                             "  minimum_desired_capacity: %6.1fK"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   543
                             "  maximum_desired_capacity: %6.1fK",
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   544
                             _capacity_at_prologue / (double) K,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   545
                             minimum_desired_capacity / (double) K,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   546
                             maximum_desired_capacity / (double) K);
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   547
    }
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   548
    assert(minimum_desired_capacity <= maximum_desired_capacity,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   549
           "sanity check");
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   550
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   551
    if (capacity_after_gc > maximum_desired_capacity) {
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   552
      // Capacity too large, compute shrinking size
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   553
      shrink_bytes = capacity_after_gc - maximum_desired_capacity;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   554
      // We don't want shrink all the way back to initSize if people call
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   555
      // System.gc(), because some programs do that between "phases" and then
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   556
      // we'd just have to grow the heap up again for the next phase.  So we
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   557
      // damp the shrinking: 0% on the first call, 10% on the second call, 40%
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   558
      // on the third call, and 100% by the fourth call.  But if we recompute
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   559
      // size without shrinking, it goes back to 0%.
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   560
      shrink_bytes = shrink_bytes / 100 * current_shrink_factor;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   561
      assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size");
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   562
      if (current_shrink_factor == 0) {
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   563
        _shrink_factor = 10;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   564
      } else {
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   565
        _shrink_factor = MIN2(current_shrink_factor * 4, (size_t) 100);
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   566
      }
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   567
      if (PrintGC && Verbose) {
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   568
        gclog_or_tty->print_cr("  "
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   569
                      "  shrinking:"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   570
                      "  initSize: %.1fK"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   571
                      "  maximum_desired_capacity: %.1fK",
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   572
                      spec()->init_size() / (double) K,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   573
                      maximum_desired_capacity / (double) K);
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   574
        gclog_or_tty->print_cr("  "
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   575
                      "  shrink_bytes: %.1fK"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   576
                      "  current_shrink_factor: %d"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   577
                      "  new shrink factor: %d"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   578
                      "  _min_heap_delta_bytes: %.1fK",
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   579
                      shrink_bytes / (double) K,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   580
                      current_shrink_factor,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   581
                      _shrink_factor,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   582
                      _min_heap_delta_bytes / (double) K);
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   583
      }
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   584
    }
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   585
  }
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   586
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   587
  if (capacity_after_gc > _capacity_at_prologue) {
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   588
    // We might have expanded for promotions, in which case we might want to
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   589
    // take back that expansion if there's room after GC.  That keeps us from
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   590
    // stretching the heap with promotions when there's plenty of room.
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   591
    size_t expansion_for_promotion = capacity_after_gc - _capacity_at_prologue;
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   592
    expansion_for_promotion = MIN2(expansion_for_promotion, max_shrink_bytes);
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   593
    // We have two shrinking computations, take the largest
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   594
    shrink_bytes = MAX2(shrink_bytes, expansion_for_promotion);
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   595
    assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size");
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   596
    if (PrintGC && Verbose) {
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   597
      gclog_or_tty->print_cr("  "
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   598
                             "  aggressive shrinking:"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   599
                             "  _capacity_at_prologue: %.1fK"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   600
                             "  capacity_after_gc: %.1fK"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   601
                             "  expansion_for_promotion: %.1fK"
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   602
                             "  shrink_bytes: %.1fK",
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   603
                             capacity_after_gc / (double) K,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   604
                             _capacity_at_prologue / (double) K,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   605
                             expansion_for_promotion / (double) K,
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   606
                             shrink_bytes / (double) K);
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   607
    }
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   608
  }
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   609
  // Don't shrink unless it's significant
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   610
  if (shrink_bytes >= _min_heap_delta_bytes) {
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   611
    shrink(shrink_bytes);
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   612
  }
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   613
}
d64161ca3e3c 8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents: 13728
diff changeset
   614
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
// Currently nothing to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
void CardGeneration::prepare_for_verify() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
void OneContigSpaceCardGeneration::collect(bool   full,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
                                           bool   clear_all_soft_refs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
                                           size_t size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
                                           bool   is_tlab) {
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 16681
diff changeset
   623
  GenCollectedHeap* gch = GenCollectedHeap::heap();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 16681
diff changeset
   624
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  SpecializationStats::clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  // Temporarily expand the span of our ref processor, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  // refs discovery is over the entire heap, not just this generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  ReferenceProcessorSpanMutator
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 16681
diff changeset
   629
    x(ref_processor(), gch->reserved_region());
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 16681
diff changeset
   630
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 16681
diff changeset
   631
  STWGCTimer* gc_timer = GenMarkSweep::gc_timer();
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18687
diff changeset
   632
  gc_timer->register_gc_start();
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 16681
diff changeset
   633
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 16681
diff changeset
   634
  SerialOldTracer* gc_tracer = GenMarkSweep::gc_tracer();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 16681
diff changeset
   635
  gc_tracer->report_gc_start(gch->gc_cause(), gc_timer->gc_start());
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 16681
diff changeset
   636
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  GenMarkSweep::invoke_at_safepoint(_level, ref_processor(), clear_all_soft_refs);
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 16681
diff changeset
   638
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18687
diff changeset
   639
  gc_timer->register_gc_end();
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 16681
diff changeset
   640
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18687
diff changeset
   641
  gc_tracer->report_gc_end(gc_timer->gc_end(), gc_timer->time_partitions());
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 16681
diff changeset
   642
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
  SpecializationStats::print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
HeapWord*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
OneContigSpaceCardGeneration::expand_and_allocate(size_t word_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
                                                  bool is_tlab,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
                                                  bool parallel) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
  assert(!is_tlab, "OneContigSpaceCardGeneration does not support TLAB allocation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  if (parallel) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    MutexLocker x(ParGCRareEvent_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
    HeapWord* result = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
    size_t byte_size = word_size * HeapWordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
    while (true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
      expand(byte_size, _min_heap_delta_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
      if (GCExpandToAllocateDelayMillis > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
        os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
      result = _the_space->par_allocate(word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
      if ( result != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
        return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
        // If there's not enough expansion space available, give up.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
        if (_virtual_space.uncommitted_size() < byte_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
          return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
        // else try again
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
    expand(word_size*HeapWordSize, _min_heap_delta_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
    return _the_space->allocate(word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   677
bool OneContigSpaceCardGeneration::expand(size_t bytes, size_t expand_bytes) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
  GCMutexLocker x(ExpandHeap_lock);
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 977
diff changeset
   679
  return CardGeneration::expand(bytes, expand_bytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
void OneContigSpaceCardGeneration::shrink(size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  assert_locked_or_safepoint(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
  size_t size = ReservedSpace::page_align_size_down(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
  if (size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
    shrink_by(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
size_t OneContigSpaceCardGeneration::capacity() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
  return _the_space->capacity();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
size_t OneContigSpaceCardGeneration::used() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  return _the_space->used();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
size_t OneContigSpaceCardGeneration::free() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
  return _the_space->free();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
MemRegion OneContigSpaceCardGeneration::used_region() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  return the_space()->used_region();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
size_t OneContigSpaceCardGeneration::unsafe_max_alloc_nogc() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  return _the_space->free();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
size_t OneContigSpaceCardGeneration::contiguous_available() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  return _the_space->free() + _virtual_space.uncommitted_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
bool OneContigSpaceCardGeneration::grow_by(size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
  assert_locked_or_safepoint(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
  bool result = _virtual_space.expand_by(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
  if (result) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
    size_t new_word_size =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
       heap_word_size(_virtual_space.committed_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
    MemRegion mr(_the_space->bottom(), new_word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
    // Expand card table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
    Universe::heap()->barrier_set()->resize_covered_region(mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
    // Expand shared block offset array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
    _bts->resize(new_word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
    // Fix for bug #4668531
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
   731
    if (ZapUnusedHeapArea) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
   732
      MemRegion mangle_region(_the_space->end(),
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
   733
      (HeapWord*)_virtual_space.high());
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
   734
      SpaceMangler::mangle_region(mangle_region);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
   735
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
    // Expand space -- also expands space's BOT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
    // (which uses (part of) shared array above)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
    _the_space->set_end((HeapWord*)_virtual_space.high());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
    // update the space and generation capacity counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
    update_counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
    if (Verbose && PrintGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
      size_t new_mem_size = _virtual_space.committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
      size_t old_mem_size = new_mem_size - bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
      gclog_or_tty->print_cr("Expanding %s from " SIZE_FORMAT "K by "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
                      SIZE_FORMAT "K to " SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
                      name(), old_mem_size/K, bytes/K, new_mem_size/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
bool OneContigSpaceCardGeneration::grow_to_reserved() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  assert_locked_or_safepoint(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
  bool success = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
  const size_t remaining_bytes = _virtual_space.uncommitted_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  if (remaining_bytes > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
    success = grow_by(remaining_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
    DEBUG_ONLY(if (!success) warning("grow to reserved failed");)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
  return success;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
void OneContigSpaceCardGeneration::shrink_by(size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
  assert_locked_or_safepoint(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
  // Shrink committed space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
  _virtual_space.shrink_by(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
  // Shrink space; this also shrinks the space's BOT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
  _the_space->set_end((HeapWord*) _virtual_space.high());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
  size_t new_word_size = heap_word_size(_the_space->capacity());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
  // Shrink the shared block offset array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
  _bts->resize(new_word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
  MemRegion mr(_the_space->bottom(), new_word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
  // Shrink the card table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
  Universe::heap()->barrier_set()->resize_covered_region(mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  if (Verbose && PrintGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
    size_t new_mem_size = _virtual_space.committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
    size_t old_mem_size = new_mem_size + bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
    gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K to " SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
                  name(), old_mem_size/K, new_mem_size/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
// Currently nothing to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
void OneContigSpaceCardGeneration::prepare_for_verify() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
4106
30919106db1d 6801625: CDS: HeapDump tests crash with internal error in compactingPermGenGen.cpp
ysr
parents: 2105
diff changeset
   792
// Override for a card-table generation with one contiguous
30919106db1d 6801625: CDS: HeapDump tests crash with internal error in compactingPermGenGen.cpp
ysr
parents: 2105
diff changeset
   793
// space. NOTE: For reasons that are lost in the fog of history,
30919106db1d 6801625: CDS: HeapDump tests crash with internal error in compactingPermGenGen.cpp
ysr
parents: 2105
diff changeset
   794
// this code is used when you iterate over perm gen objects,
30919106db1d 6801625: CDS: HeapDump tests crash with internal error in compactingPermGenGen.cpp
ysr
parents: 2105
diff changeset
   795
// even when one uses CDS, where the perm gen has a couple of
30919106db1d 6801625: CDS: HeapDump tests crash with internal error in compactingPermGenGen.cpp
ysr
parents: 2105
diff changeset
   796
// other spaces; this is because CompactingPermGenGen derives
30919106db1d 6801625: CDS: HeapDump tests crash with internal error in compactingPermGenGen.cpp
ysr
parents: 2105
diff changeset
   797
// from OneContigSpaceCardGeneration. This should be cleaned up,
30919106db1d 6801625: CDS: HeapDump tests crash with internal error in compactingPermGenGen.cpp
ysr
parents: 2105
diff changeset
   798
// see CR 6897789..
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
void OneContigSpaceCardGeneration::object_iterate(ObjectClosure* blk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
  _the_space->object_iterate(blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
void OneContigSpaceCardGeneration::space_iterate(SpaceClosure* blk,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
                                                 bool usedOnly) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  blk->do_space(_the_space);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
void OneContigSpaceCardGeneration::younger_refs_iterate(OopsInGenClosure* blk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
  blk->set_generation(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  younger_refs_in_space_iterate(_the_space, blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
  blk->reset_generation();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
void OneContigSpaceCardGeneration::save_marks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  _the_space->set_saved_mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
void OneContigSpaceCardGeneration::reset_saved_marks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
  _the_space->reset_saved_mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
bool OneContigSpaceCardGeneration::no_allocs_since_save_marks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
  return _the_space->saved_mark_at_top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
#define OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN(OopClosureType, nv_suffix)      \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
                                                                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
void OneContigSpaceCardGeneration::                                             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
oop_since_save_marks_iterate##nv_suffix(OopClosureType* blk) {                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
  blk->set_generation(this);                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
  _the_space->oop_since_save_marks_iterate##nv_suffix(blk);                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
  blk->reset_generation();                                                      \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
  save_marks();                                                                 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
ALL_SINCE_SAVE_MARKS_CLOSURES(OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
#undef OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
void OneContigSpaceCardGeneration::gc_epilogue(bool full) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
  _last_gc = WaterMark(the_space(), the_space()->top());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
  // update the generation and space performance counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
  update_counters();
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
   848
  if (ZapUnusedHeapArea) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
   849
    the_space()->check_mangled_unused_area_complete();
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
   850
  }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
   851
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
   852
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
   853
void OneContigSpaceCardGeneration::record_spaces_top() {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
   854
  assert(ZapUnusedHeapArea, "Not mangling unused space");
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
   855
  the_space()->set_top_for_allocations();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
12379
2cf45b79ce3a 4988100: oop_verify_old_oop appears to be dead
brutisso
parents: 8688
diff changeset
   858
void OneContigSpaceCardGeneration::verify() {
2cf45b79ce3a 4988100: oop_verify_old_oop appears to be dead
brutisso
parents: 8688
diff changeset
   859
  the_space()->verify();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
void OneContigSpaceCardGeneration::print_on(outputStream* st)  const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
  Generation::print_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
  st->print("   the");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
  the_space()->print_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
}