hotspot/src/share/vm/memory/generationSpec.cpp
author brutisso
Mon, 21 Nov 2011 07:47:34 +0100
changeset 11170 7663e46f3a54
parent 7397 5b173b4ca846
child 12507 6182ca66bc7b
permissions -rw-r--r--
7110718: -XX:MarkSweepAlwaysCompactCount=0 crashes the JVM Summary: Interpret MarkSweepAlwaysCompactCount < 1 as never do full compaction Reviewed-by: ysr, tonyp, jmasa, johnc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 2001, 2010, 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: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "memory/compactPermGen.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "memory/defNewGeneration.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/filemap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/genRemSet.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "memory/generationSpec.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "memory/tenuredGeneration.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/java.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#ifndef SERIALGC
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "gc_implementation/concurrentMarkSweep/cmsPermGen.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#include "gc_implementation/parNew/asParNewGeneration.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "gc_implementation/parNew/parNewGeneration.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
Generation* GenerationSpec::init(ReservedSpace rs, int level,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
                                 GenRemSet* remset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  switch (name()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    case Generation::DefNew:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
      return new DefNewGeneration(rs, init_size(), level);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    case Generation::MarkSweepCompact:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
      return new TenuredGeneration(rs, init_size(), level, remset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    case Generation::ParNew:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
      return new ParNewGeneration(rs, init_size(), level);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    case Generation::ASParNew:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
      return new ASParNewGeneration(rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
                                    init_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
                                    init_size() /* min size */,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
                                    level);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    case Generation::ConcurrentMarkSweep: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      assert(UseConcMarkSweepGC, "UseConcMarkSweepGC should be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      CardTableRS* ctrs = remset->as_CardTableRS();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
      if (ctrs == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
        vm_exit_during_initialization("Rem set incompatibility.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      // Otherwise
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      // The constructor creates the CMSCollector if needed,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      // else registers with an existing CMSCollector
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
      ConcurrentMarkSweepGeneration* g = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
      g = new ConcurrentMarkSweepGeneration(rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
                 init_size(), level, ctrs, UseCMSAdaptiveFreeLists,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
                 (FreeBlockDictionary::DictionaryChoice)CMSDictionaryChoice);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
      g->initialize_performance_counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      return g;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    case Generation::ASConcurrentMarkSweep: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
      assert(UseConcMarkSweepGC, "UseConcMarkSweepGC should be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
      CardTableRS* ctrs = remset->as_CardTableRS();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
      if (ctrs == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
        vm_exit_during_initialization("Rem set incompatibility.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
      // Otherwise
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
      // The constructor creates the CMSCollector if needed,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      // else registers with an existing CMSCollector
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
      ASConcurrentMarkSweepGeneration* g = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      g = new ASConcurrentMarkSweepGeneration(rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
                 init_size(), level, ctrs, UseCMSAdaptiveFreeLists,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
                 (FreeBlockDictionary::DictionaryChoice)CMSDictionaryChoice);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      g->initialize_performance_counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      return g;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      guarantee(false, "unrecognized GenerationName");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
PermanentGenerationSpec::PermanentGenerationSpec(PermGen::Name name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
                      size_t init_size, size_t max_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
                      size_t read_only_size, size_t read_write_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
                      size_t misc_data_size, size_t misc_code_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  _name = name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  _init_size = init_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  if (UseSharedSpaces || DumpSharedSpaces) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    _enable_shared_spaces = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    if (UseSharedSpaces) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      // Override shared space sizes from those in the file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      FileMapInfo* mapinfo = FileMapInfo::current_info();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      _read_only_size = mapinfo->space_capacity(CompactingPermGenGen::ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      _read_write_size = mapinfo->space_capacity(CompactingPermGenGen::rw);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      _misc_data_size = mapinfo->space_capacity(CompactingPermGenGen::md);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      _misc_code_size = mapinfo->space_capacity(CompactingPermGenGen::mc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      _read_only_size = read_only_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      _read_write_size = read_write_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      _misc_data_size = misc_data_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      _misc_code_size = misc_code_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    _enable_shared_spaces = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    _read_only_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    _read_write_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    _misc_data_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    _misc_code_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  _max_size = max_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
PermGen* PermanentGenerationSpec::init(ReservedSpace rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
                                       size_t init_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
                                       GenRemSet *remset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // Break the reserved spaces into pieces for the permanent space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // and the shared spaces.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  ReservedSpace perm_rs = rs.first_part(_max_size, UseSharedSpaces,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
                                        UseSharedSpaces);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  ReservedSpace shared_rs = rs.last_part(_max_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  if (enable_shared_spaces()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    if (!perm_rs.is_reserved() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
        perm_rs.base() + perm_rs.size() != shared_rs.base()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      FileMapInfo* mapinfo = FileMapInfo::current_info();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      mapinfo->fail_continue("Sharing disabled - unable to "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
                                 "reserve address space.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      shared_rs.release();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      disable_sharing();
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
  switch (name()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    case PermGen::MarkSweepCompact:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
      return new CompactingPermGen(perm_rs, shared_rs, init_size, remset, this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    case PermGen::MarkSweep:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      guarantee(false, "NYI");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    case PermGen::ConcurrentMarkSweep: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      assert(UseConcMarkSweepGC, "UseConcMarkSweepGC should be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      CardTableRS* ctrs = remset->as_CardTableRS();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      if (ctrs == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
        vm_exit_during_initialization("RemSet/generation incompatibility.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      // XXXPERM
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      return new CMSPermGen(perm_rs, init_size, ctrs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
                   (FreeBlockDictionary::DictionaryChoice)CMSDictionaryChoice);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
      guarantee(false, "unrecognized GenerationName");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
// Alignment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
void PermanentGenerationSpec::align(size_t alignment) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  _init_size       = align_size_up(_init_size,       alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  _max_size        = align_size_up(_max_size,        alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  _read_only_size  = align_size_up(_read_only_size,  alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  _read_write_size = align_size_up(_read_write_size, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  _misc_data_size  = align_size_up(_misc_data_size,  alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  _misc_code_size  = align_size_up(_misc_code_size,  alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  assert(enable_shared_spaces() || (_read_only_size + _read_write_size == 0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
         "Shared space when disabled?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
}