hotspot/src/share/vm/memory/generation.cpp
author pliden
Mon, 13 Apr 2015 15:47:48 +0200
changeset 30173 13cf7580b000
parent 29800 fa5f7a2bf717
permissions -rw-r--r--
8077413: Avoid use of Universe::heap() inside collectors Reviewed-by: stefank, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
29200
5e480434bef4 8061802: REDO - Remove the generations array
jwilhelm
parents: 28217
diff changeset
     2
 * Copyright (c) 1997, 2015, 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/space.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    40
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    41
#include "runtime/java.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    42
#include "utilities/copy.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6985
diff changeset
    43
#include "utilities/events.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
Generation::Generation(ReservedSpace rs, size_t initial_size, int level) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  _level(level),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  _ref_processor(NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  if (!_virtual_space.initialize(rs, initial_size)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    vm_exit_during_initialization("Could not reserve enough space for "
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
                    "object heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  }
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
    52
  // 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
    53
  if (ZapUnusedHeapArea) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
    54
    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
    55
      (HeapWord*)_virtual_space.high());
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
    56
    SpaceMangler::mangle_region(mangle_region);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
    57
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  _reserved = MemRegion((HeapWord*)_virtual_space.low_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
          (HeapWord*)_virtual_space.high_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
GenerationSpec* Generation::spec() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  GenCollectedHeap* gch = GenCollectedHeap::heap();
29794
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29684
diff changeset
    64
  assert(level() == 0 || level() == 1, "Bad gen level");
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29684
diff changeset
    65
  return level() == 0 ? gch->gen_policy()->young_gen_spec() : gch->gen_policy()->old_gen_spec();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
size_t Generation::max_capacity() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  return reserved().byte_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
void Generation::print_heap_change(size_t prev_used) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  if (PrintGCDetails && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    gclog_or_tty->print(" "  SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
                        "->" SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
                        "("  SIZE_FORMAT ")",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
                        prev_used, used(), capacity());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    gclog_or_tty->print(" "  SIZE_FORMAT "K"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
                        "->" SIZE_FORMAT "K"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
                        "("  SIZE_FORMAT "K)",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
                        prev_used / K, used() / K, capacity() / K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
// 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
    87
// generations needing multi-threaded refs processing or discovery override this method.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
void Generation::ref_processor_init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  assert(_ref_processor == NULL, "a reference processor already exists");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  assert(!_reserved.is_empty(), "empty generation?");
8688
493d12ccc6db 6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents: 7397
diff changeset
    91
  _ref_processor = new ReferenceProcessor(_reserved);    // a vanilla reference processor
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  if (_ref_processor == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    vm_exit_during_initialization("Could not allocate ReferenceProcessor object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
void Generation::print() const { print_on(tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
void Generation::print_on(outputStream* st)  const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  st->print(" %-20s", name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
             capacity()/K, used()/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
29800
fa5f7a2bf717 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29794
diff changeset
   104
              p2i(_virtual_space.low_boundary()),
fa5f7a2bf717 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29794
diff changeset
   105
              p2i(_virtual_space.high()),
fa5f7a2bf717 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29794
diff changeset
   106
              p2i(_virtual_space.high_boundary()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
void Generation::print_summary_info() { print_summary_info_on(tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
void Generation::print_summary_info_on(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  StatRecord* sr = stat_record();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  double time = sr->accumulated_time.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  st->print_cr("[Accumulated GC generation %d time %3.7f secs, "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
               "%d GC's, avg GC time %3.7f]",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
               level(), time, sr->invocations,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
               sr->invocations > 0 ? time / sr->invocations : 0.0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
// Utility iterator classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
class GenerationIsInReservedClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  const void* _p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  Space* sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    if (sp == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      if (s->is_in_reserved(_p)) sp = s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  GenerationIsInReservedClosure(const void* p) : _p(p), sp(NULL) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
class GenerationIsInClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  const void* _p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  Space* sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    if (sp == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      if (s->is_in(_p)) sp = s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  GenerationIsInClosure(const void* p) : _p(p), sp(NULL) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
bool Generation::is_in(const void* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  GenerationIsInClosure blk(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  ((Generation*)this)->space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  return blk.sp != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
Generation* Generation::next_gen() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  GenCollectedHeap* gch = GenCollectedHeap::heap();
29684
a36d90acae41 8057632: Remove auxiliary code used to handle the generations array
jwilhelm
parents: 29200
diff changeset
   154
  if (level() == 0) {
a36d90acae41 8057632: Remove auxiliary code used to handle the generations array
jwilhelm
parents: 29200
diff changeset
   155
    return gch->old_gen();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
size_t Generation::max_contiguous_available() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  // The largest number of contiguous free words in this or any higher generation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  size_t max = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  for (const Generation* gen = this; gen != NULL; gen = gen->next_gen()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    size_t avail = gen->contiguous_available();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    if (avail > max) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      max = avail;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  return max;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
6985
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   173
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
   174
  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
   175
  bool   res = (available >= max_promotion_in_bytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  if (PrintGC && Verbose) {
6985
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   177
    gclog_or_tty->print_cr(
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   178
      "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
   179
      res? "":" not", available, res? ">=":"<",
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   180
      max_promotion_in_bytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  }
6985
e9364ec299ac 6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents: 5547
diff changeset
   182
  return res;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
// 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
   186
oop Generation::promote(oop obj, size_t obj_size) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  assert(obj_size == (size_t)obj->size(), "bad obj_size passed in");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
#ifndef PRODUCT
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 29800
diff changeset
   190
  if (GenCollectedHeap::heap()->promotion_should_fail()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
#endif  // #ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  HeapWord* result = allocate(obj_size, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  if (result != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    Copy::aligned_disjoint_words((HeapWord*)obj, result, obj_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    return oop(result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    GenCollectedHeap* gch = GenCollectedHeap::heap();
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   201
    return gch->handle_failed_promotion(this, obj, obj_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
oop Generation::par_promote(int thread_num,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
                            oop obj, markOop m, size_t word_sz) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  // Could do a bad general impl here that gets a lock.  But no.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  ShouldNotCallThis();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
Space* Generation::space_containing(const void* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  GenerationIsInReservedClosure blk(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  // Cast away const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  ((Generation*)this)->space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  return blk.sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
// Some of these are mediocre general implementations.  Should be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
// overridden to get better performance.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
class GenerationBlockStartClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  const void* _p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  HeapWord* _start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    if (_start == NULL && s->is_in_reserved(_p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
      _start = s->block_start(_p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  GenerationBlockStartClosure(const void* p) { _p = p; _start = NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
HeapWord* Generation::block_start(const void* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  GenerationBlockStartClosure blk(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  // Cast away const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  ((Generation*)this)->space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  return blk._start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
class GenerationBlockSizeClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  const HeapWord* _p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  size_t size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    if (size == 0 && s->is_in_reserved(_p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      size = s->block_size(_p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  GenerationBlockSizeClosure(const HeapWord* p) { _p = p; size = 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
size_t Generation::block_size(const HeapWord* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  GenerationBlockSizeClosure blk(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  // Cast away const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  ((Generation*)this)->space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  assert(blk.size > 0, "seems reasonable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  return blk.size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
class GenerationBlockIsObjClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  const HeapWord* _p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  bool is_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  virtual void do_space(Space* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    if (!is_obj && s->is_in_reserved(_p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
      is_obj |= s->block_is_obj(_p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  GenerationBlockIsObjClosure(const HeapWord* p) { _p = p; is_obj = false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
bool Generation::block_is_obj(const HeapWord* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  GenerationBlockIsObjClosure blk(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  // Cast away const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  ((Generation*)this)->space_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  return blk.is_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
class GenerationOopIterateClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
 public:
23508
3b15250ea28f 8038399: Remove dead oop_iterate MemRegion variants from SharedHeap, Generation and Space classes
mgerdin
parents: 21767
diff changeset
   282
  ExtendedOopClosure* _cl;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  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
   284
    s->oop_iterate(_cl);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  }
23508
3b15250ea28f 8038399: Remove dead oop_iterate MemRegion variants from SharedHeap, Generation and Space classes
mgerdin
parents: 21767
diff changeset
   286
  GenerationOopIterateClosure(ExtendedOopClosure* cl) :
3b15250ea28f 8038399: Remove dead oop_iterate MemRegion variants from SharedHeap, Generation and Space classes
mgerdin
parents: 21767
diff changeset
   287
    _cl(cl) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   290
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
   291
  GenerationOopIterateClosure blk(cl);
1
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) {
28217
57791914628c 8067499: G1SATBCardTableModRefBS should not inherit from CardTableModRefBSForCTRS
kbarrett
parents: 28031
diff changeset
   297
  GenRemSet* rs = GenCollectedHeap::heap()->rem_set();
1
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
1893
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   316
class GenerationSafeObjIterateClosure : public SpaceClosure {
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   317
 private:
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   318
  ObjectClosure* _cl;
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   319
 public:
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   320
  virtual void do_space(Space* s) {
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   321
    s->safe_object_iterate(_cl);
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   322
  }
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   323
  GenerationSafeObjIterateClosure(ObjectClosure* cl) : _cl(cl) {}
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   324
};
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   325
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   326
void Generation::safe_object_iterate(ObjectClosure* cl) {
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   327
  GenerationSafeObjIterateClosure blk(cl);
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   328
  space_iterate(&blk);
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   329
}
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 979
diff changeset
   330
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
void Generation::prepare_for_compaction(CompactPoint* cp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  // Generic implementation, can be specialized
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  CompactibleSpace* space = first_compaction_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  while (space != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    space->prepare_for_compaction(cp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    space = space->next_compaction_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
class AdjustPointersClosure: public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  void do_space(Space* sp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    sp->adjust_pointers();
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
void Generation::adjust_pointers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  // Note that this is done over all spaces, not just the compactible
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  // ones.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  AdjustPointersClosure blk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  space_iterate(&blk, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
void Generation::compact() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  CompactibleSpace* sp = first_compaction_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  while (sp != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    sp->compact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    sp = sp->next_compaction_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
}