src/hotspot/share/memory/metaspace/spaceManager.cpp
author dcubed
Sat, 21 Sep 2019 10:13:25 -0400
changeset 58252 14c1ff687621
parent 54623 1126f0607c70
child 57464 32e61f51ee09
child 58063 bdf136b8ae0e
permissions -rw-r--r--
8231323: ProblemList jdk/jfr/jcmd/TestJcmdConfigure.java Reviewed-by: ysuenaga
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     1
/*
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 53970
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     4
 *
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     7
 * published by the Free Software Foundation.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     8
 *
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    13
 * accompanied this code).
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    14
 *
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    18
 *
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    21
 * questions.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    22
 *
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    23
 */
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    24
#include "precompiled.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    25
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    26
#include "logging/log.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    27
#include "logging/logStream.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    28
#include "memory/metaspace/chunkManager.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    29
#include "memory/metaspace/metachunk.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    30
#include "memory/metaspace/metaDebug.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    31
#include "memory/metaspace/metaspaceCommon.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    32
#include "memory/metaspace/spaceManager.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    33
#include "memory/metaspace/virtualSpaceList.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    34
#include "runtime/atomic.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    35
#include "runtime/init.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    36
#include "services/memoryService.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    37
#include "utilities/debug.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    38
#include "utilities/globalDefinitions.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    39
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    40
namespace metaspace {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    41
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    42
#define assert_counter(expected_value, real_value, msg) \
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    43
  assert( (expected_value) == (real_value),             \
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    44
         "Counter mismatch (%s): expected " SIZE_FORMAT \
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    45
         ", but got: " SIZE_FORMAT ".", msg, expected_value, \
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    46
         real_value);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    47
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    48
// SpaceManager methods
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    49
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    50
size_t SpaceManager::adjust_initial_chunk_size(size_t requested, bool is_class_space) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    51
  size_t chunk_sizes[] = {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    52
      specialized_chunk_size(is_class_space),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    53
      small_chunk_size(is_class_space),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    54
      medium_chunk_size(is_class_space)
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    55
  };
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    56
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    57
  // Adjust up to one of the fixed chunk sizes ...
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    58
  for (size_t i = 0; i < ARRAY_SIZE(chunk_sizes); i++) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    59
    if (requested <= chunk_sizes[i]) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    60
      return chunk_sizes[i];
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    61
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    62
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    63
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    64
  // ... or return the size as a humongous chunk.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    65
  return requested;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    66
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    67
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    68
size_t SpaceManager::adjust_initial_chunk_size(size_t requested) const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    69
  return adjust_initial_chunk_size(requested, is_class());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    70
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    71
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    72
size_t SpaceManager::get_initial_chunk_size(Metaspace::MetaspaceType type) const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    73
  size_t requested;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    74
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    75
  if (is_class()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    76
    switch (type) {
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
    77
    case Metaspace::BootMetaspaceType:              requested = Metaspace::first_class_chunk_word_size(); break;
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
    78
    case Metaspace::UnsafeAnonymousMetaspaceType:   requested = ClassSpecializedChunk; break;
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
    79
    case Metaspace::ReflectionMetaspaceType:        requested = ClassSpecializedChunk; break;
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
    80
    default:                                        requested = ClassSmallChunk; break;
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    81
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    82
  } else {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    83
    switch (type) {
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
    84
    case Metaspace::BootMetaspaceType:              requested = Metaspace::first_chunk_word_size(); break;
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
    85
    case Metaspace::UnsafeAnonymousMetaspaceType:   requested = SpecializedChunk; break;
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
    86
    case Metaspace::ReflectionMetaspaceType:        requested = SpecializedChunk; break;
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
    87
    default:                                        requested = SmallChunk; break;
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    88
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    89
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    90
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    91
  // Adjust to one of the fixed chunk sizes (unless humongous)
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    92
  const size_t adjusted = adjust_initial_chunk_size(requested);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    93
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    94
  assert(adjusted != 0, "Incorrect initial chunk size. Requested: "
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    95
         SIZE_FORMAT " adjusted: " SIZE_FORMAT, requested, adjusted);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    96
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    97
  return adjusted;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    98
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    99
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   100
void SpaceManager::locked_print_chunks_in_use_on(outputStream* st) const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   101
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   102
  for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   103
    st->print("SpaceManager: " UINTX_FORMAT " %s chunks.",
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   104
        num_chunks_by_type(i), chunk_size_name(i));
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   105
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   106
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   107
  chunk_manager()->locked_print_free_chunks(st);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   108
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   109
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   110
size_t SpaceManager::calc_chunk_size(size_t word_size) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   111
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   112
  // Decide between a small chunk and a medium chunk.  Up to
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   113
  // _small_chunk_limit small chunks can be allocated.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   114
  // After that a medium chunk is preferred.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   115
  size_t chunk_word_size;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   116
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
   117
  // Special case for unsafe anonymous metadata space.
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
   118
  // UnsafeAnonymous metadata space is usually small since it is used for
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
   119
  // class loader data's whose life cycle is governed by one class such as an
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
   120
  // unsafe anonymous class.  The majority within 1K - 2K range and
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   121
  // rarely about 4K (64-bits JVM).
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   122
  // Instead of jumping to SmallChunk after initial chunk exhausted, keeping allocation
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   123
  // from SpecializeChunk up to _anon_or_delegating_metadata_specialize_chunk_limit (4)
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   124
  // reduces space waste from 60+% to around 30%.
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
   125
  if ((_space_type == Metaspace::UnsafeAnonymousMetaspaceType || _space_type == Metaspace::ReflectionMetaspaceType) &&
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   126
      _mdtype == Metaspace::NonClassType &&
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   127
      num_chunks_by_type(SpecializedIndex) < anon_and_delegating_metadata_specialize_chunk_limit &&
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   128
      word_size + Metachunk::overhead() <= SpecializedChunk) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   129
    return SpecializedChunk;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   130
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   131
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   132
  if (num_chunks_by_type(MediumIndex) == 0 &&
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   133
      num_chunks_by_type(SmallIndex) < small_chunk_limit) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   134
    chunk_word_size = (size_t) small_chunk_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   135
    if (word_size + Metachunk::overhead() > small_chunk_size()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   136
      chunk_word_size = medium_chunk_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   137
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   138
  } else {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   139
    chunk_word_size = medium_chunk_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   140
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   141
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   142
  // Might still need a humongous chunk.  Enforce
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   143
  // humongous allocations sizes to be aligned up to
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   144
  // the smallest chunk size.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   145
  size_t if_humongous_sized_chunk =
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   146
    align_up(word_size + Metachunk::overhead(),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   147
                  smallest_chunk_size());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   148
  chunk_word_size =
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   149
    MAX2((size_t) chunk_word_size, if_humongous_sized_chunk);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   150
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   151
  assert(!SpaceManager::is_humongous(word_size) ||
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   152
         chunk_word_size == if_humongous_sized_chunk,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   153
         "Size calculation is wrong, word_size " SIZE_FORMAT
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   154
         " chunk_word_size " SIZE_FORMAT,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   155
         word_size, chunk_word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   156
  Log(gc, metaspace, alloc) log;
50811
f533eb5e7430 8205664: Move detailed metaspace logging from debug to trace
pliden
parents: 50193
diff changeset
   157
  if (log.is_trace() && SpaceManager::is_humongous(word_size)) {
f533eb5e7430 8205664: Move detailed metaspace logging from debug to trace
pliden
parents: 50193
diff changeset
   158
    log.trace("Metadata humongous allocation:");
f533eb5e7430 8205664: Move detailed metaspace logging from debug to trace
pliden
parents: 50193
diff changeset
   159
    log.trace("  word_size " PTR_FORMAT, word_size);
f533eb5e7430 8205664: Move detailed metaspace logging from debug to trace
pliden
parents: 50193
diff changeset
   160
    log.trace("  chunk_word_size " PTR_FORMAT, chunk_word_size);
f533eb5e7430 8205664: Move detailed metaspace logging from debug to trace
pliden
parents: 50193
diff changeset
   161
    log.trace("    chunk overhead " PTR_FORMAT, Metachunk::overhead());
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   162
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   163
  return chunk_word_size;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   164
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   165
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   166
void SpaceManager::track_metaspace_memory_usage() {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   167
  if (is_init_completed()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   168
    if (is_class()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   169
      MemoryService::track_compressed_class_memory_usage();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   170
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   171
    MemoryService::track_metaspace_memory_usage();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   172
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   173
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   174
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   175
MetaWord* SpaceManager::grow_and_allocate(size_t word_size) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   176
  assert_lock_strong(_lock);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   177
  assert(vs_list()->current_virtual_space() != NULL,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   178
         "Should have been set");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   179
  assert(current_chunk() == NULL ||
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   180
         current_chunk()->allocate(word_size) == NULL,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   181
         "Don't need to expand");
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 53970
diff changeset
   182
  MutexLocker cl(MetaspaceExpand_lock, Mutex::_no_safepoint_check_flag);
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   183
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   184
  if (log_is_enabled(Trace, gc, metaspace, freelist)) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   185
    size_t words_left = 0;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   186
    size_t words_used = 0;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   187
    if (current_chunk() != NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   188
      words_left = current_chunk()->free_word_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   189
      words_used = current_chunk()->used_word_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   190
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   191
    log_trace(gc, metaspace, freelist)("SpaceManager::grow_and_allocate for " SIZE_FORMAT " words " SIZE_FORMAT " words used " SIZE_FORMAT " words left",
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   192
                                       word_size, words_used, words_left);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   193
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   194
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   195
  // Get another chunk
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   196
  size_t chunk_word_size = calc_chunk_size(word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   197
  Metachunk* next = get_new_chunk(chunk_word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   198
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   199
  MetaWord* mem = NULL;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   200
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   201
  // If a chunk was available, add it to the in-use chunk list
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   202
  // and do an allocation from it.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   203
  if (next != NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   204
    // Add to this manager's list of chunks in use.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   205
    // If the new chunk is humongous, it was created to serve a single large allocation. In that
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   206
    // case it usually makes no sense to make it the current chunk, since the next allocation would
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   207
    // need to allocate a new chunk anyway, while we would now prematurely retire a perfectly
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   208
    // good chunk which could be used for more normal allocations.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   209
    bool make_current = true;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   210
    if (next->get_chunk_type() == HumongousIndex &&
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   211
        current_chunk() != NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   212
      make_current = false;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   213
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   214
    add_chunk(next, make_current);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   215
    mem = next->allocate(word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   216
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   217
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   218
  // Track metaspace memory usage statistic.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   219
  track_metaspace_memory_usage();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   220
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   221
  return mem;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   222
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   223
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   224
void SpaceManager::print_on(outputStream* st) const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   225
  SpaceManagerStatistics stat;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   226
  add_to_statistics(&stat); // will lock _lock.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   227
  stat.print_on(st, 1*K, false);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   228
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   229
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   230
SpaceManager::SpaceManager(Metaspace::MetadataType mdtype,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   231
                           Metaspace::MetaspaceType space_type,//
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   232
                           Mutex* lock) :
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50811
diff changeset
   233
  _lock(lock),
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   234
  _mdtype(mdtype),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   235
  _space_type(space_type),
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50811
diff changeset
   236
  _chunk_list(NULL),
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50811
diff changeset
   237
  _current_chunk(NULL),
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50811
diff changeset
   238
  _overhead_words(0),
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   239
  _capacity_words(0),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   240
  _used_words(0),
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50811
diff changeset
   241
  _block_freelists(NULL) {
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   242
  Metadebug::init_allocation_fail_alot_count();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   243
  memset(_num_chunks_by_type, 0, sizeof(_num_chunks_by_type));
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   244
  log_trace(gc, metaspace, freelist)("SpaceManager(): " PTR_FORMAT, p2i(this));
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   245
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   246
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   247
void SpaceManager::account_for_new_chunk(const Metachunk* new_chunk) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   248
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   249
  assert_lock_strong(MetaspaceExpand_lock);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   250
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   251
  _capacity_words += new_chunk->word_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   252
  _overhead_words += Metachunk::overhead();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   253
  DEBUG_ONLY(new_chunk->verify());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   254
  _num_chunks_by_type[new_chunk->get_chunk_type()] ++;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   255
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   256
  // Adjust global counters:
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   257
  MetaspaceUtils::inc_capacity(mdtype(), new_chunk->word_size());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   258
  MetaspaceUtils::inc_overhead(mdtype(), Metachunk::overhead());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   259
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   260
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   261
void SpaceManager::account_for_allocation(size_t words) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   262
  // Note: we should be locked with the ClassloaderData-specific metaspace lock.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   263
  // We may or may not be locked with the global metaspace expansion lock.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   264
  assert_lock_strong(lock());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   265
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   266
  // Add to the per SpaceManager totals. This can be done non-atomically.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   267
  _used_words += words;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   268
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   269
  // Adjust global counters. This will be done atomically.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   270
  MetaspaceUtils::inc_used(mdtype(), words);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   271
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   272
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   273
void SpaceManager::account_for_spacemanager_death() {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   274
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   275
  assert_lock_strong(MetaspaceExpand_lock);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   276
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   277
  MetaspaceUtils::dec_capacity(mdtype(), _capacity_words);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   278
  MetaspaceUtils::dec_overhead(mdtype(), _overhead_words);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   279
  MetaspaceUtils::dec_used(mdtype(), _used_words);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   280
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   281
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   282
SpaceManager::~SpaceManager() {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   283
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   284
  // This call this->_lock which can't be done while holding MetaspaceExpand_lock
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   285
  DEBUG_ONLY(verify_metrics());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   286
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 53970
diff changeset
   287
  MutexLocker fcl(MetaspaceExpand_lock, Mutex::_no_safepoint_check_flag);
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   288
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   289
  account_for_spacemanager_death();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   290
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   291
  Log(gc, metaspace, freelist) log;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   292
  if (log.is_trace()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   293
    log.trace("~SpaceManager(): " PTR_FORMAT, p2i(this));
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   294
    ResourceMark rm;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   295
    LogStream ls(log.trace());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   296
    locked_print_chunks_in_use_on(&ls);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   297
    if (block_freelists() != NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   298
      block_freelists()->print_on(&ls);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   299
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   300
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   301
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   302
  // Add all the chunks in use by this space manager
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   303
  // to the global list of free chunks.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   304
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   305
  // Follow each list of chunks-in-use and add them to the
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   306
  // free lists.  Each list is NULL terminated.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   307
  chunk_manager()->return_chunk_list(chunk_list());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   308
#ifdef ASSERT
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   309
  _chunk_list = NULL;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   310
  _current_chunk = NULL;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   311
#endif
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   312
53970
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51444
diff changeset
   313
#ifdef ASSERT
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51444
diff changeset
   314
  EVERY_NTH(VerifyMetaspaceInterval)
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51444
diff changeset
   315
    chunk_manager()->locked_verify(true);
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51444
diff changeset
   316
  END_EVERY_NTH
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51444
diff changeset
   317
#endif
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   318
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   319
  if (_block_freelists != NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   320
    delete _block_freelists;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   321
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   322
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   323
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   324
void SpaceManager::deallocate(MetaWord* p, size_t word_size) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   325
  assert_lock_strong(lock());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   326
  // Allocations and deallocations are in raw_word_size
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   327
  size_t raw_word_size = get_allocation_word_size(word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   328
  // Lazily create a block_freelist
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   329
  if (block_freelists() == NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   330
    _block_freelists = new BlockFreelist();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   331
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   332
  block_freelists()->return_block(p, raw_word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   333
  DEBUG_ONLY(Atomic::inc(&(g_internal_statistics.num_deallocs)));
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   334
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   335
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   336
// Adds a chunk to the list of chunks in use.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   337
void SpaceManager::add_chunk(Metachunk* new_chunk, bool make_current) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   338
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   339
  assert_lock_strong(_lock);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   340
  assert(new_chunk != NULL, "Should not be NULL");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   341
  assert(new_chunk->next() == NULL, "Should not be on a list");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   342
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   343
  new_chunk->reset_empty();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   344
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   345
  // Find the correct list and and set the current
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   346
  // chunk for that list.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   347
  ChunkIndex index = chunk_manager()->list_index(new_chunk->word_size());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   348
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   349
  if (make_current) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   350
    // If we are to make the chunk current, retire the old current chunk and replace
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   351
    // it with the new chunk.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   352
    retire_current_chunk();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   353
    set_current_chunk(new_chunk);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   354
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   355
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   356
  // Add the new chunk at the head of its respective chunk list.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   357
  new_chunk->set_next(_chunk_list);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   358
  _chunk_list = new_chunk;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   359
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   360
  // Adjust counters.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   361
  account_for_new_chunk(new_chunk);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   362
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   363
  assert(new_chunk->is_empty(), "Not ready for reuse");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   364
  Log(gc, metaspace, freelist) log;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   365
  if (log.is_trace()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   366
    log.trace("SpaceManager::added chunk: ");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   367
    ResourceMark rm;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   368
    LogStream ls(log.trace());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   369
    new_chunk->print_on(&ls);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   370
    chunk_manager()->locked_print_free_chunks(&ls);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   371
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   372
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   373
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   374
void SpaceManager::retire_current_chunk() {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   375
  if (current_chunk() != NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   376
    size_t remaining_words = current_chunk()->free_word_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   377
    if (remaining_words >= SmallBlocks::small_block_min_size()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   378
      MetaWord* ptr = current_chunk()->allocate(remaining_words);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   379
      deallocate(ptr, remaining_words);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   380
      account_for_allocation(remaining_words);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   381
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   382
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   383
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   384
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   385
Metachunk* SpaceManager::get_new_chunk(size_t chunk_word_size) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   386
  // Get a chunk from the chunk freelist
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   387
  Metachunk* next = chunk_manager()->chunk_freelist_allocate(chunk_word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   388
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   389
  if (next == NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   390
    next = vs_list()->get_new_chunk(chunk_word_size,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   391
                                    medium_chunk_bunch());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   392
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   393
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   394
  Log(gc, metaspace, alloc) log;
50811
f533eb5e7430 8205664: Move detailed metaspace logging from debug to trace
pliden
parents: 50193
diff changeset
   395
  if (log.is_trace() && next != NULL &&
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   396
      SpaceManager::is_humongous(next->word_size())) {
50811
f533eb5e7430 8205664: Move detailed metaspace logging from debug to trace
pliden
parents: 50193
diff changeset
   397
    log.trace("  new humongous chunk word size " PTR_FORMAT, next->word_size());
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   398
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   399
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   400
  return next;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   401
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   402
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   403
MetaWord* SpaceManager::allocate(size_t word_size) {
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 53970
diff changeset
   404
  MutexLocker cl(lock(), Mutex::_no_safepoint_check_flag);
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   405
  size_t raw_word_size = get_allocation_word_size(word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   406
  BlockFreelist* fl =  block_freelists();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   407
  MetaWord* p = NULL;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   408
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   409
  // Allocation from the dictionary is expensive in the sense that
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   410
  // the dictionary has to be searched for a size.  Don't allocate
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   411
  // from the dictionary until it starts to get fat.  Is this
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   412
  // a reasonable policy?  Maybe an skinny dictionary is fast enough
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   413
  // for allocations.  Do some profiling.  JJJ
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   414
  if (fl != NULL && fl->total_size() > allocation_from_dictionary_limit) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   415
    p = fl->get_block(raw_word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   416
    if (p != NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   417
      DEBUG_ONLY(Atomic::inc(&g_internal_statistics.num_allocs_from_deallocated_blocks));
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   418
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   419
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   420
  if (p == NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   421
    p = allocate_work(raw_word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   422
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   423
53970
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51444
diff changeset
   424
#ifdef ASSERT
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51444
diff changeset
   425
  EVERY_NTH(VerifyMetaspaceInterval)
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51444
diff changeset
   426
    verify_metrics_locked();
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51444
diff changeset
   427
  END_EVERY_NTH
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51444
diff changeset
   428
#endif
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51444
diff changeset
   429
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   430
  return p;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   431
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   432
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   433
// Returns the address of spaced allocated for "word_size".
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   434
// This methods does not know about blocks (Metablocks)
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   435
MetaWord* SpaceManager::allocate_work(size_t word_size) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   436
  assert_lock_strong(lock());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   437
#ifdef ASSERT
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   438
  if (Metadebug::test_metadata_failure()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   439
    return NULL;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   440
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   441
#endif
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   442
  // Is there space in the current chunk?
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   443
  MetaWord* result = NULL;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   444
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   445
  if (current_chunk() != NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   446
    result = current_chunk()->allocate(word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   447
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   448
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   449
  if (result == NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   450
    result = grow_and_allocate(word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   451
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   452
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   453
  if (result != NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   454
    account_for_allocation(word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   455
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   456
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   457
  return result;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   458
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   459
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   460
void SpaceManager::verify() {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   461
  Metachunk* curr = chunk_list();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   462
  while (curr != NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   463
    DEBUG_ONLY(do_verify_chunk(curr);)
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   464
    assert(curr->is_tagged_free() == false, "Chunk should be tagged as in use.");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   465
    curr = curr->next();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   466
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   467
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   468
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   469
void SpaceManager::verify_chunk_size(Metachunk* chunk) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   470
  assert(is_humongous(chunk->word_size()) ||
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   471
         chunk->word_size() == medium_chunk_size() ||
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   472
         chunk->word_size() == small_chunk_size() ||
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   473
         chunk->word_size() == specialized_chunk_size(),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   474
         "Chunk size is wrong");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   475
  return;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   476
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   477
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   478
void SpaceManager::add_to_statistics_locked(SpaceManagerStatistics* out) const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   479
  assert_lock_strong(lock());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   480
  Metachunk* chunk = chunk_list();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   481
  while (chunk != NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   482
    UsedChunksStatistics& chunk_stat = out->chunk_stats(chunk->get_chunk_type());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   483
    chunk_stat.add_num(1);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   484
    chunk_stat.add_cap(chunk->word_size());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   485
    chunk_stat.add_overhead(Metachunk::overhead());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   486
    chunk_stat.add_used(chunk->used_word_size() - Metachunk::overhead());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   487
    if (chunk != current_chunk()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   488
      chunk_stat.add_waste(chunk->free_word_size());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   489
    } else {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   490
      chunk_stat.add_free(chunk->free_word_size());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   491
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   492
    chunk = chunk->next();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   493
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   494
  if (block_freelists() != NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   495
    out->add_free_blocks_info(block_freelists()->num_blocks(), block_freelists()->total_size());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   496
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   497
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   498
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   499
void SpaceManager::add_to_statistics(SpaceManagerStatistics* out) const {
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 53970
diff changeset
   500
  MutexLocker cl(lock(), Mutex::_no_safepoint_check_flag);
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   501
  add_to_statistics_locked(out);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   502
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   503
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   504
#ifdef ASSERT
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   505
void SpaceManager::verify_metrics_locked() const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   506
  assert_lock_strong(lock());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   507
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   508
  SpaceManagerStatistics stat;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   509
  add_to_statistics_locked(&stat);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   510
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   511
  UsedChunksStatistics chunk_stats = stat.totals();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   512
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   513
  DEBUG_ONLY(chunk_stats.check_sanity());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   514
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   515
  assert_counter(_capacity_words, chunk_stats.cap(), "SpaceManager::_capacity_words");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   516
  assert_counter(_used_words, chunk_stats.used(), "SpaceManager::_used_words");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   517
  assert_counter(_overhead_words, chunk_stats.overhead(), "SpaceManager::_overhead_words");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   518
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   519
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   520
void SpaceManager::verify_metrics() const {
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 53970
diff changeset
   521
  MutexLocker cl(lock(), Mutex::_no_safepoint_check_flag);
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   522
  verify_metrics_locked();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   523
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   524
#endif // ASSERT
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   525
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   526
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   527
} // namespace metaspace
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   528