src/hotspot/share/memory/metaspace.cpp
author stuefe
Tue, 06 Mar 2018 19:24:13 +0100
changeset 49365 825f006619e5
parent 49045 9b556b613a07
child 49366 f95ef5511e1f
permissions -rw-r--r--
8198423: Improve metaspace chunk allocation Reviewed-by: goetz, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     1
/*
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48387
diff changeset
     2
 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     4
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     8
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    13
 * accompanied this code).
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    14
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    18
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    21
 * questions.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    22
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    23
 */
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    24
#include "precompiled.hpp"
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 42621
diff changeset
    25
#include "aot/aotLoader.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30580
diff changeset
    26
#include "gc/shared/collectedHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30580
diff changeset
    27
#include "gc/shared/collectorPolicy.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30580
diff changeset
    28
#include "gc/shared/gcLocker.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
    29
#include "logging/log.hpp"
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
    30
#include "logging/logStream.hpp"
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
    31
#include "memory/allocation.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    32
#include "memory/binaryTreeDictionary.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    33
#include "memory/filemap.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    34
#include "memory/freeList.hpp"
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
    35
#include "memory/metachunk.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    36
#include "memory/metaspace.hpp"
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
    37
#include "memory/metaspaceGCThresholdUpdater.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    38
#include "memory/metaspaceShared.hpp"
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
    39
#include "memory/metaspaceTracer.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    40
#include "memory/resourceArea.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    41
#include "memory/universe.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39986
diff changeset
    42
#include "runtime/atomic.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    43
#include "runtime/globals.hpp"
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
    44
#include "runtime/init.hpp"
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
    45
#include "runtime/java.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    46
#include "runtime/mutex.hpp"
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 23854
diff changeset
    47
#include "runtime/orderAccess.inline.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    48
#include "services/memTracker.hpp"
20407
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
    49
#include "services/memoryService.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    50
#include "utilities/align.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    51
#include "utilities/copy.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    52
#include "utilities/debug.hpp"
27683
1d5707553fff 8064580: Move INCLUDE_CDS include section to the end of the include list
stefank
parents: 27404
diff changeset
    53
#include "utilities/macros.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    54
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
    55
typedef BinaryTreeDictionary<Metablock, FreeList<Metablock> > BlockTreeDictionary;
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
    56
typedef BinaryTreeDictionary<Metachunk, FreeList<Metachunk> > ChunkTreeDictionary;
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
    57
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
    58
// Set this constant to enable slow integrity checking of the free chunk lists
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
    59
const bool metaspace_slow_verify = false;
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
    60
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    61
// Helper function that does a bunch of checks for a chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    62
DEBUG_ONLY(static void do_verify_chunk(Metachunk* chunk);)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    63
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    64
// Given a Metachunk, update its in-use information (both in the
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    65
// chunk and the occupancy map).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    66
static void do_update_in_use_info_for_chunk(Metachunk* chunk, bool inuse);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    67
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
    68
size_t const allocation_from_dictionary_limit = 4 * K;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    69
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    70
MetaWord* last_allocated = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    71
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
    72
size_t Metaspace::_compressed_class_space_size;
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
    73
const MetaspaceTracer* Metaspace::_tracer = NULL;
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
    74
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
    75
DEBUG_ONLY(bool Metaspace::_frozen = false;)
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
    76
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    77
enum ChunkSizes {    // in words.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    78
  ClassSpecializedChunk = 128,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    79
  SpecializedChunk = 128,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    80
  ClassSmallChunk = 256,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    81
  SmallChunk = 512,
18491
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
    82
  ClassMediumChunk = 4 * K,
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
    83
  MediumChunk = 8 * K
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    84
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    85
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    86
// Returns size of this chunk type.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    87
size_t get_size_for_nonhumongous_chunktype(ChunkIndex chunktype, bool is_class) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    88
  assert(is_valid_nonhumongous_chunktype(chunktype), "invalid chunk type.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    89
  size_t size = 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    90
  if (is_class) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    91
    switch(chunktype) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    92
      case SpecializedIndex: size = ClassSpecializedChunk; break;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    93
      case SmallIndex: size = ClassSmallChunk; break;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    94
      case MediumIndex: size = ClassMediumChunk; break;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    95
      default:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    96
        ShouldNotReachHere();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    97
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    98
  } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    99
    switch(chunktype) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   100
      case SpecializedIndex: size = SpecializedChunk; break;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   101
      case SmallIndex: size = SmallChunk; break;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   102
      case MediumIndex: size = MediumChunk; break;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   103
      default:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   104
        ShouldNotReachHere();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   105
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   106
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   107
  return size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   108
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   109
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   110
ChunkIndex get_chunk_type_by_size(size_t size, bool is_class) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   111
  if (is_class) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   112
    if (size == ClassSpecializedChunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   113
      return SpecializedIndex;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   114
    } else if (size == ClassSmallChunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   115
      return SmallIndex;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   116
    } else if (size == ClassMediumChunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   117
      return MediumIndex;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   118
    } else if (size > ClassMediumChunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   119
      assert(is_aligned(size, ClassSpecializedChunk), "Invalid chunk size");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   120
      return HumongousIndex;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   121
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   122
  } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   123
    if (size == SpecializedChunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   124
      return SpecializedIndex;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   125
    } else if (size == SmallChunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   126
      return SmallIndex;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   127
    } else if (size == MediumChunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   128
      return MediumIndex;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   129
    } else if (size > MediumChunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   130
      assert(is_aligned(size, SpecializedChunk), "Invalid chunk size");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   131
      return HumongousIndex;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   132
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   133
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   134
  ShouldNotReachHere();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   135
  return (ChunkIndex)-1;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   136
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   137
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   138
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   139
static ChunkIndex next_chunk_index(ChunkIndex i) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   140
  assert(i < NumberOfInUseLists, "Out of bound");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   141
  return (ChunkIndex) (i+1);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   142
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   143
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   144
static ChunkIndex prev_chunk_index(ChunkIndex i) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   145
  assert(i > ZeroIndex, "Out of bound");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   146
  return (ChunkIndex) (i-1);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   147
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   148
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   149
static const char* scale_unit(size_t scale) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   150
  switch(scale) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   151
    case 1: return "BYTES";
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   152
    case K: return "KB";
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   153
    case M: return "MB";
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   154
    case G: return "GB";
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   155
    default:
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   156
      ShouldNotReachHere();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   157
      return NULL;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   158
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   159
}
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   160
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   161
volatile intptr_t MetaspaceGC::_capacity_until_GC = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   162
uint MetaspaceGC::_shrink_factor = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   163
bool MetaspaceGC::_should_concurrent_collect = false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   164
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
   165
typedef class FreeList<Metachunk> ChunkList;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   166
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   167
// Manages the global free lists of chunks.
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   168
class ChunkManager : public CHeapObj<mtInternal> {
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   169
  friend class TestVirtualSpaceNodeTest;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   170
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   171
  // Free list of chunks of different sizes.
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   172
  //   SpecializedChunk
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   173
  //   SmallChunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   174
  //   MediumChunk
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   175
  ChunkList _free_chunks[NumberOfFreeLists];
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   176
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   177
  // Whether or not this is the class chunkmanager.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   178
  const bool _is_class;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   179
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   180
  // Return non-humongous chunk list by its index.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   181
  ChunkList* free_chunks(ChunkIndex index);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   182
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   183
  // Returns non-humongous chunk list for the given chunk word size.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   184
  ChunkList* find_free_chunks_list(size_t word_size);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   185
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   186
  //   HumongousChunk
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   187
  ChunkTreeDictionary _humongous_dictionary;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   188
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   189
  // Returns the humongous chunk dictionary.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   190
  ChunkTreeDictionary* humongous_dictionary() {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   191
    return &_humongous_dictionary;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   192
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   193
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
   194
  // Size, in metaspace words, of all chunks managed by this ChunkManager
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   195
  size_t _free_chunks_total;
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
   196
  // Number of chunks in this ChunkManager
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   197
  size_t _free_chunks_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   198
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
   199
  // Update counters after a chunk was added or removed removed.
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
   200
  void account_for_added_chunk(const Metachunk* c);
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
   201
  void account_for_removed_chunk(const Metachunk* c);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   202
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   203
  // Debug support
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   204
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   205
  size_t sum_free_chunks();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   206
  size_t sum_free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   207
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   208
  void locked_verify_free_chunks_total();
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   209
  void slow_locked_verify_free_chunks_total() {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   210
    if (metaspace_slow_verify) {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   211
      locked_verify_free_chunks_total();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   212
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   213
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   214
  void locked_verify_free_chunks_count();
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   215
  void slow_locked_verify_free_chunks_count() {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   216
    if (metaspace_slow_verify) {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   217
      locked_verify_free_chunks_count();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   218
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   219
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   220
  void verify_free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   221
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   222
  // Given a pointer to a chunk, attempts to merge it with neighboring
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   223
  // free chunks to form a bigger chunk. Returns true if successful.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   224
  bool attempt_to_coalesce_around_chunk(Metachunk* chunk, ChunkIndex target_chunk_type);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   225
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   226
  // Helper for chunk merging:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   227
  //  Given an address range with 1-n chunks which are all supposed to be
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   228
  //  free and hence currently managed by this ChunkManager, remove them
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   229
  //  from this ChunkManager and mark them as invalid.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   230
  // - This does not correct the occupancy map.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   231
  // - This does not adjust the counters in ChunkManager.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   232
  // - Does not adjust container count counter in containing VirtualSpaceNode.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   233
  // Returns number of chunks removed.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   234
  int remove_chunks_in_area(MetaWord* p, size_t word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   235
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   236
  // Helper for chunk splitting: given a target chunk size and a larger free chunk,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   237
  // split up the larger chunk into n smaller chunks, at least one of which should be
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   238
  // the target chunk of target chunk size. The smaller chunks, including the target
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   239
  // chunk, are returned to the freelist. The pointer to the target chunk is returned.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   240
  // Note that this chunk is supposed to be removed from the freelist right away.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   241
  Metachunk* split_chunk(size_t target_chunk_word_size, Metachunk* chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   242
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   243
 public:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   244
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   245
  struct ChunkManagerStatistics {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   246
    size_t num_by_type[NumberOfFreeLists];
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   247
    size_t single_size_by_type[NumberOfFreeLists];
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   248
    size_t total_size_by_type[NumberOfFreeLists];
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   249
    size_t num_humongous_chunks;
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   250
    size_t total_size_humongous_chunks;
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   251
  };
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   252
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   253
  void locked_get_statistics(ChunkManagerStatistics* stat) const;
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   254
  void get_statistics(ChunkManagerStatistics* stat) const;
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   255
  static void print_statistics(const ChunkManagerStatistics* stat, outputStream* out, size_t scale);
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   256
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   257
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   258
  ChunkManager(bool is_class)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   259
      : _is_class(is_class), _free_chunks_total(0), _free_chunks_count(0) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   260
    _free_chunks[SpecializedIndex].set_size(get_size_for_nonhumongous_chunktype(SpecializedIndex, is_class));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   261
    _free_chunks[SmallIndex].set_size(get_size_for_nonhumongous_chunktype(SmallIndex, is_class));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   262
    _free_chunks[MediumIndex].set_size(get_size_for_nonhumongous_chunktype(MediumIndex, is_class));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   263
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   264
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   265
  // Add or delete (return) a chunk to the global freelist.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   266
  Metachunk* chunk_freelist_allocate(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   267
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   268
  // Map a size to a list index assuming that there are lists
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   269
  // for special, small, medium, and humongous chunks.
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
   270
  ChunkIndex list_index(size_t size);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   271
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   272
  // Map a given index to the chunk size.
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   273
  size_t size_by_index(ChunkIndex index) const;
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   274
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   275
  bool is_class() const { return _is_class; }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   276
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   277
  // Convenience accessors.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   278
  size_t medium_chunk_word_size() const { return size_by_index(MediumIndex); }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   279
  size_t small_chunk_word_size() const { return size_by_index(SmallIndex); }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   280
  size_t specialized_chunk_word_size() const { return size_by_index(SpecializedIndex); }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   281
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   282
  // Take a chunk from the ChunkManager. The chunk is expected to be in
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   283
  // the chunk manager (the freelist if non-humongous, the dictionary if
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   284
  // humongous).
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   285
  void remove_chunk(Metachunk* chunk);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   286
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   287
  // Return a single chunk of type index to the ChunkManager.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   288
  void return_single_chunk(ChunkIndex index, Metachunk* chunk);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   289
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
   290
  // Add the simple linked list of chunks to the freelist of chunks
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
   291
  // of type index.
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   292
  void return_chunk_list(ChunkIndex index, Metachunk* chunk);
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
   293
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   294
  // Total of the space in the free chunks list
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
   295
  size_t free_chunks_total_words();
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
   296
  size_t free_chunks_total_bytes();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   297
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   298
  // Number of chunks in the free chunks list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   299
  size_t free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   300
20733
8dead86921fe 8026715: Remove the MetaDataDeallocateALot develop flag
stefank
parents: 20729
diff changeset
   301
  // Remove from a list by size.  Selects list based on size of chunk.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   302
  Metachunk* free_chunks_get(size_t chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   303
23470
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   304
#define index_bounds_check(index)                                         \
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   305
  assert(index == SpecializedIndex ||                                     \
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   306
         index == SmallIndex ||                                           \
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   307
         index == MediumIndex ||                                          \
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
   308
         index == HumongousIndex, "Bad index: %d", (int) index)
23470
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   309
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   310
  size_t num_free_chunks(ChunkIndex index) const {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   311
    index_bounds_check(index);
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   312
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   313
    if (index == HumongousIndex) {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   314
      return _humongous_dictionary.total_free_blocks();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   315
    }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   316
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   317
    ssize_t count = _free_chunks[index].count();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   318
    return count == -1 ? 0 : (size_t) count;
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   319
  }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   320
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   321
  size_t size_free_chunks_in_bytes(ChunkIndex index) const {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   322
    index_bounds_check(index);
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   323
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   324
    size_t word_size = 0;
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   325
    if (index == HumongousIndex) {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   326
      word_size = _humongous_dictionary.total_size();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   327
    } else {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   328
      const size_t size_per_chunk_in_words = _free_chunks[index].size();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   329
      word_size = size_per_chunk_in_words * num_free_chunks(index);
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   330
    }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   331
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   332
    return word_size * BytesPerWord;
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   333
  }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   334
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   335
  MetaspaceChunkFreeListSummary chunk_free_list_summary() const {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   336
    return MetaspaceChunkFreeListSummary(num_free_chunks(SpecializedIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   337
                                         num_free_chunks(SmallIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   338
                                         num_free_chunks(MediumIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   339
                                         num_free_chunks(HumongousIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   340
                                         size_free_chunks_in_bytes(SpecializedIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   341
                                         size_free_chunks_in_bytes(SmallIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   342
                                         size_free_chunks_in_bytes(MediumIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   343
                                         size_free_chunks_in_bytes(HumongousIndex));
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   344
  }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   345
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   346
  // Debug support
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   347
  void verify();
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   348
  void slow_verify() {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   349
    if (metaspace_slow_verify) {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   350
      verify();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   351
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   352
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   353
  void locked_verify();
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   354
  void slow_locked_verify() {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   355
    if (metaspace_slow_verify) {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   356
      locked_verify();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   357
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   358
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   359
  void verify_free_chunks_total();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   360
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   361
  void locked_print_free_chunks(outputStream* st);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   362
  void locked_print_sum_free_chunks(outputStream* st);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   363
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   364
  void print_on(outputStream* st) const;
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   365
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   366
  // Prints composition for both non-class and (if available)
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   367
  // class chunk manager.
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   368
  static void print_all_chunkmanagers(outputStream* out, size_t scale = 1);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   369
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   370
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   371
class SmallBlocks : public CHeapObj<mtClass> {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   372
  const static uint _small_block_max_size = sizeof(TreeChunk<Metablock,  FreeList<Metablock> >)/HeapWordSize;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   373
  const static uint _small_block_min_size = sizeof(Metablock)/HeapWordSize;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   374
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   375
 private:
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   376
  FreeList<Metablock> _small_lists[_small_block_max_size - _small_block_min_size];
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   377
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   378
  FreeList<Metablock>& list_at(size_t word_size) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   379
    assert(word_size >= _small_block_min_size, "There are no metaspace objects less than %u words", _small_block_min_size);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   380
    return _small_lists[word_size - _small_block_min_size];
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   381
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   382
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   383
 public:
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   384
  SmallBlocks() {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   385
    for (uint i = _small_block_min_size; i < _small_block_max_size; i++) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   386
      uint k = i - _small_block_min_size;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   387
      _small_lists[k].set_size(i);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   388
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   389
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   390
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   391
  size_t total_size() const {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   392
    size_t result = 0;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   393
    for (uint i = _small_block_min_size; i < _small_block_max_size; i++) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   394
      uint k = i - _small_block_min_size;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   395
      result = result + _small_lists[k].count() * _small_lists[k].size();
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   396
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   397
    return result;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   398
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   399
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   400
  static uint small_block_max_size() { return _small_block_max_size; }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   401
  static uint small_block_min_size() { return _small_block_min_size; }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   402
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   403
  MetaWord* get_block(size_t word_size) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   404
    if (list_at(word_size).count() > 0) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   405
      MetaWord* new_block = (MetaWord*) list_at(word_size).get_chunk_at_head();
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   406
      return new_block;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   407
    } else {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   408
      return NULL;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   409
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   410
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   411
  void return_block(Metablock* free_chunk, size_t word_size) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   412
    list_at(word_size).return_chunk_at_head(free_chunk, false);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   413
    assert(list_at(word_size).count() > 0, "Should have a chunk");
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   414
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   415
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   416
  void print_on(outputStream* st) const {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   417
    st->print_cr("SmallBlocks:");
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   418
    for (uint i = _small_block_min_size; i < _small_block_max_size; i++) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   419
      uint k = i - _small_block_min_size;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   420
      st->print_cr("small_lists size " SIZE_FORMAT " count " SIZE_FORMAT, _small_lists[k].size(), _small_lists[k].count());
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   421
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   422
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   423
};
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   424
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   425
// Used to manage the free list of Metablocks (a block corresponds
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   426
// to the allocation of a quantum of metadata).
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   427
class BlockFreelist : public CHeapObj<mtClass> {
30580
394471b86a83 8079091: Remove dictionary NULL check on common path of BlockFreeList methods
jwha
parents: 29806
diff changeset
   428
  BlockTreeDictionary* const _dictionary;
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   429
  SmallBlocks* _small_blocks;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   430
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   431
  // Only allocate and split from freelist if the size of the allocation
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   432
  // is at least 1/4th the size of the available block.
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   433
  const static int WasteMultiplier = 4;
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   434
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   435
  // Accessors
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   436
  BlockTreeDictionary* dictionary() const { return _dictionary; }
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   437
  SmallBlocks* small_blocks() {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   438
    if (_small_blocks == NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   439
      _small_blocks = new SmallBlocks();
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   440
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   441
    return _small_blocks;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   442
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   443
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   444
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   445
  BlockFreelist();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   446
  ~BlockFreelist();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   447
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   448
  // Get and return a block to the free list
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   449
  MetaWord* get_block(size_t word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   450
  void return_block(MetaWord* p, size_t word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   451
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   452
  size_t total_size() const  {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   453
    size_t result = dictionary()->total_size();
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   454
    if (_small_blocks != NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   455
      result = result + _small_blocks->total_size();
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   456
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   457
    return result;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   458
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   459
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   460
  static size_t min_dictionary_size()   { return TreeChunk<Metablock, FreeList<Metablock> >::min_size(); }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   461
  void print_on(outputStream* st) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   462
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   463
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   464
// Helper for Occupancy Bitmap. A type trait to give an all-bits-are-one-unsigned constant.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   465
template <typename T> struct all_ones  { static const T value; };
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   466
template <> struct all_ones <uint64_t> { static const uint64_t value = 0xFFFFFFFFFFFFFFFFULL; };
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   467
template <> struct all_ones <uint32_t> { static const uint32_t value = 0xFFFFFFFF; };
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   468
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   469
// The OccupancyMap is a bitmap which, for a given VirtualSpaceNode,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   470
// keeps information about
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   471
// - where a chunk starts
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   472
// - whether a chunk is in-use or free
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   473
// A bit in this bitmap represents one range of memory in the smallest
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   474
// chunk size (SpecializedChunk or ClassSpecializedChunk).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   475
class OccupancyMap : public CHeapObj<mtInternal> {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   476
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   477
  // The address range this map covers.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   478
  const MetaWord* const _reference_address;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   479
  const size_t _word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   480
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   481
  // The word size of a specialized chunk, aka the number of words one
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   482
  // bit in this map represents.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   483
  const size_t _smallest_chunk_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   484
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   485
  // map data
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   486
  // Data are organized in two bit layers:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   487
  // The first layer is the chunk-start-map. Here, a bit is set to mark
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   488
  // the corresponding region as the head of a chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   489
  // The second layer is the in-use-map. Here, a set bit indicates that
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   490
  // the corresponding belongs to a chunk which is in use.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   491
  uint8_t* _map[2];
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   492
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   493
  enum { layer_chunk_start_map = 0, layer_in_use_map = 1 };
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   494
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   495
  // length, in bytes, of bitmap data
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   496
  size_t _map_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   497
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   498
  // Returns true if bit at position pos at bit-layer layer is set.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   499
  bool get_bit_at_position(unsigned pos, unsigned layer) const {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   500
    assert(layer == 0 || layer == 1, "Invalid layer %d", layer);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   501
    const unsigned byteoffset = pos / 8;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   502
    assert(byteoffset < _map_size,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   503
           "invalid byte offset (%u), map size is " SIZE_FORMAT ".", byteoffset, _map_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   504
    const unsigned mask = 1 << (pos % 8);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   505
    return (_map[layer][byteoffset] & mask) > 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   506
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   507
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   508
  // Changes bit at position pos at bit-layer layer to value v.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   509
  void set_bit_at_position(unsigned pos, unsigned layer, bool v) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   510
    assert(layer == 0 || layer == 1, "Invalid layer %d", layer);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   511
    const unsigned byteoffset = pos / 8;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   512
    assert(byteoffset < _map_size,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   513
           "invalid byte offset (%u), map size is " SIZE_FORMAT ".", byteoffset, _map_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   514
    const unsigned mask = 1 << (pos % 8);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   515
    if (v) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   516
      _map[layer][byteoffset] |= mask;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   517
    } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   518
      _map[layer][byteoffset] &= ~mask;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   519
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   520
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   521
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   522
  // Optimized case of is_any_bit_set_in_region for 32/64bit aligned access:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   523
  // pos is 32/64 aligned and num_bits is 32/64.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   524
  // This is the typical case when coalescing to medium chunks, whose size is
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   525
  // 32 or 64 times the specialized chunk size (depending on class or non class
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   526
  // case), so they occupy 64 bits which should be 64bit aligned, because
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   527
  // chunks are chunk-size aligned.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   528
  template <typename T>
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   529
  bool is_any_bit_set_in_region_3264(unsigned pos, unsigned num_bits, unsigned layer) const {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   530
    assert(_map_size > 0, "not initialized");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   531
    assert(layer == 0 || layer == 1, "Invalid layer %d.", layer);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   532
    assert(pos % (sizeof(T) * 8) == 0, "Bit position must be aligned (%u).", pos);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   533
    assert(num_bits == (sizeof(T) * 8), "Number of bits incorrect (%u).", num_bits);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   534
    const size_t byteoffset = pos / 8;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   535
    assert(byteoffset <= (_map_size - sizeof(T)),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   536
           "Invalid byte offset (" SIZE_FORMAT "), map size is " SIZE_FORMAT ".", byteoffset, _map_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   537
    const T w = *(T*)(_map[layer] + byteoffset);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   538
    return w > 0 ? true : false;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   539
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   540
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   541
  // Returns true if any bit in region [pos1, pos1 + num_bits) is set in bit-layer layer.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   542
  bool is_any_bit_set_in_region(unsigned pos, unsigned num_bits, unsigned layer) const {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   543
    if (pos % 32 == 0 && num_bits == 32) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   544
      return is_any_bit_set_in_region_3264<uint32_t>(pos, num_bits, layer);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   545
    } else if (pos % 64 == 0 && num_bits == 64) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   546
      return is_any_bit_set_in_region_3264<uint64_t>(pos, num_bits, layer);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   547
    } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   548
      for (unsigned n = 0; n < num_bits; n ++) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   549
        if (get_bit_at_position(pos + n, layer)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   550
          return true;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   551
        }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   552
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   553
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   554
    return false;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   555
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   556
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   557
  // Returns true if any bit in region [p, p+word_size) is set in bit-layer layer.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   558
  bool is_any_bit_set_in_region(MetaWord* p, size_t word_size, unsigned layer) const {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   559
    assert(word_size % _smallest_chunk_word_size == 0,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   560
        "Region size " SIZE_FORMAT " not a multiple of smallest chunk size.", word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   561
    const unsigned pos = get_bitpos_for_address(p);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   562
    const unsigned num_bits = (unsigned) (word_size / _smallest_chunk_word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   563
    return is_any_bit_set_in_region(pos, num_bits, layer);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   564
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   565
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   566
  // Optimized case of set_bits_of_region for 32/64bit aligned access:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   567
  // pos is 32/64 aligned and num_bits is 32/64.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   568
  // This is the typical case when coalescing to medium chunks, whose size
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   569
  // is 32 or 64 times the specialized chunk size (depending on class or non
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   570
  // class case), so they occupy 64 bits which should be 64bit aligned,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   571
  // because chunks are chunk-size aligned.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   572
  template <typename T>
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   573
  void set_bits_of_region_T(unsigned pos, unsigned num_bits, unsigned layer, bool v) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   574
    assert(pos % (sizeof(T) * 8) == 0, "Bit position must be aligned to %u (%u).",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   575
           (unsigned)(sizeof(T) * 8), pos);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   576
    assert(num_bits == (sizeof(T) * 8), "Number of bits incorrect (%u), expected %u.",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   577
           num_bits, (unsigned)(sizeof(T) * 8));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   578
    const size_t byteoffset = pos / 8;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   579
    assert(byteoffset <= (_map_size - sizeof(T)),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   580
           "invalid byte offset (" SIZE_FORMAT "), map size is " SIZE_FORMAT ".", byteoffset, _map_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   581
    T* const pw = (T*)(_map[layer] + byteoffset);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   582
    *pw = v ? all_ones<T>::value : (T) 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   583
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   584
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   585
  // Set all bits in a region starting at pos to a value.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   586
  void set_bits_of_region(unsigned pos, unsigned num_bits, unsigned layer, bool v) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   587
    assert(_map_size > 0, "not initialized");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   588
    assert(layer == 0 || layer == 1, "Invalid layer %d.", layer);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   589
    if (pos % 32 == 0 && num_bits == 32) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   590
      set_bits_of_region_T<uint32_t>(pos, num_bits, layer, v);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   591
    } else if (pos % 64 == 0 && num_bits == 64) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   592
      set_bits_of_region_T<uint64_t>(pos, num_bits, layer, v);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   593
    } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   594
      for (unsigned n = 0; n < num_bits; n ++) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   595
        set_bit_at_position(pos + n, layer, v);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   596
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   597
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   598
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   599
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   600
  // Helper: sets all bits in a region [p, p+word_size).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   601
  void set_bits_of_region(MetaWord* p, size_t word_size, unsigned layer, bool v) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   602
    assert(word_size % _smallest_chunk_word_size == 0,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   603
        "Region size " SIZE_FORMAT " not a multiple of smallest chunk size.", word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   604
    const unsigned pos = get_bitpos_for_address(p);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   605
    const unsigned num_bits = (unsigned) (word_size / _smallest_chunk_word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   606
    set_bits_of_region(pos, num_bits, layer, v);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   607
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   608
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   609
  // Helper: given an address, return the bit position representing that address.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   610
  unsigned get_bitpos_for_address(const MetaWord* p) const {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   611
    assert(_reference_address != NULL, "not initialized");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   612
    assert(p >= _reference_address && p < _reference_address + _word_size,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   613
           "Address %p out of range for occupancy map [%p..%p).",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   614
            p, _reference_address, _reference_address + _word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   615
    assert(is_aligned(p, _smallest_chunk_word_size * sizeof(MetaWord)),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   616
           "Address not aligned (%p).", p);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   617
    const ptrdiff_t d = (p - _reference_address) / _smallest_chunk_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   618
    assert(d >= 0 && (size_t)d < _map_size * 8, "Sanity.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   619
    return (unsigned) d;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   620
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   621
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   622
 public:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   623
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   624
  OccupancyMap(const MetaWord* reference_address, size_t word_size, size_t smallest_chunk_word_size) :
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   625
    _reference_address(reference_address), _word_size(word_size),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   626
    _smallest_chunk_word_size(smallest_chunk_word_size) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   627
    assert(reference_address != NULL, "invalid reference address");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   628
    assert(is_aligned(reference_address, smallest_chunk_word_size),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   629
           "Reference address not aligned to smallest chunk size.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   630
    assert(is_aligned(word_size, smallest_chunk_word_size),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   631
           "Word_size shall be a multiple of the smallest chunk size.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   632
    // Calculate bitmap size: one bit per smallest_chunk_word_size'd area.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   633
    size_t num_bits = word_size / smallest_chunk_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   634
    _map_size = (num_bits + 7) / 8;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   635
    assert(_map_size * 8 >= num_bits, "sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   636
    _map[0] = (uint8_t*) os::malloc(_map_size, mtInternal);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   637
    _map[1] = (uint8_t*) os::malloc(_map_size, mtInternal);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   638
    assert(_map[0] != NULL && _map[1] != NULL, "Occupancy Map: allocation failed.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   639
    memset(_map[1], 0, _map_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   640
    memset(_map[0], 0, _map_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   641
    // Sanity test: the first respectively last possible chunk start address in
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   642
    // the covered range shall map to the first and last bit in the bitmap.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   643
    assert(get_bitpos_for_address(reference_address) == 0,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   644
      "First chunk address in range must map to fist bit in bitmap.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   645
    assert(get_bitpos_for_address(reference_address + word_size - smallest_chunk_word_size) == num_bits - 1,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   646
      "Last chunk address in range must map to last bit in bitmap.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   647
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   648
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   649
  ~OccupancyMap() {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   650
    os::free(_map[0]);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   651
    os::free(_map[1]);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   652
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   653
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   654
  // Returns true if at address x a chunk is starting.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   655
  bool chunk_starts_at_address(MetaWord* p) const {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   656
    const unsigned pos = get_bitpos_for_address(p);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   657
    return get_bit_at_position(pos, layer_chunk_start_map);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   658
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   659
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   660
  void set_chunk_starts_at_address(MetaWord* p, bool v) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   661
    const unsigned pos = get_bitpos_for_address(p);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   662
    set_bit_at_position(pos, layer_chunk_start_map, v);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   663
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   664
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   665
  // Removes all chunk-start-bits inside a region, typically as a
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   666
  // result of a chunk merge.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   667
  void wipe_chunk_start_bits_in_region(MetaWord* p, size_t word_size) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   668
    set_bits_of_region(p, word_size, layer_chunk_start_map, false);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   669
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   670
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   671
  // Returns true if there are life (in use) chunks in the region limited
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   672
  // by [p, p+word_size).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   673
  bool is_region_in_use(MetaWord* p, size_t word_size) const {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   674
    return is_any_bit_set_in_region(p, word_size, layer_in_use_map);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   675
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   676
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   677
  // Marks the region starting at p with the size word_size as in use
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   678
  // or free, depending on v.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   679
  void set_region_in_use(MetaWord* p, size_t word_size, bool v) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   680
    set_bits_of_region(p, word_size, layer_in_use_map, v);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   681
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   682
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   683
#ifdef ASSERT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   684
  // Verify occupancy map for the address range [from, to).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   685
  // We need to tell it the address range, because the memory the
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   686
  // occupancy map is covering may not be fully comitted yet.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   687
  void verify(MetaWord* from, MetaWord* to) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   688
    Metachunk* chunk = NULL;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   689
    int nth_bit_for_chunk = 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   690
    MetaWord* chunk_end = NULL;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   691
    for (MetaWord* p = from; p < to; p += _smallest_chunk_word_size) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   692
      const unsigned pos = get_bitpos_for_address(p);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   693
      // Check the chunk-starts-info:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   694
      if (get_bit_at_position(pos, layer_chunk_start_map)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   695
        // Chunk start marked in bitmap.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   696
        chunk = (Metachunk*) p;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   697
        if (chunk_end != NULL) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   698
          assert(chunk_end == p, "Unexpected chunk start found at %p (expected "
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   699
                 "the next chunk to start at %p).", p, chunk_end);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   700
        }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   701
        assert(chunk->is_valid_sentinel(), "Invalid chunk at address %p.", p);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   702
        if (chunk->get_chunk_type() != HumongousIndex) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   703
          guarantee(is_aligned(p, chunk->word_size()), "Chunk %p not aligned.", p);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   704
        }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   705
        chunk_end = p + chunk->word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   706
        nth_bit_for_chunk = 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   707
        assert(chunk_end <= to, "Chunk end overlaps test address range.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   708
      } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   709
        // No chunk start marked in bitmap.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   710
        assert(chunk != NULL, "Chunk should start at start of address range.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   711
        assert(p < chunk_end, "Did not find expected chunk start at %p.", p);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   712
        nth_bit_for_chunk ++;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   713
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   714
      // Check the in-use-info:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   715
      const bool in_use_bit = get_bit_at_position(pos, layer_in_use_map);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   716
      if (in_use_bit) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   717
        assert(!chunk->is_tagged_free(), "Chunk %p: marked in-use in map but is free (bit %u).",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   718
               chunk, nth_bit_for_chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   719
      } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   720
        assert(chunk->is_tagged_free(), "Chunk %p: marked free in map but is in use (bit %u).",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   721
               chunk, nth_bit_for_chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   722
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   723
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   724
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   725
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   726
  // Verify that a given chunk is correctly accounted for in the bitmap.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   727
  void verify_for_chunk(Metachunk* chunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   728
    assert(chunk_starts_at_address((MetaWord*) chunk),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   729
           "No chunk start marked in map for chunk %p.", chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   730
    // For chunks larger than the minimal chunk size, no other chunk
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   731
    // must start in its area.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   732
    if (chunk->word_size() > _smallest_chunk_word_size) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   733
      assert(!is_any_bit_set_in_region(((MetaWord*) chunk) + _smallest_chunk_word_size,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   734
                                       chunk->word_size() - _smallest_chunk_word_size, layer_chunk_start_map),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   735
             "No chunk must start within another chunk.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   736
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   737
    if (!chunk->is_tagged_free()) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   738
      assert(is_region_in_use((MetaWord*)chunk, chunk->word_size()),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   739
             "Chunk %p is in use but marked as free in map (%d %d).",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   740
             chunk, chunk->get_chunk_type(), chunk->get_origin());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   741
    } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   742
      assert(!is_region_in_use((MetaWord*)chunk, chunk->word_size()),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   743
             "Chunk %p is free but marked as in-use in map (%d %d).",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   744
             chunk, chunk->get_chunk_type(), chunk->get_origin());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   745
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   746
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   747
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   748
#endif // ASSERT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   749
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   750
};
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   751
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   752
// A VirtualSpaceList node.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   753
class VirtualSpaceNode : public CHeapObj<mtClass> {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   754
  friend class VirtualSpaceList;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   755
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   756
  // Link to next VirtualSpaceNode
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   757
  VirtualSpaceNode* _next;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   758
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   759
  // Whether this node is contained in class or metaspace.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   760
  const bool _is_class;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   761
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   762
  // total in the VirtualSpace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   763
  MemRegion _reserved;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   764
  ReservedSpace _rs;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   765
  VirtualSpace _virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   766
  MetaWord* _top;
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   767
  // count of chunks contained in this VirtualSpace
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   768
  uintx _container_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   769
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   770
  OccupancyMap* _occupancy_map;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   771
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   772
  // Convenience functions to access the _virtual_space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   773
  char* low()  const { return virtual_space()->low(); }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   774
  char* high() const { return virtual_space()->high(); }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   775
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   776
  // The first Metachunk will be allocated at the bottom of the
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   777
  // VirtualSpace
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   778
  Metachunk* first_chunk() { return (Metachunk*) bottom(); }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   779
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   780
  // Committed but unused space in the virtual space
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   781
  size_t free_words_in_vs() const;
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   782
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   783
  // True if this node belongs to class metaspace.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   784
  bool is_class() const { return _is_class; }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   785
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   786
  // Helper function for take_from_committed: allocate padding chunks
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   787
  // until top is at the given address.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   788
  void allocate_padding_chunks_until_top_is_at(MetaWord* target_top);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   789
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   790
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   791
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   792
  VirtualSpaceNode(bool is_class, size_t byte_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   793
  VirtualSpaceNode(bool is_class, ReservedSpace rs) :
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   794
    _is_class(is_class), _top(NULL), _next(NULL), _rs(rs), _container_count(0), _occupancy_map(NULL) {}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   795
  ~VirtualSpaceNode();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   796
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   797
  // Convenience functions for logical bottom and end
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   798
  MetaWord* bottom() const { return (MetaWord*) _virtual_space.low(); }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   799
  MetaWord* end() const { return (MetaWord*) _virtual_space.high(); }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   800
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   801
  const OccupancyMap* occupancy_map() const { return _occupancy_map; }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   802
  OccupancyMap* occupancy_map() { return _occupancy_map; }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   803
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
   804
  bool contains(const void* ptr) { return ptr >= low() && ptr < high(); }
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
   805
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   806
  size_t reserved_words() const  { return _virtual_space.reserved_size() / BytesPerWord; }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   807
  size_t committed_words() const { return _virtual_space.actual_committed_size() / BytesPerWord; }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   808
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   809
  bool is_pre_committed() const { return _virtual_space.special(); }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   810
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   811
  // address of next available space in _virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   812
  // Accessors
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   813
  VirtualSpaceNode* next() { return _next; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   814
  void set_next(VirtualSpaceNode* v) { _next = v; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   815
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   816
  void set_reserved(MemRegion const v) { _reserved = v; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   817
  void set_top(MetaWord* v) { _top = v; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   818
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   819
  // Accessors
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   820
  MemRegion* reserved() { return &_reserved; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   821
  VirtualSpace* virtual_space() const { return (VirtualSpace*) &_virtual_space; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   822
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   823
  // Returns true if "word_size" is available in the VirtualSpace
22222
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
   824
  bool is_available(size_t word_size) { return word_size <= pointer_delta(end(), _top, sizeof(MetaWord)); }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   825
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   826
  MetaWord* top() const { return _top; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   827
  void inc_top(size_t word_size) { _top += word_size; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   828
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   829
  uintx container_count() { return _container_count; }
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   830
  void inc_container_count();
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   831
  void dec_container_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   832
#ifdef ASSERT
29806
64aa40385bdd 8076173: VirtualSpaceNode container_count() and container_count_slow() have different return types
david
parents: 29800
diff changeset
   833
  uintx container_count_slow();
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   834
  void verify_container_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   835
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   836
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   837
  // used and capacity in this single entry in the list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   838
  size_t used_words_in_vs() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   839
  size_t capacity_words_in_vs() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   840
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   841
  bool initialize();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   842
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   843
  // get space from the virtual space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   844
  Metachunk* take_from_committed(size_t chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   845
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   846
  // Allocate a chunk from the virtual space and return it.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   847
  Metachunk* get_chunk_vs(size_t chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   848
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   849
  // Expands/shrinks the committed space in a virtual space.  Delegates
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   850
  // to Virtualspace
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   851
  bool expand_by(size_t min_words, size_t preferred_words);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   852
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   853
  // In preparation for deleting this node, remove all the chunks
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   854
  // in the node from any freelist.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   855
  void purge(ChunkManager* chunk_manager);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   856
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   857
  // If an allocation doesn't fit in the current node a new node is created.
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   858
  // Allocate chunks out of the remaining committed space in this node
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   859
  // to avoid wasting that memory.
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   860
  // This always adds up because all the chunk sizes are multiples of
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   861
  // the smallest chunk size.
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   862
  void retire(ChunkManager* chunk_manager);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   863
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   864
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   865
  void print_on(outputStream* st) const;
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   866
  void print_map(outputStream* st, bool is_class) const;
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   867
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   868
  // Debug support
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   869
  DEBUG_ONLY(void mangle();)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   870
  // Verify counters, all chunks in this list node and the occupancy map.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   871
  DEBUG_ONLY(void verify();)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   872
  // Verify that all free chunks in this node are ideally merged
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   873
  // (there not should be multiple small chunks where a large chunk could exist.)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   874
  DEBUG_ONLY(void verify_free_chunks_are_ideally_merged();)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   875
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   876
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   877
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   878
#define assert_is_aligned(value, alignment)                  \
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   879
  assert(is_aligned((value), (alignment)),                   \
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   880
         SIZE_FORMAT_HEX " is not aligned to "               \
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   881
         SIZE_FORMAT, (size_t)(uintptr_t)value, (alignment))
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   882
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   883
// Decide if large pages should be committed when the memory is reserved.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   884
static bool should_commit_large_pages_when_reserving(size_t bytes) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   885
  if (UseLargePages && UseLargePagesInMetaspace && !os::can_commit_large_page_memory()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   886
    size_t words = bytes / BytesPerWord;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   887
    bool is_class = false; // We never reserve large pages for the class space.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   888
    if (MetaspaceGC::can_expand(words, is_class) &&
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   889
        MetaspaceGC::allowed_expansion() >= words) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   890
      return true;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   891
    }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   892
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   893
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   894
  return false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   895
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   896
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   897
  // byte_size is the size of the associated virtualspace.
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   898
VirtualSpaceNode::VirtualSpaceNode(bool is_class, size_t bytes) :
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   899
  _is_class(is_class), _top(NULL), _next(NULL), _rs(), _container_count(0), _occupancy_map(NULL) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   900
  assert_is_aligned(bytes, Metaspace::reserve_alignment());
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
   901
  bool large_pages = should_commit_large_pages_when_reserving(bytes);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
   902
  _rs = ReservedSpace(bytes, Metaspace::reserve_alignment(), large_pages);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   903
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   904
  if (_rs.is_reserved()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   905
    assert(_rs.base() != NULL, "Catch if we get a NULL address");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   906
    assert(_rs.size() != 0, "Catch if we get a 0 size");
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   907
    assert_is_aligned(_rs.base(), Metaspace::reserve_alignment());
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   908
    assert_is_aligned(_rs.size(), Metaspace::reserve_alignment());
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   909
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   910
    MemTracker::record_virtual_memory_type((address)_rs.base(), mtClass);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   911
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   912
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   913
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   914
void VirtualSpaceNode::purge(ChunkManager* chunk_manager) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   915
  DEBUG_ONLY(this->verify();)
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   916
  Metachunk* chunk = first_chunk();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   917
  Metachunk* invalid_chunk = (Metachunk*) top();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   918
  while (chunk < invalid_chunk ) {
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   919
    assert(chunk->is_tagged_free(), "Should be tagged free");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   920
    MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   921
    chunk_manager->remove_chunk(chunk);
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   922
    chunk->remove_sentinel();
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   923
    assert(chunk->next() == NULL &&
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   924
           chunk->prev() == NULL,
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   925
           "Was not removed from its list");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   926
    chunk = (Metachunk*) next;
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   927
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   928
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   929
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   930
void VirtualSpaceNode::print_map(outputStream* st, bool is_class) const {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   931
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   932
  if (bottom() == top()) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   933
    return;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   934
  }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   935
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   936
  const size_t spec_chunk_size = is_class ? ClassSpecializedChunk : SpecializedChunk;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   937
  const size_t small_chunk_size = is_class ? ClassSmallChunk : SmallChunk;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   938
  const size_t med_chunk_size = is_class ? ClassMediumChunk : MediumChunk;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   939
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   940
  int line_len = 100;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   941
  const size_t section_len = align_up(spec_chunk_size * line_len, med_chunk_size);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   942
  line_len = (int)(section_len / spec_chunk_size);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   943
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   944
  static const int NUM_LINES = 4;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   945
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   946
  char* lines[NUM_LINES];
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   947
  for (int i = 0; i < NUM_LINES; i ++) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   948
    lines[i] = (char*)os::malloc(line_len, mtInternal);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   949
  }
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   950
  int pos = 0;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   951
  const MetaWord* p = bottom();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   952
  const Metachunk* chunk = (const Metachunk*)p;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   953
  const MetaWord* chunk_end = p + chunk->word_size();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   954
  while (p < top()) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   955
    if (pos == line_len) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   956
      pos = 0;
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   957
      for (int i = 0; i < NUM_LINES; i ++) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   958
        st->fill_to(22);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   959
        st->print_raw(lines[i], line_len);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   960
        st->cr();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   961
      }
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   962
    }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   963
    if (pos == 0) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   964
      st->print(PTR_FORMAT ":", p2i(p));
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   965
    }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   966
    if (p == chunk_end) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   967
      chunk = (Metachunk*)p;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   968
      chunk_end = p + chunk->word_size();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   969
    }
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   970
    // line 1: chunk starting points (a dot if that area is a chunk start).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   971
    lines[0][pos] = p == (const MetaWord*)chunk ? '.' : ' ';
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   972
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   973
    // Line 2: chunk type (x=spec, s=small, m=medium, h=humongous), uppercase if
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   974
    // chunk is in use.
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   975
    const bool chunk_is_free = ((Metachunk*)chunk)->is_tagged_free();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   976
    if (chunk->word_size() == spec_chunk_size) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   977
      lines[1][pos] = chunk_is_free ? 'x' : 'X';
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   978
    } else if (chunk->word_size() == small_chunk_size) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   979
      lines[1][pos] = chunk_is_free ? 's' : 'S';
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   980
    } else if (chunk->word_size() == med_chunk_size) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   981
      lines[1][pos] = chunk_is_free ? 'm' : 'M';
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   982
    } else if (chunk->word_size() > med_chunk_size) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   983
      lines[1][pos] = chunk_is_free ? 'h' : 'H';
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   984
    } else {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   985
      ShouldNotReachHere();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   986
    }
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   987
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   988
    // Line 3: chunk origin
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   989
    const ChunkOrigin origin = chunk->get_origin();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   990
    lines[2][pos] = origin == origin_normal ? ' ' : '0' + (int) origin;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   991
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   992
    // Line 4: Virgin chunk? Virgin chunks are chunks created as a byproduct of padding or splitting,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   993
    //         but were never used.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   994
    lines[3][pos] = chunk->get_use_count() > 0 ? ' ' : 'v';
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   995
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   996
    p += spec_chunk_size;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   997
    pos ++;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   998
  }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   999
  if (pos > 0) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1000
    for (int i = 0; i < NUM_LINES; i ++) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1001
      st->fill_to(22);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1002
      st->print_raw(lines[i], line_len);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1003
      st->cr();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1004
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1005
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1006
  for (int i = 0; i < NUM_LINES; i ++) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1007
    os::free(lines[i]);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1008
  }
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1009
}
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1010
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1011
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1012
#ifdef ASSERT
29806
64aa40385bdd 8076173: VirtualSpaceNode container_count() and container_count_slow() have different return types
david
parents: 29800
diff changeset
  1013
uintx VirtualSpaceNode::container_count_slow() {
64aa40385bdd 8076173: VirtualSpaceNode container_count() and container_count_slow() have different return types
david
parents: 29800
diff changeset
  1014
  uintx count = 0;
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1015
  Metachunk* chunk = first_chunk();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1016
  Metachunk* invalid_chunk = (Metachunk*) top();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1017
  while (chunk < invalid_chunk ) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1018
    MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1019
    do_verify_chunk(chunk);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1020
    // Don't count the chunks on the free lists.  Those are
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1021
    // still part of the VirtualSpaceNode but not currently
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1022
    // counted.
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  1023
    if (!chunk->is_tagged_free()) {
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1024
      count++;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1025
    }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1026
    chunk = (Metachunk*) next;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1027
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1028
  return count;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1029
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1030
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1031
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1032
#ifdef ASSERT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1033
// Verify counters, all chunks in this list node and the occupancy map.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1034
void VirtualSpaceNode::verify() {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1035
  uintx num_in_use_chunks = 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1036
  Metachunk* chunk = first_chunk();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1037
  Metachunk* invalid_chunk = (Metachunk*) top();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1038
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1039
  // Iterate the chunks in this node and verify each chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1040
  while (chunk < invalid_chunk ) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1041
    DEBUG_ONLY(do_verify_chunk(chunk);)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1042
    if (!chunk->is_tagged_free()) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1043
      num_in_use_chunks ++;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1044
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1045
    MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1046
    chunk = (Metachunk*) next;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1047
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1048
  assert(_container_count == num_in_use_chunks, "Container count mismatch (real: " UINTX_FORMAT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1049
         ", counter: " UINTX_FORMAT ".", num_in_use_chunks, _container_count);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1050
  // Also verify the occupancy map.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1051
  occupancy_map()->verify(this->bottom(), this->top());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1052
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1053
#endif // ASSERT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1054
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1055
#ifdef ASSERT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1056
// Verify that all free chunks in this node are ideally merged
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1057
// (there not should be multiple small chunks where a large chunk could exist.)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1058
void VirtualSpaceNode::verify_free_chunks_are_ideally_merged() {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1059
  Metachunk* chunk = first_chunk();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1060
  Metachunk* invalid_chunk = (Metachunk*) top();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1061
  // Shorthands.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1062
  const size_t size_med = (is_class() ? ClassMediumChunk : MediumChunk) * BytesPerWord;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1063
  const size_t size_small = (is_class() ? ClassSmallChunk : SmallChunk) * BytesPerWord;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1064
  int num_free_chunks_since_last_med_boundary = -1;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1065
  int num_free_chunks_since_last_small_boundary = -1;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1066
  while (chunk < invalid_chunk ) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1067
    // Test for missed chunk merge opportunities: count number of free chunks since last chunk boundary.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1068
    // Reset the counter when encountering a non-free chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1069
    if (chunk->get_chunk_type() != HumongousIndex) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1070
      if (chunk->is_tagged_free()) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1071
        // Count successive free, non-humongous chunks.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1072
        if (is_aligned(chunk, size_small)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1073
          assert(num_free_chunks_since_last_small_boundary <= 1,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1074
                 "Missed chunk merge opportunity at " PTR_FORMAT " for chunk size " SIZE_FORMAT_HEX ".", p2i(chunk) - size_small, size_small);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1075
          num_free_chunks_since_last_small_boundary = 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1076
        } else if (num_free_chunks_since_last_small_boundary != -1) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1077
          num_free_chunks_since_last_small_boundary ++;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1078
        }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1079
        if (is_aligned(chunk, size_med)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1080
          assert(num_free_chunks_since_last_med_boundary <= 1,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1081
                 "Missed chunk merge opportunity at " PTR_FORMAT " for chunk size " SIZE_FORMAT_HEX ".", p2i(chunk) - size_med, size_med);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1082
          num_free_chunks_since_last_med_boundary = 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1083
        } else if (num_free_chunks_since_last_med_boundary != -1) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1084
          num_free_chunks_since_last_med_boundary ++;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1085
        }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1086
      } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1087
        // Encountering a non-free chunk, reset counters.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1088
        num_free_chunks_since_last_med_boundary = -1;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1089
        num_free_chunks_since_last_small_boundary = -1;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1090
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1091
    } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1092
      // One cannot merge areas with a humongous chunk in the middle. Reset counters.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1093
      num_free_chunks_since_last_med_boundary = -1;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1094
      num_free_chunks_since_last_small_boundary = -1;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1095
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1096
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1097
    MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1098
    chunk = (Metachunk*) next;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1099
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1100
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1101
#endif // ASSERT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1102
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1103
// List of VirtualSpaces for metadata allocation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1104
class VirtualSpaceList : public CHeapObj<mtClass> {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1105
  friend class VirtualSpaceNode;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1106
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1107
  enum VirtualSpaceSizes {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1108
    VirtualSpaceSize = 256 * K
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1109
  };
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1110
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1111
  // Head of the list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1112
  VirtualSpaceNode* _virtual_space_list;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1113
  // virtual space currently being used for allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1114
  VirtualSpaceNode* _current_virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1115
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1116
  // Is this VirtualSpaceList used for the compressed class space
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1117
  bool _is_class;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1118
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1119
  // Sum of reserved and committed memory in the virtual spaces
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1120
  size_t _reserved_words;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1121
  size_t _committed_words;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1122
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1123
  // Number of virtual spaces
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1124
  size_t _virtual_space_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1125
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1126
  ~VirtualSpaceList();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1127
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1128
  VirtualSpaceNode* virtual_space_list() const { return _virtual_space_list; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1129
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1130
  void set_virtual_space_list(VirtualSpaceNode* v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1131
    _virtual_space_list = v;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1132
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1133
  void set_current_virtual_space(VirtualSpaceNode* v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1134
    _current_virtual_space = v;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1135
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1136
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1137
  void link_vs(VirtualSpaceNode* new_entry);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1138
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1139
  // Get another virtual space and add it to the list.  This
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1140
  // is typically prompted by a failed attempt to allocate a chunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1141
  // and is typically followed by the allocation of a chunk.
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1142
  bool create_new_virtual_space(size_t vs_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1143
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1144
  // Chunk up the unused committed space in the current
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1145
  // virtual space and add the chunks to the free list.
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1146
  void retire_current_virtual_space();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1147
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1148
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1149
  VirtualSpaceList(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1150
  VirtualSpaceList(ReservedSpace rs);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1151
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1152
  size_t free_bytes();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1153
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1154
  Metachunk* get_new_chunk(size_t chunk_word_size,
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1155
                           size_t suggested_commit_granularity);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1156
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1157
  bool expand_node_by(VirtualSpaceNode* node,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1158
                      size_t min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1159
                      size_t preferred_words);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1160
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1161
  bool expand_by(size_t min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1162
                 size_t preferred_words);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1163
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1164
  VirtualSpaceNode* current_virtual_space() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1165
    return _current_virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1166
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1167
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1168
  bool is_class() const { return _is_class; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1169
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1170
  bool initialization_succeeded() { return _virtual_space_list != NULL; }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1171
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1172
  size_t reserved_words()  { return _reserved_words; }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1173
  size_t reserved_bytes()  { return reserved_words() * BytesPerWord; }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1174
  size_t committed_words() { return _committed_words; }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1175
  size_t committed_bytes() { return committed_words() * BytesPerWord; }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1176
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1177
  void inc_reserved_words(size_t v);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1178
  void dec_reserved_words(size_t v);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1179
  void inc_committed_words(size_t v);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1180
  void dec_committed_words(size_t v);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1181
  void inc_virtual_space_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1182
  void dec_virtual_space_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1183
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1184
  bool contains(const void* ptr);
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1185
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1186
  // Unlink empty VirtualSpaceNodes and free it.
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1187
  void purge(ChunkManager* chunk_manager);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1188
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1189
  void print_on(outputStream* st) const;
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1190
  void print_map(outputStream* st) const;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1191
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1192
  class VirtualSpaceListIterator : public StackObj {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1193
    VirtualSpaceNode* _virtual_spaces;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1194
   public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1195
    VirtualSpaceListIterator(VirtualSpaceNode* virtual_spaces) :
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1196
      _virtual_spaces(virtual_spaces) {}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1197
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1198
    bool repeat() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1199
      return _virtual_spaces != NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1200
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1201
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1202
    VirtualSpaceNode* get_next() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1203
      VirtualSpaceNode* result = _virtual_spaces;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1204
      if (_virtual_spaces != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1205
        _virtual_spaces = _virtual_spaces->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1206
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1207
      return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1208
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1209
  };
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1210
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1211
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1212
class Metadebug : AllStatic {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1213
  // Debugging support for Metaspaces
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1214
  static int _allocation_fail_alot_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1215
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1216
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1217
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1218
  static void init_allocation_fail_alot_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1219
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1220
  static bool test_metadata_failure();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1221
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1222
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1223
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1224
int Metadebug::_allocation_fail_alot_count = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1225
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1226
//  SpaceManager - used by Metaspace to handle allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1227
class SpaceManager : public CHeapObj<mtClass> {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1228
  friend class Metaspace;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1229
  friend class Metadebug;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1230
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1231
 private:
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1232
22201
9c2ccfa3a5fe 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 21569
diff changeset
  1233
  // protects allocations
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1234
  Mutex* const _lock;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1235
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  1236
  // Type of metadata allocated.
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  1237
  const Metaspace::MetadataType   _mdtype;
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  1238
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  1239
  // Type of metaspace
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  1240
  const Metaspace::MetaspaceType  _space_type;
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  1241
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1242
  // List of chunks in use by this SpaceManager.  Allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1243
  // are done from the current chunk.  The list is used for deallocating
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1244
  // chunks when the SpaceManager is freed.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1245
  Metachunk* _chunks_in_use[NumberOfInUseLists];
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1246
  Metachunk* _current_chunk;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1247
31028
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  1248
  // Maximum number of small chunks to allocate to a SpaceManager
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1249
  static uint const _small_chunk_limit;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1250
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  1251
  // Maximum number of specialize chunks to allocate for anonymous
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  1252
  // metadata space to a SpaceManager
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  1253
  static uint const _anon_metadata_specialize_chunk_limit;
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  1254
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1255
  // Sum of all space in allocated chunks
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1256
  size_t _allocated_blocks_words;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1257
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1258
  // Sum of all allocated chunks
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1259
  size_t _allocated_chunks_words;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1260
  size_t _allocated_chunks_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1261
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1262
  // Free lists of blocks are per SpaceManager since they
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1263
  // are assumed to be in chunks in use by the SpaceManager
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1264
  // and all chunks in use by a SpaceManager are freed when
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1265
  // the class loader using the SpaceManager is collected.
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1266
  BlockFreelist* _block_freelists;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1267
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1268
  // protects virtualspace and chunk expansions
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1269
  static const char*  _expand_lock_name;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1270
  static const int    _expand_lock_rank;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1271
  static Mutex* const _expand_lock;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1272
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1273
 private:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1274
  // Accessors
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1275
  Metachunk* chunks_in_use(ChunkIndex index) const { return _chunks_in_use[index]; }
22201
9c2ccfa3a5fe 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 21569
diff changeset
  1276
  void set_chunks_in_use(ChunkIndex index, Metachunk* v) {
9c2ccfa3a5fe 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 21569
diff changeset
  1277
    _chunks_in_use[index] = v;
9c2ccfa3a5fe 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 21569
diff changeset
  1278
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1279
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1280
  BlockFreelist* block_freelists() const { return _block_freelists; }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1281
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  1282
  Metaspace::MetadataType mdtype() { return _mdtype; }
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1283
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1284
  VirtualSpaceList* vs_list()   const { return Metaspace::get_space_list(_mdtype); }
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1285
  ChunkManager* chunk_manager() const { return Metaspace::get_chunk_manager(_mdtype); }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1286
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1287
  Metachunk* current_chunk() const { return _current_chunk; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1288
  void set_current_chunk(Metachunk* v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1289
    _current_chunk = v;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1290
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1291
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1292
  Metachunk* find_current_chunk(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1293
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1294
  // Add chunk to the list of chunks in use
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1295
  void add_chunk(Metachunk* v, bool make_current);
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1296
  void retire_current_chunk();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1297
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1298
  Mutex* lock() const { return _lock; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1299
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1300
 protected:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1301
  void initialize();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1302
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1303
 public:
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  1304
  SpaceManager(Metaspace::MetadataType mdtype,
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  1305
               Metaspace::MetaspaceType space_type,
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1306
               Mutex* lock);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1307
  ~SpaceManager();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1308
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1309
  enum ChunkMultiples {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1310
    MediumChunkMultiple = 4
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1311
  };
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1312
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1313
  static size_t specialized_chunk_size(bool is_class) { return is_class ? ClassSpecializedChunk : SpecializedChunk; }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1314
  static size_t small_chunk_size(bool is_class)       { return is_class ? ClassSmallChunk : SmallChunk; }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1315
  static size_t medium_chunk_size(bool is_class)      { return is_class ? ClassMediumChunk : MediumChunk; }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1316
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1317
  static size_t smallest_chunk_size(bool is_class)    { return specialized_chunk_size(is_class); }
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1318
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1319
  // Accessors
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1320
  bool is_class() const { return _mdtype == Metaspace::ClassType; }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1321
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1322
  size_t specialized_chunk_size() const { return specialized_chunk_size(is_class()); }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1323
  size_t small_chunk_size()       const { return small_chunk_size(is_class()); }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1324
  size_t medium_chunk_size()      const { return medium_chunk_size(is_class()); }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1325
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1326
  size_t smallest_chunk_size()    const { return smallest_chunk_size(is_class()); }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1327
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1328
  size_t medium_chunk_bunch()     const { return medium_chunk_size() * MediumChunkMultiple; }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1329
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1330
  size_t allocated_blocks_words() const { return _allocated_blocks_words; }
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1331
  size_t allocated_blocks_bytes() const { return _allocated_blocks_words * BytesPerWord; }
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1332
  size_t allocated_chunks_words() const { return _allocated_chunks_words; }
25051
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  1333
  size_t allocated_chunks_bytes() const { return _allocated_chunks_words * BytesPerWord; }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1334
  size_t allocated_chunks_count() const { return _allocated_chunks_count; }
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1335
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1336
  bool is_humongous(size_t word_size) { return word_size > medium_chunk_size(); }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1337
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1338
  static Mutex* expand_lock() { return _expand_lock; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1339
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1340
  // Increment the per Metaspace and global running sums for Metachunks
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1341
  // by the given size.  This is used when a Metachunk to added to
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1342
  // the in-use list.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1343
  void inc_size_metrics(size_t words);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1344
  // Increment the per Metaspace and global running sums Metablocks by the given
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1345
  // size.  This is used when a Metablock is allocated.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1346
  void inc_used_metrics(size_t words);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1347
  // Delete the portion of the running sums for this SpaceManager. That is,
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1348
  // the globals running sums for the Metachunks and Metablocks are
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1349
  // decremented for all the Metachunks in-use by this SpaceManager.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1350
  void dec_total_from_size_metrics();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1351
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1352
  // Adjust the initial chunk size to match one of the fixed chunk list sizes,
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1353
  // or return the unadjusted size if the requested size is humongous.
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1354
  static size_t adjust_initial_chunk_size(size_t requested, bool is_class_space);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1355
  size_t adjust_initial_chunk_size(size_t requested) const;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1356
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1357
  // Get the initial chunks size for this metaspace type.
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1358
  size_t get_initial_chunk_size(Metaspace::MetaspaceType type) const;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1359
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1360
  size_t sum_capacity_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1361
  size_t sum_used_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1362
  size_t sum_free_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1363
  size_t sum_waste_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1364
  size_t sum_waste_in_chunks_in_use(ChunkIndex index ) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1365
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1366
  size_t sum_count_in_chunks_in_use();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1367
  size_t sum_count_in_chunks_in_use(ChunkIndex i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1368
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1369
  Metachunk* get_new_chunk(size_t chunk_word_size);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1370
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1371
  // Block allocation and deallocation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1372
  // Allocates a block from the current chunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1373
  MetaWord* allocate(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1374
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1375
  // Helper for allocations
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1376
  MetaWord* allocate_work(size_t word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1377
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1378
  // Returns a block to the per manager freelist
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1379
  void deallocate(MetaWord* p, size_t word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1380
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1381
  // Based on the allocation size and a minimum chunk size,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1382
  // returned chunk size (for expanding space for chunk allocation).
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1383
  size_t calc_chunk_size(size_t allocation_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1384
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1385
  // Called when an allocation from the current chunk fails.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1386
  // Gets a new chunk (may require getting a new virtual space),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1387
  // and allocates from that chunk.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1388
  MetaWord* grow_and_allocate(size_t word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1389
20407
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  1390
  // Notify memory usage to MemoryService.
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  1391
  void track_metaspace_memory_usage();
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  1392
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1393
  // debugging support.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1394
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1395
  void dump(outputStream* const out) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1396
  void print_on(outputStream* st) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1397
  void locked_print_chunks_in_use_on(outputStream* st) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1398
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1399
  void verify();
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  1400
  void verify_chunk_size(Metachunk* chunk);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1401
#ifdef ASSERT
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1402
  void verify_allocated_blocks_words();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1403
#endif
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  1404
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1405
  // This adjusts the size given to be greater than the minimum allocation size in
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1406
  // words for data in metaspace.  Esentially the minimum size is currently 3 words.
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1407
  size_t get_allocation_word_size(size_t word_size) {
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  1408
    size_t byte_size = word_size * BytesPerWord;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  1409
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  1410
    size_t raw_bytes_size = MAX2(byte_size, sizeof(Metablock));
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1411
    raw_bytes_size = align_up(raw_bytes_size, Metachunk::object_alignment());
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  1412
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  1413
    size_t raw_word_size = raw_bytes_size / BytesPerWord;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  1414
    assert(raw_word_size * BytesPerWord == raw_bytes_size, "Size problem");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  1415
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  1416
    return raw_word_size;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  1417
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1418
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1419
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1420
uint const SpaceManager::_small_chunk_limit = 4;
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  1421
uint const SpaceManager::_anon_metadata_specialize_chunk_limit = 4;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1422
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1423
const char* SpaceManager::_expand_lock_name =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1424
  "SpaceManager chunk allocation lock";
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1425
const int SpaceManager::_expand_lock_rank = Monitor::leaf - 1;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1426
Mutex* const SpaceManager::_expand_lock =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1427
  new Mutex(SpaceManager::_expand_lock_rank,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1428
            SpaceManager::_expand_lock_name,
28163
322d55d167be 8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents: 28023
diff changeset
  1429
            Mutex::_allow_vm_block_flag,
322d55d167be 8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents: 28023
diff changeset
  1430
            Monitor::_safepoint_check_never);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1431
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1432
void VirtualSpaceNode::inc_container_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1433
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1434
  _container_count++;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1435
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1436
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1437
void VirtualSpaceNode::dec_container_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1438
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1439
  _container_count--;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1440
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1441
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1442
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1443
void VirtualSpaceNode::verify_container_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1444
  assert(_container_count == container_count_slow(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1445
         "Inconsistency in container_count _container_count " UINTX_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1446
         " container_count_slow() " UINTX_FORMAT, _container_count, container_count_slow());
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1447
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1448
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1449
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1450
// BlockFreelist methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1451
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1452
BlockFreelist::BlockFreelist() : _dictionary(new BlockTreeDictionary()), _small_blocks(NULL) {}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1453
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1454
BlockFreelist::~BlockFreelist() {
30580
394471b86a83 8079091: Remove dictionary NULL check on common path of BlockFreeList methods
jwha
parents: 29806
diff changeset
  1455
  delete _dictionary;
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1456
  if (_small_blocks != NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1457
    delete _small_blocks;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1458
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1459
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1460
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1461
void BlockFreelist::return_block(MetaWord* p, size_t word_size) {
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1462
  assert(word_size >= SmallBlocks::small_block_min_size(), "never return dark matter");
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1463
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  1464
  Metablock* free_chunk = ::new (p) Metablock(word_size);
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1465
  if (word_size < SmallBlocks::small_block_max_size()) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1466
    small_blocks()->return_block(free_chunk, word_size);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1467
  } else {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1468
  dictionary()->return_chunk(free_chunk);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1469
}
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1470
  log_trace(gc, metaspace, freelist, blocks)("returning block at " INTPTR_FORMAT " size = "
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1471
            SIZE_FORMAT, p2i(free_chunk), word_size);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1472
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1473
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1474
MetaWord* BlockFreelist::get_block(size_t word_size) {
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1475
  assert(word_size >= SmallBlocks::small_block_min_size(), "never get dark matter");
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1476
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1477
  // Try small_blocks first.
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1478
  if (word_size < SmallBlocks::small_block_max_size()) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1479
    // Don't create small_blocks() until needed.  small_blocks() allocates the small block list for
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1480
    // this space manager.
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1481
    MetaWord* new_block = (MetaWord*) small_blocks()->get_block(word_size);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1482
    if (new_block != NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1483
      log_trace(gc, metaspace, freelist, blocks)("getting block at " INTPTR_FORMAT " size = " SIZE_FORMAT,
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1484
              p2i(new_block), word_size);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1485
      return new_block;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1486
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1487
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1488
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1489
  if (word_size < BlockFreelist::min_dictionary_size()) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1490
    // If allocation in small blocks fails, this is Dark Matter.  Too small for dictionary.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1491
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1492
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1493
46674
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46625
diff changeset
  1494
  Metablock* free_block = dictionary()->get_chunk(word_size);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1495
  if (free_block == NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1496
    return NULL;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1497
  }
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1498
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1499
  const size_t block_size = free_block->size();
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1500
  if (block_size > WasteMultiplier * word_size) {
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1501
    return_block((MetaWord*)free_block, block_size);
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1502
    return NULL;
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1503
  }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1504
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1505
  MetaWord* new_block = (MetaWord*)free_block;
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1506
  assert(block_size >= word_size, "Incorrect size of block from freelist");
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1507
  const size_t unused = block_size - word_size;
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1508
  if (unused >= SmallBlocks::small_block_min_size()) {
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1509
    return_block(new_block + word_size, unused);
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1510
  }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1511
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1512
  log_trace(gc, metaspace, freelist, blocks)("getting block at " INTPTR_FORMAT " size = " SIZE_FORMAT,
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1513
            p2i(new_block), word_size);
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1514
  return new_block;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1515
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1516
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1517
void BlockFreelist::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1518
  dictionary()->print_free_lists(st);
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1519
  if (_small_blocks != NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1520
    _small_blocks->print_on(st);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1521
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1522
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1523
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1524
// VirtualSpaceNode methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1525
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1526
VirtualSpaceNode::~VirtualSpaceNode() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1527
  _rs.release();
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1528
  if (_occupancy_map != NULL) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1529
    delete _occupancy_map;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1530
  }
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1531
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1532
  size_t word_size = sizeof(*this) / BytesPerWord;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1533
  Copy::fill_to_words((HeapWord*) this, word_size, 0xf1f1f1f1);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1534
#endif
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1535
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1536
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1537
size_t VirtualSpaceNode::used_words_in_vs() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1538
  return pointer_delta(top(), bottom(), sizeof(MetaWord));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1539
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1540
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1541
// Space committed in the VirtualSpace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1542
size_t VirtualSpaceNode::capacity_words_in_vs() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1543
  return pointer_delta(end(), bottom(), sizeof(MetaWord));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1544
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1545
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1546
size_t VirtualSpaceNode::free_words_in_vs() const {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1547
  return pointer_delta(end(), top(), sizeof(MetaWord));
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1548
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1549
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1550
// Given an address larger than top(), allocate padding chunks until top is at the given address.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1551
void VirtualSpaceNode::allocate_padding_chunks_until_top_is_at(MetaWord* target_top) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1552
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1553
  assert(target_top > top(), "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1554
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1555
  // Padding chunks are added to the freelist.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1556
  ChunkManager* const chunk_manager = Metaspace::get_chunk_manager(this->is_class());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1557
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1558
  // shorthands
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1559
  const size_t spec_word_size = chunk_manager->specialized_chunk_word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1560
  const size_t small_word_size = chunk_manager->small_chunk_word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1561
  const size_t med_word_size = chunk_manager->medium_chunk_word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1562
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1563
  while (top() < target_top) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1564
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1565
    // We could make this coding more generic, but right now we only deal with two possible chunk sizes
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1566
    // for padding chunks, so it is not worth it.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1567
    size_t padding_chunk_word_size = small_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1568
    if (is_aligned(top(), small_word_size * sizeof(MetaWord)) == false) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1569
      assert_is_aligned(top(), spec_word_size * sizeof(MetaWord)); // Should always hold true.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1570
      padding_chunk_word_size = spec_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1571
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1572
    MetaWord* here = top();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1573
    assert_is_aligned(here, padding_chunk_word_size * sizeof(MetaWord));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1574
    inc_top(padding_chunk_word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1575
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1576
    // Create new padding chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1577
    ChunkIndex padding_chunk_type = get_chunk_type_by_size(padding_chunk_word_size, is_class());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1578
    assert(padding_chunk_type == SpecializedIndex || padding_chunk_type == SmallIndex, "sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1579
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1580
    Metachunk* const padding_chunk =
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1581
      ::new (here) Metachunk(padding_chunk_type, is_class(), padding_chunk_word_size, this);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1582
    assert(padding_chunk == (Metachunk*)here, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1583
    DEBUG_ONLY(padding_chunk->set_origin(origin_pad);)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1584
    log_trace(gc, metaspace, freelist)("Created padding chunk in %s at "
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1585
                                       PTR_FORMAT ", size " SIZE_FORMAT_HEX ".",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1586
                                       (is_class() ? "class space " : "metaspace"),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1587
                                       p2i(padding_chunk), padding_chunk->word_size() * sizeof(MetaWord));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1588
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1589
    // Mark chunk start in occupancy map.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1590
    occupancy_map()->set_chunk_starts_at_address((MetaWord*)padding_chunk, true);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1591
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1592
    // Chunks are born as in-use (see MetaChunk ctor). So, before returning
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1593
    // the padding chunk to its chunk manager, mark it as in use (ChunkManager
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1594
    // will assert that).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1595
    do_update_in_use_info_for_chunk(padding_chunk, true);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1596
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1597
    // Return Chunk to freelist.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1598
    inc_container_count();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1599
    chunk_manager->return_single_chunk(padding_chunk_type, padding_chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1600
    // Please note: at this point, ChunkManager::return_single_chunk()
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1601
    // may already have merged the padding chunk with neighboring chunks, so
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1602
    // it may have vanished at this point. Do not reference the padding
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1603
    // chunk beyond this point.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1604
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1605
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1606
  assert(top() == target_top, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1607
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1608
} // allocate_padding_chunks_until_top_is_at()
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1609
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1610
// Allocates the chunk from the virtual space only.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1611
// This interface is also used internally for debugging.  Not all
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1612
// chunks removed here are necessarily used for allocation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1613
Metachunk* VirtualSpaceNode::take_from_committed(size_t chunk_word_size) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1614
  // Non-humongous chunks are to be allocated aligned to their chunk
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1615
  // size. So, start addresses of medium chunks are aligned to medium
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1616
  // chunk size, those of small chunks to small chunk size and so
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1617
  // forth. This facilitates merging of free chunks and reduces
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1618
  // fragmentation. Chunk sizes are spec < small < medium, with each
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1619
  // larger chunk size being a multiple of the next smaller chunk
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1620
  // size.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1621
  // Because of this alignment, me may need to create a number of padding
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1622
  // chunks. These chunks are created and added to the freelist.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1623
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1624
  // The chunk manager to which we will give our padding chunks.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1625
  ChunkManager* const chunk_manager = Metaspace::get_chunk_manager(this->is_class());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1626
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1627
  // shorthands
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1628
  const size_t spec_word_size = chunk_manager->specialized_chunk_word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1629
  const size_t small_word_size = chunk_manager->small_chunk_word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1630
  const size_t med_word_size = chunk_manager->medium_chunk_word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1631
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1632
  assert(chunk_word_size == spec_word_size || chunk_word_size == small_word_size ||
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1633
         chunk_word_size >= med_word_size, "Invalid chunk size requested.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1634
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1635
  // Chunk alignment (in bytes) == chunk size unless humongous.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1636
  // Humongous chunks are aligned to the smallest chunk size (spec).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1637
  const size_t required_chunk_alignment = (chunk_word_size > med_word_size ?
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1638
                                           spec_word_size : chunk_word_size) * sizeof(MetaWord);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1639
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1640
  // Do we have enough space to create the requested chunk plus
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1641
  // any padding chunks needed?
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1642
  MetaWord* const next_aligned =
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1643
    static_cast<MetaWord*>(align_up(top(), required_chunk_alignment));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1644
  if (!is_available((next_aligned - top()) + chunk_word_size)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1645
    return NULL;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1646
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1647
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1648
  // Before allocating the requested chunk, allocate padding chunks if necessary.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1649
  // We only need to do this for small or medium chunks: specialized chunks are the
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1650
  // smallest size, hence always aligned. Homungous chunks are allocated unaligned
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1651
  // (implicitly, also aligned to smallest chunk size).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1652
  if ((chunk_word_size == med_word_size || chunk_word_size == small_word_size) && next_aligned > top())  {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1653
    log_trace(gc, metaspace, freelist)("Creating padding chunks in %s between %p and %p...",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1654
        (is_class() ? "class space " : "metaspace"),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1655
        top(), next_aligned);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1656
    allocate_padding_chunks_until_top_is_at(next_aligned);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1657
    // Now, top should be aligned correctly.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1658
    assert_is_aligned(top(), required_chunk_alignment);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1659
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1660
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1661
  // Now, top should be aligned correctly.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1662
  assert_is_aligned(top(), required_chunk_alignment);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1663
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1664
  // Bottom of the new chunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1665
  MetaWord* chunk_limit = top();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1666
  assert(chunk_limit != NULL, "Not safe to call this method");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1667
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1668
  // The virtual spaces are always expanded by the
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1669
  // commit granularity to enforce the following condition.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1670
  // Without this the is_available check will not work correctly.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1671
  assert(_virtual_space.committed_size() == _virtual_space.actual_committed_size(),
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1672
      "The committed memory doesn't match the expanded memory.");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1673
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1674
  if (!is_available(chunk_word_size)) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1675
    LogTarget(Debug, gc, metaspace, freelist) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1676
    if (lt.is_enabled()) {
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1677
      LogStream ls(lt);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1678
      ls.print("VirtualSpaceNode::take_from_committed() not available " SIZE_FORMAT " words ", chunk_word_size);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1679
      // Dump some information about the virtual space that is nearly full
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1680
      print_on(&ls);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1681
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1682
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1683
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1684
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1685
  // Take the space  (bump top on the current virtual space).
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1686
  inc_top(chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1687
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1688
  // Initialize the chunk
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1689
  ChunkIndex chunk_type = get_chunk_type_by_size(chunk_word_size, is_class());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1690
  Metachunk* result = ::new (chunk_limit) Metachunk(chunk_type, is_class(), chunk_word_size, this);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1691
  assert(result == (Metachunk*)chunk_limit, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1692
  occupancy_map()->set_chunk_starts_at_address((MetaWord*)result, true);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1693
  do_update_in_use_info_for_chunk(result, true);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1694
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1695
  inc_container_count();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1696
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1697
  DEBUG_ONLY(chunk_manager->locked_verify());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1698
  DEBUG_ONLY(this->verify());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1699
  DEBUG_ONLY(do_verify_chunk(result));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1700
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1701
  result->inc_use_count();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1702
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1703
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1704
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1705
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1706
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1707
// Expand the virtual space (commit more of the reserved space)
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1708
bool VirtualSpaceNode::expand_by(size_t min_words, size_t preferred_words) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1709
  size_t min_bytes = min_words * BytesPerWord;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1710
  size_t preferred_bytes = preferred_words * BytesPerWord;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1711
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1712
  size_t uncommitted = virtual_space()->reserved_size() - virtual_space()->actual_committed_size();
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1713
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1714
  if (uncommitted < min_bytes) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1715
    return false;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1716
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1717
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1718
  size_t commit = MIN2(preferred_bytes, uncommitted);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1719
  bool result = virtual_space()->expand_by(commit, false);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1720
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1721
  if (result) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1722
    log_trace(gc, metaspace, freelist)("Expanded %s virtual space list node by " SIZE_FORMAT " words.",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1723
              (is_class() ? "class" : "non-class"), commit);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1724
  } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1725
    log_trace(gc, metaspace, freelist)("Failed to expand %s virtual space list node by " SIZE_FORMAT " words.",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1726
              (is_class() ? "class" : "non-class"), commit);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1727
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1728
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1729
  assert(result, "Failed to commit memory");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1730
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1731
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1732
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1733
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1734
Metachunk* VirtualSpaceNode::get_chunk_vs(size_t chunk_word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1735
  assert_lock_strong(SpaceManager::expand_lock());
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1736
  Metachunk* result = take_from_committed(chunk_word_size);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1737
  return result;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1738
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1739
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1740
bool VirtualSpaceNode::initialize() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1741
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1742
  if (!_rs.is_reserved()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1743
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1744
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1745
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1746
  // These are necessary restriction to make sure that the virtual space always
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1747
  // grows in steps of Metaspace::commit_alignment(). If both base and size are
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1748
  // aligned only the middle alignment of the VirtualSpace is used.
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1749
  assert_is_aligned(_rs.base(), Metaspace::commit_alignment());
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1750
  assert_is_aligned(_rs.size(), Metaspace::commit_alignment());
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1751
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1752
  // ReservedSpaces marked as special will have the entire memory
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1753
  // pre-committed. Setting a committed size will make sure that
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1754
  // committed_size and actual_committed_size agrees.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1755
  size_t pre_committed_size = _rs.special() ? _rs.size() : 0;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1756
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1757
  bool result = virtual_space()->initialize_with_granularity(_rs, pre_committed_size,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1758
                                            Metaspace::commit_alignment());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1759
  if (result) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1760
    assert(virtual_space()->committed_size() == virtual_space()->actual_committed_size(),
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1761
        "Checking that the pre-committed memory was registered by the VirtualSpace");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1762
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1763
    set_top((MetaWord*)virtual_space()->low());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1764
    set_reserved(MemRegion((HeapWord*)_rs.base(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1765
                 (HeapWord*)(_rs.base() + _rs.size())));
13729
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
  1766
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
  1767
    assert(reserved()->start() == (HeapWord*) _rs.base(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1768
           "Reserved start was not set properly " PTR_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1769
           " != " PTR_FORMAT, p2i(reserved()->start()), p2i(_rs.base()));
13729
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
  1770
    assert(reserved()->word_size() == _rs.size() / BytesPerWord,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1771
           "Reserved size was not set properly " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1772
           " != " SIZE_FORMAT, reserved()->word_size(),
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1773
           _rs.size() / BytesPerWord);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1774
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1775
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1776
  // Initialize Occupancy Map.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1777
  const size_t smallest_chunk_size = is_class() ? ClassSpecializedChunk : SpecializedChunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1778
  _occupancy_map = new OccupancyMap(bottom(), reserved_words(), smallest_chunk_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1779
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1780
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1781
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1782
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1783
void VirtualSpaceNode::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1784
  size_t used = used_words_in_vs();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1785
  size_t capacity = capacity_words_in_vs();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1786
  VirtualSpace* vs = virtual_space();
29800
fa5f7a2bf717 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29697
diff changeset
  1787
  st->print_cr("   space @ " PTR_FORMAT " " SIZE_FORMAT "K, " SIZE_FORMAT_W(3) "%% used "
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1788
           "[" PTR_FORMAT ", " PTR_FORMAT ", "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1789
           PTR_FORMAT ", " PTR_FORMAT ")",
29800
fa5f7a2bf717 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29697
diff changeset
  1790
           p2i(vs), capacity / K,
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1791
           capacity == 0 ? 0 : used * 100 / capacity,
29800
fa5f7a2bf717 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29697
diff changeset
  1792
           p2i(bottom()), p2i(top()), p2i(end()),
fa5f7a2bf717 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29697
diff changeset
  1793
           p2i(vs->high_boundary()));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1794
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1795
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
  1796
#ifdef ASSERT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1797
void VirtualSpaceNode::mangle() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1798
  size_t word_size = capacity_words_in_vs();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1799
  Copy::fill_to_words((HeapWord*) low(), word_size, 0xf1f1f1f1);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1800
}
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
  1801
#endif // ASSERT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1802
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1803
// VirtualSpaceList methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1804
// Space allocated from the VirtualSpace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1805
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1806
VirtualSpaceList::~VirtualSpaceList() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1807
  VirtualSpaceListIterator iter(virtual_space_list());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1808
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1809
    VirtualSpaceNode* vsl = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1810
    delete vsl;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1811
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1812
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1813
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1814
void VirtualSpaceList::inc_reserved_words(size_t v) {
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1815
  assert_lock_strong(SpaceManager::expand_lock());
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1816
  _reserved_words = _reserved_words + v;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1817
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1818
void VirtualSpaceList::dec_reserved_words(size_t v) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1819
  assert_lock_strong(SpaceManager::expand_lock());
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1820
  _reserved_words = _reserved_words - v;
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1821
}
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1822
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1823
#define assert_committed_below_limit()                        \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1824
  assert(MetaspaceAux::committed_bytes() <= MaxMetaspaceSize, \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1825
         "Too much committed memory. Committed: " SIZE_FORMAT \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1826
         " limit (MaxMetaspaceSize): " SIZE_FORMAT,           \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1827
         MetaspaceAux::committed_bytes(), MaxMetaspaceSize);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1828
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1829
void VirtualSpaceList::inc_committed_words(size_t v) {
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1830
  assert_lock_strong(SpaceManager::expand_lock());
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1831
  _committed_words = _committed_words + v;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1832
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1833
  assert_committed_below_limit();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1834
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1835
void VirtualSpaceList::dec_committed_words(size_t v) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1836
  assert_lock_strong(SpaceManager::expand_lock());
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1837
  _committed_words = _committed_words - v;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1838
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1839
  assert_committed_below_limit();
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1840
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1841
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1842
void VirtualSpaceList::inc_virtual_space_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1843
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1844
  _virtual_space_count++;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1845
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1846
void VirtualSpaceList::dec_virtual_space_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1847
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1848
  _virtual_space_count--;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1849
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1850
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1851
void ChunkManager::remove_chunk(Metachunk* chunk) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1852
  size_t word_size = chunk->word_size();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1853
  ChunkIndex index = list_index(word_size);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1854
  if (index != HumongousIndex) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1855
    free_chunks(index)->remove_chunk(chunk);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1856
  } else {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1857
    humongous_dictionary()->remove_chunk(chunk);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1858
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1859
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1860
  // Chunk has been removed from the chunks free list, update counters.
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1861
  account_for_removed_chunk(chunk);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1862
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1863
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1864
bool ChunkManager::attempt_to_coalesce_around_chunk(Metachunk* chunk, ChunkIndex target_chunk_type) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1865
  assert_lock_strong(SpaceManager::expand_lock());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1866
  assert(chunk != NULL, "invalid chunk pointer");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1867
  // Check for valid merge combinations.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1868
  assert((chunk->get_chunk_type() == SpecializedIndex &&
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1869
          (target_chunk_type == SmallIndex || target_chunk_type == MediumIndex)) ||
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1870
         (chunk->get_chunk_type() == SmallIndex && target_chunk_type == MediumIndex),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1871
        "Invalid chunk merge combination.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1872
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1873
  const size_t target_chunk_word_size =
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1874
    get_size_for_nonhumongous_chunktype(target_chunk_type, this->is_class());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1875
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1876
  // [ prospective merge region )
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1877
  MetaWord* const p_merge_region_start =
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1878
    (MetaWord*) align_down(chunk, target_chunk_word_size * sizeof(MetaWord));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1879
  MetaWord* const p_merge_region_end =
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1880
    p_merge_region_start + target_chunk_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1881
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1882
  // We need the VirtualSpaceNode containing this chunk and its occupancy map.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1883
  VirtualSpaceNode* const vsn = chunk->container();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1884
  OccupancyMap* const ocmap = vsn->occupancy_map();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1885
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1886
  // The prospective chunk merge range must be completely contained by the
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1887
  // committed range of the virtual space node.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1888
  if (p_merge_region_start < vsn->bottom() || p_merge_region_end > vsn->top()) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1889
    return false;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1890
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1891
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1892
  // Only attempt to merge this range if at its start a chunk starts and at its end
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1893
  // a chunk ends. If a chunk (can only be humongous) straddles either start or end
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1894
  // of that range, we cannot merge.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1895
  if (!ocmap->chunk_starts_at_address(p_merge_region_start)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1896
    return false;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1897
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1898
  if (p_merge_region_end < vsn->top() &&
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1899
      !ocmap->chunk_starts_at_address(p_merge_region_end)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1900
    return false;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1901
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1902
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1903
  // Now check if the prospective merge area contains live chunks. If it does we cannot merge.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1904
  if (ocmap->is_region_in_use(p_merge_region_start, target_chunk_word_size)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1905
    return false;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1906
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1907
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1908
  // Success! Remove all chunks in this region...
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1909
  log_trace(gc, metaspace, freelist)("%s: coalescing chunks in area [%p-%p)...",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1910
    (is_class() ? "class space" : "metaspace"),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1911
    p_merge_region_start, p_merge_region_end);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1912
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1913
  const int num_chunks_removed =
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1914
    remove_chunks_in_area(p_merge_region_start, target_chunk_word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1915
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1916
  // ... and create a single new bigger chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1917
  Metachunk* const p_new_chunk =
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1918
      ::new (p_merge_region_start) Metachunk(target_chunk_type, is_class(), target_chunk_word_size, vsn);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1919
  assert(p_new_chunk == (Metachunk*)p_merge_region_start, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1920
  p_new_chunk->set_origin(origin_merge);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1921
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1922
  log_trace(gc, metaspace, freelist)("%s: created coalesced chunk at %p, size " SIZE_FORMAT_HEX ".",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1923
    (is_class() ? "class space" : "metaspace"),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1924
    p_new_chunk, p_new_chunk->word_size() * sizeof(MetaWord));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1925
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1926
  // Fix occupancy map: remove old start bits of the small chunks and set new start bit.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1927
  ocmap->wipe_chunk_start_bits_in_region(p_merge_region_start, target_chunk_word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1928
  ocmap->set_chunk_starts_at_address(p_merge_region_start, true);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1929
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1930
  // Mark chunk as free. Note: it is not necessary to update the occupancy
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1931
  // map in-use map, because the old chunks were also free, so nothing
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1932
  // should have changed.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1933
  p_new_chunk->set_is_tagged_free(true);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1934
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1935
  // Add new chunk to its freelist.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1936
  ChunkList* const list = free_chunks(target_chunk_type);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1937
  list->return_chunk_at_head(p_new_chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1938
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1939
  // And adjust ChunkManager:: _free_chunks_count (_free_chunks_total
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1940
  // should not have changed, because the size of the space should be the same)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1941
  _free_chunks_count -= num_chunks_removed;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1942
  _free_chunks_count ++;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1943
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1944
  // VirtualSpaceNode::container_count does not have to be modified:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1945
  // it means "number of active (non-free) chunks", so merging free chunks
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1946
  // should not affect that count.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1947
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1948
  // At the end of a chunk merge, run verification tests.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1949
  DEBUG_ONLY(this->locked_verify());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1950
  DEBUG_ONLY(vsn->verify());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1951
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1952
  return true;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1953
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1954
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1955
// Remove all chunks in the given area - the chunks are supposed to be free -
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1956
// from their corresponding freelists. Mark them as invalid.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1957
// - This does not correct the occupancy map.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1958
// - This does not adjust the counters in ChunkManager.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1959
// - Does not adjust container count counter in containing VirtualSpaceNode
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1960
// Returns number of chunks removed.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1961
int ChunkManager::remove_chunks_in_area(MetaWord* p, size_t word_size) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1962
  assert(p != NULL && word_size > 0, "Invalid range.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1963
  const size_t smallest_chunk_size = get_size_for_nonhumongous_chunktype(SpecializedIndex, is_class());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1964
  assert_is_aligned(word_size, smallest_chunk_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1965
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1966
  Metachunk* const start = (Metachunk*) p;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1967
  const Metachunk* const end = (Metachunk*)(p + word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1968
  Metachunk* cur = start;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1969
  int num_removed = 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1970
  while (cur < end) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1971
    Metachunk* next = (Metachunk*)(((MetaWord*)cur) + cur->word_size());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1972
    DEBUG_ONLY(do_verify_chunk(cur));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1973
    assert(cur->get_chunk_type() != HumongousIndex, "Unexpected humongous chunk found at %p.", cur);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1974
    assert(cur->is_tagged_free(), "Chunk expected to be free (%p)", cur);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1975
    log_trace(gc, metaspace, freelist)("%s: removing chunk %p, size " SIZE_FORMAT_HEX ".",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1976
      (is_class() ? "class space" : "metaspace"),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1977
      cur, cur->word_size() * sizeof(MetaWord));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1978
    cur->remove_sentinel();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1979
    // Note: cannot call ChunkManager::remove_chunk, because that
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1980
    // modifies the counters in ChunkManager, which we do not want. So
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1981
    // we call remove_chunk on the freelist directly (see also the
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1982
    // splitting function which does the same).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1983
    ChunkList* const list = free_chunks(list_index(cur->word_size()));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1984
    list->remove_chunk(cur);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1985
    num_removed ++;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1986
    cur = next;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1987
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1988
  return num_removed;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1989
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1990
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1991
// Walk the list of VirtualSpaceNodes and delete
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1992
// nodes with a 0 container_count.  Remove Metachunks in
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1993
// the node from their respective freelists.
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1994
void VirtualSpaceList::purge(ChunkManager* chunk_manager) {
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1995
  assert(SafepointSynchronize::is_at_safepoint(), "must be called at safepoint for contains to work");
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1996
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1997
  // Don't use a VirtualSpaceListIterator because this
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1998
  // list is being changed and a straightforward use of an iterator is not safe.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1999
  VirtualSpaceNode* purged_vsl = NULL;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2000
  VirtualSpaceNode* prev_vsl = virtual_space_list();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2001
  VirtualSpaceNode* next_vsl = prev_vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2002
  while (next_vsl != NULL) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2003
    VirtualSpaceNode* vsl = next_vsl;
36177
b2b76aba8e42 8149643: Remove check of counters in VirtualSpaceNode::inc_container_count
jmasa
parents: 35905
diff changeset
  2004
    DEBUG_ONLY(vsl->verify_container_count();)
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2005
    next_vsl = vsl->next();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2006
    // Don't free the current virtual space since it will likely
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2007
    // be needed soon.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2008
    if (vsl->container_count() == 0 && vsl != current_virtual_space()) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2009
      log_trace(gc, metaspace, freelist)("Purging VirtualSpaceNode " PTR_FORMAT " (capacity: " SIZE_FORMAT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2010
                                         ", used: " SIZE_FORMAT ").", p2i(vsl), vsl->capacity_words_in_vs(), vsl->used_words_in_vs());
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2011
      // Unlink it from the list
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2012
      if (prev_vsl == vsl) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2013
        // This is the case of the current node being the first node.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2014
        assert(vsl == virtual_space_list(), "Expected to be the first node");
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2015
        set_virtual_space_list(vsl->next());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2016
      } else {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2017
        prev_vsl->set_next(vsl->next());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2018
      }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2019
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2020
      vsl->purge(chunk_manager);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2021
      dec_reserved_words(vsl->reserved_words());
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2022
      dec_committed_words(vsl->committed_words());
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2023
      dec_virtual_space_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2024
      purged_vsl = vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2025
      delete vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2026
    } else {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2027
      prev_vsl = vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2028
    }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2029
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2030
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2031
  if (purged_vsl != NULL) {
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2032
    // List should be stable enough to use an iterator here.
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2033
    VirtualSpaceListIterator iter(virtual_space_list());
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2034
    while (iter.repeat()) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2035
      VirtualSpaceNode* vsl = iter.get_next();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2036
      assert(vsl != purged_vsl, "Purge of vsl failed");
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2037
    }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2038
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2039
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2040
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2041
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2042
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2043
// This function looks at the mmap regions in the metaspace without locking.
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2044
// The chunks are added with store ordering and not deleted except for at
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2045
// unloading time during a safepoint.
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2046
bool VirtualSpaceList::contains(const void* ptr) {
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2047
  // List should be stable enough to use an iterator here because removing virtual
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2048
  // space nodes is only allowed at a safepoint.
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2049
  VirtualSpaceListIterator iter(virtual_space_list());
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2050
  while (iter.repeat()) {
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2051
    VirtualSpaceNode* vsn = iter.get_next();
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2052
    if (vsn->contains(ptr)) {
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2053
      return true;
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2054
    }
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2055
  }
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2056
  return false;
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2057
}
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2058
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2059
void VirtualSpaceList::retire_current_virtual_space() {
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2060
  assert_lock_strong(SpaceManager::expand_lock());
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2061
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2062
  VirtualSpaceNode* vsn = current_virtual_space();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2063
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2064
  ChunkManager* cm = is_class() ? Metaspace::chunk_manager_class() :
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2065
                                  Metaspace::chunk_manager_metadata();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2066
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2067
  vsn->retire(cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2068
}
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2069
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2070
void VirtualSpaceNode::retire(ChunkManager* chunk_manager) {
36177
b2b76aba8e42 8149643: Remove check of counters in VirtualSpaceNode::inc_container_count
jmasa
parents: 35905
diff changeset
  2071
  DEBUG_ONLY(verify_container_count();)
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2072
  assert(this->is_class() == chunk_manager->is_class(), "Wrong ChunkManager?");
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2073
  for (int i = (int)MediumIndex; i >= (int)ZeroIndex; --i) {
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2074
    ChunkIndex index = (ChunkIndex)i;
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2075
    size_t chunk_size = chunk_manager->size_by_index(index);
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2076
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2077
    while (free_words_in_vs() >= chunk_size) {
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2078
      Metachunk* chunk = get_chunk_vs(chunk_size);
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2079
      // Chunk will be allocated aligned, so allocation may require
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2080
      // additional padding chunks. That may cause above allocation to
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2081
      // fail. Just ignore the failed allocation and continue with the
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2082
      // next smaller chunk size. As the VirtualSpaceNode comitted
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2083
      // size should be a multiple of the smallest chunk size, we
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2084
      // should always be able to fill the VirtualSpace completely.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2085
      if (chunk == NULL) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2086
        break;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2087
      }
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2088
      chunk_manager->return_single_chunk(index, chunk);
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2089
    }
36177
b2b76aba8e42 8149643: Remove check of counters in VirtualSpaceNode::inc_container_count
jmasa
parents: 35905
diff changeset
  2090
    DEBUG_ONLY(verify_container_count();)
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2091
  }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2092
  assert(free_words_in_vs() == 0, "should be empty now");
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2093
}
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2094
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2095
VirtualSpaceList::VirtualSpaceList(size_t word_size) :
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2096
                                   _is_class(false),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2097
                                   _virtual_space_list(NULL),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2098
                                   _current_virtual_space(NULL),
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2099
                                   _reserved_words(0),
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2100
                                   _committed_words(0),
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2101
                                   _virtual_space_count(0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2102
  MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2103
                   Mutex::_no_safepoint_check_flag);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2104
  create_new_virtual_space(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2105
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2106
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2107
VirtualSpaceList::VirtualSpaceList(ReservedSpace rs) :
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2108
                                   _is_class(true),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2109
                                   _virtual_space_list(NULL),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2110
                                   _current_virtual_space(NULL),
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2111
                                   _reserved_words(0),
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2112
                                   _committed_words(0),
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2113
                                   _virtual_space_count(0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2114
  MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2115
                   Mutex::_no_safepoint_check_flag);
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2116
  VirtualSpaceNode* class_entry = new VirtualSpaceNode(is_class(), rs);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2117
  bool succeeded = class_entry->initialize();
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2118
  if (succeeded) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2119
    link_vs(class_entry);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2120
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2121
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2122
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2123
size_t VirtualSpaceList::free_bytes() {
47543
198cb8e20aef 8187331: VirtualSpaceList tracks free space on wrong node
zgu
parents: 47216
diff changeset
  2124
  return current_virtual_space()->free_words_in_vs() * BytesPerWord;
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2125
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2126
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2127
// Allocate another meta virtual space and add it to the list.
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2128
bool VirtualSpaceList::create_new_virtual_space(size_t vs_word_size) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2129
  assert_lock_strong(SpaceManager::expand_lock());
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2130
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2131
  if (is_class()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2132
    assert(false, "We currently don't support more than one VirtualSpace for"
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2133
                  " the compressed class space. The initialization of the"
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2134
                  " CCS uses another code path and should not hit this path.");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2135
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2136
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2137
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2138
  if (vs_word_size == 0) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2139
    assert(false, "vs_word_size should always be at least _reserve_alignment large.");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2140
    return false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2141
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2142
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2143
  // Reserve the space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2144
  size_t vs_byte_size = vs_word_size * BytesPerWord;
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  2145
  assert_is_aligned(vs_byte_size, Metaspace::reserve_alignment());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2146
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2147
  // Allocate the meta virtual space and initialize it.
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2148
  VirtualSpaceNode* new_entry = new VirtualSpaceNode(is_class(), vs_byte_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2149
  if (!new_entry->initialize()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2150
    delete new_entry;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2151
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2152
  } else {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2153
    assert(new_entry->reserved_words() == vs_word_size,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2154
        "Reserved memory size differs from requested memory size");
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2155
    // ensure lock-free iteration sees fully initialized node
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2156
    OrderAccess::storestore();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2157
    link_vs(new_entry);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2158
    return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2159
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2160
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2161
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2162
void VirtualSpaceList::link_vs(VirtualSpaceNode* new_entry) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2163
  if (virtual_space_list() == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2164
      set_virtual_space_list(new_entry);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2165
  } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2166
    current_virtual_space()->set_next(new_entry);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2167
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2168
  set_current_virtual_space(new_entry);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2169
  inc_reserved_words(new_entry->reserved_words());
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2170
  inc_committed_words(new_entry->committed_words());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2171
  inc_virtual_space_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2172
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2173
  new_entry->mangle();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2174
#endif
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2175
  LogTarget(Trace, gc, metaspace) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2176
  if (lt.is_enabled()) {
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2177
    LogStream ls(lt);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2178
    VirtualSpaceNode* vsl = current_virtual_space();
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2179
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2180
    vsl->print_on(&ls);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2181
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2182
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2183
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2184
bool VirtualSpaceList::expand_node_by(VirtualSpaceNode* node,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2185
                                      size_t min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2186
                                      size_t preferred_words) {
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2187
  size_t before = node->committed_words();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2188
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2189
  bool result = node->expand_by(min_words, preferred_words);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2190
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2191
  size_t after = node->committed_words();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2192
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2193
  // after and before can be the same if the memory was pre-committed.
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2194
  assert(after >= before, "Inconsistency");
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2195
  inc_committed_words(after - before);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2196
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2197
  return result;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2198
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2199
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2200
bool VirtualSpaceList::expand_by(size_t min_words, size_t preferred_words) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  2201
  assert_is_aligned(min_words,       Metaspace::commit_alignment_words());
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  2202
  assert_is_aligned(preferred_words, Metaspace::commit_alignment_words());
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2203
  assert(min_words <= preferred_words, "Invalid arguments");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2204
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2205
  const char* const class_or_not = (is_class() ? "class" : "non-class");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2206
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2207
  if (!MetaspaceGC::can_expand(min_words, this->is_class())) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2208
    log_trace(gc, metaspace, freelist)("Cannot expand %s virtual space list.",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2209
              class_or_not);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2210
    return  false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2211
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2212
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2213
  size_t allowed_expansion_words = MetaspaceGC::allowed_expansion();
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2214
  if (allowed_expansion_words < min_words) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2215
    log_trace(gc, metaspace, freelist)("Cannot expand %s virtual space list (must try gc first).",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2216
              class_or_not);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2217
    return false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2218
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2219
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2220
  size_t max_expansion_words = MIN2(preferred_words, allowed_expansion_words);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2221
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2222
  // Commit more memory from the the current virtual space.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2223
  bool vs_expanded = expand_node_by(current_virtual_space(),
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2224
                                    min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2225
                                    max_expansion_words);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2226
  if (vs_expanded) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2227
     log_trace(gc, metaspace, freelist)("Expanded %s virtual space list.",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2228
               class_or_not);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2229
     return true;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2230
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2231
  log_trace(gc, metaspace, freelist)("%s virtual space list: retire current node.",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2232
            class_or_not);
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2233
  retire_current_virtual_space();
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2234
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2235
  // Get another virtual space.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2236
  size_t grow_vs_words = MAX2((size_t)VirtualSpaceSize, preferred_words);
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  2237
  grow_vs_words = align_up(grow_vs_words, Metaspace::reserve_alignment_words());
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2238
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2239
  if (create_new_virtual_space(grow_vs_words)) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2240
    if (current_virtual_space()->is_pre_committed()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2241
      // The memory was pre-committed, so we are done here.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2242
      assert(min_words <= current_virtual_space()->committed_words(),
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2243
          "The new VirtualSpace was pre-committed, so it"
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2244
          "should be large enough to fit the alloc request.");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2245
      return true;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2246
    }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2247
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2248
    return expand_node_by(current_virtual_space(),
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2249
                          min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2250
                          max_expansion_words);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2251
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2252
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2253
  return false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2254
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2255
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2256
// Given a chunk, calculate the largest possible padding space which
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2257
// could be required when allocating it.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2258
static size_t largest_possible_padding_size_for_chunk(size_t chunk_word_size, bool is_class) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2259
  const ChunkIndex chunk_type = get_chunk_type_by_size(chunk_word_size, is_class);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2260
  if (chunk_type != HumongousIndex) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2261
    // Normal, non-humongous chunks are allocated at chunk size
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2262
    // boundaries, so the largest padding space required would be that
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2263
    // minus the smallest chunk size.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2264
    const size_t smallest_chunk_size = is_class ? ClassSpecializedChunk : SpecializedChunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2265
    return chunk_word_size - smallest_chunk_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2266
  } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2267
    // Humongous chunks are allocated at smallest-chunksize
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2268
    // boundaries, so there is no padding required.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2269
    return 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2270
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2271
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2272
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2273
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2274
Metachunk* VirtualSpaceList::get_new_chunk(size_t chunk_word_size, size_t suggested_commit_granularity) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2275
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2276
  // Allocate a chunk out of the current virtual space.
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2277
  Metachunk* next = current_virtual_space()->get_chunk_vs(chunk_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2278
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2279
  if (next != NULL) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2280
    return next;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2281
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2282
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2283
  // The expand amount is currently only determined by the requested sizes
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2284
  // and not how much committed memory is left in the current virtual space.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2285
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2286
  // We must have enough space for the requested size and any
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2287
  // additional reqired padding chunks.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2288
  const size_t size_for_padding = largest_possible_padding_size_for_chunk(chunk_word_size, this->is_class());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2289
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2290
  size_t min_word_size       = align_up(chunk_word_size + size_for_padding, Metaspace::commit_alignment_words());
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  2291
  size_t preferred_word_size = align_up(suggested_commit_granularity, Metaspace::commit_alignment_words());
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2292
  if (min_word_size >= preferred_word_size) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2293
    // Can happen when humongous chunks are allocated.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2294
    preferred_word_size = min_word_size;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2295
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2296
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2297
  bool expanded = expand_by(min_word_size, preferred_word_size);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2298
  if (expanded) {
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2299
    next = current_virtual_space()->get_chunk_vs(chunk_word_size);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2300
    assert(next != NULL, "The allocation was expected to succeed after the expansion");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2301
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2302
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2303
   return next;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2304
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2305
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2306
void VirtualSpaceList::print_on(outputStream* st) const {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2307
  VirtualSpaceListIterator iter(virtual_space_list());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2308
  while (iter.repeat()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2309
    VirtualSpaceNode* node = iter.get_next();
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2310
    node->print_on(st);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2311
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2312
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2313
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2314
void VirtualSpaceList::print_map(outputStream* st) const {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2315
  VirtualSpaceNode* list = virtual_space_list();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2316
  VirtualSpaceListIterator iter(list);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2317
  unsigned i = 0;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2318
  while (iter.repeat()) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2319
    st->print_cr("Node %u:", i);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2320
    VirtualSpaceNode* node = iter.get_next();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2321
    node->print_map(st, this->is_class());
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2322
    i ++;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2323
  }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2324
}
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2325
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2326
// MetaspaceGC methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2327
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2328
// VM_CollectForMetadataAllocation is the vm operation used to GC.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2329
// Within the VM operation after the GC the attempt to allocate the metadata
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2330
// should succeed.  If the GC did not free enough space for the metaspace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2331
// allocation, the HWM is increased so that another virtualspace will be
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2332
// allocated for the metadata.  With perm gen the increase in the perm
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2333
// gen had bounds, MinMetaspaceExpansion and MaxMetaspaceExpansion.  The
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2334
// metaspace policy uses those as the small and large steps for the HWM.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2335
//
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2336
// After the GC the compute_new_size() for MetaspaceGC is called to
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2337
// resize the capacity of the metaspaces.  The current implementation
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2338
// is based on the flags MinMetaspaceFreeRatio and MaxMetaspaceFreeRatio used
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2339
// to resize the Java heap by some GC's.  New flags can be implemented
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2340
// if really needed.  MinMetaspaceFreeRatio is used to calculate how much
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2341
// free space is desirable in the metaspace capacity to decide how much
15610
528d799702c7 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 15488
diff changeset
  2342
// to increase the HWM.  MaxMetaspaceFreeRatio is used to decide how much
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2343
// free space is desirable in the metaspace capacity before decreasing
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2344
// the HWM.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2345
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2346
// Calculate the amount to increase the high water mark (HWM).
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2347
// Increase by a minimum amount (MinMetaspaceExpansion) so that
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2348
// another expansion is not requested too soon.  If that is not
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2349
// enough to satisfy the allocation, increase by MaxMetaspaceExpansion.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2350
// If that is still not enough, expand by the size of the allocation
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2351
// plus some.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2352
size_t MetaspaceGC::delta_capacity_until_GC(size_t bytes) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2353
  size_t min_delta = MinMetaspaceExpansion;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2354
  size_t max_delta = MaxMetaspaceExpansion;
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  2355
  size_t delta = align_up(bytes, Metaspace::commit_alignment());
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2356
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2357
  if (delta <= min_delta) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2358
    delta = min_delta;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2359
  } else if (delta <= max_delta) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2360
    // Don't want to hit the high water mark on the next
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2361
    // allocation so make the delta greater than just enough
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2362
    // for this allocation.
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2363
    delta = max_delta;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2364
  } else {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2365
    // This allocation is large but the next ones are probably not
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2366
    // so increase by the minimum.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2367
    delta = delta + min_delta;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2368
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2369
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  2370
  assert_is_aligned(delta, Metaspace::commit_alignment());
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2371
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2372
  return delta;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2373
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2374
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2375
size_t MetaspaceGC::capacity_until_GC() {
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  2376
  size_t value = OrderAccess::load_acquire(&_capacity_until_GC);
27693
3eee985a97e7 8059492: Wrong spelling in assert: "Not initialied properly?"
aharlap
parents: 27683
diff changeset
  2377
  assert(value >= MetaspaceSize, "Not initialized properly?");
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2378
  return value;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2379
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2380
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2381
bool MetaspaceGC::inc_capacity_until_GC(size_t v, size_t* new_cap_until_GC, size_t* old_cap_until_GC) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  2382
  assert_is_aligned(v, Metaspace::commit_alignment());
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2383
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  2384
  intptr_t capacity_until_GC = _capacity_until_GC;
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  2385
  intptr_t new_value = capacity_until_GC + v;
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2386
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2387
  if (new_value < capacity_until_GC) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2388
    // The addition wrapped around, set new_value to aligned max value.
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  2389
    new_value = align_down(max_uintx, Metaspace::commit_alignment());
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2390
  }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2391
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  2392
  intptr_t expected = _capacity_until_GC;
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  2393
  intptr_t actual = Atomic::cmpxchg(new_value, &_capacity_until_GC, expected);
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2394
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2395
  if (expected != actual) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2396
    return false;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2397
  }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2398
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2399
  if (new_cap_until_GC != NULL) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2400
    *new_cap_until_GC = new_value;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2401
  }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2402
  if (old_cap_until_GC != NULL) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2403
    *old_cap_until_GC = capacity_until_GC;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2404
  }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2405
  return true;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2406
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2407
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2408
size_t MetaspaceGC::dec_capacity_until_GC(size_t v) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  2409
  assert_is_aligned(v, Metaspace::commit_alignment());
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2410
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  2411
  return (size_t)Atomic::sub((intptr_t)v, &_capacity_until_GC);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2412
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2413
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2414
void MetaspaceGC::initialize() {
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2415
  // Set the high-water mark to MaxMetapaceSize during VM initializaton since
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2416
  // we can't do a GC during initialization.
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2417
  _capacity_until_GC = MaxMetaspaceSize;
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2418
}
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2419
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2420
void MetaspaceGC::post_initialize() {
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2421
  // Reset the high-water mark once the VM initialization is done.
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2422
  _capacity_until_GC = MAX2(MetaspaceAux::committed_bytes(), MetaspaceSize);
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2423
}
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2424
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2425
bool MetaspaceGC::can_expand(size_t word_size, bool is_class) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2426
  // Check if the compressed class space is full.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2427
  if (is_class && Metaspace::using_class_space()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2428
    size_t class_committed = MetaspaceAux::committed_bytes(Metaspace::ClassType);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2429
    if (class_committed + word_size * BytesPerWord > CompressedClassSpaceSize) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2430
      log_trace(gc, metaspace, freelist)("Cannot expand %s metaspace by " SIZE_FORMAT " words (CompressedClassSpaceSize = " SIZE_FORMAT " words)",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2431
                (is_class ? "class" : "non-class"), word_size, CompressedClassSpaceSize / sizeof(MetaWord));
18491
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  2432
      return false;
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  2433
    }
16391
7bf8a7699f5f 8004241: NPG: Metaspace occupies more memory than specified by -XX:MaxMetaspaceSize option
mgerdin
parents: 16387
diff changeset
  2434
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2435
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2436
  // Check if the user has imposed a limit on the metaspace memory.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2437
  size_t committed_bytes = MetaspaceAux::committed_bytes();
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2438
  if (committed_bytes + word_size * BytesPerWord > MaxMetaspaceSize) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2439
    log_trace(gc, metaspace, freelist)("Cannot expand %s metaspace by " SIZE_FORMAT " words (MaxMetaspaceSize = " SIZE_FORMAT " words)",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2440
              (is_class ? "class" : "non-class"), word_size, MaxMetaspaceSize / sizeof(MetaWord));
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2441
    return false;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2442
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2443
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2444
  return true;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2445
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2446
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2447
size_t MetaspaceGC::allowed_expansion() {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2448
  size_t committed_bytes = MetaspaceAux::committed_bytes();
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2449
  size_t capacity_until_gc = capacity_until_GC();
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2450
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2451
  assert(capacity_until_gc >= committed_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2452
         "capacity_until_gc: " SIZE_FORMAT " < committed_bytes: " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2453
         capacity_until_gc, committed_bytes);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2454
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2455
  size_t left_until_max  = MaxMetaspaceSize - committed_bytes;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2456
  size_t left_until_GC = capacity_until_gc - committed_bytes;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2457
  size_t left_to_commit = MIN2(left_until_GC, left_until_max);
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2458
  log_trace(gc, metaspace, freelist)("allowed expansion words: " SIZE_FORMAT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2459
            " (left_until_max: " SIZE_FORMAT ", left_until_GC: " SIZE_FORMAT ".",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2460
            left_to_commit / BytesPerWord, left_until_max / BytesPerWord, left_until_GC / BytesPerWord);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2461
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2462
  return left_to_commit / BytesPerWord;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2463
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2464
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2465
void MetaspaceGC::compute_new_size() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2466
  assert(_shrink_factor <= 100, "invalid shrink factor");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2467
  uint current_shrink_factor = _shrink_factor;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2468
  _shrink_factor = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2469
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2470
  // Using committed_bytes() for used_after_gc is an overestimation, since the
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2471
  // chunk free lists are included in committed_bytes() and the memory in an
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2472
  // un-fragmented chunk free list is available for future allocations.
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2473
  // However, if the chunk free lists becomes fragmented, then the memory may
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2474
  // not be available for future allocations and the memory is therefore "in use".
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2475
  // Including the chunk free lists in the definition of "in use" is therefore
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2476
  // necessary. Not including the chunk free lists can cause capacity_until_GC to
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2477
  // shrink below committed_bytes() and this has caused serious bugs in the past.
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2478
  const size_t used_after_gc = MetaspaceAux::committed_bytes();
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2479
  const size_t capacity_until_GC = MetaspaceGC::capacity_until_GC();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2480
15610
528d799702c7 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 15488
diff changeset
  2481
  const double minimum_free_percentage = MinMetaspaceFreeRatio / 100.0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2482
  const double maximum_used_percentage = 1.0 - minimum_free_percentage;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2483
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2484
  const double min_tmp = used_after_gc / maximum_used_percentage;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2485
  size_t minimum_desired_capacity =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2486
    (size_t)MIN2(min_tmp, double(max_uintx));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2487
  // Don't shrink less than the initial generation size
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2488
  minimum_desired_capacity = MAX2(minimum_desired_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2489
                                  MetaspaceSize);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2490
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2491
  log_trace(gc, metaspace)("MetaspaceGC::compute_new_size: ");
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2492
  log_trace(gc, metaspace)("    minimum_free_percentage: %6.2f  maximum_used_percentage: %6.2f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2493
                           minimum_free_percentage, maximum_used_percentage);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2494
  log_trace(gc, metaspace)("     used_after_gc       : %6.1fKB", used_after_gc / (double) K);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2495
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2496
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2497
  size_t shrink_bytes = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2498
  if (capacity_until_GC < minimum_desired_capacity) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2499
    // If we have less capacity below the metaspace HWM, then
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2500
    // increment the HWM.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2501
    size_t expand_bytes = minimum_desired_capacity - capacity_until_GC;
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  2502
    expand_bytes = align_up(expand_bytes, Metaspace::commit_alignment());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2503
    // Don't expand unless it's significant
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2504
    if (expand_bytes >= MinMetaspaceExpansion) {
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2505
      size_t new_capacity_until_GC = 0;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2506
      bool succeeded = MetaspaceGC::inc_capacity_until_GC(expand_bytes, &new_capacity_until_GC);
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2507
      assert(succeeded, "Should always succesfully increment HWM when at safepoint");
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2508
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  2509
      Metaspace::tracer()->report_gc_threshold(capacity_until_GC,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  2510
                                               new_capacity_until_GC,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  2511
                                               MetaspaceGCThresholdUpdater::ComputeNewSize);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2512
      log_trace(gc, metaspace)("    expanding:  minimum_desired_capacity: %6.1fKB  expand_bytes: %6.1fKB  MinMetaspaceExpansion: %6.1fKB  new metaspace HWM:  %6.1fKB",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2513
                               minimum_desired_capacity / (double) K,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2514
                               expand_bytes / (double) K,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2515
                               MinMetaspaceExpansion / (double) K,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2516
                               new_capacity_until_GC / (double) K);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2517
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2518
    return;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2519
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2520
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2521
  // No expansion, now see if we want to shrink
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2522
  // We would never want to shrink more than this
22499
33777708d0fc 8031779: Assert in MetaspaceGC is always true
ehelin
parents: 22248
diff changeset
  2523
  assert(capacity_until_GC >= minimum_desired_capacity,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2524
         SIZE_FORMAT " >= " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2525
         capacity_until_GC, minimum_desired_capacity);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2526
  size_t max_shrink_bytes = capacity_until_GC - minimum_desired_capacity;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2527
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2528
  // Should shrinking be considered?
15610
528d799702c7 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 15488
diff changeset
  2529
  if (MaxMetaspaceFreeRatio < 100) {
528d799702c7 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 15488
diff changeset
  2530
    const double maximum_free_percentage = MaxMetaspaceFreeRatio / 100.0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2531
    const double minimum_used_percentage = 1.0 - maximum_free_percentage;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2532
    const double max_tmp = used_after_gc / minimum_used_percentage;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2533
    size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2534
    maximum_desired_capacity = MAX2(maximum_desired_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2535
                                    MetaspaceSize);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2536
    log_trace(gc, metaspace)("    maximum_free_percentage: %6.2f  minimum_used_percentage: %6.2f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2537
                             maximum_free_percentage, minimum_used_percentage);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2538
    log_trace(gc, metaspace)("    minimum_desired_capacity: %6.1fKB  maximum_desired_capacity: %6.1fKB",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2539
                             minimum_desired_capacity / (double) K, maximum_desired_capacity / (double) K);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2540
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2541
    assert(minimum_desired_capacity <= maximum_desired_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2542
           "sanity check");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2543
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2544
    if (capacity_until_GC > maximum_desired_capacity) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2545
      // Capacity too large, compute shrinking size
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2546
      shrink_bytes = capacity_until_GC - maximum_desired_capacity;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2547
      // We don't want shrink all the way back to initSize if people call
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2548
      // System.gc(), because some programs do that between "phases" and then
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2549
      // we'd just have to grow the heap up again for the next phase.  So we
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2550
      // damp the shrinking: 0% on the first call, 10% on the second call, 40%
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2551
      // on the third call, and 100% by the fourth call.  But if we recompute
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2552
      // size without shrinking, it goes back to 0%.
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2553
      shrink_bytes = shrink_bytes / 100 * current_shrink_factor;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2554
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  2555
      shrink_bytes = align_down(shrink_bytes, Metaspace::commit_alignment());
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2556
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2557
      assert(shrink_bytes <= max_shrink_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2558
             "invalid shrink size " SIZE_FORMAT " not <= " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2559
             shrink_bytes, max_shrink_bytes);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2560
      if (current_shrink_factor == 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2561
        _shrink_factor = 10;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2562
      } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2563
        _shrink_factor = MIN2(current_shrink_factor * 4, (uint) 100);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2564
      }
37151
bcda1fb89431 8151845: Comment in globals.hpp for MetaspaceSize is incorrect.
jmasa
parents: 37139
diff changeset
  2565
      log_trace(gc, metaspace)("    shrinking:  initThreshold: %.1fK  maximum_desired_capacity: %.1fK",
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2566
                               MetaspaceSize / (double) K, maximum_desired_capacity / (double) K);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2567
      log_trace(gc, metaspace)("    shrink_bytes: %.1fK  current_shrink_factor: %d  new shrink factor: %d  MinMetaspaceExpansion: %.1fK",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2568
                               shrink_bytes / (double) K, current_shrink_factor, _shrink_factor, MinMetaspaceExpansion / (double) K);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2569
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2570
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2571
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2572
  // Don't shrink unless it's significant
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2573
  if (shrink_bytes >= MinMetaspaceExpansion &&
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2574
      ((capacity_until_GC - shrink_bytes) >= MetaspaceSize)) {
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  2575
    size_t new_capacity_until_GC = MetaspaceGC::dec_capacity_until_GC(shrink_bytes);
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  2576
    Metaspace::tracer()->report_gc_threshold(capacity_until_GC,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  2577
                                             new_capacity_until_GC,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  2578
                                             MetaspaceGCThresholdUpdater::ComputeNewSize);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2579
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2580
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2581
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2582
// Metadebug methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2583
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2584
void Metadebug::init_allocation_fail_alot_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2585
  if (MetadataAllocationFailALot) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2586
    _allocation_fail_alot_count =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2587
      1+(long)((double)MetadataAllocationFailALotInterval*os::random()/(max_jint+1.0));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2588
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2589
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2590
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2591
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2592
bool Metadebug::test_metadata_failure() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2593
  if (MetadataAllocationFailALot &&
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2594
      Threads::is_vm_complete()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2595
    if (_allocation_fail_alot_count > 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2596
      _allocation_fail_alot_count--;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2597
    } else {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2598
      log_trace(gc, metaspace, freelist)("Metadata allocation failing for MetadataAllocationFailALot");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2599
      init_allocation_fail_alot_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2600
      return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2601
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2602
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2603
  return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2604
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2605
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2606
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2607
// ChunkManager methods
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2608
size_t ChunkManager::free_chunks_total_words() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2609
  return _free_chunks_total;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2610
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2611
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2612
size_t ChunkManager::free_chunks_total_bytes() {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2613
  return free_chunks_total_words() * BytesPerWord;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2614
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2615
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2616
// Update internal accounting after a chunk was added
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2617
void ChunkManager::account_for_added_chunk(const Metachunk* c) {
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2618
  assert_lock_strong(SpaceManager::expand_lock());
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2619
  _free_chunks_count ++;
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2620
  _free_chunks_total += c->word_size();
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2621
}
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2622
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2623
// Update internal accounting after a chunk was removed
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2624
void ChunkManager::account_for_removed_chunk(const Metachunk* c) {
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2625
  assert_lock_strong(SpaceManager::expand_lock());
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2626
  assert(_free_chunks_count >= 1,
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2627
    "ChunkManager::_free_chunks_count: about to go negative (" SIZE_FORMAT ").", _free_chunks_count);
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2628
  assert(_free_chunks_total >= c->word_size(),
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2629
    "ChunkManager::_free_chunks_total: about to go negative"
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2630
     "(now: " SIZE_FORMAT ", decrement value: " SIZE_FORMAT ").", _free_chunks_total, c->word_size());
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2631
  _free_chunks_count --;
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2632
  _free_chunks_total -= c->word_size();
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2633
}
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2634
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2635
size_t ChunkManager::free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2636
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2637
  if (!UseConcMarkSweepGC && !SpaceManager::expand_lock()->is_locked()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2638
    MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2639
                     Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2640
    // This lock is only needed in debug because the verification
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2641
    // of the _free_chunks_totals walks the list of free chunks
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2642
    slow_locked_verify_free_chunks_count();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2643
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2644
#endif
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2645
  return _free_chunks_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2646
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2647
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2648
ChunkIndex ChunkManager::list_index(size_t size) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2649
  if (size_by_index(SpecializedIndex) == size) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2650
    return SpecializedIndex;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2651
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2652
  if (size_by_index(SmallIndex) == size) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2653
    return SmallIndex;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2654
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2655
  const size_t med_size = size_by_index(MediumIndex);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2656
  if (med_size == size) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2657
    return MediumIndex;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2658
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2659
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2660
  assert(size > med_size, "Not a humongous chunk");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2661
  return HumongousIndex;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2662
}
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2663
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2664
size_t ChunkManager::size_by_index(ChunkIndex index) const {
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2665
  index_bounds_check(index);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2666
  assert(index != HumongousIndex, "Do not call for humongous chunks.");
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2667
  return _free_chunks[index].size();
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2668
}
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2669
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2670
void ChunkManager::locked_verify_free_chunks_total() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2671
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2672
  assert(sum_free_chunks() == _free_chunks_total,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2673
         "_free_chunks_total " SIZE_FORMAT " is not the"
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2674
         " same as sum " SIZE_FORMAT, _free_chunks_total,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2675
         sum_free_chunks());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2676
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2677
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2678
void ChunkManager::verify_free_chunks_total() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2679
  MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2680
                     Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2681
  locked_verify_free_chunks_total();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2682
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2683
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2684
void ChunkManager::locked_verify_free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2685
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2686
  assert(sum_free_chunks_count() == _free_chunks_count,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2687
         "_free_chunks_count " SIZE_FORMAT " is not the"
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2688
         " same as sum " SIZE_FORMAT, _free_chunks_count,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2689
         sum_free_chunks_count());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2690
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2691
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2692
void ChunkManager::verify_free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2693
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2694
  MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2695
                     Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2696
  locked_verify_free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2697
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2698
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2699
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2700
void ChunkManager::verify() {
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2701
  MutexLockerEx cl(SpaceManager::expand_lock(),
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2702
                     Mutex::_no_safepoint_check_flag);
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2703
  locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2704
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2705
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2706
void ChunkManager::locked_verify() {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2707
  locked_verify_free_chunks_count();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2708
  locked_verify_free_chunks_total();
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2709
  for (ChunkIndex i = ZeroIndex; i < NumberOfFreeLists; i = next_chunk_index(i)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2710
    ChunkList* list = free_chunks(i);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2711
    if (list != NULL) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2712
      Metachunk* chunk = list->head();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2713
      while (chunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2714
        DEBUG_ONLY(do_verify_chunk(chunk);)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2715
        assert(chunk->is_tagged_free(), "Chunk should be tagged as free.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2716
        chunk = chunk->next();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2717
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2718
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2719
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2720
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2721
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2722
void ChunkManager::locked_print_free_chunks(outputStream* st) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2723
  assert_lock_strong(SpaceManager::expand_lock());
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2724
  st->print_cr("Free chunk total " SIZE_FORMAT "  count " SIZE_FORMAT,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2725
                _free_chunks_total, _free_chunks_count);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2726
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2727
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2728
void ChunkManager::locked_print_sum_free_chunks(outputStream* st) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2729
  assert_lock_strong(SpaceManager::expand_lock());
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2730
  st->print_cr("Sum free chunk total " SIZE_FORMAT "  count " SIZE_FORMAT,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2731
                sum_free_chunks(), sum_free_chunks_count());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2732
}
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  2733
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2734
ChunkList* ChunkManager::free_chunks(ChunkIndex index) {
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  2735
  assert(index == SpecializedIndex || index == SmallIndex || index == MediumIndex,
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  2736
         "Bad index: %d", (int)index);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  2737
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2738
  return &_free_chunks[index];
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2739
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2740
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2741
// These methods that sum the free chunk lists are used in printing
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2742
// methods that are used in product builds.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2743
size_t ChunkManager::sum_free_chunks() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2744
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2745
  size_t result = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2746
  for (ChunkIndex i = ZeroIndex; i < NumberOfFreeLists; i = next_chunk_index(i)) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2747
    ChunkList* list = free_chunks(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2748
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2749
    if (list == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2750
      continue;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2751
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2752
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2753
    result = result + list->count() * list->size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2754
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2755
  result = result + humongous_dictionary()->total_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2756
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2757
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2758
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2759
size_t ChunkManager::sum_free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2760
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2761
  size_t count = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2762
  for (ChunkIndex i = ZeroIndex; i < NumberOfFreeLists; i = next_chunk_index(i)) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2763
    ChunkList* list = free_chunks(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2764
    if (list == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2765
      continue;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2766
    }
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2767
    count = count + list->count();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2768
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2769
  count = count + humongous_dictionary()->total_free_blocks();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2770
  return count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2771
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2772
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2773
ChunkList* ChunkManager::find_free_chunks_list(size_t word_size) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2774
  ChunkIndex index = list_index(word_size);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2775
  assert(index < HumongousIndex, "No humongous list");
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2776
  return free_chunks(index);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2777
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2778
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2779
// Helper for chunk splitting: given a target chunk size and a larger free chunk,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2780
// split up the larger chunk into n smaller chunks, at least one of which should be
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2781
// the target chunk of target chunk size. The smaller chunks, including the target
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2782
// chunk, are returned to the freelist. The pointer to the target chunk is returned.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2783
// Note that this chunk is supposed to be removed from the freelist right away.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2784
Metachunk* ChunkManager::split_chunk(size_t target_chunk_word_size, Metachunk* larger_chunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2785
  assert(larger_chunk->word_size() > target_chunk_word_size, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2786
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2787
  const ChunkIndex larger_chunk_index = larger_chunk->get_chunk_type();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2788
  const ChunkIndex target_chunk_index = get_chunk_type_by_size(target_chunk_word_size, is_class());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2789
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2790
  MetaWord* const region_start = (MetaWord*)larger_chunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2791
  const size_t region_word_len = larger_chunk->word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2792
  MetaWord* const region_end = region_start + region_word_len;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2793
  VirtualSpaceNode* const vsn = larger_chunk->container();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2794
  OccupancyMap* const ocmap = vsn->occupancy_map();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2795
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2796
  // Any larger non-humongous chunk size is a multiple of any smaller chunk size.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2797
  // Since non-humongous chunks are aligned to their chunk size, the larger chunk should start
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2798
  // at an address suitable to place the smaller target chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2799
  assert_is_aligned(region_start, target_chunk_word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2800
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2801
  // Remove old chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2802
  free_chunks(larger_chunk_index)->remove_chunk(larger_chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2803
  larger_chunk->remove_sentinel();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2804
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2805
  // Prevent access to the old chunk from here on.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2806
  larger_chunk = NULL;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2807
  // ... and wipe it.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2808
  DEBUG_ONLY(memset(region_start, 0xfe, region_word_len * BytesPerWord));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2809
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2810
  // In its place create first the target chunk...
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2811
  MetaWord* p = region_start;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2812
  Metachunk* target_chunk = ::new (p) Metachunk(target_chunk_index, is_class(), target_chunk_word_size, vsn);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2813
  assert(target_chunk == (Metachunk*)p, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2814
  target_chunk->set_origin(origin_split);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2815
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2816
  // Note: we do not need to mark its start in the occupancy map
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2817
  // because it coincides with the old chunk start.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2818
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2819
  // Mark chunk as free and return to the freelist.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2820
  do_update_in_use_info_for_chunk(target_chunk, false);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2821
  free_chunks(target_chunk_index)->return_chunk_at_head(target_chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2822
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2823
  // This chunk should now be valid and can be verified.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2824
  DEBUG_ONLY(do_verify_chunk(target_chunk));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2825
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2826
  // In the remaining space create the remainder chunks.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2827
  p += target_chunk->word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2828
  assert(p < region_end, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2829
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2830
  while (p < region_end) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2831
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2832
    // Find the largest chunk size which fits the alignment requirements at address p.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2833
    ChunkIndex this_chunk_index = prev_chunk_index(larger_chunk_index);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2834
    size_t this_chunk_word_size = 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2835
    for(;;) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2836
      this_chunk_word_size = get_size_for_nonhumongous_chunktype(this_chunk_index, is_class());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2837
      if (is_aligned(p, this_chunk_word_size * BytesPerWord)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2838
        break;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2839
      } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2840
        this_chunk_index = prev_chunk_index(this_chunk_index);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2841
        assert(this_chunk_index >= target_chunk_index, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2842
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2843
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2844
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2845
    assert(this_chunk_word_size >= target_chunk_word_size, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2846
    assert(is_aligned(p, this_chunk_word_size * BytesPerWord), "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2847
    assert(p + this_chunk_word_size <= region_end, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2848
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2849
    // Create splitting chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2850
    Metachunk* this_chunk = ::new (p) Metachunk(this_chunk_index, is_class(), this_chunk_word_size, vsn);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2851
    assert(this_chunk == (Metachunk*)p, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2852
    this_chunk->set_origin(origin_split);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2853
    ocmap->set_chunk_starts_at_address(p, true);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2854
    do_update_in_use_info_for_chunk(this_chunk, false);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2855
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2856
    // This chunk should be valid and can be verified.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2857
    DEBUG_ONLY(do_verify_chunk(this_chunk));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2858
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2859
    // Return this chunk to freelist and correct counter.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2860
    free_chunks(this_chunk_index)->return_chunk_at_head(this_chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2861
    _free_chunks_count ++;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2862
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2863
    log_trace(gc, metaspace, freelist)("Created chunk at " PTR_FORMAT ", word size "
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2864
      SIZE_FORMAT_HEX " (%s), in split region [" PTR_FORMAT "..." PTR_FORMAT ").",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2865
      p2i(this_chunk), this_chunk->word_size(), chunk_size_name(this_chunk_index),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2866
      p2i(region_start), p2i(region_end));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2867
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2868
    p += this_chunk_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2869
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2870
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2871
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2872
  return target_chunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2873
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2874
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2875
Metachunk* ChunkManager::free_chunks_get(size_t word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2876
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2877
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2878
  slow_locked_verify();
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2879
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2880
  Metachunk* chunk = NULL;
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2881
  bool we_did_split_a_chunk = false;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2882
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2883
  if (list_index(word_size) != HumongousIndex) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2884
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2885
    ChunkList* free_list = find_free_chunks_list(word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2886
    assert(free_list != NULL, "Sanity check");
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2887
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2888
    chunk = free_list->head();
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2889
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2890
    if (chunk == NULL) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2891
      // Split large chunks into smaller chunks if there are no smaller chunks, just large chunks.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2892
      // This is the counterpart of the coalescing-upon-chunk-return.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2893
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2894
      ChunkIndex target_chunk_index = get_chunk_type_by_size(word_size, is_class());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2895
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2896
      // Is there a larger chunk we could split?
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2897
      Metachunk* larger_chunk = NULL;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2898
      ChunkIndex larger_chunk_index = next_chunk_index(target_chunk_index);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2899
      while (larger_chunk == NULL && larger_chunk_index < NumberOfFreeLists) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2900
        larger_chunk = free_chunks(larger_chunk_index)->head();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2901
        if (larger_chunk == NULL) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2902
          larger_chunk_index = next_chunk_index(larger_chunk_index);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2903
        }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2904
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2905
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2906
      if (larger_chunk != NULL) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2907
        assert(larger_chunk->word_size() > word_size, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2908
        assert(larger_chunk->get_chunk_type() == larger_chunk_index, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2909
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2910
        // We found a larger chunk. Lets split it up:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2911
        // - remove old chunk
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2912
        // - in its place, create new smaller chunks, with at least one chunk
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2913
        //   being of target size, the others sized as large as possible. This
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2914
        //   is to make sure the resulting chunks are "as coalesced as possible"
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2915
        //   (similar to VirtualSpaceNode::retire()).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2916
        // Note: during this operation both ChunkManager and VirtualSpaceNode
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2917
        //  are temporarily invalid, so be careful with asserts.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2918
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2919
        log_trace(gc, metaspace, freelist)("%s: splitting chunk " PTR_FORMAT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2920
           ", word size " SIZE_FORMAT_HEX " (%s), to get a chunk of word size " SIZE_FORMAT_HEX " (%s)...",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2921
          (is_class() ? "class space" : "metaspace"), p2i(larger_chunk), larger_chunk->word_size(),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2922
          chunk_size_name(larger_chunk_index), word_size, chunk_size_name(target_chunk_index));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2923
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2924
        chunk = split_chunk(word_size, larger_chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2925
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2926
        // This should have worked.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2927
        assert(chunk != NULL, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2928
        assert(chunk->word_size() == word_size, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2929
        assert(chunk->is_tagged_free(), "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2930
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2931
        we_did_split_a_chunk = true;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2932
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2933
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2934
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2935
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2936
    if (chunk == NULL) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2937
      return NULL;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2938
    }
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2939
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2940
    // Remove the chunk as the head of the list.
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2941
    free_list->remove_chunk(chunk);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2942
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2943
    log_trace(gc, metaspace, freelist)("ChunkManager::free_chunks_get: free_list: " PTR_FORMAT " chunks left: " SSIZE_FORMAT ".",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2944
                                       p2i(free_list), free_list->count());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2945
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2946
  } else {
46674
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46625
diff changeset
  2947
    chunk = humongous_dictionary()->get_chunk(word_size);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2948
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2949
    if (chunk == NULL) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2950
      return NULL;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2951
    }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2952
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2953
    log_debug(gc, metaspace, alloc)("Free list allocate humongous chunk size " SIZE_FORMAT " for requested size " SIZE_FORMAT " waste " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2954
                                    chunk->word_size(), word_size, chunk->word_size() - word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2955
  }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2956
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2957
  // Chunk has been removed from the chunk manager; update counters.
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2958
  account_for_removed_chunk(chunk);
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2959
  do_update_in_use_info_for_chunk(chunk, true);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2960
  chunk->container()->inc_container_count();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2961
  chunk->inc_use_count();
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2962
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2963
  // Remove it from the links to this freelist
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2964
  chunk->set_next(NULL);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2965
  chunk->set_prev(NULL);
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2966
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2967
  // Run some verifications (some more if we did a chunk split)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2968
#ifdef ASSERT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2969
  locked_verify();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2970
  VirtualSpaceNode* const vsn = chunk->container();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2971
  vsn->verify();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2972
  if (we_did_split_a_chunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2973
    vsn->verify_free_chunks_are_ideally_merged();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2974
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2975
#endif
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2976
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2977
  return chunk;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2978
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2979
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2980
Metachunk* ChunkManager::chunk_freelist_allocate(size_t word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2981
  assert_lock_strong(SpaceManager::expand_lock());
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2982
  slow_locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2983
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2984
  // Take from the beginning of the list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2985
  Metachunk* chunk = free_chunks_get(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2986
  if (chunk == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2987
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2988
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2989
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2990
  assert((word_size <= chunk->word_size()) ||
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  2991
         (list_index(chunk->word_size()) == HumongousIndex),
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2992
         "Non-humongous variable sized chunk");
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2993
  LogTarget(Debug, gc, metaspace, freelist) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2994
  if (lt.is_enabled()) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2995
    size_t list_count;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2996
    if (list_index(word_size) < HumongousIndex) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2997
      ChunkList* list = find_free_chunks_list(word_size);
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2998
      list_count = list->count();
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2999
    } else {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3000
      list_count = humongous_dictionary()->total_count();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3001
    }
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3002
    LogStream ls(lt);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3003
    ls.print("ChunkManager::chunk_freelist_allocate: " PTR_FORMAT " chunk " PTR_FORMAT "  size " SIZE_FORMAT " count " SIZE_FORMAT " ",
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3004
             p2i(this), p2i(chunk), chunk->word_size(), list_count);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3005
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3006
    locked_print_free_chunks(&ls);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3007
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3008
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3009
  return chunk;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3010
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3011
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3012
void ChunkManager::return_single_chunk(ChunkIndex index, Metachunk* chunk) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3013
  assert_lock_strong(SpaceManager::expand_lock());
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3014
  DEBUG_ONLY(do_verify_chunk(chunk);)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3015
  assert(chunk->get_chunk_type() == index, "Chunk does not match expected index.");
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3016
  assert(chunk != NULL, "Expected chunk.");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3017
  assert(chunk->container() != NULL, "Container should have been set.");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3018
  assert(chunk->is_tagged_free() == false, "Chunk should be in use.");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3019
  index_bounds_check(index);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3020
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3021
  // Note: mangle *before* returning the chunk to the freelist or dictionary. It does not
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3022
  // matter for the freelist (non-humongous chunks), but the humongous chunk dictionary
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3023
  // keeps tree node pointers in the chunk payload area which mangle will overwrite.
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3024
  DEBUG_ONLY(chunk->mangle(badMetaWordVal);)
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3025
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3026
  if (index != HumongousIndex) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3027
    // Return non-humongous chunk to freelist.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3028
    ChunkList* list = free_chunks(index);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3029
    assert(list->size() == chunk->word_size(), "Wrong chunk type.");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3030
    list->return_chunk_at_head(chunk);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3031
    log_trace(gc, metaspace, freelist)("returned one %s chunk at " PTR_FORMAT " to freelist.",
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3032
        chunk_size_name(index), p2i(chunk));
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3033
  } else {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3034
    // Return humongous chunk to dictionary.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3035
    assert(chunk->word_size() > free_chunks(MediumIndex)->size(), "Wrong chunk type.");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3036
    assert(chunk->word_size() % free_chunks(SpecializedIndex)->size() == 0,
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3037
           "Humongous chunk has wrong alignment.");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3038
    _humongous_dictionary.return_chunk(chunk);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3039
    log_trace(gc, metaspace, freelist)("returned one %s chunk at " PTR_FORMAT " (word size " SIZE_FORMAT ") to freelist.",
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3040
        chunk_size_name(index), p2i(chunk), chunk->word_size());
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3041
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3042
  chunk->container()->dec_container_count();
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3043
  do_update_in_use_info_for_chunk(chunk, false);
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3044
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  3045
  // Chunk has been added; update counters.
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  3046
  account_for_added_chunk(chunk);
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  3047
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3048
  // Attempt coalesce returned chunks with its neighboring chunks:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3049
  // if this chunk is small or special, attempt to coalesce to a medium chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3050
  if (index == SmallIndex || index == SpecializedIndex) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3051
    if (!attempt_to_coalesce_around_chunk(chunk, MediumIndex)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3052
      // This did not work. But if this chunk is special, we still may form a small chunk?
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3053
      if (index == SpecializedIndex) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3054
        if (!attempt_to_coalesce_around_chunk(chunk, SmallIndex)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3055
          // give up.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3056
        }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3057
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3058
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3059
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3060
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3061
}
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3062
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3063
void ChunkManager::return_chunk_list(ChunkIndex index, Metachunk* chunks) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3064
  index_bounds_check(index);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3065
  if (chunks == NULL) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3066
    return;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3067
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3068
  LogTarget(Trace, gc, metaspace, freelist) log;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3069
  if (log.is_enabled()) { // tracing
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3070
    log.print("returning list of %s chunks...", chunk_size_name(index));
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3071
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3072
  unsigned num_chunks_returned = 0;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3073
  size_t size_chunks_returned = 0;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3074
  Metachunk* cur = chunks;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3075
  while (cur != NULL) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3076
    // Capture the next link before it is changed
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3077
    // by the call to return_chunk_at_head();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3078
    Metachunk* next = cur->next();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3079
    if (log.is_enabled()) { // tracing
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3080
      num_chunks_returned ++;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3081
      size_chunks_returned += cur->word_size();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3082
    }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3083
    return_single_chunk(index, cur);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3084
    cur = next;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3085
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3086
  if (log.is_enabled()) { // tracing
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3087
    log.print("returned %u %s chunks to freelist, total word size " SIZE_FORMAT ".",
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3088
        num_chunks_returned, chunk_size_name(index), size_chunks_returned);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3089
    if (index != HumongousIndex) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3090
      log.print("updated freelist count: " SIZE_FORMAT ".", free_chunks(index)->size());
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3091
    } else {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3092
      log.print("updated dictionary count " SIZE_FORMAT ".", _humongous_dictionary.total_count());
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3093
    }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3094
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3095
}
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3096
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3097
void ChunkManager::print_on(outputStream* out) const {
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3098
  _humongous_dictionary.report_statistics(out);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3099
}
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3100
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3101
void ChunkManager::locked_get_statistics(ChunkManagerStatistics* stat) const {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3102
  assert_lock_strong(SpaceManager::expand_lock());
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3103
  for (ChunkIndex i = ZeroIndex; i < NumberOfFreeLists; i = next_chunk_index(i)) {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3104
    stat->num_by_type[i] = num_free_chunks(i);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3105
    stat->single_size_by_type[i] = size_by_index(i);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3106
    stat->total_size_by_type[i] = size_free_chunks_in_bytes(i);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3107
  }
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3108
  stat->num_humongous_chunks = num_free_chunks(HumongousIndex);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3109
  stat->total_size_humongous_chunks = size_free_chunks_in_bytes(HumongousIndex);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3110
}
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3111
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3112
void ChunkManager::get_statistics(ChunkManagerStatistics* stat) const {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3113
  MutexLockerEx cl(SpaceManager::expand_lock(),
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3114
                   Mutex::_no_safepoint_check_flag);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3115
  locked_get_statistics(stat);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3116
}
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3117
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3118
void ChunkManager::print_statistics(const ChunkManagerStatistics* stat, outputStream* out, size_t scale) {
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3119
  size_t total = 0;
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3120
  assert(scale == 1 || scale == K || scale == M || scale == G, "Invalid scale");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3121
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3122
  const char* unit = scale_unit(scale);
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3123
  for (ChunkIndex i = ZeroIndex; i < NumberOfFreeLists; i = next_chunk_index(i)) {
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3124
    out->print("  " SIZE_FORMAT " %s (" SIZE_FORMAT " bytes) chunks, total ",
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3125
                   stat->num_by_type[i], chunk_size_name(i),
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3126
                   stat->single_size_by_type[i]);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3127
    if (scale == 1) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3128
      out->print_cr(SIZE_FORMAT " bytes", stat->total_size_by_type[i]);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3129
    } else {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3130
      out->print_cr("%.2f%s", (float)stat->total_size_by_type[i] / scale, unit);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3131
    }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3132
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3133
    total += stat->total_size_by_type[i];
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3134
  }
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3135
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3136
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3137
  total += stat->total_size_humongous_chunks;
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3138
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3139
  if (scale == 1) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3140
    out->print_cr("  " SIZE_FORMAT " humongous chunks, total " SIZE_FORMAT " bytes",
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3141
    stat->num_humongous_chunks, stat->total_size_humongous_chunks);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3142
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3143
    out->print_cr("  total size: " SIZE_FORMAT " bytes.", total);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3144
  } else {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3145
    out->print_cr("  " SIZE_FORMAT " humongous chunks, total %.2f%s",
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3146
    stat->num_humongous_chunks,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3147
    (float)stat->total_size_humongous_chunks / scale, unit);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3148
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3149
    out->print_cr("  total size: %.2f%s.", (float)total / scale, unit);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3150
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3151
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3152
}
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3153
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3154
void ChunkManager::print_all_chunkmanagers(outputStream* out, size_t scale) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3155
  assert(scale == 1 || scale == K || scale == M || scale == G, "Invalid scale");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3156
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3157
  // Note: keep lock protection only to retrieving statistics; keep printing
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3158
  // out of lock protection
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3159
  ChunkManagerStatistics stat;
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3160
  out->print_cr("Chunkmanager (non-class):");
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3161
  const ChunkManager* const non_class_cm = Metaspace::chunk_manager_metadata();
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3162
  if (non_class_cm != NULL) {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3163
    non_class_cm->get_statistics(&stat);
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3164
    ChunkManager::print_statistics(&stat, out, scale);
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3165
  } else {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3166
    out->print_cr("unavailable.");
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3167
  }
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3168
  out->print_cr("Chunkmanager (class):");
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3169
  const ChunkManager* const class_cm = Metaspace::chunk_manager_class();
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3170
  if (class_cm != NULL) {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3171
    class_cm->get_statistics(&stat);
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3172
    ChunkManager::print_statistics(&stat, out, scale);
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3173
  } else {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3174
    out->print_cr("unavailable.");
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3175
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3176
}
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3177
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3178
// SpaceManager methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3179
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3180
size_t SpaceManager::adjust_initial_chunk_size(size_t requested, bool is_class_space) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3181
  size_t chunk_sizes[] = {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3182
      specialized_chunk_size(is_class_space),
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3183
      small_chunk_size(is_class_space),
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3184
      medium_chunk_size(is_class_space)
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3185
  };
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3186
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3187
  // Adjust up to one of the fixed chunk sizes ...
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3188
  for (size_t i = 0; i < ARRAY_SIZE(chunk_sizes); i++) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3189
    if (requested <= chunk_sizes[i]) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3190
      return chunk_sizes[i];
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3191
    }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3192
  }
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3193
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3194
  // ... or return the size as a humongous chunk.
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3195
  return requested;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3196
}
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3197
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3198
size_t SpaceManager::adjust_initial_chunk_size(size_t requested) const {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3199
  return adjust_initial_chunk_size(requested, is_class());
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3200
}
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3201
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3202
size_t SpaceManager::get_initial_chunk_size(Metaspace::MetaspaceType type) const {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3203
  size_t requested;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3204
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3205
  if (is_class()) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3206
    switch (type) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3207
    case Metaspace::BootMetaspaceType:       requested = Metaspace::first_class_chunk_word_size(); break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3208
    case Metaspace::AnonymousMetaspaceType:  requested = ClassSpecializedChunk; break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3209
    case Metaspace::ReflectionMetaspaceType: requested = ClassSpecializedChunk; break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3210
    default:                                 requested = ClassSmallChunk; break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3211
    }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3212
  } else {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3213
    switch (type) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3214
    case Metaspace::BootMetaspaceType:       requested = Metaspace::first_chunk_word_size(); break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3215
    case Metaspace::AnonymousMetaspaceType:  requested = SpecializedChunk; break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3216
    case Metaspace::ReflectionMetaspaceType: requested = SpecializedChunk; break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3217
    default:                                 requested = SmallChunk; break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3218
    }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3219
  }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3220
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3221
  // Adjust to one of the fixed chunk sizes (unless humongous)
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3222
  const size_t adjusted = adjust_initial_chunk_size(requested);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3223
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3224
  assert(adjusted != 0, "Incorrect initial chunk size. Requested: "
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3225
         SIZE_FORMAT " adjusted: " SIZE_FORMAT, requested, adjusted);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3226
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3227
  return adjusted;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3228
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3229
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3230
size_t SpaceManager::sum_free_in_chunks_in_use() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3231
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3232
  size_t free = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3233
  for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3234
    Metachunk* chunk = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3235
    while (chunk != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3236
      free += chunk->free_word_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3237
      chunk = chunk->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3238
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3239
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3240
  return free;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3241
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3242
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3243
size_t SpaceManager::sum_waste_in_chunks_in_use() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3244
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3245
  size_t result = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3246
  for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3247
   result += sum_waste_in_chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3248
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3249
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3250
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3251
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3252
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3253
size_t SpaceManager::sum_waste_in_chunks_in_use(ChunkIndex index) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3254
  size_t result = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3255
  Metachunk* chunk = chunks_in_use(index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3256
  // Count the free space in all the chunk but not the
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3257
  // current chunk from which allocations are still being done.
18491
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  3258
  while (chunk != NULL) {
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  3259
    if (chunk != current_chunk()) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3260
      result += chunk->free_word_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3261
    }
18491
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  3262
    chunk = chunk->next();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3263
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3264
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3265
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3266
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3267
size_t SpaceManager::sum_capacity_in_chunks_in_use() const {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3268
  // For CMS use "allocated_chunks_words()" which does not need the
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3269
  // Metaspace lock.  For the other collectors sum over the
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3270
  // lists.  Use both methods as a check that "allocated_chunks_words()"
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3271
  // is correct.  That is, sum_capacity_in_chunks() is too expensive
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3272
  // to use in the product and allocated_chunks_words() should be used
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3273
  // but allow for  checking that allocated_chunks_words() returns the same
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3274
  // value as sum_capacity_in_chunks_in_use() which is the definitive
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3275
  // answer.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3276
  if (UseConcMarkSweepGC) {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3277
    return allocated_chunks_words();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3278
  } else {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3279
    MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3280
    size_t sum = 0;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3281
    for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3282
      Metachunk* chunk = chunks_in_use(i);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3283
      while (chunk != NULL) {
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3284
        sum += chunk->word_size();
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3285
        chunk = chunk->next();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3286
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3287
    }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3288
  return sum;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3289
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3290
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3291
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3292
size_t SpaceManager::sum_count_in_chunks_in_use() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3293
  size_t count = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3294
  for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3295
    count = count + sum_count_in_chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3296
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3297
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3298
  return count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3299
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3300
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3301
size_t SpaceManager::sum_count_in_chunks_in_use(ChunkIndex i) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3302
  size_t count = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3303
  Metachunk* chunk = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3304
  while (chunk != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3305
    count++;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3306
    chunk = chunk->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3307
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3308
  return count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3309
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3310
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3311
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3312
size_t SpaceManager::sum_used_in_chunks_in_use() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3313
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3314
  size_t used = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3315
  for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3316
    Metachunk* chunk = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3317
    while (chunk != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3318
      used += chunk->used_word_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3319
      chunk = chunk->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3320
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3321
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3322
  return used;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3323
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3324
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3325
void SpaceManager::locked_print_chunks_in_use_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3326
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3327
  for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3328
    Metachunk* chunk = chunks_in_use(i);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3329
    st->print("SpaceManager: %s " PTR_FORMAT,
29800
fa5f7a2bf717 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29697
diff changeset
  3330
                 chunk_size_name(i), p2i(chunk));
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3331
    if (chunk != NULL) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3332
      st->print_cr(" free " SIZE_FORMAT,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3333
                   chunk->free_word_size());
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3334
    } else {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24351
diff changeset
  3335
      st->cr();
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3336
    }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3337
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3338
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3339
  chunk_manager()->locked_print_free_chunks(st);
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3340
  chunk_manager()->locked_print_sum_free_chunks(st);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3341
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3342
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3343
size_t SpaceManager::calc_chunk_size(size_t word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3344
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3345
  // Decide between a small chunk and a medium chunk.  Up to
31028
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  3346
  // _small_chunk_limit small chunks can be allocated.
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  3347
  // After that a medium chunk is preferred.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3348
  size_t chunk_word_size;
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3349
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3350
  // Special case for anonymous metadata space.
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3351
  // Anonymous metadata space is usually small, with majority within 1K - 2K range and
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3352
  // rarely about 4K (64-bits JVM).
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3353
  // Instead of jumping to SmallChunk after initial chunk exhausted, keeping allocation
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3354
  // from SpecializeChunk up to _anon_metadata_specialize_chunk_limit (4) reduces space waste
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3355
  // from 60+% to around 30%.
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3356
  if (_space_type == Metaspace::AnonymousMetaspaceType &&
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3357
      _mdtype == Metaspace::NonClassType &&
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3358
      sum_count_in_chunks_in_use(SpecializedIndex) < _anon_metadata_specialize_chunk_limit &&
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3359
      word_size + Metachunk::overhead() <= SpecializedChunk) {
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3360
    return SpecializedChunk;
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3361
  }
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3362
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3363
  if (chunks_in_use(MediumIndex) == NULL &&
18491
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  3364
      sum_count_in_chunks_in_use(SmallIndex) < _small_chunk_limit) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3365
    chunk_word_size = (size_t) small_chunk_size();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3366
    if (word_size + Metachunk::overhead() > small_chunk_size()) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3367
      chunk_word_size = medium_chunk_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3368
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3369
  } else {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3370
    chunk_word_size = medium_chunk_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3371
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3372
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3373
  // Might still need a humongous chunk.  Enforce
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3374
  // humongous allocations sizes to be aligned up to
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3375
  // the smallest chunk size.
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3376
  size_t if_humongous_sized_chunk =
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  3377
    align_up(word_size + Metachunk::overhead(),
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3378
                  smallest_chunk_size());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3379
  chunk_word_size =
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3380
    MAX2((size_t) chunk_word_size, if_humongous_sized_chunk);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3381
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3382
  assert(!SpaceManager::is_humongous(word_size) ||
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3383
         chunk_word_size == if_humongous_sized_chunk,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3384
         "Size calculation is wrong, word_size " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3385
         " chunk_word_size " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3386
         word_size, chunk_word_size);
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37151
diff changeset
  3387
  Log(gc, metaspace, alloc) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3388
  if (log.is_debug() && SpaceManager::is_humongous(word_size)) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3389
    log.debug("Metadata humongous allocation:");
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3390
    log.debug("  word_size " PTR_FORMAT, word_size);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3391
    log.debug("  chunk_word_size " PTR_FORMAT, chunk_word_size);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3392
    log.debug("    chunk overhead " PTR_FORMAT, Metachunk::overhead());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3393
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3394
  return chunk_word_size;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3395
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3396
20407
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3397
void SpaceManager::track_metaspace_memory_usage() {
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3398
  if (is_init_completed()) {
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3399
    if (is_class()) {
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3400
      MemoryService::track_compressed_class_memory_usage();
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3401
    }
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3402
    MemoryService::track_metaspace_memory_usage();
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3403
  }
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3404
}
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3405
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3406
MetaWord* SpaceManager::grow_and_allocate(size_t word_size) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3407
  assert(vs_list()->current_virtual_space() != NULL,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3408
         "Should have been set");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3409
  assert(current_chunk() == NULL ||
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3410
         current_chunk()->allocate(word_size) == NULL,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3411
         "Don't need to expand");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3412
  MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3413
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3414
  if (log_is_enabled(Trace, gc, metaspace, freelist)) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3415
    size_t words_left = 0;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3416
    size_t words_used = 0;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3417
    if (current_chunk() != NULL) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3418
      words_left = current_chunk()->free_word_size();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3419
      words_used = current_chunk()->used_word_size();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3420
    }
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3421
    log_trace(gc, metaspace, freelist)("SpaceManager::grow_and_allocate for " SIZE_FORMAT " words " SIZE_FORMAT " words used " SIZE_FORMAT " words left",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3422
                                       word_size, words_used, words_left);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3423
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3424
31028
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  3425
  // Get another chunk
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3426
  size_t chunk_word_size = calc_chunk_size(word_size);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3427
  Metachunk* next = get_new_chunk(chunk_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3428
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3429
  MetaWord* mem = NULL;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3430
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3431
  // If a chunk was available, add it to the in-use chunk list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3432
  // and do an allocation from it.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3433
  if (next != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3434
    // Add to this manager's list of chunks in use.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3435
    add_chunk(next, false);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3436
    mem = next->allocate(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3437
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3438
20407
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3439
  // Track metaspace memory usage statistic.
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3440
  track_metaspace_memory_usage();
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3441
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3442
  return mem;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3443
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3444
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3445
void SpaceManager::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3446
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3447
  for (ChunkIndex i = ZeroIndex;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3448
       i < NumberOfInUseLists ;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3449
       i = next_chunk_index(i) ) {
29800
fa5f7a2bf717 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29697
diff changeset
  3450
    st->print_cr("  chunks_in_use " PTR_FORMAT " chunk size " SIZE_FORMAT,
fa5f7a2bf717 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29697
diff changeset
  3451
                 p2i(chunks_in_use(i)),
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3452
                 chunks_in_use(i) == NULL ? 0 : chunks_in_use(i)->word_size());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3453
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3454
  st->print_cr("    waste:  Small " SIZE_FORMAT " Medium " SIZE_FORMAT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3455
               " Humongous " SIZE_FORMAT,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3456
               sum_waste_in_chunks_in_use(SmallIndex),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3457
               sum_waste_in_chunks_in_use(MediumIndex),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3458
               sum_waste_in_chunks_in_use(HumongousIndex));
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3459
  // block free lists
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3460
  if (block_freelists() != NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3461
    st->print_cr("total in block free lists " SIZE_FORMAT,
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3462
      block_freelists()->total_size());
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3463
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3464
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3465
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3466
SpaceManager::SpaceManager(Metaspace::MetadataType mdtype,
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3467
                           Metaspace::MetaspaceType space_type,
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3468
                           Mutex* lock) :
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3469
  _mdtype(mdtype),
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3470
  _space_type(space_type),
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3471
  _allocated_blocks_words(0),
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3472
  _allocated_chunks_words(0),
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3473
  _allocated_chunks_count(0),
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3474
  _block_freelists(NULL),
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3475
  _lock(lock)
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3476
{
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3477
  initialize();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3478
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3479
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3480
void SpaceManager::inc_size_metrics(size_t words) {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3481
  assert_lock_strong(SpaceManager::expand_lock());
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3482
  // Total of allocated Metachunks and allocated Metachunks count
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3483
  // for each SpaceManager
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3484
  _allocated_chunks_words = _allocated_chunks_words + words;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3485
  _allocated_chunks_count++;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3486
  // Global total of capacity in allocated Metachunks
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3487
  MetaspaceAux::inc_capacity(mdtype(), words);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3488
  // Global total of allocated Metablocks.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3489
  // used_words_slow() includes the overhead in each
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3490
  // Metachunk so include it in the used when the
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3491
  // Metachunk is first added (so only added once per
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3492
  // Metachunk).
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3493
  MetaspaceAux::inc_used(mdtype(), Metachunk::overhead());
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3494
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3495
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3496
void SpaceManager::inc_used_metrics(size_t words) {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3497
  // Add to the per SpaceManager total
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  3498
  Atomic::add(words, &_allocated_blocks_words);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3499
  // Add to the global total
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3500
  MetaspaceAux::inc_used(mdtype(), words);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3501
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3502
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3503
void SpaceManager::dec_total_from_size_metrics() {
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3504
  MetaspaceAux::dec_capacity(mdtype(), allocated_chunks_words());
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3505
  MetaspaceAux::dec_used(mdtype(), allocated_blocks_words());
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3506
  // Also deduct the overhead per Metachunk
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3507
  MetaspaceAux::dec_used(mdtype(), allocated_chunks_count() * Metachunk::overhead());
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3508
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3509
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3510
void SpaceManager::initialize() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3511
  Metadebug::init_allocation_fail_alot_count();
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3512
  for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3513
    _chunks_in_use[i] = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3514
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3515
  _current_chunk = NULL;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3516
  log_trace(gc, metaspace, freelist)("SpaceManager(): " PTR_FORMAT, p2i(this));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3517
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3518
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3519
SpaceManager::~SpaceManager() {
16385
4a05c6d94b04 8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents: 15954
diff changeset
  3520
  // This call this->_lock which can't be done while holding expand_lock()
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3521
  assert(sum_capacity_in_chunks_in_use() == allocated_chunks_words(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3522
         "sum_capacity_in_chunks_in_use() " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3523
         " allocated_chunks_words() " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3524
         sum_capacity_in_chunks_in_use(), allocated_chunks_words());
16385
4a05c6d94b04 8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents: 15954
diff changeset
  3525
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3526
  MutexLockerEx fcl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3527
                    Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3528
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3529
  assert(sum_count_in_chunks_in_use() == allocated_chunks_count(),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3530
         "sum_count_in_chunks_in_use() " SIZE_FORMAT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3531
         " allocated_chunks_count() " SIZE_FORMAT,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3532
         sum_count_in_chunks_in_use(), allocated_chunks_count());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3533
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3534
  chunk_manager()->slow_locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3535
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3536
  dec_total_from_size_metrics();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3537
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37151
diff changeset
  3538
  Log(gc, metaspace, freelist) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3539
  if (log.is_trace()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3540
    log.trace("~SpaceManager(): " PTR_FORMAT, p2i(this));
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3541
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3542
    LogStream ls(log.trace());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3543
    locked_print_chunks_in_use_on(&ls);
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3544
    if (block_freelists() != NULL) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3545
      block_freelists()->print_on(&ls);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3546
    }
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3547
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3548
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3549
  // Add all the chunks in use by this space manager
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3550
  // to the global list of free chunks.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3551
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3552
  // Follow each list of chunks-in-use and add them to the
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3553
  // free lists.  Each list is NULL terminated.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3554
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3555
  for (ChunkIndex i = ZeroIndex; i <= HumongousIndex; i = next_chunk_index(i)) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3556
    Metachunk* chunks = chunks_in_use(i);
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3557
    chunk_manager()->return_chunk_list(i, chunks);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3558
    set_chunks_in_use(i, NULL);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3559
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3560
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3561
  chunk_manager()->slow_locked_verify();
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3562
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3563
  if (_block_freelists != NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3564
    delete _block_freelists;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3565
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3566
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3567
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3568
void SpaceManager::deallocate(MetaWord* p, size_t word_size) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3569
  assert_lock_strong(_lock);
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3570
  // Allocations and deallocations are in raw_word_size
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3571
  size_t raw_word_size = get_allocation_word_size(word_size);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3572
  // Lazily create a block_freelist
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3573
  if (block_freelists() == NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3574
    _block_freelists = new BlockFreelist();
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3575
  }
18987
a1b541fe1159 8019845: Memory leak during class redefinition
fparain
parents: 18492
diff changeset
  3576
  block_freelists()->return_block(p, raw_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3577
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3578
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3579
// Adds a chunk to the list of chunks in use.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3580
void SpaceManager::add_chunk(Metachunk* new_chunk, bool make_current) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3581
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3582
  assert(new_chunk != NULL, "Should not be NULL");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3583
  assert(new_chunk->next() == NULL, "Should not be on a list");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3584
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3585
  new_chunk->reset_empty();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3586
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3587
  // Find the correct list and and set the current
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3588
  // chunk for that list.
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  3589
  ChunkIndex index = chunk_manager()->list_index(new_chunk->word_size());
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3590
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3591
  if (index != HumongousIndex) {
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3592
    retire_current_chunk();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3593
    set_current_chunk(new_chunk);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3594
    new_chunk->set_next(chunks_in_use(index));
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3595
    set_chunks_in_use(index, new_chunk);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3596
  } else {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3597
    // For null class loader data and DumpSharedSpaces, the first chunk isn't
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3598
    // small, so small will be null.  Link this first chunk as the current
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3599
    // chunk.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3600
    if (make_current) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3601
      // Set as the current chunk but otherwise treat as a humongous chunk.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3602
      set_current_chunk(new_chunk);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3603
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3604
    // Link at head.  The _current_chunk only points to a humongous chunk for
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3605
    // the null class loader metaspace (class and data virtual space managers)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3606
    // any humongous chunks so will not point to the tail
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3607
    // of the humongous chunks list.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3608
    new_chunk->set_next(chunks_in_use(HumongousIndex));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3609
    set_chunks_in_use(HumongousIndex, new_chunk);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3610
15087
8849ea877278 8005486: NPG: Incorrect assertion in ChunkManager::list_index()
jmasa
parents: 15086
diff changeset
  3611
    assert(new_chunk->word_size() > medium_chunk_size(), "List inconsistency");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3612
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3613
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3614
  // Add to the running sum of capacity
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3615
  inc_size_metrics(new_chunk->word_size());
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3616
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3617
  assert(new_chunk->is_empty(), "Not ready for reuse");
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37151
diff changeset
  3618
  Log(gc, metaspace, freelist) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3619
  if (log.is_trace()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3620
    log.trace("SpaceManager::add_chunk: " SIZE_FORMAT ") ", sum_count_in_chunks_in_use());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3621
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3622
    LogStream ls(log.trace());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3623
    new_chunk->print_on(&ls);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3624
    chunk_manager()->locked_print_free_chunks(&ls);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3625
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3626
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3627
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3628
void SpaceManager::retire_current_chunk() {
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3629
  if (current_chunk() != NULL) {
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3630
    size_t remaining_words = current_chunk()->free_word_size();
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3631
    if (remaining_words >= BlockFreelist::min_dictionary_size()) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3632
      MetaWord* ptr = current_chunk()->allocate(remaining_words);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3633
      deallocate(ptr, remaining_words);
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3634
      inc_used_metrics(remaining_words);
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3635
    }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3636
  }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3637
}
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3638
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3639
Metachunk* SpaceManager::get_new_chunk(size_t chunk_word_size) {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3640
  // Get a chunk from the chunk freelist
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3641
  Metachunk* next = chunk_manager()->chunk_freelist_allocate(chunk_word_size);
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3642
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3643
  if (next == NULL) {
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3644
    next = vs_list()->get_new_chunk(chunk_word_size,
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3645
                                    medium_chunk_bunch());
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3646
  }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3647
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37151
diff changeset
  3648
  Log(gc, metaspace, alloc) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3649
  if (log.is_debug() && next != NULL &&
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3650
      SpaceManager::is_humongous(next->word_size())) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3651
    log.debug("  new humongous chunk word size " PTR_FORMAT, next->word_size());
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3652
  }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3653
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3654
  return next;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3655
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3656
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3657
MetaWord* SpaceManager::allocate(size_t word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3658
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3659
  size_t raw_word_size = get_allocation_word_size(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3660
  BlockFreelist* fl =  block_freelists();
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3661
  MetaWord* p = NULL;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3662
  // Allocation from the dictionary is expensive in the sense that
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3663
  // the dictionary has to be searched for a size.  Don't allocate
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3664
  // from the dictionary until it starts to get fat.  Is this
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3665
  // a reasonable policy?  Maybe an skinny dictionary is fast enough
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3666
  // for allocations.  Do some profiling.  JJJ
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3667
  if (fl != NULL && fl->total_size() > allocation_from_dictionary_limit) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3668
    p = fl->get_block(raw_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3669
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3670
  if (p == NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3671
    p = allocate_work(raw_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3672
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3673
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3674
  return p;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3675
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3676
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3677
// Returns the address of spaced allocated for "word_size".
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3678
// This methods does not know about blocks (Metablocks)
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3679
MetaWord* SpaceManager::allocate_work(size_t word_size) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3680
  assert_lock_strong(_lock);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3681
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3682
  if (Metadebug::test_metadata_failure()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3683
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3684
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3685
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3686
  // Is there space in the current chunk?
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3687
  MetaWord* result = NULL;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3688
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3689
  if (current_chunk() != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3690
    result = current_chunk()->allocate(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3691
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3692
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3693
  if (result == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3694
    result = grow_and_allocate(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3695
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3696
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3697
  if (result != NULL) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3698
    inc_used_metrics(word_size);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3699
    assert(result != (MetaWord*) chunks_in_use(MediumIndex),
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3700
           "Head of the list is being allocated");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3701
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3702
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3703
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3704
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3705
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3706
void SpaceManager::verify() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3707
  // If there are blocks in the dictionary, then
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22499
diff changeset
  3708
  // verification of chunks does not work since
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3709
  // being in the dictionary alters a chunk.
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3710
  if (block_freelists() != NULL && block_freelists()->total_size() == 0) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3711
    for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3712
      Metachunk* curr = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3713
      while (curr != NULL) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3714
        DEBUG_ONLY(do_verify_chunk(curr);)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3715
        assert(curr->is_tagged_free() == false, "Chunk should be tagged as in use.");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3716
        curr = curr->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3717
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3718
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3719
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3720
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3721
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  3722
void SpaceManager::verify_chunk_size(Metachunk* chunk) {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  3723
  assert(is_humongous(chunk->word_size()) ||
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3724
         chunk->word_size() == medium_chunk_size() ||
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3725
         chunk->word_size() == small_chunk_size() ||
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3726
         chunk->word_size() == specialized_chunk_size(),
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  3727
         "Chunk size is wrong");
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  3728
  return;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  3729
}
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  3730
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3731
#ifdef ASSERT
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3732
void SpaceManager::verify_allocated_blocks_words() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3733
  // Verification is only guaranteed at a safepoint.
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3734
  assert(SafepointSynchronize::is_at_safepoint() || !Universe::is_fully_initialized(),
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3735
    "Verification can fail if the applications is running");
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3736
  assert(allocated_blocks_words() == sum_used_in_chunks_in_use(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3737
         "allocation total is not consistent " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3738
         " vs " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3739
         allocated_blocks_words(), sum_used_in_chunks_in_use());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3740
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3741
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3742
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3743
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3744
void SpaceManager::dump(outputStream* const out) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3745
  size_t curr_total = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3746
  size_t waste = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3747
  uint i = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3748
  size_t used = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3749
  size_t capacity = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3750
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3751
  // Add up statistics for all chunks in this SpaceManager.
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3752
  for (ChunkIndex index = ZeroIndex;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3753
       index < NumberOfInUseLists;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3754
       index = next_chunk_index(index)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3755
    for (Metachunk* curr = chunks_in_use(index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3756
         curr != NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3757
         curr = curr->next()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3758
      out->print("%d) ", i++);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3759
      curr->print_on(out);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3760
      curr_total += curr->word_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3761
      used += curr->used_word_size();
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3762
      capacity += curr->word_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3763
      waste += curr->free_word_size() + curr->overhead();;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3764
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3765
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3766
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3767
  if (log_is_enabled(Trace, gc, metaspace, freelist)) {
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3768
    if (block_freelists() != NULL) block_freelists()->print_on(out);
19992
ecae893d6947 8024751: Fix bugs in TraceMetadata
stefank
parents: 19990
diff changeset
  3769
  }
ecae893d6947 8024751: Fix bugs in TraceMetadata
stefank
parents: 19990
diff changeset
  3770
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3771
  size_t free = current_chunk() == NULL ? 0 : current_chunk()->free_word_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3772
  // Free space isn't wasted.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3773
  waste -= free;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3774
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3775
  out->print_cr("total of all chunks "  SIZE_FORMAT " used " SIZE_FORMAT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3776
                " free " SIZE_FORMAT " capacity " SIZE_FORMAT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3777
                " waste " SIZE_FORMAT, curr_total, used, free, capacity, waste);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3778
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3779
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3780
// MetaspaceAux
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3781
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3782
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3783
size_t MetaspaceAux::_capacity_words[] = {0, 0};
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47543
diff changeset
  3784
volatile size_t MetaspaceAux::_used_words[] = {0, 0};
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3785
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  3786
size_t MetaspaceAux::free_bytes(Metaspace::MetadataType mdtype) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  3787
  VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  3788
  return list == NULL ? 0 : list->free_bytes();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  3789
}
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  3790
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3791
size_t MetaspaceAux::free_bytes() {
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  3792
  return free_bytes(Metaspace::ClassType) + free_bytes(Metaspace::NonClassType);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3793
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3794
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3795
void MetaspaceAux::dec_capacity(Metaspace::MetadataType mdtype, size_t words) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3796
  assert_lock_strong(SpaceManager::expand_lock());
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3797
  assert(words <= capacity_words(mdtype),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3798
         "About to decrement below 0: words " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3799
         " is greater than _capacity_words[%u] " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3800
         words, mdtype, capacity_words(mdtype));
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3801
  _capacity_words[mdtype] -= words;
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3802
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3803
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3804
void MetaspaceAux::inc_capacity(Metaspace::MetadataType mdtype, size_t words) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3805
  assert_lock_strong(SpaceManager::expand_lock());
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3806
  // Needs to be atomic
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3807
  _capacity_words[mdtype] += words;
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3808
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3809
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3810
void MetaspaceAux::dec_used(Metaspace::MetadataType mdtype, size_t words) {
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3811
  assert(words <= used_words(mdtype),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3812
         "About to decrement below 0: words " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3813
         " is greater than _used_words[%u] " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3814
         words, mdtype, used_words(mdtype));
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3815
  // For CMS deallocation of the Metaspaces occurs during the
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3816
  // sweep which is a concurrent phase.  Protection by the expand_lock()
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3817
  // is not enough since allocation is on a per Metaspace basis
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3818
  // and protected by the Metaspace lock.
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  3819
  Atomic::sub(words, &_used_words[mdtype]);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3820
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3821
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3822
void MetaspaceAux::inc_used(Metaspace::MetadataType mdtype, size_t words) {
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3823
  // _used_words tracks allocations for
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3824
  // each piece of metadata.  Those allocations are
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3825
  // generally done concurrently by different application
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3826
  // threads so must be done atomically.
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  3827
  Atomic::add(words, &_used_words[mdtype]);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3828
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3829
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3830
size_t MetaspaceAux::used_bytes_slow(Metaspace::MetadataType mdtype) {
13733
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3831
  size_t used = 0;
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3832
  ClassLoaderDataGraphMetaspaceIterator iter;
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3833
  while (iter.repeat()) {
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3834
    Metaspace* msp = iter.get_next();
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3835
    // Sum allocated_blocks_words for each metaspace
13733
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3836
    if (msp != NULL) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3837
      used += msp->used_words_slow(mdtype);
13733
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3838
    }
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3839
  }
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3840
  return used * BytesPerWord;
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3841
}
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3842
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3843
size_t MetaspaceAux::free_bytes_slow(Metaspace::MetadataType mdtype) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3844
  size_t free = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3845
  ClassLoaderDataGraphMetaspaceIterator iter;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3846
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3847
    Metaspace* msp = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3848
    if (msp != NULL) {
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3849
      free += msp->free_words_slow(mdtype);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3850
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3851
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3852
  return free * BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3853
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3854
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3855
size_t MetaspaceAux::capacity_bytes_slow(Metaspace::MetadataType mdtype) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3856
  if ((mdtype == Metaspace::ClassType) && !Metaspace::using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3857
    return 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3858
  }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3859
  // Don't count the space in the freelists.  That space will be
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3860
  // added to the capacity calculation as needed.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3861
  size_t capacity = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3862
  ClassLoaderDataGraphMetaspaceIterator iter;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3863
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3864
    Metaspace* msp = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3865
    if (msp != NULL) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3866
      capacity += msp->capacity_words_slow(mdtype);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3867
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3868
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3869
  return capacity * BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3870
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3871
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3872
size_t MetaspaceAux::capacity_bytes_slow() {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3873
#ifdef PRODUCT
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3874
  // Use capacity_bytes() in PRODUCT instead of this function.
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3875
  guarantee(false, "Should not call capacity_bytes_slow() in the PRODUCT");
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3876
#endif
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3877
  size_t class_capacity = capacity_bytes_slow(Metaspace::ClassType);
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3878
  size_t non_class_capacity = capacity_bytes_slow(Metaspace::NonClassType);
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3879
  assert(capacity_bytes() == class_capacity + non_class_capacity,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3880
         "bad accounting: capacity_bytes() " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3881
         " class_capacity + non_class_capacity " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3882
         " class_capacity " SIZE_FORMAT " non_class_capacity " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3883
         capacity_bytes(), class_capacity + non_class_capacity,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3884
         class_capacity, non_class_capacity);
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3885
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3886
  return class_capacity + non_class_capacity;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3887
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3888
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3889
size_t MetaspaceAux::reserved_bytes(Metaspace::MetadataType mdtype) {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3890
  VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3891
  return list == NULL ? 0 : list->reserved_bytes();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3892
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3893
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3894
size_t MetaspaceAux::committed_bytes(Metaspace::MetadataType mdtype) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3895
  VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3896
  return list == NULL ? 0 : list->committed_bytes();
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3897
}
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3898
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3899
size_t MetaspaceAux::min_chunk_size_words() { return Metaspace::first_chunk_word_size(); }
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3900
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3901
size_t MetaspaceAux::free_chunks_total_words(Metaspace::MetadataType mdtype) {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3902
  ChunkManager* chunk_manager = Metaspace::get_chunk_manager(mdtype);
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3903
  if (chunk_manager == NULL) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3904
    return 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3905
  }
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3906
  chunk_manager->slow_verify();
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3907
  return chunk_manager->free_chunks_total_words();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3908
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3909
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3910
size_t MetaspaceAux::free_chunks_total_bytes(Metaspace::MetadataType mdtype) {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3911
  return free_chunks_total_words(mdtype) * BytesPerWord;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3912
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3913
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3914
size_t MetaspaceAux::free_chunks_total_words() {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3915
  return free_chunks_total_words(Metaspace::ClassType) +
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3916
         free_chunks_total_words(Metaspace::NonClassType);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3917
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3918
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3919
size_t MetaspaceAux::free_chunks_total_bytes() {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3920
  return free_chunks_total_words() * BytesPerWord;
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3921
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3922
23470
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3923
bool MetaspaceAux::has_chunk_free_list(Metaspace::MetadataType mdtype) {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3924
  return Metaspace::get_chunk_manager(mdtype) != NULL;
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3925
}
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3926
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3927
MetaspaceChunkFreeListSummary MetaspaceAux::chunk_free_list_summary(Metaspace::MetadataType mdtype) {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3928
  if (!has_chunk_free_list(mdtype)) {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3929
    return MetaspaceChunkFreeListSummary();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3930
  }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3931
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3932
  const ChunkManager* cm = Metaspace::get_chunk_manager(mdtype);
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3933
  return cm->chunk_free_list_summary();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3934
}
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3935
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3936
void MetaspaceAux::print_metaspace_change(size_t prev_metadata_used) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3937
  log_info(gc, metaspace)("Metaspace: "  SIZE_FORMAT "K->" SIZE_FORMAT "K("  SIZE_FORMAT "K)",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3938
                          prev_metadata_used/K, used_bytes()/K, reserved_bytes()/K);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3939
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3940
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3941
void MetaspaceAux::print_on(outputStream* out) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3942
  Metaspace::MetadataType nct = Metaspace::NonClassType;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3943
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3944
  out->print_cr(" Metaspace       "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3945
                "used "      SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3946
                "capacity "  SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3947
                "committed " SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3948
                "reserved "  SIZE_FORMAT "K",
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3949
                used_bytes()/K,
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3950
                capacity_bytes()/K,
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3951
                committed_bytes()/K,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3952
                reserved_bytes()/K);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3953
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3954
  if (Metaspace::using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3955
    Metaspace::MetadataType ct = Metaspace::ClassType;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3956
    out->print_cr("  class space    "
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3957
                  "used "      SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3958
                  "capacity "  SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3959
                  "committed " SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3960
                  "reserved "  SIZE_FORMAT "K",
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3961
                  used_bytes(ct)/K,
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3962
                  capacity_bytes(ct)/K,
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3963
                  committed_bytes(ct)/K,
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3964
                  reserved_bytes(ct)/K);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3965
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3966
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3967
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3968
// Print information for class space and data space separately.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3969
// This is almost the same as above.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3970
void MetaspaceAux::print_on(outputStream* out, Metaspace::MetadataType mdtype) {
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3971
  size_t free_chunks_capacity_bytes = free_chunks_total_bytes(mdtype);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3972
  size_t capacity_bytes = capacity_bytes_slow(mdtype);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3973
  size_t used_bytes = used_bytes_slow(mdtype);
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3974
  size_t free_bytes = free_bytes_slow(mdtype);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3975
  size_t used_and_free = used_bytes + free_bytes +
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3976
                           free_chunks_capacity_bytes;
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3977
  out->print_cr("  Chunk accounting: (used in chunks " SIZE_FORMAT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3978
             "K + unused in chunks " SIZE_FORMAT "K  + "
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3979
             " capacity in free chunks " SIZE_FORMAT "K) = " SIZE_FORMAT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3980
             "K  capacity in allocated chunks " SIZE_FORMAT "K",
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3981
             used_bytes / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3982
             free_bytes / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3983
             free_chunks_capacity_bytes / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3984
             used_and_free / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3985
             capacity_bytes / K);
15954
fbcf5f5047c6 8009282: Assertion "assert(used_and_free == capacity_bytes) failed: Accounting is wrong" failed with -XX:+Verbose -XX:+TraceMetadataChunkAllocation
mgerdin
parents: 15610
diff changeset
  3986
  // Accounting can only be correct if we got the values during a safepoint
fbcf5f5047c6 8009282: Assertion "assert(used_and_free == capacity_bytes) failed: Accounting is wrong" failed with -XX:+Verbose -XX:+TraceMetadataChunkAllocation
mgerdin
parents: 15610
diff changeset
  3987
  assert(!SafepointSynchronize::is_at_safepoint() || used_and_free == capacity_bytes, "Accounting is wrong");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3988
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3989
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3990
// Print total fragmentation for class metaspaces
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3991
void MetaspaceAux::print_class_waste(outputStream* out) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3992
  assert(Metaspace::using_class_space(), "class metaspace not used");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3993
  size_t cls_specialized_waste = 0, cls_small_waste = 0, cls_medium_waste = 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3994
  size_t cls_specialized_count = 0, cls_small_count = 0, cls_medium_count = 0, cls_humongous_count = 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3995
  ClassLoaderDataGraphMetaspaceIterator iter;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3996
  while (iter.repeat()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3997
    Metaspace* msp = iter.get_next();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3998
    if (msp != NULL) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3999
      cls_specialized_waste += msp->class_vsm()->sum_waste_in_chunks_in_use(SpecializedIndex);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4000
      cls_specialized_count += msp->class_vsm()->sum_count_in_chunks_in_use(SpecializedIndex);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4001
      cls_small_waste += msp->class_vsm()->sum_waste_in_chunks_in_use(SmallIndex);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4002
      cls_small_count += msp->class_vsm()->sum_count_in_chunks_in_use(SmallIndex);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4003
      cls_medium_waste += msp->class_vsm()->sum_waste_in_chunks_in_use(MediumIndex);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4004
      cls_medium_count += msp->class_vsm()->sum_count_in_chunks_in_use(MediumIndex);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4005
      cls_humongous_count += msp->class_vsm()->sum_count_in_chunks_in_use(HumongousIndex);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4006
    }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4007
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4008
  out->print_cr(" class: " SIZE_FORMAT " specialized(s) " SIZE_FORMAT ", "
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4009
                SIZE_FORMAT " small(s) " SIZE_FORMAT ", "
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4010
                SIZE_FORMAT " medium(s) " SIZE_FORMAT ", "
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4011
                "large count " SIZE_FORMAT,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4012
                cls_specialized_count, cls_specialized_waste,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4013
                cls_small_count, cls_small_waste,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4014
                cls_medium_count, cls_medium_waste, cls_humongous_count);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4015
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4016
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4017
// Print total fragmentation for data and class metaspaces separately
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4018
void MetaspaceAux::print_waste(outputStream* out) {
18491
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  4019
  size_t specialized_waste = 0, small_waste = 0, medium_waste = 0;
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  4020
  size_t specialized_count = 0, small_count = 0, medium_count = 0, humongous_count = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4021
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4022
  ClassLoaderDataGraphMetaspaceIterator iter;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4023
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4024
    Metaspace* msp = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4025
    if (msp != NULL) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4026
      specialized_waste += msp->vsm()->sum_waste_in_chunks_in_use(SpecializedIndex);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4027
      specialized_count += msp->vsm()->sum_count_in_chunks_in_use(SpecializedIndex);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4028
      small_waste += msp->vsm()->sum_waste_in_chunks_in_use(SmallIndex);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4029
      small_count += msp->vsm()->sum_count_in_chunks_in_use(SmallIndex);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4030
      medium_waste += msp->vsm()->sum_waste_in_chunks_in_use(MediumIndex);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4031
      medium_count += msp->vsm()->sum_count_in_chunks_in_use(MediumIndex);
18491
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  4032
      humongous_count += msp->vsm()->sum_count_in_chunks_in_use(HumongousIndex);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4033
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4034
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4035
  out->print_cr("Total fragmentation waste (words) doesn't count free space");
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4036
  out->print_cr("  data: " SIZE_FORMAT " specialized(s) " SIZE_FORMAT ", "
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4037
                        SIZE_FORMAT " small(s) " SIZE_FORMAT ", "
18491
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  4038
                        SIZE_FORMAT " medium(s) " SIZE_FORMAT ", "
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  4039
                        "large count " SIZE_FORMAT,
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4040
             specialized_count, specialized_waste, small_count,
18491
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  4041
             small_waste, medium_count, medium_waste, humongous_count);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4042
  if (Metaspace::using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4043
    print_class_waste(out);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4044
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4045
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4046
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4047
class MetadataStats VALUE_OBJ_CLASS_SPEC {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4048
private:
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4049
  size_t _capacity;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4050
  size_t _used;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4051
  size_t _free;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4052
  size_t _waste;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4053
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4054
public:
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4055
  MetadataStats() : _capacity(0), _used(0), _free(0), _waste(0) { }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4056
  MetadataStats(size_t capacity, size_t used, size_t free, size_t waste)
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4057
  : _capacity(capacity), _used(used), _free(free), _waste(waste) { }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4058
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4059
  void add(const MetadataStats& stats) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4060
    _capacity += stats.capacity();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4061
    _used += stats.used();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4062
    _free += stats.free();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4063
    _waste += stats.waste();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4064
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4065
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4066
  size_t capacity() const { return _capacity; }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4067
  size_t used() const     { return _used; }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4068
  size_t free() const     { return _free; }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4069
  size_t waste() const    { return _waste; }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4070
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4071
  void print_on(outputStream* out, size_t scale) const;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4072
};
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4073
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4074
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4075
void MetadataStats::print_on(outputStream* out, size_t scale) const {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4076
  const char* unit = scale_unit(scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4077
  out->print_cr("capacity=%10.2f%s used=%10.2f%s free=%10.2f%s waste=%10.2f%s",
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4078
    (float)capacity() / scale, unit,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4079
    (float)used() / scale, unit,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4080
    (float)free() / scale, unit,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4081
    (float)waste() / scale, unit);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4082
}
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4083
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4084
class PrintCLDMetaspaceInfoClosure : public CLDClosure {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4085
private:
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4086
  outputStream*  _out;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4087
  size_t         _scale;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4088
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4089
  size_t         _total_count;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4090
  MetadataStats  _total_metadata;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4091
  MetadataStats  _total_class;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4092
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4093
  size_t         _total_anon_count;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4094
  MetadataStats  _total_anon_metadata;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4095
  MetadataStats  _total_anon_class;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4096
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4097
public:
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4098
  PrintCLDMetaspaceInfoClosure(outputStream* out, size_t scale = K)
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4099
  : _out(out), _scale(scale), _total_count(0), _total_anon_count(0) { }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4100
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4101
  ~PrintCLDMetaspaceInfoClosure() {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4102
    print_summary();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4103
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4104
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4105
  void do_cld(ClassLoaderData* cld) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4106
    assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4107
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4108
    if (cld->is_unloading()) return;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4109
    Metaspace* msp = cld->metaspace_or_null();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4110
    if (msp == NULL) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4111
      return;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4112
    }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4113
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4114
    bool anonymous = false;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4115
    if (cld->is_anonymous()) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4116
      _out->print_cr("ClassLoader: for anonymous class");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4117
      anonymous = true;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4118
    } else {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4119
      ResourceMark rm;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4120
      _out->print_cr("ClassLoader: %s", cld->loader_name());
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4121
    }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4122
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4123
    print_metaspace(msp, anonymous);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4124
    _out->cr();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4125
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4126
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4127
private:
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4128
  void print_metaspace(Metaspace* msp, bool anonymous);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4129
  void print_summary() const;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4130
};
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4131
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4132
void PrintCLDMetaspaceInfoClosure::print_metaspace(Metaspace* msp, bool anonymous){
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4133
  assert(msp != NULL, "Sanity");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4134
  SpaceManager* vsm = msp->vsm();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4135
  const char* unit = scale_unit(_scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4136
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4137
  size_t capacity = vsm->sum_capacity_in_chunks_in_use() * BytesPerWord;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4138
  size_t used = vsm->sum_used_in_chunks_in_use() * BytesPerWord;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4139
  size_t free = vsm->sum_free_in_chunks_in_use() * BytesPerWord;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4140
  size_t waste = vsm->sum_waste_in_chunks_in_use() * BytesPerWord;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4141
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4142
  _total_count ++;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4143
  MetadataStats metadata_stats(capacity, used, free, waste);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4144
  _total_metadata.add(metadata_stats);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4145
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4146
  if (anonymous) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4147
    _total_anon_count ++;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4148
    _total_anon_metadata.add(metadata_stats);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4149
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4150
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4151
  _out->print("  Metadata   ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4152
  metadata_stats.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4153
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4154
  if (Metaspace::using_class_space()) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4155
    vsm = msp->class_vsm();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4156
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4157
    capacity = vsm->sum_capacity_in_chunks_in_use() * BytesPerWord;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4158
    used = vsm->sum_used_in_chunks_in_use() * BytesPerWord;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4159
    free = vsm->sum_free_in_chunks_in_use() * BytesPerWord;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4160
    waste = vsm->sum_waste_in_chunks_in_use() * BytesPerWord;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4161
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4162
    MetadataStats class_stats(capacity, used, free, waste);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4163
    _total_class.add(class_stats);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4164
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4165
    if (anonymous) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4166
      _total_anon_class.add(class_stats);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4167
    }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4168
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4169
    _out->print("  Class data ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4170
    class_stats.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4171
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4172
}
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4173
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4174
void PrintCLDMetaspaceInfoClosure::print_summary() const {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4175
  const char* unit = scale_unit(_scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4176
  _out->cr();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4177
  _out->print_cr("Summary:");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4178
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4179
  MetadataStats total;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4180
  total.add(_total_metadata);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4181
  total.add(_total_class);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4182
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4183
  _out->print("  Total class loaders=" SIZE_FORMAT_W(6) " ", _total_count);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4184
  total.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4185
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4186
  _out->print("                    Metadata ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4187
  _total_metadata.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4188
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4189
  if (Metaspace::using_class_space()) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4190
    _out->print("                  Class data ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4191
    _total_class.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4192
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4193
  _out->cr();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4194
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4195
  MetadataStats total_anon;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4196
  total_anon.add(_total_anon_metadata);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4197
  total_anon.add(_total_anon_class);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4198
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4199
  _out->print("For anonymous classes=" SIZE_FORMAT_W(6) " ", _total_anon_count);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4200
  total_anon.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4201
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4202
  _out->print("                    Metadata ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4203
  _total_anon_metadata.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4204
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4205
  if (Metaspace::using_class_space()) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4206
    _out->print("                  Class data ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4207
    _total_anon_class.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4208
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4209
}
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4210
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4211
void MetaspaceAux::print_metadata_for_nmt(outputStream* out, size_t scale) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4212
  const char* unit = scale_unit(scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4213
  out->print_cr("Metaspaces:");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4214
  out->print_cr("  Metadata space: reserved=" SIZE_FORMAT_W(10) "%s committed=" SIZE_FORMAT_W(10) "%s",
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4215
    reserved_bytes(Metaspace::NonClassType) / scale, unit,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4216
    committed_bytes(Metaspace::NonClassType) / scale, unit);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4217
  if (Metaspace::using_class_space()) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4218
    out->print_cr("  Class    space: reserved=" SIZE_FORMAT_W(10) "%s committed=" SIZE_FORMAT_W(10) "%s",
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4219
    reserved_bytes(Metaspace::ClassType) / scale, unit,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4220
    committed_bytes(Metaspace::ClassType) / scale, unit);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4221
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4222
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4223
  out->cr();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4224
  ChunkManager::print_all_chunkmanagers(out, scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4225
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4226
  out->cr();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4227
  out->print_cr("Per-classloader metadata:");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4228
  out->cr();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4229
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4230
  PrintCLDMetaspaceInfoClosure cl(out, scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4231
  ClassLoaderDataGraph::cld_do(&cl);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4232
}
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4233
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4234
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4235
// Dump global metaspace things from the end of ClassLoaderDataGraph
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4236
void MetaspaceAux::dump(outputStream* out) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4237
  out->print_cr("All Metaspace:");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4238
  out->print("data space: "); print_on(out, Metaspace::NonClassType);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4239
  out->print("class space: "); print_on(out, Metaspace::ClassType);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4240
  print_waste(out);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4241
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4242
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4243
// Prints an ASCII representation of the given space.
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4244
void MetaspaceAux::print_metaspace_map(outputStream* out, Metaspace::MetadataType mdtype) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4245
  MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4246
  const bool for_class = mdtype == Metaspace::ClassType ? true : false;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4247
  VirtualSpaceList* const vsl = for_class ? Metaspace::class_space_list() : Metaspace::space_list();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4248
  if (vsl != NULL) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4249
    if (for_class) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4250
      if (!Metaspace::using_class_space()) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4251
        out->print_cr("No Class Space.");
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4252
        return;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4253
      }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4254
      out->print_raw("---- Metaspace Map (Class Space) ----");
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4255
    } else {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4256
      out->print_raw("---- Metaspace Map (Non-Class Space) ----");
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4257
    }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4258
    // Print legend:
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4259
    out->cr();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4260
    out->print_cr("Chunk Types (uppercase chunks are in use): x-specialized, s-small, m-medium, h-humongous.");
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4261
    out->cr();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4262
    VirtualSpaceList* const vsl = for_class ? Metaspace::class_space_list() : Metaspace::space_list();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4263
    vsl->print_map(out);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4264
    out->cr();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4265
  }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4266
}
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4267
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  4268
void MetaspaceAux::verify_free_chunks() {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4269
  Metaspace::chunk_manager_metadata()->verify();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4270
  if (Metaspace::using_class_space()) {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4271
    Metaspace::chunk_manager_class()->verify();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4272
  }
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  4273
}
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  4274
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4275
void MetaspaceAux::verify_capacity() {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4276
#ifdef ASSERT
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  4277
  size_t running_sum_capacity_bytes = capacity_bytes();
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4278
  // For purposes of the running sum of capacity, verify against capacity
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4279
  size_t capacity_in_use_bytes = capacity_bytes_slow();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4280
  assert(running_sum_capacity_bytes == capacity_in_use_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4281
         "capacity_words() * BytesPerWord " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4282
         " capacity_bytes_slow()" SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4283
         running_sum_capacity_bytes, capacity_in_use_bytes);
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4284
  for (Metaspace::MetadataType i = Metaspace::ClassType;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4285
       i < Metaspace:: MetadataTypeCount;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4286
       i = (Metaspace::MetadataType)(i + 1)) {
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4287
    size_t capacity_in_use_bytes = capacity_bytes_slow(i);
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  4288
    assert(capacity_bytes(i) == capacity_in_use_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4289
           "capacity_bytes(%u) " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4290
           " capacity_bytes_slow(%u)" SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4291
           i, capacity_bytes(i), i, capacity_in_use_bytes);
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4292
  }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4293
#endif
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4294
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4295
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4296
void MetaspaceAux::verify_used() {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4297
#ifdef ASSERT
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  4298
  size_t running_sum_used_bytes = used_bytes();
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4299
  // For purposes of the running sum of used, verify against used
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4300
  size_t used_in_use_bytes = used_bytes_slow();
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  4301
  assert(used_bytes() == used_in_use_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4302
         "used_bytes() " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4303
         " used_bytes_slow()" SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4304
         used_bytes(), used_in_use_bytes);
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4305
  for (Metaspace::MetadataType i = Metaspace::ClassType;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4306
       i < Metaspace:: MetadataTypeCount;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4307
       i = (Metaspace::MetadataType)(i + 1)) {
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4308
    size_t used_in_use_bytes = used_bytes_slow(i);
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  4309
    assert(used_bytes(i) == used_in_use_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4310
           "used_bytes(%u) " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4311
           " used_bytes_slow(%u)" SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4312
           i, used_bytes(i), i, used_in_use_bytes);
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4313
  }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4314
#endif
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4315
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4316
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4317
void MetaspaceAux::verify_metrics() {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4318
  verify_capacity();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4319
  verify_used();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4320
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4321
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4322
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4323
// Metaspace methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4324
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4325
size_t Metaspace::_first_chunk_word_size = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4326
size_t Metaspace::_first_class_chunk_word_size = 0;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4327
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4328
size_t Metaspace::_commit_alignment = 0;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4329
size_t Metaspace::_reserve_alignment = 0;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4330
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4331
Metaspace::Metaspace(Mutex* lock, MetaspaceType type) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4332
  initialize(lock, type);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4333
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4334
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4335
Metaspace::~Metaspace() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4336
  delete _vsm;
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4337
  if (using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4338
    delete _class_vsm;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4339
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4340
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4341
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4342
VirtualSpaceList* Metaspace::_space_list = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4343
VirtualSpaceList* Metaspace::_class_space_list = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4344
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4345
ChunkManager* Metaspace::_chunk_manager_metadata = NULL;
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4346
ChunkManager* Metaspace::_chunk_manager_class = NULL;
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4347
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4348
#define VIRTUALSPACEMULTIPLIER 2
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4349
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4350
#ifdef _LP64
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4351
static const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1);
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4352
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4353
void Metaspace::set_narrow_klass_base_and_shift(address metaspace_base, address cds_base) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4354
  assert(!DumpSharedSpaces, "narrow_klass is set by MetaspaceShared class.");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4355
  // Figure out the narrow_klass_base and the narrow_klass_shift.  The
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4356
  // narrow_klass_base is the lower of the metaspace base and the cds base
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4357
  // (if cds is enabled).  The narrow_klass_shift depends on the distance
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4358
  // between the lower base and higher address.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4359
  address lower_base;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4360
  address higher_address;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4361
#if INCLUDE_CDS
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4362
  if (UseSharedSpaces) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4363
    higher_address = MAX2((address)(cds_base + MetaspaceShared::core_spaces_size()),
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4364
                          (address)(metaspace_base + compressed_class_space_size()));
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4365
    lower_base = MIN2(metaspace_base, cds_base);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4366
  } else
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4367
#endif
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4368
  {
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4369
    higher_address = metaspace_base + compressed_class_space_size();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4370
    lower_base = metaspace_base;
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4371
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4372
    uint64_t klass_encoding_max = UnscaledClassSpaceMax << LogKlassAlignmentInBytes;
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4373
    // If compressed class space fits in lower 32G, we don't need a base.
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4374
    if (higher_address <= (address)klass_encoding_max) {
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22499
diff changeset
  4375
      lower_base = 0; // Effectively lower base is zero.
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4376
    }
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4377
  }
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4378
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4379
  Universe::set_narrow_klass_base(lower_base);
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4380
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4381
  // CDS uses LogKlassAlignmentInBytes for narrow_klass_shift. See
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4382
  // MetaspaceShared::initialize_dumptime_shared_and_meta_spaces() for
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4383
  // how dump time narrow_klass_shift is set. Although, CDS can work
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4384
  // with zero-shift mode also, to be consistent with AOT it uses
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4385
  // LogKlassAlignmentInBytes for klass shift so archived java heap objects
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4386
  // can be used at same time as AOT code.
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4387
  if (!UseSharedSpaces
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4388
      && (uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4389
    Universe::set_narrow_klass_shift(0);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4390
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4391
    Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4392
  }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 42621
diff changeset
  4393
  AOTLoader::set_narrow_klass_shift();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4394
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4395
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4396
#if INCLUDE_CDS
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4397
// Return TRUE if the specified metaspace_base and cds_base are close enough
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4398
// to work with compressed klass pointers.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4399
bool Metaspace::can_use_cds_with_metaspace_addr(char* metaspace_base, address cds_base) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4400
  assert(cds_base != 0 && UseSharedSpaces, "Only use with CDS");
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  4401
  assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4402
  address lower_base = MIN2((address)metaspace_base, cds_base);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4403
  address higher_address = MAX2((address)(cds_base + MetaspaceShared::core_spaces_size()),
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4404
                                (address)(metaspace_base + compressed_class_space_size()));
21518
067dd7967128 8027616: Off by one error in putback for compressed oops nashorn performance improvement
coleenp
parents: 21189
diff changeset
  4405
  return ((uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4406
}
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4407
#endif
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4408
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4409
// Try to allocate the metaspace at the requested addr.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4410
void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, address cds_base) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4411
  assert(!DumpSharedSpaces, "compress klass space is allocated by MetaspaceShared class.");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4412
  assert(using_class_space(), "called improperly");
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  4413
  assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4414
  assert(compressed_class_space_size() < KlassEncodingMetaspaceMax,
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4415
         "Metaspace size is too big");
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4416
  assert_is_aligned(requested_addr, _reserve_alignment);
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4417
  assert_is_aligned(cds_base, _reserve_alignment);
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4418
  assert_is_aligned(compressed_class_space_size(), _reserve_alignment);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4419
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4420
  // Don't use large pages for the class space.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4421
  bool large_pages = false;
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4422
39229
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4423
#if !(defined(AARCH64) || defined(AIX))
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4424
  ReservedSpace metaspace_rs = ReservedSpace(compressed_class_space_size(),
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4425
                                             _reserve_alignment,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4426
                                             large_pages,
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28163
diff changeset
  4427
                                             requested_addr);
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4428
#else // AARCH64
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4429
  ReservedSpace metaspace_rs;
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4430
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4431
  // Our compressed klass pointers may fit nicely into the lower 32
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4432
  // bits.
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4433
  if ((uint64_t)requested_addr + compressed_class_space_size() < 4*G) {
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4434
    metaspace_rs = ReservedSpace(compressed_class_space_size(),
39229
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4435
                                 _reserve_alignment,
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4436
                                 large_pages,
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4437
                                 requested_addr);
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4438
  }
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4439
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4440
  if (! metaspace_rs.is_reserved()) {
39229
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4441
    // Aarch64: Try to align metaspace so that we can decode a compressed
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4442
    // klass with a single MOVK instruction.  We can do this iff the
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4443
    // compressed class base is a multiple of 4G.
39229
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4444
    // Aix: Search for a place where we can find memory. If we need to load
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4445
    // the base, 4G alignment is helpful, too.
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4446
    size_t increment = AARCH64_ONLY(4*)G;
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4447
    for (char *a = align_up(requested_addr, increment);
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4448
         a < (char*)(1024*G);
39229
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4449
         a += increment) {
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4450
      if (a == (char *)(32*G)) {
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4451
        // Go faster from here on. Zero-based is no longer possible.
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4452
        increment = 4*G;
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4453
      }
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4454
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4455
#if INCLUDE_CDS
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4456
      if (UseSharedSpaces
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4457
          && ! can_use_cds_with_metaspace_addr(a, cds_base)) {
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4458
        // We failed to find an aligned base that will reach.  Fall
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4459
        // back to using our requested addr.
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4460
        metaspace_rs = ReservedSpace(compressed_class_space_size(),
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4461
                                     _reserve_alignment,
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4462
                                     large_pages,
29187
b3e445e08548 8071563: AARCH64 staging fail to build
enevill
parents: 29185
diff changeset
  4463
                                     requested_addr);
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4464
        break;
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4465
      }
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4466
#endif
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4467
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4468
      metaspace_rs = ReservedSpace(compressed_class_space_size(),
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4469
                                   _reserve_alignment,
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4470
                                   large_pages,
29187
b3e445e08548 8071563: AARCH64 staging fail to build
enevill
parents: 29185
diff changeset
  4471
                                   a);
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4472
      if (metaspace_rs.is_reserved())
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4473
        break;
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4474
    }
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4475
  }
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4476
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4477
#endif // AARCH64
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4478
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4479
  if (!metaspace_rs.is_reserved()) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4480
#if INCLUDE_CDS
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4481
    if (UseSharedSpaces) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4482
      size_t increment = align_up(1*G, _reserve_alignment);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4483
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4484
      // Keep trying to allocate the metaspace, increasing the requested_addr
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4485
      // by 1GB each time, until we reach an address that will no longer allow
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4486
      // use of CDS with compressed klass pointers.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4487
      char *addr = requested_addr;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4488
      while (!metaspace_rs.is_reserved() && (addr + increment > addr) &&
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4489
             can_use_cds_with_metaspace_addr(addr + increment, cds_base)) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4490
        addr = addr + increment;
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4491
        metaspace_rs = ReservedSpace(compressed_class_space_size(),
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28163
diff changeset
  4492
                                     _reserve_alignment, large_pages, addr);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4493
      }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4494
    }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4495
#endif
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4496
    // If no successful allocation then try to allocate the space anywhere.  If
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4497
    // that fails then OOM doom.  At this point we cannot try allocating the
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  4498
    // metaspace as if UseCompressedClassPointers is off because too much
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  4499
    // initialization has happened that depends on UseCompressedClassPointers.
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  4500
    // So, UseCompressedClassPointers cannot be turned off at this point.
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4501
    if (!metaspace_rs.is_reserved()) {
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4502
      metaspace_rs = ReservedSpace(compressed_class_space_size(),
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4503
                                   _reserve_alignment, large_pages);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4504
      if (!metaspace_rs.is_reserved()) {
29800
fa5f7a2bf717 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29697
diff changeset
  4505
        vm_exit_during_initialization(err_msg("Could not allocate metaspace: " SIZE_FORMAT " bytes",
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4506
                                              compressed_class_space_size()));
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4507
      }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4508
    }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4509
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4510
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4511
  // If we got here then the metaspace got allocated.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4512
  MemTracker::record_virtual_memory_type((address)metaspace_rs.base(), mtClass);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4513
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4514
#if INCLUDE_CDS
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4515
  // Verify that we can use shared spaces.  Otherwise, turn off CDS.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4516
  if (UseSharedSpaces && !can_use_cds_with_metaspace_addr(metaspace_rs.base(), cds_base)) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4517
    FileMapInfo::stop_sharing_and_unmap(
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4518
        "Could not allocate metaspace at a compatible address");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4519
  }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4520
#endif
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4521
  set_narrow_klass_base_and_shift((address)metaspace_rs.base(),
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4522
                                  UseSharedSpaces ? (address)cds_base : 0);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4523
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4524
  initialize_class_space(metaspace_rs);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4525
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  4526
  LogTarget(Trace, gc, metaspace) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  4527
  if (lt.is_enabled()) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  4528
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  4529
    LogStream ls(lt);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  4530
    print_compressed_class_space(&ls, requested_addr);
31335
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4531
  }
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4532
}
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4533
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4534
void Metaspace::print_compressed_class_space(outputStream* st, const char* requested_addr) {
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4535
  st->print_cr("Narrow klass base: " PTR_FORMAT ", Narrow klass shift: %d",
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4536
               p2i(Universe::narrow_klass_base()), Universe::narrow_klass_shift());
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4537
  if (_class_space_list != NULL) {
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4538
    address base = (address)_class_space_list->current_virtual_space()->bottom();
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4539
    st->print("Compressed class space size: " SIZE_FORMAT " Address: " PTR_FORMAT,
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4540
                 compressed_class_space_size(), p2i(base));
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4541
    if (requested_addr != 0) {
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4542
      st->print(" Req Addr: " PTR_FORMAT, p2i(requested_addr));
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4543
    }
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4544
    st->cr();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4545
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4546
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4547
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  4548
// For UseCompressedClassPointers the class space is reserved above the top of
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4549
// the Java heap.  The argument passed in is at the base of the compressed space.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4550
void Metaspace::initialize_class_space(ReservedSpace rs) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4551
  // The reserved space size may be bigger because of alignment, esp with UseLargePages
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  4552
  assert(rs.size() >= CompressedClassSpaceSize,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4553
         SIZE_FORMAT " != " SIZE_FORMAT, rs.size(), CompressedClassSpaceSize);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4554
  assert(using_class_space(), "Must be using class space");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4555
  _class_space_list = new VirtualSpaceList(rs);
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4556
  _chunk_manager_class = new ChunkManager(true/*is_class*/);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4557
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4558
  if (!_class_space_list->initialization_succeeded()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4559
    vm_exit_during_initialization("Failed to setup compressed class space virtual space list.");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4560
  }
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4561
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4562
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4563
#endif
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4564
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4565
void Metaspace::ergo_initialize() {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4566
  if (DumpSharedSpaces) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4567
    // Using large pages when dumping the shared archive is currently not implemented.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4568
    FLAG_SET_ERGO(bool, UseLargePagesInMetaspace, false);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4569
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4570
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4571
  size_t page_size = os::vm_page_size();
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4572
  if (UseLargePages && UseLargePagesInMetaspace) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4573
    page_size = os::large_page_size();
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4574
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4575
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4576
  _commit_alignment  = page_size;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4577
  _reserve_alignment = MAX2(page_size, (size_t)os::vm_allocation_granularity());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4578
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4579
  // Do not use FLAG_SET_ERGO to update MaxMetaspaceSize, since this will
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4580
  // override if MaxMetaspaceSize was set on the command line or not.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4581
  // This information is needed later to conform to the specification of the
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4582
  // java.lang.management.MemoryUsage API.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4583
  //
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4584
  // Ideally, we would be able to set the default value of MaxMetaspaceSize in
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4585
  // globals.hpp to the aligned value, but this is not possible, since the
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4586
  // alignment depends on other flags being parsed.
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4587
  MaxMetaspaceSize = align_down_bounded(MaxMetaspaceSize, _reserve_alignment);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4588
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4589
  if (MetaspaceSize > MaxMetaspaceSize) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4590
    MetaspaceSize = MaxMetaspaceSize;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4591
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4592
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4593
  MetaspaceSize = align_down_bounded(MetaspaceSize, _commit_alignment);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4594
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4595
  assert(MetaspaceSize <= MaxMetaspaceSize, "MetaspaceSize should be limited by MaxMetaspaceSize");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4596
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4597
  MinMetaspaceExpansion = align_down_bounded(MinMetaspaceExpansion, _commit_alignment);
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4598
  MaxMetaspaceExpansion = align_down_bounded(MaxMetaspaceExpansion, _commit_alignment);
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4599
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4600
  CompressedClassSpaceSize = align_down_bounded(CompressedClassSpaceSize, _reserve_alignment);
47654
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4601
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4602
  // Initial virtual space size will be calculated at global_initialize()
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4603
  size_t min_metaspace_sz =
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4604
      VIRTUALSPACEMULTIPLIER * InitialBootClassLoaderMetaspaceSize;
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4605
  if (UseCompressedClassPointers) {
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4606
    if ((min_metaspace_sz + CompressedClassSpaceSize) >  MaxMetaspaceSize) {
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4607
      if (min_metaspace_sz >= MaxMetaspaceSize) {
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4608
        vm_exit_during_initialization("MaxMetaspaceSize is too small.");
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4609
      } else {
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4610
        FLAG_SET_ERGO(size_t, CompressedClassSpaceSize,
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4611
                      MaxMetaspaceSize - min_metaspace_sz);
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4612
      }
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4613
    }
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4614
  } else if (min_metaspace_sz >= MaxMetaspaceSize) {
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4615
    FLAG_SET_ERGO(size_t, InitialBootClassLoaderMetaspaceSize,
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4616
                  min_metaspace_sz);
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4617
  }
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4618
48387
7daebcef2e0d 8193386: CompressedClassSize too large with MaxMetaspace
coleenp
parents: 48148
diff changeset
  4619
  set_compressed_class_space_size(CompressedClassSpaceSize);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4620
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4621
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4622
void Metaspace::global_initialize() {
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  4623
  MetaspaceGC::initialize();
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  4624
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4625
#if INCLUDE_CDS
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4626
  if (DumpSharedSpaces) {
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4627
    MetaspaceShared::initialize_dumptime_shared_and_meta_spaces();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4628
  } else if (UseSharedSpaces) {
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4629
    // If any of the archived space fails to map, UseSharedSpaces
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4630
    // is reset to false. Fall through to the
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4631
    // (!DumpSharedSpaces && !UseSharedSpaces) case to set up class
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4632
    // metaspace.
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4633
    MetaspaceShared::initialize_runtime_shared_and_meta_spaces();
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4634
  }
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4635
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4636
  if (!DumpSharedSpaces && !UseSharedSpaces)
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4637
#endif // INCLUDE_CDS
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4638
  {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4639
#ifdef _LP64
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4640
    if (using_class_space()) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4641
      char* base = (char*)align_up(Universe::heap()->reserved_region().end(), _reserve_alignment);
31362
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
  4642
      allocate_metaspace_compressed_klass_ptrs(base, 0);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4643
    }
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4644
#endif // _LP64
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4645
  }
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4646
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4647
  // Initialize these before initializing the VirtualSpaceList
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4648
  _first_chunk_word_size = InitialBootClassLoaderMetaspaceSize / BytesPerWord;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4649
  _first_chunk_word_size = align_word_size_up(_first_chunk_word_size);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4650
  // Make the first class chunk bigger than a medium chunk so it's not put
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4651
  // on the medium chunk list.   The next chunk will be small and progress
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4652
  // from there.  This size calculated by -version.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4653
  _first_class_chunk_word_size = MIN2((size_t)MediumChunk*6,
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4654
                                     (CompressedClassSpaceSize/BytesPerWord)*2);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4655
  _first_class_chunk_word_size = align_word_size_up(_first_class_chunk_word_size);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4656
  // Arbitrarily set the initial virtual space to a multiple
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4657
  // of the boot class loader size.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4658
  size_t word_size = VIRTUALSPACEMULTIPLIER * _first_chunk_word_size;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4659
  word_size = align_up(word_size, Metaspace::reserve_alignment_words());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4660
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4661
  // Initialize the list of virtual spaces.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4662
  _space_list = new VirtualSpaceList(word_size);
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4663
  _chunk_manager_metadata = new ChunkManager(false/*metaspace*/);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4664
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4665
  if (!_space_list->initialization_succeeded()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4666
    vm_exit_during_initialization("Unable to setup metadata virtual space list.", NULL);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4667
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4668
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  4669
  _tracer = new MetaspaceTracer();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4670
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4671
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  4672
void Metaspace::post_initialize() {
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  4673
  MetaspaceGC::post_initialize();
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  4674
}
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  4675
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4676
void Metaspace::initialize_first_chunk(MetaspaceType type, MetadataType mdtype) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4677
  Metachunk* chunk = get_initialization_chunk(type, mdtype);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4678
  if (chunk != NULL) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4679
    // Add to this manager's list of chunks in use and current_chunk().
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4680
    get_space_manager(mdtype)->add_chunk(chunk, true);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4681
  }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4682
}
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4683
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4684
Metachunk* Metaspace::get_initialization_chunk(MetaspaceType type, MetadataType mdtype) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4685
  size_t chunk_word_size = get_space_manager(mdtype)->get_initial_chunk_size(type);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4686
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4687
  // Get a chunk from the chunk freelist
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4688
  Metachunk* chunk = get_chunk_manager(mdtype)->chunk_freelist_allocate(chunk_word_size);
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4689
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4690
  if (chunk == NULL) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4691
    chunk = get_space_list(mdtype)->get_new_chunk(chunk_word_size,
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4692
                                                  get_space_manager(mdtype)->medium_chunk_bunch());
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4693
  }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4694
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4695
  return chunk;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4696
}
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4697
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4698
void Metaspace::verify_global_initialization() {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4699
  assert(space_list() != NULL, "Metadata VirtualSpaceList has not been initialized");
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4700
  assert(chunk_manager_metadata() != NULL, "Metadata ChunkManager has not been initialized");
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4701
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4702
  if (using_class_space()) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4703
    assert(class_space_list() != NULL, "Class VirtualSpaceList has not been initialized");
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4704
    assert(chunk_manager_class() != NULL, "Class ChunkManager has not been initialized");
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4705
  }
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4706
}
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4707
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4708
void Metaspace::initialize(Mutex* lock, MetaspaceType type) {
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4709
  verify_global_initialization();
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4710
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4711
  // Allocate SpaceManager for metadata objects.
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  4712
  _vsm = new SpaceManager(NonClassType, type, lock);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4713
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4714
  if (using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4715
    // Allocate SpaceManager for classes.
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  4716
    _class_vsm = new SpaceManager(ClassType, type, lock);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4717
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4718
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4719
  MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4720
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4721
  // Allocate chunk for metadata objects
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4722
  initialize_first_chunk(type, NonClassType);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4723
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4724
  // Allocate chunk for class metadata objects
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4725
  if (using_class_space()) {
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4726
    initialize_first_chunk(type, ClassType);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4727
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4728
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4729
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4730
size_t Metaspace::align_word_size_up(size_t word_size) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4731
  size_t byte_size = word_size * wordSize;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4732
  return ReservedSpace::allocation_align_size_up(byte_size) / wordSize;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4733
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4734
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4735
MetaWord* Metaspace::allocate(size_t word_size, MetadataType mdtype) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4736
  assert(!_frozen, "sanity");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4737
  // Don't use class_vsm() unless UseCompressedClassPointers is true.
20306
f6805e2a0dd8 8025279: metaspace/flags/maxMetaspaceSize throws OOM: out of Compressed Klass space
mgerdin
parents: 20084
diff changeset
  4738
  if (is_class_space_allocation(mdtype)) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  4739
    return  class_vsm()->allocate(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4740
  } else {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  4741
    return  vsm()->allocate(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4742
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4743
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4744
13755
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  4745
MetaWord* Metaspace::expand_and_allocate(size_t word_size, MetadataType mdtype) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4746
  assert(!_frozen, "sanity");
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4747
  size_t delta_bytes = MetaspaceGC::delta_capacity_until_GC(word_size * BytesPerWord);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4748
  assert(delta_bytes > 0, "Must be");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4749
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  4750
  size_t before = 0;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  4751
  size_t after = 0;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  4752
  MetaWord* res;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  4753
  bool incremented;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  4754
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  4755
  // Each thread increments the HWM at most once. Even if the thread fails to increment
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  4756
  // the HWM, an allocation is still attempted. This is because another thread must then
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  4757
  // have incremented the HWM and therefore the allocation might still succeed.
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  4758
  do {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  4759
    incremented = MetaspaceGC::inc_capacity_until_GC(delta_bytes, &after, &before);
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  4760
    res = allocate(word_size, mdtype);
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  4761
  } while (!incremented && res == NULL);
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  4762
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  4763
  if (incremented) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  4764
    tracer()->report_gc_threshold(before, after,
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  4765
                                  MetaspaceGCThresholdUpdater::ExpandAndAllocate);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  4766
    log_trace(gc, metaspace)("Increase capacity to GC from " SIZE_FORMAT " to " SIZE_FORMAT, before, after);
13755
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  4767
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  4768
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  4769
  return res;
13755
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  4770
}
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  4771
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4772
size_t Metaspace::used_words_slow(MetadataType mdtype) const {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4773
  if (mdtype == ClassType) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4774
    return using_class_space() ? class_vsm()->sum_used_in_chunks_in_use() : 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4775
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4776
    return vsm()->sum_used_in_chunks_in_use();  // includes overhead!
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4777
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4778
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4779
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  4780
size_t Metaspace::free_words_slow(MetadataType mdtype) const {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4781
  assert(!_frozen, "sanity");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4782
  if (mdtype == ClassType) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4783
    return using_class_space() ? class_vsm()->sum_free_in_chunks_in_use() : 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4784
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4785
    return vsm()->sum_free_in_chunks_in_use();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4786
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4787
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4788
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4789
// Space capacity in the Metaspace.  It includes
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4790
// space in the list of chunks from which allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4791
// have been made. Don't include space in the global freelist and
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4792
// in the space available in the dictionary which
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4793
// is already counted in some chunk.
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4794
size_t Metaspace::capacity_words_slow(MetadataType mdtype) const {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4795
  if (mdtype == ClassType) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4796
    return using_class_space() ? class_vsm()->sum_capacity_in_chunks_in_use() : 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4797
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4798
    return vsm()->sum_capacity_in_chunks_in_use();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4799
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4800
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4801
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4802
size_t Metaspace::used_bytes_slow(MetadataType mdtype) const {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4803
  return used_words_slow(mdtype) * BytesPerWord;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4804
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4805
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4806
size_t Metaspace::capacity_bytes_slow(MetadataType mdtype) const {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4807
  return capacity_words_slow(mdtype) * BytesPerWord;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4808
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4809
25051
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  4810
size_t Metaspace::allocated_blocks_bytes() const {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  4811
  return vsm()->allocated_blocks_bytes() +
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  4812
      (using_class_space() ? class_vsm()->allocated_blocks_bytes() : 0);
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  4813
}
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  4814
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  4815
size_t Metaspace::allocated_chunks_bytes() const {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  4816
  return vsm()->allocated_chunks_bytes() +
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  4817
      (using_class_space() ? class_vsm()->allocated_chunks_bytes() : 0);
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  4818
}
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  4819
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4820
void Metaspace::deallocate(MetaWord* ptr, size_t word_size, bool is_class) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4821
  assert(!_frozen, "sanity");
23503
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  4822
  assert(!SafepointSynchronize::is_at_safepoint()
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  4823
         || Thread::current()->is_VM_thread(), "should be the VM thread");
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  4824
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  4825
  MutexLockerEx ml(vsm()->lock(), Mutex::_no_safepoint_check_flag);
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  4826
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  4827
  if (is_class && using_class_space()) {
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  4828
    class_vsm()->deallocate(ptr, word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4829
  } else {
23503
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  4830
    vsm()->deallocate(ptr, word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4831
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4832
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4833
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  4834
MetaWord* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4835
                              MetaspaceObj::Type type, TRAPS) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4836
  assert(!_frozen, "sanity");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4837
  if (HAS_PENDING_EXCEPTION) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4838
    assert(false, "Should not allocate with exception pending");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4839
    return NULL;  // caller does a CHECK_NULL too
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4840
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4841
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4842
  assert(loader_data != NULL, "Should never pass around a NULL loader_data. "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4843
        "ClassLoaderData::the_null_class_loader_data() should have been used.");
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4844
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4845
  MetadataType mdtype = (type == MetaspaceObj::ClassType) ? ClassType : NonClassType;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4846
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4847
  // Try to allocate metadata.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4848
  MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4849
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4850
  if (result == NULL) {
23468
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4851
    tracer()->report_metaspace_allocation_failure(loader_data, word_size, type, mdtype);
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4852
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4853
    // Allocation failed.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4854
    if (is_init_completed()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4855
      // Only start a GC if the bootstrapping has completed.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4856
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4857
      // Try to clean out some memory and retry.
49045
9b556b613a07 8198509: Move satisfy_failed_metadata_allocation out from CollectorPolicy
stefank
parents: 48971
diff changeset
  4858
      result = Universe::heap()->satisfy_failed_metadata_allocation(loader_data, word_size, mdtype);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4859
    }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4860
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4861
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4862
  if (result == NULL) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4863
    report_metadata_oome(loader_data, word_size, type, mdtype, CHECK_NULL);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4864
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4865
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  4866
  // Zero initialize.
35898
ddc274f0052f 8145628: hotspot metadata classes shouldn't use HeapWordSize or heap related macros like align_object_size
coleenp
parents: 35231
diff changeset
  4867
  Copy::fill_to_words((HeapWord*)result, word_size, 0);
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  4868
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  4869
  return result;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4870
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4871
21186
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4872
size_t Metaspace::class_chunk_size(size_t word_size) {
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4873
  assert(using_class_space(), "Has to use class space");
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4874
  return class_vsm()->calc_chunk_size(word_size);
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4875
}
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4876
23469
0a4d02776968 8036701: Add trace event when a metaspace throws out of memory error
ehelin
parents: 23468
diff changeset
  4877
void Metaspace::report_metadata_oome(ClassLoaderData* loader_data, size_t word_size, MetaspaceObj::Type type, MetadataType mdtype, TRAPS) {
0a4d02776968 8036701: Add trace event when a metaspace throws out of memory error
ehelin
parents: 23468
diff changeset
  4878
  tracer()->report_metadata_oom(loader_data, word_size, type, mdtype);
0a4d02776968 8036701: Add trace event when a metaspace throws out of memory error
ehelin
parents: 23468
diff changeset
  4879
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4880
  // If result is still null, we are out of memory.
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37151
diff changeset
  4881
  Log(gc, metaspace, freelist) log;
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  4882
  if (log.is_info()) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  4883
    log.info("Metaspace (%s) allocation failed for size " SIZE_FORMAT,
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  4884
             is_class_space_allocation(mdtype) ? "class" : "data", word_size);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  4885
    ResourceMark rm;
46723
5c418c5fcade 8185262: Keep default logging for Metaspace OOM short and concise
stuefe
parents: 46709
diff changeset
  4886
    if (log.is_debug()) {
5c418c5fcade 8185262: Keep default logging for Metaspace OOM short and concise
stuefe
parents: 46709
diff changeset
  4887
      if (loader_data->metaspace_or_null() != NULL) {
5c418c5fcade 8185262: Keep default logging for Metaspace OOM short and concise
stuefe
parents: 46709
diff changeset
  4888
        LogStream ls(log.debug());
5c418c5fcade 8185262: Keep default logging for Metaspace OOM short and concise
stuefe
parents: 46709
diff changeset
  4889
        loader_data->dump(&ls);
5c418c5fcade 8185262: Keep default logging for Metaspace OOM short and concise
stuefe
parents: 46709
diff changeset
  4890
      }
5c418c5fcade 8185262: Keep default logging for Metaspace OOM short and concise
stuefe
parents: 46709
diff changeset
  4891
    }
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  4892
    LogStream ls(log.info());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  4893
    MetaspaceAux::dump(&ls);
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4894
    MetaspaceAux::print_metaspace_map(&ls, mdtype);
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  4895
    ChunkManager::print_all_chunkmanagers(&ls);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4896
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4897
21186
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4898
  bool out_of_compressed_class_space = false;
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4899
  if (is_class_space_allocation(mdtype)) {
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4900
    Metaspace* metaspace = loader_data->metaspace_non_null();
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4901
    out_of_compressed_class_space =
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4902
      MetaspaceAux::committed_bytes(Metaspace::ClassType) +
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4903
      (metaspace->class_chunk_size(word_size) * BytesPerWord) >
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4904
      CompressedClassSpaceSize;
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4905
  }
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4906
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4907
  // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
21186
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4908
  const char* space_string = out_of_compressed_class_space ?
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4909
    "Compressed class space" : "Metaspace";
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4910
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4911
  report_java_out_of_memory(space_string);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4912
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4913
  if (JvmtiExport::should_post_resource_exhausted()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4914
    JvmtiExport::post_resource_exhausted(
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4915
        JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4916
        space_string);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4917
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4918
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4919
  if (!is_init_completed()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4920
    vm_exit_during_initialization("OutOfMemoryError", space_string);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4921
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4922
21186
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4923
  if (out_of_compressed_class_space) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4924
    THROW_OOP(Universe::out_of_memory_error_class_metaspace());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4925
  } else {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4926
    THROW_OOP(Universe::out_of_memory_error_metaspace());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4927
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4928
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4929
23468
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4930
const char* Metaspace::metadata_type_name(Metaspace::MetadataType mdtype) {
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4931
  switch (mdtype) {
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4932
    case Metaspace::ClassType: return "Class";
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4933
    case Metaspace::NonClassType: return "Metadata";
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4934
    default:
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4935
      assert(false, "Got bad mdtype: %d", (int) mdtype);
23468
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4936
      return NULL;
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4937
  }
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4938
}
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4939
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4940
void Metaspace::purge(MetadataType mdtype) {
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4941
  get_space_list(mdtype)->purge(get_chunk_manager(mdtype));
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4942
}
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4943
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  4944
void Metaspace::purge() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  4945
  MutexLockerEx cl(SpaceManager::expand_lock(),
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  4946
                   Mutex::_no_safepoint_check_flag);
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4947
  purge(NonClassType);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4948
  if (using_class_space()) {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4949
    purge(ClassType);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4950
  }
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  4951
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  4952
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4953
void Metaspace::print_on(outputStream* out) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4954
  // Print both class virtual space counts and metaspace.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4955
  if (Verbose) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4956
    vsm()->print_on(out);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4957
    if (using_class_space()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4958
      class_vsm()->print_on(out);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4959
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4960
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4961
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4962
22201
9c2ccfa3a5fe 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 21569
diff changeset
  4963
bool Metaspace::contains(const void* ptr) {
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48387
diff changeset
  4964
  if (MetaspaceShared::is_in_shared_metaspace(ptr)) {
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  4965
    return true;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4966
  }
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 42650
diff changeset
  4967
  return contains_non_shared(ptr);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 42650
diff changeset
  4968
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 42650
diff changeset
  4969
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 42650
diff changeset
  4970
bool Metaspace::contains_non_shared(const void* ptr) {
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  4971
  if (using_class_space() && get_space_list(ClassType)->contains(ptr)) {
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  4972
     return true;
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  4973
  }
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  4974
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  4975
  return get_space_list(NonClassType)->contains(ptr);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4976
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4977
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4978
void Metaspace::verify() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4979
  vsm()->verify();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4980
  if (using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4981
    class_vsm()->verify();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4982
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4983
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4984
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4985
void Metaspace::dump(outputStream* const out) const {
29800
fa5f7a2bf717 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29697
diff changeset
  4986
  out->print_cr("\nVirtual space manager: " INTPTR_FORMAT, p2i(vsm()));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4987
  vsm()->dump(out);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4988
  if (using_class_space()) {
29800
fa5f7a2bf717 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29697
diff changeset
  4989
    out->print_cr("\nClass space manager: " INTPTR_FORMAT, p2i(class_vsm()));
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4990
    class_vsm()->dump(out);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4991
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4992
}
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4993
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4994
#ifdef ASSERT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4995
static void do_verify_chunk(Metachunk* chunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4996
  guarantee(chunk != NULL, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4997
  // Verify chunk itself; then verify that it is consistent with the
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4998
  // occupany map of its containing node.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4999
  chunk->verify();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5000
  VirtualSpaceNode* const vsn = chunk->container();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5001
  OccupancyMap* const ocmap = vsn->occupancy_map();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5002
  ocmap->verify_for_chunk(chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5003
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5004
#endif
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5005
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5006
static void do_update_in_use_info_for_chunk(Metachunk* chunk, bool inuse) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5007
  chunk->set_is_tagged_free(!inuse);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5008
  OccupancyMap* const ocmap = chunk->container()->occupancy_map();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5009
  ocmap->set_region_in_use((MetaWord*)chunk, chunk->word_size(), inuse);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5010
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5011
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5012
/////////////// Unit tests ///////////////
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5013
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5014
#ifndef PRODUCT
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5015
20084
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5016
class TestMetaspaceAuxTest : AllStatic {
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5017
 public:
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5018
  static void test_reserved() {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5019
    size_t reserved = MetaspaceAux::reserved_bytes();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5020
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5021
    assert(reserved > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5022
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5023
    size_t committed  = MetaspaceAux::committed_bytes();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5024
    assert(committed <= reserved, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5025
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5026
    size_t reserved_metadata = MetaspaceAux::reserved_bytes(Metaspace::NonClassType);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5027
    assert(reserved_metadata > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5028
    assert(reserved_metadata <= reserved, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5029
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5030
    if (UseCompressedClassPointers) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5031
      size_t reserved_class    = MetaspaceAux::reserved_bytes(Metaspace::ClassType);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5032
      assert(reserved_class > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5033
      assert(reserved_class < reserved, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5034
    }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5035
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5036
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5037
  static void test_committed() {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5038
    size_t committed = MetaspaceAux::committed_bytes();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5039
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5040
    assert(committed > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5041
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5042
    size_t reserved  = MetaspaceAux::reserved_bytes();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5043
    assert(committed <= reserved, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5044
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5045
    size_t committed_metadata = MetaspaceAux::committed_bytes(Metaspace::NonClassType);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5046
    assert(committed_metadata > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5047
    assert(committed_metadata <= committed, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5048
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5049
    if (UseCompressedClassPointers) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5050
      size_t committed_class    = MetaspaceAux::committed_bytes(Metaspace::ClassType);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5051
      assert(committed_class > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5052
      assert(committed_class < committed, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5053
    }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5054
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5055
20084
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5056
  static void test_virtual_space_list_large_chunk() {
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5057
    VirtualSpaceList* vs_list = new VirtualSpaceList(os::vm_allocation_granularity());
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5058
    MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5059
    // A size larger than VirtualSpaceSize (256k) and add one page to make it _not_ be
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5060
    // vm_allocation_granularity aligned on Windows.
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5061
    size_t large_size = (size_t)(2*256*K + (os::vm_page_size()/BytesPerWord));
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5062
    large_size += (os::vm_page_size()/BytesPerWord);
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5063
    vs_list->get_new_chunk(large_size, 0);
20084
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5064
  }
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5065
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5066
  static void test() {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5067
    test_reserved();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5068
    test_committed();
20084
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5069
    test_virtual_space_list_large_chunk();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5070
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5071
};
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5072
20084
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5073
void TestMetaspaceAux_test() {
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5074
  TestMetaspaceAuxTest::test();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5075
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5076
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5077
class TestVirtualSpaceNodeTest {
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5078
  static void chunk_up(size_t words_left, size_t& num_medium_chunks,
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5079
                                          size_t& num_small_chunks,
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5080
                                          size_t& num_specialized_chunks) {
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5081
    num_medium_chunks = words_left / MediumChunk;
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5082
    words_left = words_left % MediumChunk;
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5083
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5084
    num_small_chunks = words_left / SmallChunk;
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5085
    words_left = words_left % SmallChunk;
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5086
    // how many specialized chunks can we get?
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5087
    num_specialized_chunks = words_left / SpecializedChunk;
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5088
    assert(words_left % SpecializedChunk == 0, "should be nothing left");
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5089
  }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5090
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5091
 public:
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5092
  static void test() {
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5093
    MutexLockerEx ml(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5094
    const size_t vsn_test_size_words = MediumChunk  * 4;
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5095
    const size_t vsn_test_size_bytes = vsn_test_size_words * BytesPerWord;
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5096
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5097
    // The chunk sizes must be multiples of eachother, or this will fail
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5098
    STATIC_ASSERT(MediumChunk % SmallChunk == 0);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5099
    STATIC_ASSERT(SmallChunk % SpecializedChunk == 0);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5100
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5101
    { // No committed memory in VSN
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5102
      ChunkManager cm(false);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5103
      VirtualSpaceNode vsn(false, vsn_test_size_bytes);
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5104
      vsn.initialize();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5105
      vsn.retire(&cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5106
      assert(cm.sum_free_chunks_count() == 0, "did not commit any memory in the VSN");
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5107
    }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5108
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5109
    { // All of VSN is committed, half is used by chunks
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5110
      ChunkManager cm(false);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5111
      VirtualSpaceNode vsn(false, vsn_test_size_bytes);
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5112
      vsn.initialize();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5113
      vsn.expand_by(vsn_test_size_words, vsn_test_size_words);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5114
      vsn.get_chunk_vs(MediumChunk);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5115
      vsn.get_chunk_vs(MediumChunk);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5116
      vsn.retire(&cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5117
      assert(cm.sum_free_chunks_count() == 2, "should have been memory left for 2 medium chunks");
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5118
      assert(cm.sum_free_chunks() == 2*MediumChunk, "sizes should add up");
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5119
    }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5120
28497
a7aecf0ffb6b 8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents: 28372
diff changeset
  5121
    const size_t page_chunks = 4 * (size_t)os::vm_page_size() / BytesPerWord;
a7aecf0ffb6b 8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents: 28372
diff changeset
  5122
    // This doesn't work for systems with vm_page_size >= 16K.
a7aecf0ffb6b 8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents: 28372
diff changeset
  5123
    if (page_chunks < MediumChunk) {
a7aecf0ffb6b 8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents: 28372
diff changeset
  5124
      // 4 pages of VSN is committed, some is used by chunks
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5125
      ChunkManager cm(false);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5126
      VirtualSpaceNode vsn(false, vsn_test_size_bytes);
28497
a7aecf0ffb6b 8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents: 28372
diff changeset
  5127
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5128
      vsn.initialize();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5129
      vsn.expand_by(page_chunks, page_chunks);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5130
      vsn.get_chunk_vs(SmallChunk);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5131
      vsn.get_chunk_vs(SpecializedChunk);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5132
      vsn.retire(&cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5133
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5134
      // committed - used = words left to retire
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5135
      const size_t words_left = page_chunks - SmallChunk - SpecializedChunk;
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5136
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5137
      size_t num_medium_chunks, num_small_chunks, num_spec_chunks;
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5138
      chunk_up(words_left, num_medium_chunks, num_small_chunks, num_spec_chunks);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5139
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5140
      assert(num_medium_chunks == 0, "should not get any medium chunks");
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5141
      assert(cm.sum_free_chunks_count() == (num_small_chunks + num_spec_chunks), "should be space for 3 chunks");
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5142
      assert(cm.sum_free_chunks() == words_left, "sizes should add up");
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5143
    }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5144
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5145
    { // Half of VSN is committed, a humongous chunk is used
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5146
      ChunkManager cm(false);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5147
      VirtualSpaceNode vsn(false, vsn_test_size_bytes);
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5148
      vsn.initialize();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5149
      vsn.expand_by(MediumChunk * 2, MediumChunk * 2);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5150
      vsn.get_chunk_vs(MediumChunk + SpecializedChunk); // Humongous chunks will be aligned up to MediumChunk + SpecializedChunk
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5151
      vsn.retire(&cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5152
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5153
      const size_t words_left = MediumChunk * 2 - (MediumChunk + SpecializedChunk);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5154
      size_t num_medium_chunks, num_small_chunks, num_spec_chunks;
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5155
      chunk_up(words_left, num_medium_chunks, num_small_chunks, num_spec_chunks);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5156
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5157
      assert(num_medium_chunks == 0, "should not get any medium chunks");
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5158
      assert(cm.sum_free_chunks_count() == (num_small_chunks + num_spec_chunks), "should be space for 3 chunks");
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5159
      assert(cm.sum_free_chunks() == words_left, "sizes should add up");
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5160
    }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5161
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5162
  }
22222
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5163
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5164
#define assert_is_available_positive(word_size) \
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5165
  assert(vsn.is_available(word_size), \
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  5166
         #word_size ": " PTR_FORMAT " bytes were not available in " \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  5167
         "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  5168
         (uintptr_t)(word_size * BytesPerWord), p2i(vsn.bottom()), p2i(vsn.end()));
22222
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5169
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5170
#define assert_is_available_negative(word_size) \
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5171
  assert(!vsn.is_available(word_size), \
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  5172
         #word_size ": " PTR_FORMAT " bytes should not be available in " \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  5173
         "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  5174
         (uintptr_t)(word_size * BytesPerWord), p2i(vsn.bottom()), p2i(vsn.end()));
22222
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5175
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5176
  static void test_is_available_positive() {
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5177
    // Reserve some memory.
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5178
    VirtualSpaceNode vsn(false, os::vm_allocation_granularity());
22222
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5179
    assert(vsn.initialize(), "Failed to setup VirtualSpaceNode");
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5180
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5181
    // Commit some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5182
    size_t commit_word_size = os::vm_allocation_granularity() / BytesPerWord;
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5183
    bool expanded = vsn.expand_by(commit_word_size, commit_word_size);
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5184
    assert(expanded, "Failed to commit");
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5185
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5186
    // Check that is_available accepts the committed size.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5187
    assert_is_available_positive(commit_word_size);
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5188
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5189
    // Check that is_available accepts half the committed size.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5190
    size_t expand_word_size = commit_word_size / 2;
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5191
    assert_is_available_positive(expand_word_size);
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5192
  }
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5193
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5194
  static void test_is_available_negative() {
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5195
    // Reserve some memory.
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5196
    VirtualSpaceNode vsn(false, os::vm_allocation_granularity());
22222
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5197
    assert(vsn.initialize(), "Failed to setup VirtualSpaceNode");
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5198
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5199
    // Commit some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5200
    size_t commit_word_size = os::vm_allocation_granularity() / BytesPerWord;
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5201
    bool expanded = vsn.expand_by(commit_word_size, commit_word_size);
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5202
    assert(expanded, "Failed to commit");
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5203
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5204
    // Check that is_available doesn't accept a too large size.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5205
    size_t two_times_commit_word_size = commit_word_size * 2;
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5206
    assert_is_available_negative(two_times_commit_word_size);
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5207
  }
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5208
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5209
  static void test_is_available_overflow() {
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5210
    // Reserve some memory.
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5211
    VirtualSpaceNode vsn(false, os::vm_allocation_granularity());
22222
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5212
    assert(vsn.initialize(), "Failed to setup VirtualSpaceNode");
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5213
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5214
    // Commit some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5215
    size_t commit_word_size = os::vm_allocation_granularity() / BytesPerWord;
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5216
    bool expanded = vsn.expand_by(commit_word_size, commit_word_size);
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5217
    assert(expanded, "Failed to commit");
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5218
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5219
    // Calculate a size that will overflow the virtual space size.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5220
    void* virtual_space_max = (void*)(uintptr_t)-1;
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5221
    size_t bottom_to_max = pointer_delta(virtual_space_max, vsn.bottom(), 1);
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5222
    size_t overflow_size = bottom_to_max + BytesPerWord;
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5223
    size_t overflow_word_size = overflow_size / BytesPerWord;
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5224
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5225
    // Check that is_available can handle the overflow.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5226
    assert_is_available_negative(overflow_word_size);
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5227
  }
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5228
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5229
  static void test_is_available() {
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5230
    TestVirtualSpaceNodeTest::test_is_available_positive();
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5231
    TestVirtualSpaceNodeTest::test_is_available_negative();
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5232
    TestVirtualSpaceNodeTest::test_is_available_overflow();
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5233
  }
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5234
};
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5235
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5236
// The following test is placed here instead of a gtest / unittest file
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5237
// because the ChunkManager class is only available in this file.
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5238
void ChunkManager_test_list_index() {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5239
  ChunkManager manager(true);
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5240
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5241
  // Test previous bug where a query for a humongous class metachunk,
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5242
  // incorrectly matched the non-class medium metachunk size.
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5243
  {
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5244
    assert(MediumChunk > ClassMediumChunk, "Precondition for test");
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5245
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5246
    ChunkIndex index = manager.list_index(MediumChunk);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5247
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5248
    assert(index == HumongousIndex,
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5249
           "Requested size is larger than ClassMediumChunk,"
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5250
           " so should return HumongousIndex. Got index: %d", (int)index);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5251
  }
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5252
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5253
  // Check the specified sizes as well.
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5254
  {
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5255
    ChunkIndex index = manager.list_index(ClassSpecializedChunk);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5256
    assert(index == SpecializedIndex, "Wrong index returned. Got index: %d", (int)index);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5257
  }
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5258
  {
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5259
    ChunkIndex index = manager.list_index(ClassSmallChunk);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5260
    assert(index == SmallIndex, "Wrong index returned. Got index: %d", (int)index);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5261
  }
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5262
  {
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5263
    ChunkIndex index = manager.list_index(ClassMediumChunk);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5264
    assert(index == MediumIndex, "Wrong index returned. Got index: %d", (int)index);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5265
  }
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5266
  {
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5267
    ChunkIndex index = manager.list_index(ClassMediumChunk + 1);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5268
    assert(index == HumongousIndex, "Wrong index returned. Got index: %d", (int)index);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5269
  }
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5270
}
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5271
46602
f63ae85597f1 8183228: Fix optimized build after JDK-8170933
stuefe
parents: 46587
diff changeset
  5272
#endif // !PRODUCT
f63ae85597f1 8183228: Fix optimized build after JDK-8170933
stuefe
parents: 46587
diff changeset
  5273
f63ae85597f1 8183228: Fix optimized build after JDK-8170933
stuefe
parents: 46587
diff changeset
  5274
#ifdef ASSERT
f63ae85597f1 8183228: Fix optimized build after JDK-8170933
stuefe
parents: 46587
diff changeset
  5275
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5276
// The following test is placed here instead of a gtest / unittest file
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5277
// because the ChunkManager class is only available in this file.
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5278
class SpaceManagerTest : AllStatic {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5279
  friend void SpaceManager_test_adjust_initial_chunk_size();
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5280
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5281
  static void test_adjust_initial_chunk_size(bool is_class) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5282
    const size_t smallest = SpaceManager::smallest_chunk_size(is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5283
    const size_t normal   = SpaceManager::small_chunk_size(is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5284
    const size_t medium   = SpaceManager::medium_chunk_size(is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5285
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5286
#define test_adjust_initial_chunk_size(value, expected, is_class_value)          \
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5287
    do {                                                                         \
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5288
      size_t v = value;                                                          \
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5289
      size_t e = expected;                                                       \
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5290
      assert(SpaceManager::adjust_initial_chunk_size(v, (is_class_value)) == e,  \
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5291
             "Expected: " SIZE_FORMAT " got: " SIZE_FORMAT, e, v);               \
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5292
    } while (0)
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5293
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5294
    // Smallest (specialized)
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5295
    test_adjust_initial_chunk_size(1,            smallest, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5296
    test_adjust_initial_chunk_size(smallest - 1, smallest, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5297
    test_adjust_initial_chunk_size(smallest,     smallest, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5298
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5299
    // Small
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5300
    test_adjust_initial_chunk_size(smallest + 1, normal, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5301
    test_adjust_initial_chunk_size(normal - 1,   normal, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5302
    test_adjust_initial_chunk_size(normal,       normal, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5303
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5304
    // Medium
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5305
    test_adjust_initial_chunk_size(normal + 1, medium, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5306
    test_adjust_initial_chunk_size(medium - 1, medium, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5307
    test_adjust_initial_chunk_size(medium,     medium, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5308
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5309
    // Humongous
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5310
    test_adjust_initial_chunk_size(medium + 1, medium + 1, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5311
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5312
#undef test_adjust_initial_chunk_size
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5313
  }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5314
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5315
  static void test_adjust_initial_chunk_size() {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5316
    test_adjust_initial_chunk_size(false);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5317
    test_adjust_initial_chunk_size(true);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5318
  }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5319
};
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5320
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5321
void SpaceManager_test_adjust_initial_chunk_size() {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5322
  SpaceManagerTest::test_adjust_initial_chunk_size();
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5323
}
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5324
46602
f63ae85597f1 8183228: Fix optimized build after JDK-8170933
stuefe
parents: 46587
diff changeset
  5325
#endif // ASSERT
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5326
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5327
struct chunkmanager_statistics_t {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5328
  int num_specialized_chunks;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5329
  int num_small_chunks;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5330
  int num_medium_chunks;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5331
  int num_humongous_chunks;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5332
};
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5333
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5334
extern void test_metaspace_retrieve_chunkmanager_statistics(Metaspace::MetadataType mdType, chunkmanager_statistics_t* out) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5335
  ChunkManager* const chunk_manager = Metaspace::get_chunk_manager(mdType);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5336
  ChunkManager::ChunkManagerStatistics stat;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5337
  chunk_manager->get_statistics(&stat);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5338
  out->num_specialized_chunks = (int)stat.num_by_type[SpecializedIndex];
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5339
  out->num_small_chunks = (int)stat.num_by_type[SmallIndex];
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5340
  out->num_medium_chunks = (int)stat.num_by_type[MediumIndex];
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5341
  out->num_humongous_chunks = (int)stat.num_humongous_chunks;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5342
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5343
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5344
struct chunk_geometry_t {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5345
  size_t specialized_chunk_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5346
  size_t small_chunk_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5347
  size_t medium_chunk_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5348
};
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5349
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5350
extern void test_metaspace_retrieve_chunk_geometry(Metaspace::MetadataType mdType, chunk_geometry_t* out) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5351
  if (mdType == Metaspace::NonClassType) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5352
    out->specialized_chunk_word_size = SpecializedChunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5353
    out->small_chunk_word_size = SmallChunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5354
    out->medium_chunk_word_size = MediumChunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5355
  } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5356
    out->specialized_chunk_word_size = ClassSpecializedChunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5357
    out->small_chunk_word_size = ClassSmallChunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5358
    out->medium_chunk_word_size = ClassMediumChunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5359
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5360
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5361