hotspot/src/share/vm/memory/generation.cpp
author coleenp
Sun, 13 Apr 2008 17:43:42 -0400
changeset 360 21d113ecbf6a
parent 1 489c9b5090e2
child 971 f0b20be4165d
child 670 ddf3e9583f2f
permissions -rw-r--r--
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes Summary: Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_generation.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
Generation::Generation(ReservedSpace rs, size_t initial_size, int level) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
  _level(level),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  _ref_processor(NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  if (!_virtual_space.initialize(rs, initial_size)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
    vm_exit_during_initialization("Could not reserve enough space for "
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
                    "object heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  _reserved = MemRegion((HeapWord*)_virtual_space.low_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
          (HeapWord*)_virtual_space.high_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
GenerationSpec* Generation::spec() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  GenCollectedHeap* gch = GenCollectedHeap::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  assert(0 <= level() && level() < gch->_n_gens, "Bad gen level");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  return gch->_gen_specs[level()];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
size_t Generation::max_capacity() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  return reserved().byte_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
void Generation::print_heap_change(size_t prev_used) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  if (PrintGCDetails && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    gclog_or_tty->print(" "  SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
                        "->" SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
                        "("  SIZE_FORMAT ")",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
                        prev_used, used(), capacity());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    gclog_or_tty->print(" "  SIZE_FORMAT "K"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
                        "->" SIZE_FORMAT "K"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
                        "("  SIZE_FORMAT "K)",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
                        prev_used / K, used() / K, capacity() / K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
// By default we get a single threaded default reference processor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
// generations needing multi-threaded refs discovery override this method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
void Generation::ref_processor_init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  assert(_ref_processor == NULL, "a reference processor already exists");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  assert(!_reserved.is_empty(), "empty generation?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  _ref_processor =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    new ReferenceProcessor(_reserved,                  // span
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
                           refs_discovery_is_atomic(), // atomic_discovery
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
                           refs_discovery_is_mt());    // mt_discovery
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  if (_ref_processor == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    vm_exit_during_initialization("Could not allocate ReferenceProcessor object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
void Generation::print() const { print_on(tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
void Generation::print_on(outputStream* st)  const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  st->print(" %-20s", name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
             capacity()/K, used()/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
              _virtual_space.low_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
              _virtual_space.high(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
              _virtual_space.high_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
void Generation::print_summary_info() { print_summary_info_on(tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
void Generation::print_summary_info_on(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  StatRecord* sr = stat_record();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  double time = sr->accumulated_time.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  st->print_cr("[Accumulated GC generation %d time %3.7f secs, "
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
               "%d GC's, avg GC time %3.7f]",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
               level(), time, sr->invocations,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
               sr->invocations > 0 ? time / sr->invocations : 0.0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
// Utility iterator classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
class GenerationIsInReservedClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  const void* _p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  Space* sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    if (sp == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      if (s->is_in_reserved(_p)) sp = s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  GenerationIsInReservedClosure(const void* p) : _p(p), sp(NULL) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
class GenerationIsInClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  const void* _p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  Space* sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    if (sp == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      if (s->is_in(_p)) sp = s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  GenerationIsInClosure(const void* p) : _p(p), sp(NULL) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
bool Generation::is_in(const void* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  GenerationIsInClosure blk(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  ((Generation*)this)->space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  return blk.sp != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
DefNewGeneration* Generation::as_DefNewGeneration() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  assert((kind() == Generation::DefNew) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
         (kind() == Generation::ParNew) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
         (kind() == Generation::ASParNew),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    "Wrong youngest generation type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  return (DefNewGeneration*) this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
Generation* Generation::next_gen() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  GenCollectedHeap* gch = GenCollectedHeap::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  int next = level() + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  if (next < gch->_n_gens) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    return gch->_gens[next];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
size_t Generation::max_contiguous_available() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // The largest number of contiguous free words in this or any higher generation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  size_t max = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  for (const Generation* gen = this; gen != NULL; gen = gen->next_gen()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    size_t avail = gen->contiguous_available();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    if (avail > max) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      max = avail;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  return max;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
bool Generation::promotion_attempt_is_safe(size_t promotion_in_bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
                                           bool not_used) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  if (PrintGC && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    gclog_or_tty->print_cr("Generation::promotion_attempt_is_safe"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
                " contiguous_available: " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
                " promotion_in_bytes: " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
                max_contiguous_available(), promotion_in_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  return max_contiguous_available() >= promotion_in_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
// 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
   174
oop Generation::promote(oop obj, size_t obj_size) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  assert(obj_size == (size_t)obj->size(), "bad obj_size passed in");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  if (Universe::heap()->promotion_should_fail()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
#endif  // #ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  HeapWord* result = allocate(obj_size, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  if (result != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    Copy::aligned_disjoint_words((HeapWord*)obj, result, obj_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    return oop(result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    GenCollectedHeap* gch = GenCollectedHeap::heap();
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   189
    return gch->handle_failed_promotion(this, obj, obj_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
oop Generation::par_promote(int thread_num,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
                            oop obj, markOop m, size_t word_sz) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  // Could do a bad general impl here that gets a lock.  But no.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  ShouldNotCallThis();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
void Generation::par_promote_alloc_undo(int thread_num,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
                                        HeapWord* obj, size_t word_sz) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  // Could do a bad general impl here that gets a lock.  But no.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  guarantee(false, "No good general implementation.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
Space* Generation::space_containing(const void* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  GenerationIsInReservedClosure blk(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  // Cast away const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  ((Generation*)this)->space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  return blk.sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
// Some of these are mediocre general implementations.  Should be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
// overridden to get better performance.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
class GenerationBlockStartClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  const void* _p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  HeapWord* _start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    if (_start == NULL && s->is_in_reserved(_p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      _start = s->block_start(_p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  GenerationBlockStartClosure(const void* p) { _p = p; _start = NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
HeapWord* Generation::block_start(const void* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  GenerationBlockStartClosure 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._start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
class GenerationBlockSizeClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  const HeapWord* _p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  size_t size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    if (size == 0 && s->is_in_reserved(_p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      size = s->block_size(_p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  GenerationBlockSizeClosure(const HeapWord* p) { _p = p; size = 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
size_t Generation::block_size(const HeapWord* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  GenerationBlockSizeClosure blk(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  // Cast away const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  ((Generation*)this)->space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  assert(blk.size > 0, "seems reasonable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  return blk.size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
class GenerationBlockIsObjClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  const HeapWord* _p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  bool is_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    if (!is_obj && s->is_in_reserved(_p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      is_obj |= s->block_is_obj(_p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  GenerationBlockIsObjClosure(const HeapWord* p) { _p = p; is_obj = false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
bool Generation::block_is_obj(const HeapWord* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  GenerationBlockIsObjClosure blk(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  // Cast away const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  ((Generation*)this)->space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  return blk.is_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
class GenerationOopIterateClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  OopClosure* cl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  MemRegion mr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    s->oop_iterate(mr, cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  GenerationOopIterateClosure(OopClosure* _cl, MemRegion _mr) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    cl(_cl), mr(_mr) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
void Generation::oop_iterate(OopClosure* cl) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  GenerationOopIterateClosure blk(cl, _reserved);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
void Generation::oop_iterate(MemRegion mr, OopClosure* cl) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  GenerationOopIterateClosure blk(cl, mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
void Generation::younger_refs_in_space_iterate(Space* sp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
                                               OopsInGenClosure* cl) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  GenRemSet* rs = SharedHeap::heap()->rem_set();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  rs->younger_refs_in_space_iterate(sp, cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
class GenerationObjIterateClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  ObjectClosure* _cl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    s->object_iterate(_cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  GenerationObjIterateClosure(ObjectClosure* cl) : _cl(cl) {}
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::object_iterate(ObjectClosure* cl) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  GenerationObjIterateClosure blk(cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
void Generation::prepare_for_compaction(CompactPoint* cp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  // Generic implementation, can be specialized
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  CompactibleSpace* space = first_compaction_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  while (space != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    space->prepare_for_compaction(cp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    space = space->next_compaction_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
class AdjustPointersClosure: public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  void do_space(Space* sp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    sp->adjust_pointers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
void Generation::adjust_pointers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  // Note that this is done over all spaces, not just the compactible
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  // ones.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  AdjustPointersClosure blk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  space_iterate(&blk, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
void Generation::compact() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  CompactibleSpace* sp = first_compaction_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  while (sp != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    sp->compact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    sp = sp->next_compaction_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
CardGeneration::CardGeneration(ReservedSpace rs, size_t initial_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
                               int level,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
                               GenRemSet* remset) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  Generation(rs, initial_byte_size, level), _rs(remset)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  HeapWord* start = (HeapWord*)rs.base();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  size_t reserved_byte_size = rs.size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  assert((uintptr_t(start) & 3) == 0, "bad alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  assert((reserved_byte_size & 3) == 0, "bad alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  MemRegion reserved_mr(start, heap_word_size(reserved_byte_size));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  _bts = new BlockOffsetSharedArray(reserved_mr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
                                    heap_word_size(initial_byte_size));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  MemRegion committed_mr(start, heap_word_size(initial_byte_size));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  _rs->resize_covered_region(committed_mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  if (_bts == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    vm_exit_during_initialization("Could not allocate a BlockOffsetArray");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  // Verify that the start and end of this generation is the start of a card.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  // If this wasn't true, a single card could span more than on generation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  // which would cause problems when we commit/uncommit memory, and when we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  // clear and dirty cards.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  guarantee(_rs->is_aligned(reserved_mr.start()), "generation must be card aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  if (reserved_mr.end() != Universe::heap()->reserved_region().end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    // 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
   371
    // the end if we try.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    guarantee(_rs->is_aligned(reserved_mr.end()), "generation must be card aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
// No young generation references, clear this generation's cards.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
void CardGeneration::clear_remembered_set() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  _rs->clear(reserved());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
// Objects in this generation may have moved, invalidate this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
// generation's cards.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
void CardGeneration::invalidate_remembered_set() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  _rs->invalidate(used_region());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
// Currently nothing to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
void CardGeneration::prepare_for_verify() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
void OneContigSpaceCardGeneration::collect(bool   full,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
                                           bool   clear_all_soft_refs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
                                           size_t size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
                                           bool   is_tlab) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  SpecializationStats::clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  // Temporarily expand the span of our ref processor, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  // refs discovery is over the entire heap, not just this generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  ReferenceProcessorSpanMutator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    x(ref_processor(), GenCollectedHeap::heap()->reserved_region());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  GenMarkSweep::invoke_at_safepoint(_level, ref_processor(), clear_all_soft_refs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  SpecializationStats::print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
HeapWord*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
OneContigSpaceCardGeneration::expand_and_allocate(size_t word_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
                                                  bool is_tlab,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
                                                  bool parallel) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  assert(!is_tlab, "OneContigSpaceCardGeneration does not support TLAB allocation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  if (parallel) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    MutexLocker x(ParGCRareEvent_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    HeapWord* result = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    size_t byte_size = word_size * HeapWordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
    while (true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
      expand(byte_size, _min_heap_delta_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
      if (GCExpandToAllocateDelayMillis > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
        os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
      result = _the_space->par_allocate(word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
      if ( result != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
        return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
        // If there's not enough expansion space available, give up.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
        if (_virtual_space.uncommitted_size() < byte_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
          return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
        // else try again
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
    expand(word_size*HeapWordSize, _min_heap_delta_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
    return _the_space->allocate(word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
void OneContigSpaceCardGeneration::expand(size_t bytes, size_t expand_bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  GCMutexLocker x(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  size_t aligned_bytes  = ReservedSpace::page_align_size_up(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  size_t aligned_expand_bytes = ReservedSpace::page_align_size_up(expand_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  bool success = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  if (aligned_expand_bytes > aligned_bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    success = grow_by(aligned_expand_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  if (!success) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
    success = grow_by(aligned_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  if (!success) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    grow_to_reserved();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  if (GC_locker::is_active()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    if (PrintGC && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
      gclog_or_tty->print_cr("Garbage collection disabled, expanded heap instead");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
void OneContigSpaceCardGeneration::shrink(size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  assert_locked_or_safepoint(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  size_t size = ReservedSpace::page_align_size_down(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  if (size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    shrink_by(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
size_t OneContigSpaceCardGeneration::capacity() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  return _the_space->capacity();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
size_t OneContigSpaceCardGeneration::used() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  return _the_space->used();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
size_t OneContigSpaceCardGeneration::free() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  return _the_space->free();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
MemRegion OneContigSpaceCardGeneration::used_region() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  return the_space()->used_region();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
size_t OneContigSpaceCardGeneration::unsafe_max_alloc_nogc() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  return _the_space->free();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
size_t OneContigSpaceCardGeneration::contiguous_available() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  return _the_space->free() + _virtual_space.uncommitted_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
bool OneContigSpaceCardGeneration::grow_by(size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  assert_locked_or_safepoint(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  bool result = _virtual_space.expand_by(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  if (result) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    size_t new_word_size =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
       heap_word_size(_virtual_space.committed_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    MemRegion mr(_the_space->bottom(), new_word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
    // Expand card table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    Universe::heap()->barrier_set()->resize_covered_region(mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    // Expand shared block offset array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    _bts->resize(new_word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
    // Fix for bug #4668531
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    MemRegion mangle_region(_the_space->end(), (HeapWord*)_virtual_space.high());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    _the_space->mangle_region(mangle_region);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
    // Expand space -- also expands space's BOT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
    // (which uses (part of) shared array above)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
    _the_space->set_end((HeapWord*)_virtual_space.high());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
    // update the space and generation capacity counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
    update_counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
    if (Verbose && PrintGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
      size_t new_mem_size = _virtual_space.committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
      size_t old_mem_size = new_mem_size - bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
      gclog_or_tty->print_cr("Expanding %s from " SIZE_FORMAT "K by "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
                      SIZE_FORMAT "K to " SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
                      name(), old_mem_size/K, bytes/K, new_mem_size/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
bool OneContigSpaceCardGeneration::grow_to_reserved() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  assert_locked_or_safepoint(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  bool success = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  const size_t remaining_bytes = _virtual_space.uncommitted_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  if (remaining_bytes > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
    success = grow_by(remaining_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
    DEBUG_ONLY(if (!success) warning("grow to reserved failed");)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  return success;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
void OneContigSpaceCardGeneration::shrink_by(size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  assert_locked_or_safepoint(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  // Shrink committed space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  _virtual_space.shrink_by(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  // Shrink space; this also shrinks the space's BOT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  _the_space->set_end((HeapWord*) _virtual_space.high());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  size_t new_word_size = heap_word_size(_the_space->capacity());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  // Shrink the shared block offset array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  _bts->resize(new_word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  MemRegion mr(_the_space->bottom(), new_word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
  // Shrink the card table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
  Universe::heap()->barrier_set()->resize_covered_region(mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  if (Verbose && PrintGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
    size_t new_mem_size = _virtual_space.committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
    size_t old_mem_size = new_mem_size + bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
    gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K to " SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
                  name(), old_mem_size/K, new_mem_size/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
// Currently nothing to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
void OneContigSpaceCardGeneration::prepare_for_verify() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
void OneContigSpaceCardGeneration::object_iterate(ObjectClosure* blk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
  _the_space->object_iterate(blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
void OneContigSpaceCardGeneration::space_iterate(SpaceClosure* blk,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
                                                 bool usedOnly) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  blk->do_space(_the_space);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
void OneContigSpaceCardGeneration::object_iterate_since_last_GC(ObjectClosure* blk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
  // Deal with delayed initialization of _the_space,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  // and lack of initialization of _last_gc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  if (_last_gc.space() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
    assert(the_space() != NULL, "shouldn't be NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
    _last_gc = the_space()->bottom_mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  the_space()->object_iterate_from(_last_gc, blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
void OneContigSpaceCardGeneration::younger_refs_iterate(OopsInGenClosure* blk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
  blk->set_generation(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
  younger_refs_in_space_iterate(_the_space, blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  blk->reset_generation();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
void OneContigSpaceCardGeneration::save_marks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  _the_space->set_saved_mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
void OneContigSpaceCardGeneration::reset_saved_marks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
  _the_space->reset_saved_mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
bool OneContigSpaceCardGeneration::no_allocs_since_save_marks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  return _the_space->saved_mark_at_top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
#define OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN(OopClosureType, nv_suffix)      \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
                                                                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
void OneContigSpaceCardGeneration::                                             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
oop_since_save_marks_iterate##nv_suffix(OopClosureType* blk) {                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
  blk->set_generation(this);                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  _the_space->oop_since_save_marks_iterate##nv_suffix(blk);                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  blk->reset_generation();                                                      \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  save_marks();                                                                 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
ALL_SINCE_SAVE_MARKS_CLOSURES(OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
#undef OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
void OneContigSpaceCardGeneration::gc_epilogue(bool full) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
  _last_gc = WaterMark(the_space(), the_space()->top());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  // update the generation and space performance counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  update_counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
void OneContigSpaceCardGeneration::verify(bool allow_dirty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  the_space()->verify(allow_dirty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
void OneContigSpaceCardGeneration::print_on(outputStream* st)  const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
  Generation::print_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  st->print("   the");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  the_space()->print_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
}