hotspot/src/share/vm/memory/generationSpec.cpp
author ysr
Tue, 03 Nov 2009 16:43:16 -0800
changeset 4106 30919106db1d
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6801625: CDS: HeapDump tests crash with internal error in compactingPermGenGen.cpp Summary: Allow iteration over the shared spaces when using CDS, repealing previous proscription. Deferred further required CDS-related cleanups of perm gen to CR 6897789. Reviewed-by: phh, jmasa
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 2001-2005 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/_generationSpec.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
Generation* GenerationSpec::init(ReservedSpace rs, int level,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
                                 GenRemSet* remset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  switch (name()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
    case Generation::DefNew:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
      return new DefNewGeneration(rs, init_size(), level);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
    case Generation::MarkSweepCompact:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
      return new TenuredGeneration(rs, init_size(), level, remset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    case Generation::ParNew:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
      return new ParNewGeneration(rs, init_size(), level);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    case Generation::ASParNew:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
      return new ASParNewGeneration(rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
                                    init_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
                                    init_size() /* min size */,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
                                    level);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    case Generation::ConcurrentMarkSweep: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
      assert(UseConcMarkSweepGC, "UseConcMarkSweepGC should be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
      CardTableRS* ctrs = remset->as_CardTableRS();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
      if (ctrs == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
        vm_exit_during_initialization("Rem set incompatibility.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
      // Otherwise
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
      // The constructor creates the CMSCollector if needed,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      // else registers with an existing CMSCollector
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
      ConcurrentMarkSweepGeneration* g = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
      g = new ConcurrentMarkSweepGeneration(rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
                 init_size(), level, ctrs, UseCMSAdaptiveFreeLists,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
                 (FreeBlockDictionary::DictionaryChoice)CMSDictionaryChoice);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      g->initialize_performance_counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      return g;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    case Generation::ASConcurrentMarkSweep: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
      assert(UseConcMarkSweepGC, "UseConcMarkSweepGC should be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
      CardTableRS* ctrs = remset->as_CardTableRS();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
      if (ctrs == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
        vm_exit_during_initialization("Rem set incompatibility.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
      // Otherwise
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
      // The constructor creates the CMSCollector if needed,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      // else registers with an existing CMSCollector
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
      ASConcurrentMarkSweepGeneration* g = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      g = new ASConcurrentMarkSweepGeneration(rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
                 init_size(), level, ctrs, UseCMSAdaptiveFreeLists,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
                 (FreeBlockDictionary::DictionaryChoice)CMSDictionaryChoice);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
      g->initialize_performance_counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
      return g;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      guarantee(false, "unrecognized GenerationName");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
PermanentGenerationSpec::PermanentGenerationSpec(PermGen::Name name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
                      size_t init_size, size_t max_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
                      size_t read_only_size, size_t read_write_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
                      size_t misc_data_size, size_t misc_code_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  _name = name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  _init_size = init_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  if (UseSharedSpaces || DumpSharedSpaces) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    _enable_shared_spaces = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    if (UseSharedSpaces) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      // Override shared space sizes from those in the file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      FileMapInfo* mapinfo = FileMapInfo::current_info();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      _read_only_size = mapinfo->space_capacity(CompactingPermGenGen::ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      _read_write_size = mapinfo->space_capacity(CompactingPermGenGen::rw);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      _misc_data_size = mapinfo->space_capacity(CompactingPermGenGen::md);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      _misc_code_size = mapinfo->space_capacity(CompactingPermGenGen::mc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
      _read_only_size = read_only_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
      _read_write_size = read_write_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      _misc_data_size = misc_data_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      _misc_code_size = misc_code_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    _enable_shared_spaces = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    _read_only_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    _read_write_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    _misc_data_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    _misc_code_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  _max_size = max_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
PermGen* PermanentGenerationSpec::init(ReservedSpace rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
                                       size_t init_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
                                       GenRemSet *remset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // Break the reserved spaces into pieces for the permanent space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  // and the shared spaces.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  ReservedSpace perm_rs = rs.first_part(_max_size, UseSharedSpaces,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
                                        UseSharedSpaces);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  ReservedSpace shared_rs = rs.last_part(_max_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  if (enable_shared_spaces()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    if (!perm_rs.is_reserved() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
        perm_rs.base() + perm_rs.size() != shared_rs.base()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      FileMapInfo* mapinfo = FileMapInfo::current_info();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      mapinfo->fail_continue("Sharing disabled - unable to "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
                                 "reserve address space.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      shared_rs.release();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      disable_sharing();
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
  switch (name()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    case PermGen::MarkSweepCompact:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      return new CompactingPermGen(perm_rs, shared_rs, init_size, remset, this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    case PermGen::MarkSweep:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      guarantee(false, "NYI");
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
    case PermGen::ConcurrentMarkSweep: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      assert(UseConcMarkSweepGC, "UseConcMarkSweepGC should be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      CardTableRS* ctrs = remset->as_CardTableRS();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      if (ctrs == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
        vm_exit_during_initialization("RemSet/generation incompatibility.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
      // XXXPERM
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      return new CMSPermGen(perm_rs, init_size, ctrs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
                   (FreeBlockDictionary::DictionaryChoice)CMSDictionaryChoice);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      guarantee(false, "unrecognized GenerationName");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
// Alignment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
void PermanentGenerationSpec::align(size_t alignment) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  _init_size       = align_size_up(_init_size,       alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  _max_size        = align_size_up(_max_size,        alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  _read_only_size  = align_size_up(_read_only_size,  alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  _read_write_size = align_size_up(_read_write_size, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  _misc_data_size  = align_size_up(_misc_data_size,  alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  _misc_code_size  = align_size_up(_misc_code_size,  alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  assert(enable_shared_spaces() || (_read_only_size + _read_write_size == 0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
         "Shared space when disabled?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
}