src/hotspot/share/memory/metaspace/metaspaceCommon.cpp
author dcubed
Sat, 21 Sep 2019 10:13:25 -0400
changeset 58252 14c1ff687621
parent 54820 fcf83b204c27
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:
49980
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
     1
/*
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
     4
 *
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
     7
 * published by the Free Software Foundation.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
     8
 *
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    13
 * accompanied this code).
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    14
 *
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    18
 *
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    21
 * questions.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    22
 *
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    23
 */
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    24
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    25
#include "precompiled.hpp"
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    26
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    27
#include "memory/metaspace/metaspaceCommon.hpp"
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
    28
#include "memory/metaspace/virtualSpaceNode.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
    29
#include "utilities/debug.hpp"
49980
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    30
#include "utilities/globalDefinitions.hpp"
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    31
#include "utilities/ostream.hpp"
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    32
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    33
namespace metaspace {
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
    34
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
    35
DEBUG_ONLY(internal_statistics_t g_internal_statistics;)
49980
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    36
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    37
// Print a size, in words, scaled.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    38
void print_scaled_words(outputStream* st, size_t word_size, size_t scale, int width) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    39
  print_human_readable_size(st, word_size * sizeof(MetaWord), scale, width);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    40
}
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    41
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    42
// Convenience helper: prints a size value and a percentage.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    43
void print_scaled_words_and_percentage(outputStream* st, size_t word_size, size_t compare_word_size, size_t scale, int width) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    44
  print_scaled_words(st, word_size, scale, width);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    45
  st->print(" (");
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    46
  print_percentage(st, compare_word_size, word_size);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    47
  st->print(")");
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    48
}
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    49
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    50
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    51
// Print a human readable size.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    52
// byte_size: size, in bytes, to be printed.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    53
// scale: one of 1 (byte-wise printing), sizeof(word) (word-size printing), K, M, G (scaled by KB, MB, GB respectively,
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    54
//         or 0, which means the best scale is choosen dynamically.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    55
// width: printing width.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    56
void print_human_readable_size(outputStream* st, size_t byte_size, size_t scale, int width)  {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    57
  if (scale == 0) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    58
    // Dynamic mode. Choose scale for this value.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    59
    if (byte_size == 0) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    60
      // Zero values are printed as bytes.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    61
      scale = 1;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    62
    } else {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    63
      if (byte_size >= G) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    64
        scale = G;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    65
      } else if (byte_size >= M) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    66
        scale = M;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    67
      } else if (byte_size >= K) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    68
        scale = K;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    69
      } else {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    70
        scale = 1;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    71
      }
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    72
    }
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    73
    return print_human_readable_size(st, byte_size, scale, width);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    74
  }
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    75
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    76
#ifdef ASSERT
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    77
  assert(scale == 1 || scale == BytesPerWord || scale == K || scale == M || scale == G, "Invalid scale");
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    78
  // Special case: printing wordsize should only be done with word-sized values
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    79
  if (scale == BytesPerWord) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    80
    assert(byte_size % BytesPerWord == 0, "not word sized");
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    81
  }
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    82
#endif
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    83
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    84
  if (scale == 1) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    85
    st->print("%*" PRIuPTR " bytes", width, byte_size);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    86
  } else if (scale == BytesPerWord) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    87
    st->print("%*" PRIuPTR " words", width, byte_size / BytesPerWord);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    88
  } else {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    89
    const char* display_unit = "";
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    90
    switch(scale) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    91
      case 1: display_unit = "bytes"; break;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    92
      case BytesPerWord: display_unit = "words"; break;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    93
      case K: display_unit = "KB"; break;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    94
      case M: display_unit = "MB"; break;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    95
      case G: display_unit = "GB"; break;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    96
      default:
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    97
        ShouldNotReachHere();
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    98
    }
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    99
    float display_value = (float) byte_size / scale;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   100
    // Since we use width to display a number with two trailing digits, increase it a bit.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   101
    width += 3;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   102
    // Prevent very small but non-null values showing up as 0.00.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   103
    if (byte_size > 0 && display_value < 0.01f) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   104
      st->print("%*s %s", width, "<0.01", display_unit);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   105
    } else {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   106
      st->print("%*.2f %s", width, display_value, display_unit);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   107
    }
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   108
  }
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   109
}
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   110
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   111
// Prints a percentage value. Values smaller than 1% but not 0 are displayed as "<1%", values
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   112
// larger than 99% but not 100% are displayed as ">100%".
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   113
void print_percentage(outputStream* st, size_t total, size_t part) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   114
  if (total == 0) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   115
    st->print("  ?%%");
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   116
  } else if (part == 0) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   117
    st->print("  0%%");
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   118
  } else if (part == total) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   119
    st->print("100%%");
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   120
  } else {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   121
    // Note: clearly print very-small-but-not-0% and very-large-but-not-100% percentages.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   122
    float p = ((float)part / total) * 100.0f;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   123
    if (p < 1.0f) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   124
      st->print(" <1%%");
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   125
    } else if (p > 99.0f){
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   126
      st->print(">99%%");
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   127
    } else {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   128
      st->print("%3.0f%%", p);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   129
    }
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   130
  }
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   131
}
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   132
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   133
// Returns size of this chunk type.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   134
size_t get_size_for_nonhumongous_chunktype(ChunkIndex chunktype, bool is_class) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   135
  assert(is_valid_nonhumongous_chunktype(chunktype), "invalid chunk type.");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   136
  size_t size = 0;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   137
  if (is_class) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   138
    switch(chunktype) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   139
      case SpecializedIndex: size = ClassSpecializedChunk; break;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   140
      case SmallIndex: size = ClassSmallChunk; break;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   141
      case MediumIndex: size = ClassMediumChunk; break;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   142
      default:
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   143
        ShouldNotReachHere();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   144
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   145
  } else {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   146
    switch(chunktype) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   147
      case SpecializedIndex: size = SpecializedChunk; break;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   148
      case SmallIndex: size = SmallChunk; break;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   149
      case MediumIndex: size = MediumChunk; break;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   150
      default:
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   151
        ShouldNotReachHere();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   152
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   153
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   154
  return size;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   155
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   156
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   157
ChunkIndex get_chunk_type_by_size(size_t size, bool is_class) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   158
  if (is_class) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   159
    if (size == ClassSpecializedChunk) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   160
      return SpecializedIndex;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   161
    } else if (size == ClassSmallChunk) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   162
      return SmallIndex;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   163
    } else if (size == ClassMediumChunk) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   164
      return MediumIndex;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   165
    } else if (size > ClassMediumChunk) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   166
      // A valid humongous chunk size is a multiple of the smallest chunk size.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   167
      assert(is_aligned(size, ClassSpecializedChunk), "Invalid chunk size");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   168
      return HumongousIndex;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   169
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   170
  } else {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   171
    if (size == SpecializedChunk) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   172
      return SpecializedIndex;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   173
    } else if (size == SmallChunk) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   174
      return SmallIndex;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   175
    } else if (size == MediumChunk) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   176
      return MediumIndex;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   177
    } else if (size > MediumChunk) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   178
      // A valid humongous chunk size is a multiple of the smallest chunk size.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   179
      assert(is_aligned(size, SpecializedChunk), "Invalid chunk size");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   180
      return HumongousIndex;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   181
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   182
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   183
  ShouldNotReachHere();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   184
  return (ChunkIndex)-1;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   185
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   186
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   187
ChunkIndex next_chunk_index(ChunkIndex i) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   188
  assert(i < NumberOfInUseLists, "Out of bound");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   189
  return (ChunkIndex) (i+1);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   190
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   191
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   192
ChunkIndex prev_chunk_index(ChunkIndex i) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   193
  assert(i > ZeroIndex, "Out of bound");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   194
  return (ChunkIndex) (i-1);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   195
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   196
54820
fcf83b204c27 8222015: Small VM.metaspace improvements
stuefe
parents: 50193
diff changeset
   197
const char* loaders_plural(uintx num) {
fcf83b204c27 8222015: Small VM.metaspace improvements
stuefe
parents: 50193
diff changeset
   198
  return num == 1 ? "loader" : "loaders";
fcf83b204c27 8222015: Small VM.metaspace improvements
stuefe
parents: 50193
diff changeset
   199
}
fcf83b204c27 8222015: Small VM.metaspace improvements
stuefe
parents: 50193
diff changeset
   200
fcf83b204c27 8222015: Small VM.metaspace improvements
stuefe
parents: 50193
diff changeset
   201
const char* classes_plural(uintx num) {
fcf83b204c27 8222015: Small VM.metaspace improvements
stuefe
parents: 50193
diff changeset
   202
  return num == 1 ? "class" : "classes";
fcf83b204c27 8222015: Small VM.metaspace improvements
stuefe
parents: 50193
diff changeset
   203
}
fcf83b204c27 8222015: Small VM.metaspace improvements
stuefe
parents: 50193
diff changeset
   204
fcf83b204c27 8222015: Small VM.metaspace improvements
stuefe
parents: 50193
diff changeset
   205
void print_number_of_classes(outputStream* out, uintx classes, uintx classes_shared) {
fcf83b204c27 8222015: Small VM.metaspace improvements
stuefe
parents: 50193
diff changeset
   206
  out->print(UINTX_FORMAT " %s", classes, classes_plural(classes));
fcf83b204c27 8222015: Small VM.metaspace improvements
stuefe
parents: 50193
diff changeset
   207
  if (classes_shared > 0) {
fcf83b204c27 8222015: Small VM.metaspace improvements
stuefe
parents: 50193
diff changeset
   208
    out->print(" (" UINTX_FORMAT " shared)", classes_shared);
fcf83b204c27 8222015: Small VM.metaspace improvements
stuefe
parents: 50193
diff changeset
   209
  }
fcf83b204c27 8222015: Small VM.metaspace improvements
stuefe
parents: 50193
diff changeset
   210
}
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   211
49980
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   212
} // namespace metaspace
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49980
diff changeset
   213