src/hotspot/share/memory/metaspace.cpp
author coleenp
Mon, 26 Mar 2018 09:35:20 -0400
changeset 49601 bfc70d5d291a
parent 49594 898ef81cbc0e
child 49652 a74836b05c28
permissions -rw-r--r--
8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp Summary: We should avoid having global locks buried in cpp files Reviewed-by: tschatzl, lfoltan, gtriantafill, stuefe
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"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
    28
#include "logging/log.hpp"
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
    29
#include "logging/logStream.hpp"
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
    30
#include "memory/allocation.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    31
#include "memory/binaryTreeDictionary.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    32
#include "memory/filemap.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    33
#include "memory/freeList.hpp"
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
    34
#include "memory/metachunk.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    35
#include "memory/metaspace.hpp"
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
    36
#include "memory/metaspaceGCThresholdUpdater.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    37
#include "memory/metaspaceShared.hpp"
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
    38
#include "memory/metaspaceTracer.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    39
#include "memory/resourceArea.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    40
#include "memory/universe.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39986
diff changeset
    41
#include "runtime/atomic.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    42
#include "runtime/globals.hpp"
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
    43
#include "runtime/init.hpp"
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
    44
#include "runtime/java.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    45
#include "runtime/mutex.hpp"
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 23854
diff changeset
    46
#include "runtime/orderAccess.inline.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    47
#include "services/memTracker.hpp"
20407
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
    48
#include "services/memoryService.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    49
#include "utilities/align.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    50
#include "utilities/copy.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    51
#include "utilities/debug.hpp"
27683
1d5707553fff 8064580: Move INCLUDE_CDS include section to the end of the include list
stefank
parents: 27404
diff changeset
    52
#include "utilities/macros.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    53
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
    54
typedef BinaryTreeDictionary<Metablock, FreeList<Metablock> > BlockTreeDictionary;
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
    55
typedef BinaryTreeDictionary<Metachunk, FreeList<Metachunk> > ChunkTreeDictionary;
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
    56
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    57
// Helper function that does a bunch of checks for a chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    58
DEBUG_ONLY(static void do_verify_chunk(Metachunk* chunk);)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    59
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    60
// Given a Metachunk, update its in-use information (both in the
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    61
// chunk and the occupancy map).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    62
static void do_update_in_use_info_for_chunk(Metachunk* chunk, bool inuse);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    63
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
    64
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
    65
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    66
MetaWord* last_allocated = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    67
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
    68
size_t Metaspace::_compressed_class_space_size;
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
    69
const MetaspaceTracer* Metaspace::_tracer = NULL;
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
    70
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
    71
DEBUG_ONLY(bool Metaspace::_frozen = false;)
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
    72
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    73
enum ChunkSizes {    // in words.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    74
  ClassSpecializedChunk = 128,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    75
  SpecializedChunk = 128,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    76
  ClassSmallChunk = 256,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    77
  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
    78
  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
    79
  MediumChunk = 8 * K
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    80
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    81
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    82
// Returns size of this chunk type.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    83
size_t get_size_for_nonhumongous_chunktype(ChunkIndex chunktype, bool is_class) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    84
  assert(is_valid_nonhumongous_chunktype(chunktype), "invalid chunk type.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    85
  size_t size = 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    86
  if (is_class) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    87
    switch(chunktype) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    88
      case SpecializedIndex: size = ClassSpecializedChunk; break;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    89
      case SmallIndex: size = ClassSmallChunk; break;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    90
      case MediumIndex: size = ClassMediumChunk; break;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    91
      default:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    92
        ShouldNotReachHere();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    93
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    94
  } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    95
    switch(chunktype) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    96
      case SpecializedIndex: size = SpecializedChunk; break;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    97
      case SmallIndex: size = SmallChunk; break;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    98
      case MediumIndex: size = MediumChunk; break;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
    99
      default:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   100
        ShouldNotReachHere();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   101
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   102
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   103
  return size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   104
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   105
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   106
ChunkIndex get_chunk_type_by_size(size_t size, bool is_class) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   107
  if (is_class) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   108
    if (size == ClassSpecializedChunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   109
      return SpecializedIndex;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   110
    } else if (size == ClassSmallChunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   111
      return SmallIndex;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   112
    } else if (size == ClassMediumChunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   113
      return MediumIndex;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   114
    } else if (size > ClassMediumChunk) {
49453
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
   115
      // A valid humongous chunk size is a multiple of the smallest chunk size.
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   116
      assert(is_aligned(size, ClassSpecializedChunk), "Invalid chunk size");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   117
      return HumongousIndex;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   118
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   119
  } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   120
    if (size == SpecializedChunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   121
      return SpecializedIndex;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   122
    } else if (size == SmallChunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   123
      return SmallIndex;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   124
    } else if (size == MediumChunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   125
      return MediumIndex;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   126
    } else if (size > MediumChunk) {
49453
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
   127
      // A valid humongous chunk size is a multiple of the smallest chunk size.
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   128
      assert(is_aligned(size, SpecializedChunk), "Invalid chunk size");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   129
      return HumongousIndex;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   130
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   131
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   132
  ShouldNotReachHere();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   133
  return (ChunkIndex)-1;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   134
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   135
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   136
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   137
static ChunkIndex next_chunk_index(ChunkIndex i) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   138
  assert(i < NumberOfInUseLists, "Out of bound");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   139
  return (ChunkIndex) (i+1);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   140
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   141
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   142
static ChunkIndex prev_chunk_index(ChunkIndex i) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   143
  assert(i > ZeroIndex, "Out of bound");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   144
  return (ChunkIndex) (i-1);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   145
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   146
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   147
static const char* scale_unit(size_t scale) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   148
  switch(scale) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   149
    case 1: return "BYTES";
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   150
    case K: return "KB";
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   151
    case M: return "MB";
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   152
    case G: return "GB";
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   153
    default:
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   154
      ShouldNotReachHere();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   155
      return NULL;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   156
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   157
}
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   158
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   159
volatile intptr_t MetaspaceGC::_capacity_until_GC = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   160
uint MetaspaceGC::_shrink_factor = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   161
bool MetaspaceGC::_should_concurrent_collect = false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   162
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
   163
typedef class FreeList<Metachunk> ChunkList;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   164
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   165
// Manages the global free lists of chunks.
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   166
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
   167
  friend class TestVirtualSpaceNodeTest;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   168
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   169
  // Free list of chunks of different sizes.
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   170
  //   SpecializedChunk
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   171
  //   SmallChunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   172
  //   MediumChunk
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   173
  ChunkList _free_chunks[NumberOfFreeLists];
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   174
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   175
  // Whether or not this is the class chunkmanager.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   176
  const bool _is_class;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   177
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   178
  // 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
   179
  ChunkList* free_chunks(ChunkIndex index);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   180
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   181
  // 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
   182
  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
   183
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   184
  //   HumongousChunk
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   185
  ChunkTreeDictionary _humongous_dictionary;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   186
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   187
  // Returns the humongous chunk dictionary.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   188
  ChunkTreeDictionary* humongous_dictionary() {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   189
    return &_humongous_dictionary;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   190
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   191
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
   192
  // 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
   193
  size_t _free_chunks_total;
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
   194
  // Number of chunks in this ChunkManager
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   195
  size_t _free_chunks_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   196
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
   197
  // Update counters after a chunk was added or removed removed.
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
   198
  void account_for_added_chunk(const Metachunk* c);
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
   199
  void account_for_removed_chunk(const Metachunk* c);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   200
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   201
  // Debug support
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
  size_t sum_free_chunks();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   204
  size_t sum_free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   205
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   206
  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
   207
  void slow_locked_verify_free_chunks_total() {
49405
e88237c5ac83 8199656: Make slow metaspace verifications switchable in debug builds
stuefe
parents: 49402
diff changeset
   208
    if (VerifyMetaspace) {
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   209
      locked_verify_free_chunks_total();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   210
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   211
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   212
  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
   213
  void slow_locked_verify_free_chunks_count() {
49405
e88237c5ac83 8199656: Make slow metaspace verifications switchable in debug builds
stuefe
parents: 49402
diff changeset
   214
    if (VerifyMetaspace) {
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   215
      locked_verify_free_chunks_count();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   216
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   217
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   218
  void verify_free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   219
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   220
  // Given a pointer to a chunk, attempts to merge it with neighboring
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   221
  // free chunks to form a bigger chunk. Returns true if successful.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   222
  bool attempt_to_coalesce_around_chunk(Metachunk* chunk, ChunkIndex target_chunk_type);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   223
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   224
  // Helper for chunk merging:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   225
  //  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
   226
  //  free and hence currently managed by this ChunkManager, remove them
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   227
  //  from this ChunkManager and mark them as invalid.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   228
  // - This does not correct the occupancy map.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   229
  // - This does not adjust the counters in ChunkManager.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   230
  // - Does not adjust container count counter in containing VirtualSpaceNode.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   231
  // Returns number of chunks removed.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   232
  int remove_chunks_in_area(MetaWord* p, size_t word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   233
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   234
  // 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
   235
  // 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
   236
  // the target chunk of target chunk size. The smaller chunks, including the target
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   237
  // 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
   238
  // 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
   239
  Metachunk* split_chunk(size_t target_chunk_word_size, Metachunk* chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   240
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   241
 public:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   242
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   243
  struct ChunkManagerStatistics {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   244
    size_t num_by_type[NumberOfFreeLists];
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   245
    size_t single_size_by_type[NumberOfFreeLists];
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   246
    size_t total_size_by_type[NumberOfFreeLists];
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   247
    size_t num_humongous_chunks;
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   248
    size_t total_size_humongous_chunks;
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   249
  };
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   250
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   251
  void locked_get_statistics(ChunkManagerStatistics* stat) const;
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   252
  void get_statistics(ChunkManagerStatistics* stat) const;
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   253
  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
   254
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   255
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   256
  ChunkManager(bool is_class)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   257
      : _is_class(is_class), _free_chunks_total(0), _free_chunks_count(0) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   258
    _free_chunks[SpecializedIndex].set_size(get_size_for_nonhumongous_chunktype(SpecializedIndex, is_class));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   259
    _free_chunks[SmallIndex].set_size(get_size_for_nonhumongous_chunktype(SmallIndex, is_class));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   260
    _free_chunks[MediumIndex].set_size(get_size_for_nonhumongous_chunktype(MediumIndex, is_class));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   261
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   262
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   263
  // 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
   264
  Metachunk* chunk_freelist_allocate(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   265
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   266
  // 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
   267
  // 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
   268
  ChunkIndex list_index(size_t size);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   269
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   270
  // Map a given index to the chunk size.
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   271
  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
   272
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   273
  bool is_class() const { return _is_class; }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   274
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   275
  // Convenience accessors.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   276
  size_t medium_chunk_word_size() const { return size_by_index(MediumIndex); }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   277
  size_t small_chunk_word_size() const { return size_by_index(SmallIndex); }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   278
  size_t specialized_chunk_word_size() const { return size_by_index(SpecializedIndex); }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   279
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   280
  // 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
   281
  // 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
   282
  // humongous).
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   283
  void remove_chunk(Metachunk* chunk);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   284
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   285
  // 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
   286
  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
   287
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
   288
  // 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
   289
  // of type index.
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   290
  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
   291
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   292
  // Total of the space in the free chunks list
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
   293
  size_t free_chunks_total_words();
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
   294
  size_t free_chunks_total_bytes();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   295
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   296
  // Number of chunks in the free chunks list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   297
  size_t free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   298
20733
8dead86921fe 8026715: Remove the MetaDataDeallocateALot develop flag
stefank
parents: 20729
diff changeset
   299
  // 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
   300
  Metachunk* free_chunks_get(size_t chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   301
23470
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   302
#define index_bounds_check(index)                                         \
49453
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
   303
  assert(is_valid_chunktype(index), "Bad index: %d", (int) index)
23470
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   304
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   305
  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
   306
    index_bounds_check(index);
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   307
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   308
    if (index == HumongousIndex) {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   309
      return _humongous_dictionary.total_free_blocks();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   310
    }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   311
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   312
    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
   313
    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
   314
  }
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
  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
   317
    index_bounds_check(index);
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   318
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   319
    size_t word_size = 0;
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   320
    if (index == HumongousIndex) {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   321
      word_size = _humongous_dictionary.total_size();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   322
    } else {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   323
      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
   324
      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
   325
    }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   326
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   327
    return word_size * BytesPerWord;
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   328
  }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   329
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   330
  MetaspaceChunkFreeListSummary chunk_free_list_summary() const {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   331
    return MetaspaceChunkFreeListSummary(num_free_chunks(SpecializedIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   332
                                         num_free_chunks(SmallIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   333
                                         num_free_chunks(MediumIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   334
                                         num_free_chunks(HumongousIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   335
                                         size_free_chunks_in_bytes(SpecializedIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   336
                                         size_free_chunks_in_bytes(SmallIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   337
                                         size_free_chunks_in_bytes(MediumIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   338
                                         size_free_chunks_in_bytes(HumongousIndex));
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   339
  }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   340
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   341
  // Debug support
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   342
  void verify();
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   343
  void slow_verify() {
49405
e88237c5ac83 8199656: Make slow metaspace verifications switchable in debug builds
stuefe
parents: 49402
diff changeset
   344
    if (VerifyMetaspace) {
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   345
      verify();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   346
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   347
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   348
  void locked_verify();
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   349
  void slow_locked_verify() {
49405
e88237c5ac83 8199656: Make slow metaspace verifications switchable in debug builds
stuefe
parents: 49402
diff changeset
   350
    if (VerifyMetaspace) {
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   351
      locked_verify();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   352
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   353
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   354
  void verify_free_chunks_total();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   355
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   356
  void locked_print_free_chunks(outputStream* st);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   357
  void locked_print_sum_free_chunks(outputStream* st);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   358
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   359
  void print_on(outputStream* st) const;
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   360
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   361
  // Prints composition for both non-class and (if available)
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   362
  // class chunk manager.
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   363
  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
   364
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   365
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   366
class SmallBlocks : public CHeapObj<mtClass> {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   367
  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
   368
  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
   369
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   370
 private:
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   371
  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
   372
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   373
  FreeList<Metablock>& list_at(size_t word_size) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   374
    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
   375
    return _small_lists[word_size - _small_block_min_size];
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   376
  }
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
 public:
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   379
  SmallBlocks() {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   380
    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
   381
      uint k = i - _small_block_min_size;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   382
      _small_lists[k].set_size(i);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   383
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   384
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   385
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   386
  size_t total_size() const {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   387
    size_t result = 0;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   388
    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
   389
      uint k = i - _small_block_min_size;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   390
      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
   391
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   392
    return result;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   393
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   394
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   395
  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
   396
  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
   397
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   398
  MetaWord* get_block(size_t word_size) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   399
    if (list_at(word_size).count() > 0) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   400
      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
   401
      return new_block;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   402
    } else {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   403
      return NULL;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   404
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   405
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   406
  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
   407
    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
   408
    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
   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 print_on(outputStream* st) const {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   412
    st->print_cr("SmallBlocks:");
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   413
    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
   414
      uint k = i - _small_block_min_size;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   415
      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
   416
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   417
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   418
};
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   419
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   420
// 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
   421
// to the allocation of a quantum of metadata).
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   422
class BlockFreelist : public CHeapObj<mtClass> {
30580
394471b86a83 8079091: Remove dictionary NULL check on common path of BlockFreeList methods
jwha
parents: 29806
diff changeset
   423
  BlockTreeDictionary* const _dictionary;
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   424
  SmallBlocks* _small_blocks;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   425
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   426
  // 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
   427
  // 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
   428
  const static int WasteMultiplier = 4;
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   429
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   430
  // Accessors
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   431
  BlockTreeDictionary* dictionary() const { return _dictionary; }
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   432
  SmallBlocks* small_blocks() {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   433
    if (_small_blocks == NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   434
      _small_blocks = new SmallBlocks();
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   435
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   436
    return _small_blocks;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   437
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   438
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   439
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   440
  BlockFreelist();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   441
  ~BlockFreelist();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   442
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   443
  // Get and return a block to the free list
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   444
  MetaWord* get_block(size_t word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   445
  void return_block(MetaWord* p, size_t word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   446
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   447
  size_t total_size() const  {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   448
    size_t result = dictionary()->total_size();
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   449
    if (_small_blocks != NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   450
      result = result + _small_blocks->total_size();
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   451
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   452
    return result;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   453
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   454
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   455
  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
   456
  void print_on(outputStream* st) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   457
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   458
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   459
// 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
   460
template <typename T> struct all_ones  { static const T value; };
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   461
template <> struct all_ones <uint64_t> { static const uint64_t value = 0xFFFFFFFFFFFFFFFFULL; };
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   462
template <> struct all_ones <uint32_t> { static const uint32_t value = 0xFFFFFFFF; };
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   463
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   464
// The OccupancyMap is a bitmap which, for a given VirtualSpaceNode,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   465
// keeps information about
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   466
// - where a chunk starts
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   467
// - whether a chunk is in-use or free
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   468
// A bit in this bitmap represents one range of memory in the smallest
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   469
// chunk size (SpecializedChunk or ClassSpecializedChunk).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   470
class OccupancyMap : public CHeapObj<mtInternal> {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   471
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   472
  // The address range this map covers.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   473
  const MetaWord* const _reference_address;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   474
  const size_t _word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   475
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   476
  // The word size of a specialized chunk, aka the number of words one
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   477
  // bit in this map represents.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   478
  const size_t _smallest_chunk_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   479
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   480
  // map data
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   481
  // Data are organized in two bit layers:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   482
  // 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
   483
  // the corresponding region as the head of a chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   484
  // 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
   485
  // the corresponding belongs to a chunk which is in use.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   486
  uint8_t* _map[2];
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   487
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   488
  enum { layer_chunk_start_map = 0, layer_in_use_map = 1 };
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   489
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   490
  // length, in bytes, of bitmap data
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   491
  size_t _map_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   492
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   493
  // Returns true if bit at position pos at bit-layer layer is set.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   494
  bool get_bit_at_position(unsigned pos, unsigned layer) const {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   495
    assert(layer == 0 || layer == 1, "Invalid layer %d", layer);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   496
    const unsigned byteoffset = pos / 8;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   497
    assert(byteoffset < _map_size,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   498
           "invalid byte offset (%u), map size is " SIZE_FORMAT ".", byteoffset, _map_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   499
    const unsigned mask = 1 << (pos % 8);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   500
    return (_map[layer][byteoffset] & mask) > 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   501
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   502
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   503
  // Changes bit at position pos at bit-layer layer to value v.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   504
  void set_bit_at_position(unsigned pos, unsigned layer, bool v) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   505
    assert(layer == 0 || layer == 1, "Invalid layer %d", layer);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   506
    const unsigned byteoffset = pos / 8;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   507
    assert(byteoffset < _map_size,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   508
           "invalid byte offset (%u), map size is " SIZE_FORMAT ".", byteoffset, _map_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   509
    const unsigned mask = 1 << (pos % 8);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   510
    if (v) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   511
      _map[layer][byteoffset] |= mask;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   512
    } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   513
      _map[layer][byteoffset] &= ~mask;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   514
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   515
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   516
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   517
  // 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
   518
  // pos is 32/64 aligned and num_bits is 32/64.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   519
  // This is the typical case when coalescing to medium chunks, whose size is
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   520
  // 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
   521
  // case), so they occupy 64 bits which should be 64bit aligned, because
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   522
  // chunks are chunk-size aligned.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   523
  template <typename T>
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   524
  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
   525
    assert(_map_size > 0, "not initialized");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   526
    assert(layer == 0 || layer == 1, "Invalid layer %d.", layer);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   527
    assert(pos % (sizeof(T) * 8) == 0, "Bit position must be aligned (%u).", pos);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   528
    assert(num_bits == (sizeof(T) * 8), "Number of bits incorrect (%u).", num_bits);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   529
    const size_t byteoffset = pos / 8;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   530
    assert(byteoffset <= (_map_size - sizeof(T)),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   531
           "Invalid byte offset (" SIZE_FORMAT "), map size is " SIZE_FORMAT ".", byteoffset, _map_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   532
    const T w = *(T*)(_map[layer] + byteoffset);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   533
    return w > 0 ? true : false;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   534
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   535
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   536
  // 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
   537
  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
   538
    if (pos % 32 == 0 && num_bits == 32) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   539
      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
   540
    } else if (pos % 64 == 0 && num_bits == 64) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   541
      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
   542
    } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   543
      for (unsigned n = 0; n < num_bits; n ++) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   544
        if (get_bit_at_position(pos + n, layer)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   545
          return true;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   546
        }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   547
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   548
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   549
    return false;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   550
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   551
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   552
  // 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
   553
  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
   554
    assert(word_size % _smallest_chunk_word_size == 0,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   555
        "Region size " SIZE_FORMAT " not a multiple of smallest chunk size.", word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   556
    const unsigned pos = get_bitpos_for_address(p);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   557
    const unsigned num_bits = (unsigned) (word_size / _smallest_chunk_word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   558
    return is_any_bit_set_in_region(pos, num_bits, layer);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   559
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   560
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   561
  // Optimized case of set_bits_of_region for 32/64bit aligned access:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   562
  // pos is 32/64 aligned and num_bits is 32/64.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   563
  // This is the typical case when coalescing to medium chunks, whose size
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   564
  // 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
   565
  // class case), so they occupy 64 bits which should be 64bit aligned,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   566
  // because chunks are chunk-size aligned.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   567
  template <typename T>
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   568
  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
   569
    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
   570
           (unsigned)(sizeof(T) * 8), pos);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   571
    assert(num_bits == (sizeof(T) * 8), "Number of bits incorrect (%u), expected %u.",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   572
           num_bits, (unsigned)(sizeof(T) * 8));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   573
    const size_t byteoffset = pos / 8;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   574
    assert(byteoffset <= (_map_size - sizeof(T)),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   575
           "invalid byte offset (" SIZE_FORMAT "), map size is " SIZE_FORMAT ".", byteoffset, _map_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   576
    T* const pw = (T*)(_map[layer] + byteoffset);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   577
    *pw = v ? all_ones<T>::value : (T) 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   578
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   579
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   580
  // Set all bits in a region starting at pos to a value.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   581
  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
   582
    assert(_map_size > 0, "not initialized");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   583
    assert(layer == 0 || layer == 1, "Invalid layer %d.", layer);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   584
    if (pos % 32 == 0 && num_bits == 32) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   585
      set_bits_of_region_T<uint32_t>(pos, num_bits, layer, v);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   586
    } else if (pos % 64 == 0 && num_bits == 64) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   587
      set_bits_of_region_T<uint64_t>(pos, num_bits, layer, v);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   588
    } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   589
      for (unsigned n = 0; n < num_bits; n ++) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   590
        set_bit_at_position(pos + n, layer, v);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   591
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   592
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   593
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   594
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   595
  // Helper: sets all bits in a region [p, p+word_size).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   596
  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
   597
    assert(word_size % _smallest_chunk_word_size == 0,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   598
        "Region size " SIZE_FORMAT " not a multiple of smallest chunk size.", word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   599
    const unsigned pos = get_bitpos_for_address(p);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   600
    const unsigned num_bits = (unsigned) (word_size / _smallest_chunk_word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   601
    set_bits_of_region(pos, num_bits, layer, v);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   602
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   603
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   604
  // Helper: given an address, return the bit position representing that address.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   605
  unsigned get_bitpos_for_address(const MetaWord* p) const {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   606
    assert(_reference_address != NULL, "not initialized");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   607
    assert(p >= _reference_address && p < _reference_address + _word_size,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   608
           "Address %p out of range for occupancy map [%p..%p).",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   609
            p, _reference_address, _reference_address + _word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   610
    assert(is_aligned(p, _smallest_chunk_word_size * sizeof(MetaWord)),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   611
           "Address not aligned (%p).", p);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   612
    const ptrdiff_t d = (p - _reference_address) / _smallest_chunk_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   613
    assert(d >= 0 && (size_t)d < _map_size * 8, "Sanity.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   614
    return (unsigned) d;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   615
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   616
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   617
 public:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   618
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   619
  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
   620
    _reference_address(reference_address), _word_size(word_size),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   621
    _smallest_chunk_word_size(smallest_chunk_word_size) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   622
    assert(reference_address != NULL, "invalid reference address");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   623
    assert(is_aligned(reference_address, smallest_chunk_word_size),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   624
           "Reference address not aligned to smallest chunk size.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   625
    assert(is_aligned(word_size, smallest_chunk_word_size),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   626
           "Word_size shall be a multiple of the smallest chunk size.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   627
    // Calculate bitmap size: one bit per smallest_chunk_word_size'd area.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   628
    size_t num_bits = word_size / smallest_chunk_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   629
    _map_size = (num_bits + 7) / 8;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   630
    assert(_map_size * 8 >= num_bits, "sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   631
    _map[0] = (uint8_t*) os::malloc(_map_size, mtInternal);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   632
    _map[1] = (uint8_t*) os::malloc(_map_size, mtInternal);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   633
    assert(_map[0] != NULL && _map[1] != NULL, "Occupancy Map: allocation failed.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   634
    memset(_map[1], 0, _map_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   635
    memset(_map[0], 0, _map_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   636
    // Sanity test: the first respectively last possible chunk start address in
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   637
    // 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
   638
    assert(get_bitpos_for_address(reference_address) == 0,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   639
      "First chunk address in range must map to fist bit in bitmap.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   640
    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
   641
      "Last chunk address in range must map to last bit in bitmap.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   642
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   643
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   644
  ~OccupancyMap() {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   645
    os::free(_map[0]);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   646
    os::free(_map[1]);
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
  // Returns true if at address x a chunk is starting.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   650
  bool chunk_starts_at_address(MetaWord* p) const {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   651
    const unsigned pos = get_bitpos_for_address(p);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   652
    return get_bit_at_position(pos, layer_chunk_start_map);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   653
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   654
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   655
  void set_chunk_starts_at_address(MetaWord* p, bool v) {
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
    set_bit_at_position(pos, layer_chunk_start_map, v);
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
  // Removes all chunk-start-bits inside a region, typically as a
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   661
  // result of a chunk merge.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   662
  void wipe_chunk_start_bits_in_region(MetaWord* p, size_t word_size) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   663
    set_bits_of_region(p, word_size, layer_chunk_start_map, false);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   664
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   665
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   666
  // Returns true if there are life (in use) chunks in the region limited
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   667
  // by [p, p+word_size).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   668
  bool is_region_in_use(MetaWord* p, size_t word_size) const {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   669
    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
   670
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   671
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   672
  // 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
   673
  // or free, depending on v.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   674
  void set_region_in_use(MetaWord* p, size_t word_size, bool v) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   675
    set_bits_of_region(p, word_size, layer_in_use_map, v);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   676
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   677
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   678
#ifdef ASSERT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   679
  // Verify occupancy map for the address range [from, to).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   680
  // We need to tell it the address range, because the memory the
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   681
  // occupancy map is covering may not be fully comitted yet.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   682
  void verify(MetaWord* from, MetaWord* to) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   683
    Metachunk* chunk = NULL;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   684
    int nth_bit_for_chunk = 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   685
    MetaWord* chunk_end = NULL;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   686
    for (MetaWord* p = from; p < to; p += _smallest_chunk_word_size) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   687
      const unsigned pos = get_bitpos_for_address(p);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   688
      // Check the chunk-starts-info:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   689
      if (get_bit_at_position(pos, layer_chunk_start_map)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   690
        // Chunk start marked in bitmap.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   691
        chunk = (Metachunk*) p;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   692
        if (chunk_end != NULL) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   693
          assert(chunk_end == p, "Unexpected chunk start found at %p (expected "
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   694
                 "the next chunk to start at %p).", p, chunk_end);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   695
        }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   696
        assert(chunk->is_valid_sentinel(), "Invalid chunk at address %p.", p);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   697
        if (chunk->get_chunk_type() != HumongousIndex) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   698
          guarantee(is_aligned(p, chunk->word_size()), "Chunk %p not aligned.", p);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   699
        }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   700
        chunk_end = p + chunk->word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   701
        nth_bit_for_chunk = 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   702
        assert(chunk_end <= to, "Chunk end overlaps test address range.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   703
      } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   704
        // No chunk start marked in bitmap.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   705
        assert(chunk != NULL, "Chunk should start at start of address range.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   706
        assert(p < chunk_end, "Did not find expected chunk start at %p.", p);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   707
        nth_bit_for_chunk ++;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   708
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   709
      // Check the in-use-info:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   710
      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
   711
      if (in_use_bit) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   712
        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
   713
               chunk, nth_bit_for_chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   714
      } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   715
        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
   716
               chunk, nth_bit_for_chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   717
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   718
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   719
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   720
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   721
  // Verify that a given chunk is correctly accounted for in the bitmap.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   722
  void verify_for_chunk(Metachunk* chunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   723
    assert(chunk_starts_at_address((MetaWord*) chunk),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   724
           "No chunk start marked in map for chunk %p.", chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   725
    // For chunks larger than the minimal chunk size, no other chunk
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   726
    // must start in its area.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   727
    if (chunk->word_size() > _smallest_chunk_word_size) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   728
      assert(!is_any_bit_set_in_region(((MetaWord*) chunk) + _smallest_chunk_word_size,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   729
                                       chunk->word_size() - _smallest_chunk_word_size, layer_chunk_start_map),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   730
             "No chunk must start within another chunk.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   731
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   732
    if (!chunk->is_tagged_free()) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   733
      assert(is_region_in_use((MetaWord*)chunk, chunk->word_size()),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   734
             "Chunk %p is in use but marked as free in map (%d %d).",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   735
             chunk, chunk->get_chunk_type(), chunk->get_origin());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   736
    } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   737
      assert(!is_region_in_use((MetaWord*)chunk, chunk->word_size()),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   738
             "Chunk %p is free but marked as in-use in map (%d %d).",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   739
             chunk, chunk->get_chunk_type(), chunk->get_origin());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   740
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   741
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   742
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   743
#endif // ASSERT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   744
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   745
};
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   746
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   747
// A VirtualSpaceList node.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   748
class VirtualSpaceNode : public CHeapObj<mtClass> {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   749
  friend class VirtualSpaceList;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   750
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   751
  // Link to next VirtualSpaceNode
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   752
  VirtualSpaceNode* _next;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   753
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   754
  // Whether this node is contained in class or metaspace.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   755
  const bool _is_class;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   756
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   757
  // total in the VirtualSpace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   758
  MemRegion _reserved;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   759
  ReservedSpace _rs;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   760
  VirtualSpace _virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   761
  MetaWord* _top;
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   762
  // count of chunks contained in this VirtualSpace
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   763
  uintx _container_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   764
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   765
  OccupancyMap* _occupancy_map;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   766
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   767
  // Convenience functions to access the _virtual_space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   768
  char* low()  const { return virtual_space()->low(); }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   769
  char* high() const { return virtual_space()->high(); }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   770
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   771
  // The first Metachunk will be allocated at the bottom of the
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   772
  // VirtualSpace
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   773
  Metachunk* first_chunk() { return (Metachunk*) bottom(); }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   774
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   775
  // 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
   776
  size_t free_words_in_vs() const;
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   777
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   778
  // True if this node belongs to class metaspace.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   779
  bool is_class() const { return _is_class; }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   780
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   781
  // Helper function for take_from_committed: allocate padding chunks
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   782
  // until top is at the given address.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   783
  void allocate_padding_chunks_until_top_is_at(MetaWord* target_top);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   784
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   785
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   786
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   787
  VirtualSpaceNode(bool is_class, size_t byte_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   788
  VirtualSpaceNode(bool is_class, ReservedSpace rs) :
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   789
    _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
   790
  ~VirtualSpaceNode();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   791
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   792
  // Convenience functions for logical bottom and end
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   793
  MetaWord* bottom() const { return (MetaWord*) _virtual_space.low(); }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   794
  MetaWord* end() const { return (MetaWord*) _virtual_space.high(); }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   795
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   796
  const OccupancyMap* occupancy_map() const { return _occupancy_map; }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   797
  OccupancyMap* occupancy_map() { return _occupancy_map; }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   798
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
   799
  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
   800
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   801
  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
   802
  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
   803
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   804
  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
   805
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   806
  // address of next available space in _virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   807
  // Accessors
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   808
  VirtualSpaceNode* next() { return _next; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   809
  void set_next(VirtualSpaceNode* v) { _next = v; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   810
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   811
  void set_reserved(MemRegion const v) { _reserved = v; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   812
  void set_top(MetaWord* v) { _top = v; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   813
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   814
  // Accessors
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   815
  MemRegion* reserved() { return &_reserved; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   816
  VirtualSpace* virtual_space() const { return (VirtualSpace*) &_virtual_space; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   817
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   818
  // 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
   819
  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
   820
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   821
  MetaWord* top() const { return _top; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   822
  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
   823
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   824
  uintx container_count() { return _container_count; }
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   825
  void inc_container_count();
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   826
  void dec_container_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   827
#ifdef ASSERT
29806
64aa40385bdd 8076173: VirtualSpaceNode container_count() and container_count_slow() have different return types
david
parents: 29800
diff changeset
   828
  uintx container_count_slow();
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   829
  void verify_container_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   830
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   831
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   832
  // 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
   833
  size_t used_words_in_vs() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   834
  size_t capacity_words_in_vs() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   835
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   836
  bool initialize();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   837
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   838
  // get space from the virtual space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   839
  Metachunk* take_from_committed(size_t chunk_word_size);
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
  // 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
   842
  Metachunk* get_chunk_vs(size_t chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   843
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   844
  // 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
   845
  // to Virtualspace
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   846
  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
   847
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   848
  // In preparation for deleting this node, remove all the chunks
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   849
  // in the node from any freelist.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   850
  void purge(ChunkManager* chunk_manager);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   851
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   852
  // 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
   853
  // 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
   854
  // 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
   855
  // 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
   856
  // 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
   857
  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
   858
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   859
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   860
  void print_on(outputStream* st) const;
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   861
  void print_map(outputStream* st, bool is_class) const;
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   862
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   863
  // Debug support
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   864
  DEBUG_ONLY(void mangle();)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   865
  // Verify counters, all chunks in this list node and the occupancy map.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   866
  DEBUG_ONLY(void verify();)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   867
  // Verify that all free chunks in this node are ideally merged
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   868
  // (there not should be multiple small chunks where a large chunk could exist.)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   869
  DEBUG_ONLY(void verify_free_chunks_are_ideally_merged();)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   870
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   871
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   872
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   873
#define assert_is_aligned(value, alignment)                  \
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   874
  assert(is_aligned((value), (alignment)),                   \
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   875
         SIZE_FORMAT_HEX " is not aligned to "               \
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   876
         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
   877
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   878
// 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
   879
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
   880
  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
   881
    size_t words = bytes / BytesPerWord;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   882
    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
   883
    if (MetaspaceGC::can_expand(words, is_class) &&
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   884
        MetaspaceGC::allowed_expansion() >= words) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   885
      return true;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   886
    }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   887
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   888
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   889
  return false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   890
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   891
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   892
  // byte_size is the size of the associated virtualspace.
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   893
VirtualSpaceNode::VirtualSpaceNode(bool is_class, size_t bytes) :
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   894
  _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
   895
  assert_is_aligned(bytes, Metaspace::reserve_alignment());
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
   896
  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
   897
  _rs = ReservedSpace(bytes, Metaspace::reserve_alignment(), large_pages);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   898
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   899
  if (_rs.is_reserved()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   900
    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
   901
    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
   902
    assert_is_aligned(_rs.base(), Metaspace::reserve_alignment());
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   903
    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
   904
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   905
    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
   906
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   907
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   908
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   909
void VirtualSpaceNode::purge(ChunkManager* chunk_manager) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   910
  DEBUG_ONLY(this->verify();)
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   911
  Metachunk* chunk = first_chunk();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   912
  Metachunk* invalid_chunk = (Metachunk*) top();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   913
  while (chunk < invalid_chunk ) {
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   914
    assert(chunk->is_tagged_free(), "Should be tagged free");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   915
    MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   916
    chunk_manager->remove_chunk(chunk);
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   917
    chunk->remove_sentinel();
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   918
    assert(chunk->next() == NULL &&
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   919
           chunk->prev() == NULL,
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   920
           "Was not removed from its list");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   921
    chunk = (Metachunk*) next;
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   922
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   923
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   924
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   925
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
   926
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   927
  if (bottom() == top()) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   928
    return;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   929
  }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   930
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   931
  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
   932
  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
   933
  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
   934
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   935
  int line_len = 100;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   936
  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
   937
  line_len = (int)(section_len / spec_chunk_size);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   938
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   939
  static const int NUM_LINES = 4;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   940
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   941
  char* lines[NUM_LINES];
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   942
  for (int i = 0; i < NUM_LINES; i ++) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   943
    lines[i] = (char*)os::malloc(line_len, mtInternal);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   944
  }
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   945
  int pos = 0;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   946
  const MetaWord* p = bottom();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   947
  const Metachunk* chunk = (const Metachunk*)p;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   948
  const MetaWord* chunk_end = p + chunk->word_size();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   949
  while (p < top()) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   950
    if (pos == line_len) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   951
      pos = 0;
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   952
      for (int i = 0; i < NUM_LINES; i ++) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   953
        st->fill_to(22);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   954
        st->print_raw(lines[i], line_len);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   955
        st->cr();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   956
      }
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   957
    }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   958
    if (pos == 0) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   959
      st->print(PTR_FORMAT ":", p2i(p));
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   960
    }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   961
    if (p == chunk_end) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   962
      chunk = (Metachunk*)p;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   963
      chunk_end = p + chunk->word_size();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   964
    }
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   965
    // 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
   966
    lines[0][pos] = p == (const MetaWord*)chunk ? '.' : ' ';
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   967
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   968
    // 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
   969
    // chunk is in use.
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   970
    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
   971
    if (chunk->word_size() == spec_chunk_size) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   972
      lines[1][pos] = chunk_is_free ? 'x' : 'X';
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   973
    } else if (chunk->word_size() == small_chunk_size) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   974
      lines[1][pos] = chunk_is_free ? 's' : 'S';
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   975
    } else if (chunk->word_size() == med_chunk_size) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   976
      lines[1][pos] = chunk_is_free ? 'm' : 'M';
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   977
    } else if (chunk->word_size() > med_chunk_size) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   978
      lines[1][pos] = chunk_is_free ? 'h' : 'H';
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   979
    } else {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   980
      ShouldNotReachHere();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   981
    }
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   982
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   983
    // Line 3: chunk origin
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   984
    const ChunkOrigin origin = chunk->get_origin();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   985
    lines[2][pos] = origin == origin_normal ? ' ' : '0' + (int) origin;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   986
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   987
    // 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
   988
    //         but were never used.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   989
    lines[3][pos] = chunk->get_use_count() > 0 ? ' ' : 'v';
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   990
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   991
    p += spec_chunk_size;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   992
    pos ++;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   993
  }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   994
  if (pos > 0) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   995
    for (int i = 0; i < NUM_LINES; i ++) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   996
      st->fill_to(22);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   997
      st->print_raw(lines[i], line_len);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   998
      st->cr();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
   999
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1000
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1001
  for (int i = 0; i < NUM_LINES; i ++) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1002
    os::free(lines[i]);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1003
  }
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1004
}
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1005
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1006
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1007
#ifdef ASSERT
29806
64aa40385bdd 8076173: VirtualSpaceNode container_count() and container_count_slow() have different return types
david
parents: 29800
diff changeset
  1008
uintx VirtualSpaceNode::container_count_slow() {
64aa40385bdd 8076173: VirtualSpaceNode container_count() and container_count_slow() have different return types
david
parents: 29800
diff changeset
  1009
  uintx count = 0;
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1010
  Metachunk* chunk = first_chunk();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1011
  Metachunk* invalid_chunk = (Metachunk*) top();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1012
  while (chunk < invalid_chunk ) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1013
    MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1014
    do_verify_chunk(chunk);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1015
    // Don't count the chunks on the free lists.  Those are
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1016
    // still part of the VirtualSpaceNode but not currently
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1017
    // counted.
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  1018
    if (!chunk->is_tagged_free()) {
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1019
      count++;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1020
    }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1021
    chunk = (Metachunk*) next;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1022
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1023
  return count;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1024
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1025
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1026
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1027
#ifdef ASSERT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1028
// Verify counters, all chunks in this list node and the occupancy map.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1029
void VirtualSpaceNode::verify() {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1030
  uintx num_in_use_chunks = 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1031
  Metachunk* chunk = first_chunk();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1032
  Metachunk* invalid_chunk = (Metachunk*) top();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1033
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1034
  // Iterate the chunks in this node and verify each chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1035
  while (chunk < invalid_chunk ) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1036
    DEBUG_ONLY(do_verify_chunk(chunk);)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1037
    if (!chunk->is_tagged_free()) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1038
      num_in_use_chunks ++;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1039
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1040
    MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1041
    chunk = (Metachunk*) next;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1042
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1043
  assert(_container_count == num_in_use_chunks, "Container count mismatch (real: " UINTX_FORMAT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1044
         ", counter: " UINTX_FORMAT ".", num_in_use_chunks, _container_count);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1045
  // Also verify the occupancy map.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1046
  occupancy_map()->verify(this->bottom(), this->top());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1047
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1048
#endif // ASSERT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1049
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1050
#ifdef ASSERT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1051
// Verify that all free chunks in this node are ideally merged
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1052
// (there not should be multiple small chunks where a large chunk could exist.)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1053
void VirtualSpaceNode::verify_free_chunks_are_ideally_merged() {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1054
  Metachunk* chunk = first_chunk();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1055
  Metachunk* invalid_chunk = (Metachunk*) top();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1056
  // Shorthands.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1057
  const size_t size_med = (is_class() ? ClassMediumChunk : MediumChunk) * BytesPerWord;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1058
  const size_t size_small = (is_class() ? ClassSmallChunk : SmallChunk) * BytesPerWord;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1059
  int num_free_chunks_since_last_med_boundary = -1;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1060
  int num_free_chunks_since_last_small_boundary = -1;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1061
  while (chunk < invalid_chunk ) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1062
    // 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
  1063
    // Reset the counter when encountering a non-free chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1064
    if (chunk->get_chunk_type() != HumongousIndex) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1065
      if (chunk->is_tagged_free()) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1066
        // Count successive free, non-humongous chunks.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1067
        if (is_aligned(chunk, size_small)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1068
          assert(num_free_chunks_since_last_small_boundary <= 1,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1069
                 "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
  1070
          num_free_chunks_since_last_small_boundary = 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1071
        } else if (num_free_chunks_since_last_small_boundary != -1) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1072
          num_free_chunks_since_last_small_boundary ++;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1073
        }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1074
        if (is_aligned(chunk, size_med)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1075
          assert(num_free_chunks_since_last_med_boundary <= 1,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1076
                 "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
  1077
          num_free_chunks_since_last_med_boundary = 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1078
        } else if (num_free_chunks_since_last_med_boundary != -1) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1079
          num_free_chunks_since_last_med_boundary ++;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1080
        }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1081
      } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1082
        // Encountering a non-free chunk, reset counters.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1083
        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_small_boundary = -1;
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
      // One cannot merge areas with a humongous chunk in the middle. 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
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1092
    MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1093
    chunk = (Metachunk*) next;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1094
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1095
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1096
#endif // ASSERT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1097
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1098
// List of VirtualSpaces for metadata allocation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1099
class VirtualSpaceList : public CHeapObj<mtClass> {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1100
  friend class VirtualSpaceNode;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1101
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1102
  enum VirtualSpaceSizes {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1103
    VirtualSpaceSize = 256 * K
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1104
  };
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1105
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1106
  // Head of the list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1107
  VirtualSpaceNode* _virtual_space_list;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1108
  // virtual space currently being used for allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1109
  VirtualSpaceNode* _current_virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1110
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1111
  // 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
  1112
  bool _is_class;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1113
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1114
  // 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
  1115
  size_t _reserved_words;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1116
  size_t _committed_words;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1117
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1118
  // Number of virtual spaces
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1119
  size_t _virtual_space_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1120
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1121
  ~VirtualSpaceList();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1122
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1123
  VirtualSpaceNode* virtual_space_list() const { return _virtual_space_list; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1124
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1125
  void set_virtual_space_list(VirtualSpaceNode* v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1126
    _virtual_space_list = v;
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
  void set_current_virtual_space(VirtualSpaceNode* v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1129
    _current_virtual_space = v;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1130
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1131
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1132
  void link_vs(VirtualSpaceNode* new_entry);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1133
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1134
  // 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
  1135
  // 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
  1136
  // 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
  1137
  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
  1138
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1139
  // 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
  1140
  // 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
  1141
  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
  1142
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1143
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1144
  VirtualSpaceList(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1145
  VirtualSpaceList(ReservedSpace rs);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1146
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1147
  size_t free_bytes();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1148
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1149
  Metachunk* get_new_chunk(size_t chunk_word_size,
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1150
                           size_t suggested_commit_granularity);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1151
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1152
  bool expand_node_by(VirtualSpaceNode* node,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1153
                      size_t min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1154
                      size_t preferred_words);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1155
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1156
  bool expand_by(size_t min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1157
                 size_t preferred_words);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1158
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1159
  VirtualSpaceNode* current_virtual_space() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1160
    return _current_virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1161
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1162
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1163
  bool is_class() const { return _is_class; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1164
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1165
  bool initialization_succeeded() { return _virtual_space_list != NULL; }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1166
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1167
  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
  1168
  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
  1169
  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
  1170
  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
  1171
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1172
  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
  1173
  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
  1174
  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
  1175
  void dec_committed_words(size_t v);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1176
  void inc_virtual_space_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1177
  void dec_virtual_space_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1178
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1179
  bool contains(const void* ptr);
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1180
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1181
  // Unlink empty VirtualSpaceNodes and free it.
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1182
  void purge(ChunkManager* chunk_manager);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1183
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1184
  void print_on(outputStream* st) const;
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1185
  void print_map(outputStream* st) const;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1186
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1187
  class VirtualSpaceListIterator : public StackObj {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1188
    VirtualSpaceNode* _virtual_spaces;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1189
   public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1190
    VirtualSpaceListIterator(VirtualSpaceNode* virtual_spaces) :
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1191
      _virtual_spaces(virtual_spaces) {}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1192
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1193
    bool repeat() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1194
      return _virtual_spaces != NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1195
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1196
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1197
    VirtualSpaceNode* get_next() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1198
      VirtualSpaceNode* result = _virtual_spaces;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1199
      if (_virtual_spaces != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1200
        _virtual_spaces = _virtual_spaces->next();
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
      return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1203
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1204
  };
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1205
};
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
class Metadebug : AllStatic {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1208
  // Debugging support for Metaspaces
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1209
  static int _allocation_fail_alot_count;
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
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1212
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1213
  static void init_allocation_fail_alot_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1214
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1215
  static bool test_metadata_failure();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1216
#endif
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
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1219
int Metadebug::_allocation_fail_alot_count = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1220
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1221
//  SpaceManager - used by Metaspace to handle allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1222
class SpaceManager : public CHeapObj<mtClass> {
49401
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  1223
  friend class ClassLoaderMetaspace;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1224
  friend class Metadebug;
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
 private:
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1227
22201
9c2ccfa3a5fe 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 21569
diff changeset
  1228
  // protects allocations
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1229
  Mutex* const _lock;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1230
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  1231
  // Type of metadata allocated.
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  1232
  const Metaspace::MetadataType   _mdtype;
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  1233
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  1234
  // Type of metaspace
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  1235
  const Metaspace::MetaspaceType  _space_type;
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  1236
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1237
  // List of chunks in use by this SpaceManager.  Allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1238
  // 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
  1239
  // chunks when the SpaceManager is freed.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1240
  Metachunk* _chunks_in_use[NumberOfInUseLists];
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1241
  Metachunk* _current_chunk;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1242
31028
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  1243
  // 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
  1244
  static uint const _small_chunk_limit;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1245
49395
c382614abe59 8191924: Adjust DelegatingClassLoader's metadata space sizing algorithm
zgu
parents: 49389
diff changeset
  1246
  // Maximum number of specialize chunks to allocate for anonymous and delegating
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  1247
  // metadata space to a SpaceManager
49395
c382614abe59 8191924: Adjust DelegatingClassLoader's metadata space sizing algorithm
zgu
parents: 49389
diff changeset
  1248
  static uint const _anon_and_delegating_metadata_specialize_chunk_limit;
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  1249
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1250
  // 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
  1251
  size_t _allocated_blocks_words;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1252
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1253
  // Sum of all allocated chunks
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1254
  size_t _allocated_chunks_words;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1255
  size_t _allocated_chunks_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1256
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1257
  // Free lists of blocks are per SpaceManager since they
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1258
  // 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
  1259
  // 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
  1260
  // the class loader using the SpaceManager is collected.
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1261
  BlockFreelist* _block_freelists;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1262
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1263
 private:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1264
  // Accessors
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1265
  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
  1266
  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
  1267
    _chunks_in_use[index] = v;
9c2ccfa3a5fe 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 21569
diff changeset
  1268
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1269
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1270
  BlockFreelist* block_freelists() const { return _block_freelists; }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1271
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  1272
  Metaspace::MetadataType mdtype() { return _mdtype; }
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1273
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1274
  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
  1275
  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
  1276
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1277
  Metachunk* current_chunk() const { return _current_chunk; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1278
  void set_current_chunk(Metachunk* v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1279
    _current_chunk = v;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1280
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1281
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1282
  Metachunk* find_current_chunk(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1283
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1284
  // Add chunk to the list of chunks in use
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1285
  void add_chunk(Metachunk* v, bool make_current);
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1286
  void retire_current_chunk();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1287
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1288
  Mutex* lock() const { return _lock; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1289
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1290
 protected:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1291
  void initialize();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1292
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1293
 public:
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  1294
  SpaceManager(Metaspace::MetadataType mdtype,
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  1295
               Metaspace::MetaspaceType space_type,
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1296
               Mutex* lock);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1297
  ~SpaceManager();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1298
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1299
  enum ChunkMultiples {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1300
    MediumChunkMultiple = 4
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1301
  };
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1302
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1303
  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
  1304
  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
  1305
  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
  1306
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1307
  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
  1308
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1309
  // Accessors
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1310
  bool is_class() const { return _mdtype == Metaspace::ClassType; }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1311
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1312
  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
  1313
  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
  1314
  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
  1315
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1316
  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
  1317
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1318
  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
  1319
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1320
  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
  1321
  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
  1322
  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
  1323
  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
  1324
  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
  1325
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1326
  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
  1327
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1328
  // 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
  1329
  // 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
  1330
  // the in-use list.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1331
  void inc_size_metrics(size_t words);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1332
  // 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
  1333
  // 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
  1334
  void inc_used_metrics(size_t words);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1335
  // 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
  1336
  // 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
  1337
  // 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
  1338
  void dec_total_from_size_metrics();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1339
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1340
  // 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
  1341
  // 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
  1342
  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
  1343
  size_t adjust_initial_chunk_size(size_t requested) const;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1344
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1345
  // Get the initial chunks size for this metaspace type.
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1346
  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
  1347
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1348
  size_t sum_capacity_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1349
  size_t sum_used_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1350
  size_t sum_free_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1351
  size_t sum_waste_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1352
  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
  1353
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1354
  size_t sum_count_in_chunks_in_use();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1355
  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
  1356
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1357
  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
  1358
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1359
  // Block allocation and deallocation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1360
  // Allocates a block from the current chunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1361
  MetaWord* allocate(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1362
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1363
  // Helper for allocations
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1364
  MetaWord* allocate_work(size_t word_size);
13728
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
  // Returns a block to the per manager freelist
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1367
  void deallocate(MetaWord* p, size_t word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1368
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1369
  // 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
  1370
  // returned chunk size (for expanding space for chunk allocation).
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1371
  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
  1372
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1373
  // Called when an allocation from the current chunk fails.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1374
  // 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
  1375
  // and allocates from that chunk.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1376
  MetaWord* grow_and_allocate(size_t word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1377
20407
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  1378
  // Notify memory usage to MemoryService.
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  1379
  void track_metaspace_memory_usage();
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  1380
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1381
  // debugging support.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1382
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1383
  void dump(outputStream* const out) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1384
  void print_on(outputStream* st) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1385
  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
  1386
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1387
  void verify();
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  1388
  void verify_chunk_size(Metachunk* chunk);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1389
#ifdef ASSERT
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1390
  void verify_allocated_blocks_words();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1391
#endif
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  1392
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1393
  // 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
  1394
  // 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
  1395
  size_t get_allocation_word_size(size_t word_size) {
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  1396
    size_t byte_size = word_size * BytesPerWord;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  1397
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  1398
    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
  1399
    raw_bytes_size = align_up(raw_bytes_size, Metachunk::object_alignment());
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  1400
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  1401
    size_t raw_word_size = raw_bytes_size / BytesPerWord;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  1402
    assert(raw_word_size * BytesPerWord == raw_bytes_size, "Size problem");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  1403
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  1404
    return raw_word_size;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  1405
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1406
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1407
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1408
uint const SpaceManager::_small_chunk_limit = 4;
49395
c382614abe59 8191924: Adjust DelegatingClassLoader's metadata space sizing algorithm
zgu
parents: 49389
diff changeset
  1409
uint const SpaceManager::_anon_and_delegating_metadata_specialize_chunk_limit = 4;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1410
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1411
void VirtualSpaceNode::inc_container_count() {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  1412
  assert_lock_strong(MetaspaceExpand_lock);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1413
  _container_count++;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1414
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1415
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1416
void VirtualSpaceNode::dec_container_count() {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  1417
  assert_lock_strong(MetaspaceExpand_lock);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1418
  _container_count--;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1419
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1420
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1421
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1422
void VirtualSpaceNode::verify_container_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1423
  assert(_container_count == container_count_slow(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1424
         "Inconsistency in container_count _container_count " UINTX_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1425
         " container_count_slow() " UINTX_FORMAT, _container_count, container_count_slow());
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1426
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1427
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1428
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1429
// BlockFreelist methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1430
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1431
BlockFreelist::BlockFreelist() : _dictionary(new BlockTreeDictionary()), _small_blocks(NULL) {}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1432
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1433
BlockFreelist::~BlockFreelist() {
30580
394471b86a83 8079091: Remove dictionary NULL check on common path of BlockFreeList methods
jwha
parents: 29806
diff changeset
  1434
  delete _dictionary;
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1435
  if (_small_blocks != NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1436
    delete _small_blocks;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1437
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1438
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1439
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1440
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
  1441
  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
  1442
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  1443
  Metablock* free_chunk = ::new (p) Metablock(word_size);
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1444
  if (word_size < SmallBlocks::small_block_max_size()) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1445
    small_blocks()->return_block(free_chunk, word_size);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1446
  } else {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1447
  dictionary()->return_chunk(free_chunk);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1448
}
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1449
  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
  1450
            SIZE_FORMAT, p2i(free_chunk), word_size);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1451
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1452
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1453
MetaWord* BlockFreelist::get_block(size_t word_size) {
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1454
  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
  1455
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1456
  // Try small_blocks first.
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1457
  if (word_size < SmallBlocks::small_block_max_size()) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1458
    // 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
  1459
    // this space manager.
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1460
    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
  1461
    if (new_block != NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1462
      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
  1463
              p2i(new_block), word_size);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1464
      return new_block;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1465
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1466
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1467
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1468
  if (word_size < BlockFreelist::min_dictionary_size()) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1469
    // 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
  1470
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1471
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1472
46674
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46625
diff changeset
  1473
  Metablock* free_block = dictionary()->get_chunk(word_size);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1474
  if (free_block == NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1475
    return NULL;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1476
  }
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1477
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1478
  const size_t block_size = free_block->size();
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1479
  if (block_size > WasteMultiplier * word_size) {
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1480
    return_block((MetaWord*)free_block, block_size);
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1481
    return NULL;
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1482
  }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1483
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1484
  MetaWord* new_block = (MetaWord*)free_block;
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1485
  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
  1486
  const size_t unused = block_size - word_size;
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1487
  if (unused >= SmallBlocks::small_block_min_size()) {
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1488
    return_block(new_block + word_size, unused);
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1489
  }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1490
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1491
  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
  1492
            p2i(new_block), word_size);
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1493
  return new_block;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1494
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1495
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1496
void BlockFreelist::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1497
  dictionary()->print_free_lists(st);
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1498
  if (_small_blocks != NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1499
    _small_blocks->print_on(st);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1500
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1501
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1502
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1503
// VirtualSpaceNode methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1504
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1505
VirtualSpaceNode::~VirtualSpaceNode() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1506
  _rs.release();
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1507
  if (_occupancy_map != NULL) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1508
    delete _occupancy_map;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1509
  }
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1510
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1511
  size_t word_size = sizeof(*this) / BytesPerWord;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1512
  Copy::fill_to_words((HeapWord*) this, word_size, 0xf1f1f1f1);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1513
#endif
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1514
}
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
size_t VirtualSpaceNode::used_words_in_vs() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1517
  return pointer_delta(top(), bottom(), sizeof(MetaWord));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1518
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1519
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1520
// Space committed in the VirtualSpace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1521
size_t VirtualSpaceNode::capacity_words_in_vs() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1522
  return pointer_delta(end(), bottom(), sizeof(MetaWord));
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
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1525
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
  1526
  return pointer_delta(end(), top(), sizeof(MetaWord));
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1527
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1528
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1529
// 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
  1530
void VirtualSpaceNode::allocate_padding_chunks_until_top_is_at(MetaWord* target_top) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1531
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1532
  assert(target_top > top(), "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1533
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1534
  // Padding chunks are added to the freelist.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1535
  ChunkManager* const chunk_manager = Metaspace::get_chunk_manager(this->is_class());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1536
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1537
  // shorthands
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1538
  const size_t spec_word_size = chunk_manager->specialized_chunk_word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1539
  const size_t small_word_size = chunk_manager->small_chunk_word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1540
  const size_t med_word_size = chunk_manager->medium_chunk_word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1541
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1542
  while (top() < target_top) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1543
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1544
    // 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
  1545
    // for padding chunks, so it is not worth it.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1546
    size_t padding_chunk_word_size = small_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1547
    if (is_aligned(top(), small_word_size * sizeof(MetaWord)) == false) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1548
      assert_is_aligned(top(), spec_word_size * sizeof(MetaWord)); // Should always hold true.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1549
      padding_chunk_word_size = spec_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1550
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1551
    MetaWord* here = top();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1552
    assert_is_aligned(here, padding_chunk_word_size * sizeof(MetaWord));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1553
    inc_top(padding_chunk_word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1554
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1555
    // Create new padding chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1556
    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
  1557
    assert(padding_chunk_type == SpecializedIndex || padding_chunk_type == SmallIndex, "sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1558
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1559
    Metachunk* const padding_chunk =
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1560
      ::new (here) Metachunk(padding_chunk_type, is_class(), padding_chunk_word_size, this);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1561
    assert(padding_chunk == (Metachunk*)here, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1562
    DEBUG_ONLY(padding_chunk->set_origin(origin_pad);)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1563
    log_trace(gc, metaspace, freelist)("Created padding chunk in %s at "
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1564
                                       PTR_FORMAT ", size " SIZE_FORMAT_HEX ".",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1565
                                       (is_class() ? "class space " : "metaspace"),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1566
                                       p2i(padding_chunk), padding_chunk->word_size() * sizeof(MetaWord));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1567
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1568
    // Mark chunk start in occupancy map.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1569
    occupancy_map()->set_chunk_starts_at_address((MetaWord*)padding_chunk, true);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1570
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1571
    // Chunks are born as in-use (see MetaChunk ctor). So, before returning
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1572
    // the padding chunk to its chunk manager, mark it as in use (ChunkManager
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1573
    // will assert that).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1574
    do_update_in_use_info_for_chunk(padding_chunk, true);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1575
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1576
    // Return Chunk to freelist.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1577
    inc_container_count();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1578
    chunk_manager->return_single_chunk(padding_chunk_type, padding_chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1579
    // Please note: at this point, ChunkManager::return_single_chunk()
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1580
    // may already have merged the padding chunk with neighboring chunks, so
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1581
    // it may have vanished at this point. Do not reference the padding
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1582
    // chunk beyond this point.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1583
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1584
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1585
  assert(top() == target_top, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1586
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1587
} // allocate_padding_chunks_until_top_is_at()
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1588
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1589
// Allocates the chunk from the virtual space only.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1590
// 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
  1591
// chunks removed here are necessarily used for allocation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1592
Metachunk* VirtualSpaceNode::take_from_committed(size_t chunk_word_size) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1593
  // Non-humongous chunks are to be allocated aligned to their chunk
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1594
  // size. So, start addresses of medium chunks are aligned to medium
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1595
  // chunk size, those of small chunks to small chunk size and so
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1596
  // forth. This facilitates merging of free chunks and reduces
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1597
  // fragmentation. Chunk sizes are spec < small < medium, with each
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1598
  // larger chunk size being a multiple of the next smaller chunk
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1599
  // size.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1600
  // Because of this alignment, me may need to create a number of padding
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1601
  // chunks. These chunks are created and added to the freelist.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1602
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1603
  // The chunk manager to which we will give our padding chunks.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1604
  ChunkManager* const chunk_manager = Metaspace::get_chunk_manager(this->is_class());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1605
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1606
  // shorthands
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1607
  const size_t spec_word_size = chunk_manager->specialized_chunk_word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1608
  const size_t small_word_size = chunk_manager->small_chunk_word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1609
  const size_t med_word_size = chunk_manager->medium_chunk_word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1610
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1611
  assert(chunk_word_size == spec_word_size || chunk_word_size == small_word_size ||
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1612
         chunk_word_size >= med_word_size, "Invalid chunk size requested.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1613
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1614
  // Chunk alignment (in bytes) == chunk size unless humongous.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1615
  // Humongous chunks are aligned to the smallest chunk size (spec).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1616
  const size_t required_chunk_alignment = (chunk_word_size > med_word_size ?
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1617
                                           spec_word_size : chunk_word_size) * sizeof(MetaWord);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1618
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1619
  // Do we have enough space to create the requested chunk plus
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1620
  // any padding chunks needed?
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1621
  MetaWord* const next_aligned =
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1622
    static_cast<MetaWord*>(align_up(top(), required_chunk_alignment));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1623
  if (!is_available((next_aligned - top()) + chunk_word_size)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1624
    return NULL;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1625
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1626
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1627
  // Before allocating the requested chunk, allocate padding chunks if necessary.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1628
  // 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
  1629
  // smallest size, hence always aligned. Homungous chunks are allocated unaligned
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1630
  // (implicitly, also aligned to smallest chunk size).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1631
  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
  1632
    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
  1633
        (is_class() ? "class space " : "metaspace"),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1634
        top(), next_aligned);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1635
    allocate_padding_chunks_until_top_is_at(next_aligned);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1636
    // Now, top should be aligned correctly.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1637
    assert_is_aligned(top(), required_chunk_alignment);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1638
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1639
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1640
  // Now, top should be aligned correctly.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1641
  assert_is_aligned(top(), required_chunk_alignment);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1642
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1643
  // Bottom of the new chunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1644
  MetaWord* chunk_limit = top();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1645
  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
  1646
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1647
  // 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
  1648
  // commit granularity to enforce the following condition.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1649
  // 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
  1650
  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
  1651
      "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
  1652
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1653
  if (!is_available(chunk_word_size)) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1654
    LogTarget(Debug, gc, metaspace, freelist) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1655
    if (lt.is_enabled()) {
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1656
      LogStream ls(lt);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1657
      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
  1658
      // 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
  1659
      print_on(&ls);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1660
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1661
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1662
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1663
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1664
  // 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
  1665
  inc_top(chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1666
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1667
  // Initialize the chunk
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1668
  ChunkIndex chunk_type = get_chunk_type_by_size(chunk_word_size, is_class());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1669
  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
  1670
  assert(result == (Metachunk*)chunk_limit, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1671
  occupancy_map()->set_chunk_starts_at_address((MetaWord*)result, true);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1672
  do_update_in_use_info_for_chunk(result, true);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1673
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1674
  inc_container_count();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1675
49405
e88237c5ac83 8199656: Make slow metaspace verifications switchable in debug builds
stuefe
parents: 49402
diff changeset
  1676
  if (VerifyMetaspace) {
49386
d89e98d85841 8199518: test/hotspot/jtreg/runtime/SelectionResolution tests take a lot longer to run with fastdebug after JDK-8198423
stuefe
parents: 49372
diff changeset
  1677
    DEBUG_ONLY(chunk_manager->locked_verify());
d89e98d85841 8199518: test/hotspot/jtreg/runtime/SelectionResolution tests take a lot longer to run with fastdebug after JDK-8198423
stuefe
parents: 49372
diff changeset
  1678
    DEBUG_ONLY(this->verify());
d89e98d85841 8199518: test/hotspot/jtreg/runtime/SelectionResolution tests take a lot longer to run with fastdebug after JDK-8198423
stuefe
parents: 49372
diff changeset
  1679
  }
d89e98d85841 8199518: test/hotspot/jtreg/runtime/SelectionResolution tests take a lot longer to run with fastdebug after JDK-8198423
stuefe
parents: 49372
diff changeset
  1680
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1681
  DEBUG_ONLY(do_verify_chunk(result));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1682
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1683
  result->inc_use_count();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1684
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1685
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1686
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1687
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1688
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1689
// 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
  1690
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
  1691
  size_t min_bytes = min_words * BytesPerWord;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1692
  size_t preferred_bytes = preferred_words * BytesPerWord;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1693
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1694
  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
  1695
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1696
  if (uncommitted < min_bytes) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1697
    return false;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1698
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1699
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1700
  size_t commit = MIN2(preferred_bytes, uncommitted);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1701
  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
  1702
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1703
  if (result) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1704
    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
  1705
              (is_class() ? "class" : "non-class"), commit);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1706
  } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1707
    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
  1708
              (is_class() ? "class" : "non-class"), commit);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1709
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1710
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1711
  assert(result, "Failed to commit memory");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1712
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1713
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1714
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1715
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1716
Metachunk* VirtualSpaceNode::get_chunk_vs(size_t chunk_word_size) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  1717
  assert_lock_strong(MetaspaceExpand_lock);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1718
  Metachunk* result = take_from_committed(chunk_word_size);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1719
  return result;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1720
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1721
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1722
bool VirtualSpaceNode::initialize() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1723
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1724
  if (!_rs.is_reserved()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1725
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1726
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1727
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1728
  // 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
  1729
  // 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
  1730
  // 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
  1731
  assert_is_aligned(_rs.base(), Metaspace::commit_alignment());
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1732
  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
  1733
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1734
  // 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
  1735
  // 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
  1736
  // committed_size and actual_committed_size agrees.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1737
  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
  1738
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1739
  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
  1740
                                            Metaspace::commit_alignment());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1741
  if (result) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1742
    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
  1743
        "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
  1744
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1745
    set_top((MetaWord*)virtual_space()->low());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1746
    set_reserved(MemRegion((HeapWord*)_rs.base(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1747
                 (HeapWord*)(_rs.base() + _rs.size())));
13729
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
  1748
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
  1749
    assert(reserved()->start() == (HeapWord*) _rs.base(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1750
           "Reserved start was not set properly " PTR_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1751
           " != " PTR_FORMAT, p2i(reserved()->start()), p2i(_rs.base()));
13729
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
  1752
    assert(reserved()->word_size() == _rs.size() / BytesPerWord,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1753
           "Reserved size was not set properly " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1754
           " != " SIZE_FORMAT, reserved()->word_size(),
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1755
           _rs.size() / BytesPerWord);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1756
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1757
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1758
  // Initialize Occupancy Map.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1759
  const size_t smallest_chunk_size = is_class() ? ClassSpecializedChunk : SpecializedChunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1760
  _occupancy_map = new OccupancyMap(bottom(), reserved_words(), smallest_chunk_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1761
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1762
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1763
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1764
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1765
void VirtualSpaceNode::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1766
  size_t used = used_words_in_vs();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1767
  size_t capacity = capacity_words_in_vs();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1768
  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
  1769
  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
  1770
           "[" PTR_FORMAT ", " PTR_FORMAT ", "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1771
           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
  1772
           p2i(vs), capacity / K,
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1773
           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
  1774
           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
  1775
           p2i(vs->high_boundary()));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1776
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1777
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
  1778
#ifdef ASSERT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1779
void VirtualSpaceNode::mangle() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1780
  size_t word_size = capacity_words_in_vs();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1781
  Copy::fill_to_words((HeapWord*) low(), word_size, 0xf1f1f1f1);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1782
}
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
  1783
#endif // ASSERT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1784
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1785
// VirtualSpaceList methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1786
// Space allocated from the VirtualSpace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1787
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1788
VirtualSpaceList::~VirtualSpaceList() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1789
  VirtualSpaceListIterator iter(virtual_space_list());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1790
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1791
    VirtualSpaceNode* vsl = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1792
    delete vsl;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1793
  }
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
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1796
void VirtualSpaceList::inc_reserved_words(size_t v) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  1797
  assert_lock_strong(MetaspaceExpand_lock);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1798
  _reserved_words = _reserved_words + v;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1799
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1800
void VirtualSpaceList::dec_reserved_words(size_t v) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  1801
  assert_lock_strong(MetaspaceExpand_lock);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1802
  _reserved_words = _reserved_words - v;
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1803
}
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1804
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1805
#define assert_committed_below_limit()                        \
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  1806
  assert(MetaspaceUtils::committed_bytes() <= MaxMetaspaceSize, \
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1807
         "Too much committed memory. Committed: " SIZE_FORMAT \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1808
         " limit (MaxMetaspaceSize): " SIZE_FORMAT,           \
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  1809
          MetaspaceUtils::committed_bytes(), MaxMetaspaceSize);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1810
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1811
void VirtualSpaceList::inc_committed_words(size_t v) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  1812
  assert_lock_strong(MetaspaceExpand_lock);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1813
  _committed_words = _committed_words + v;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1814
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1815
  assert_committed_below_limit();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1816
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1817
void VirtualSpaceList::dec_committed_words(size_t v) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  1818
  assert_lock_strong(MetaspaceExpand_lock);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1819
  _committed_words = _committed_words - v;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1820
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1821
  assert_committed_below_limit();
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1822
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1823
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1824
void VirtualSpaceList::inc_virtual_space_count() {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  1825
  assert_lock_strong(MetaspaceExpand_lock);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1826
  _virtual_space_count++;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1827
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1828
void VirtualSpaceList::dec_virtual_space_count() {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  1829
  assert_lock_strong(MetaspaceExpand_lock);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1830
  _virtual_space_count--;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1831
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1832
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1833
void ChunkManager::remove_chunk(Metachunk* chunk) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1834
  size_t word_size = chunk->word_size();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1835
  ChunkIndex index = list_index(word_size);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1836
  if (index != HumongousIndex) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1837
    free_chunks(index)->remove_chunk(chunk);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1838
  } else {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1839
    humongous_dictionary()->remove_chunk(chunk);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1840
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1841
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1842
  // Chunk has been removed from the chunks free list, update counters.
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1843
  account_for_removed_chunk(chunk);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1844
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1845
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1846
bool ChunkManager::attempt_to_coalesce_around_chunk(Metachunk* chunk, ChunkIndex target_chunk_type) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  1847
  assert_lock_strong(MetaspaceExpand_lock);
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1848
  assert(chunk != NULL, "invalid chunk pointer");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1849
  // Check for valid merge combinations.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1850
  assert((chunk->get_chunk_type() == SpecializedIndex &&
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1851
          (target_chunk_type == SmallIndex || target_chunk_type == MediumIndex)) ||
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1852
         (chunk->get_chunk_type() == SmallIndex && target_chunk_type == MediumIndex),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1853
        "Invalid chunk merge combination.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1854
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1855
  const size_t target_chunk_word_size =
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1856
    get_size_for_nonhumongous_chunktype(target_chunk_type, this->is_class());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1857
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1858
  // [ prospective merge region )
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1859
  MetaWord* const p_merge_region_start =
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1860
    (MetaWord*) align_down(chunk, target_chunk_word_size * sizeof(MetaWord));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1861
  MetaWord* const p_merge_region_end =
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1862
    p_merge_region_start + target_chunk_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1863
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1864
  // We need the VirtualSpaceNode containing this chunk and its occupancy map.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1865
  VirtualSpaceNode* const vsn = chunk->container();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1866
  OccupancyMap* const ocmap = vsn->occupancy_map();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1867
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1868
  // The prospective chunk merge range must be completely contained by the
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1869
  // committed range of the virtual space node.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1870
  if (p_merge_region_start < vsn->bottom() || p_merge_region_end > vsn->top()) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1871
    return false;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1872
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1873
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1874
  // 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
  1875
  // 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
  1876
  // of that range, we cannot merge.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1877
  if (!ocmap->chunk_starts_at_address(p_merge_region_start)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1878
    return false;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1879
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1880
  if (p_merge_region_end < vsn->top() &&
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1881
      !ocmap->chunk_starts_at_address(p_merge_region_end)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1882
    return false;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1883
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1884
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1885
  // 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
  1886
  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
  1887
    return false;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1888
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1889
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1890
  // Success! Remove all chunks in this region...
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1891
  log_trace(gc, metaspace, freelist)("%s: coalescing chunks in area [%p-%p)...",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1892
    (is_class() ? "class space" : "metaspace"),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1893
    p_merge_region_start, p_merge_region_end);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1894
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1895
  const int num_chunks_removed =
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1896
    remove_chunks_in_area(p_merge_region_start, target_chunk_word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1897
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1898
  // ... and create a single new bigger chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1899
  Metachunk* const p_new_chunk =
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1900
      ::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
  1901
  assert(p_new_chunk == (Metachunk*)p_merge_region_start, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1902
  p_new_chunk->set_origin(origin_merge);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1903
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1904
  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
  1905
    (is_class() ? "class space" : "metaspace"),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1906
    p_new_chunk, p_new_chunk->word_size() * sizeof(MetaWord));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1907
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1908
  // 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
  1909
  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
  1910
  ocmap->set_chunk_starts_at_address(p_merge_region_start, true);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1911
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1912
  // Mark chunk as free. Note: it is not necessary to update the occupancy
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1913
  // map in-use map, because the old chunks were also free, so nothing
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1914
  // should have changed.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1915
  p_new_chunk->set_is_tagged_free(true);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1916
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1917
  // Add new chunk to its freelist.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1918
  ChunkList* const list = free_chunks(target_chunk_type);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1919
  list->return_chunk_at_head(p_new_chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1920
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1921
  // And adjust ChunkManager:: _free_chunks_count (_free_chunks_total
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1922
  // 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
  1923
  _free_chunks_count -= num_chunks_removed;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1924
  _free_chunks_count ++;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1925
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1926
  // VirtualSpaceNode::container_count does not have to be modified:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1927
  // it means "number of active (non-free) chunks", so merging free chunks
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1928
  // should not affect that count.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1929
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1930
  // At the end of a chunk merge, run verification tests.
49405
e88237c5ac83 8199656: Make slow metaspace verifications switchable in debug builds
stuefe
parents: 49402
diff changeset
  1931
  if (VerifyMetaspace) {
49386
d89e98d85841 8199518: test/hotspot/jtreg/runtime/SelectionResolution tests take a lot longer to run with fastdebug after JDK-8198423
stuefe
parents: 49372
diff changeset
  1932
    DEBUG_ONLY(this->locked_verify());
d89e98d85841 8199518: test/hotspot/jtreg/runtime/SelectionResolution tests take a lot longer to run with fastdebug after JDK-8198423
stuefe
parents: 49372
diff changeset
  1933
    DEBUG_ONLY(vsn->verify());
d89e98d85841 8199518: test/hotspot/jtreg/runtime/SelectionResolution tests take a lot longer to run with fastdebug after JDK-8198423
stuefe
parents: 49372
diff changeset
  1934
  }
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1935
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1936
  return true;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1937
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1938
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1939
// 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
  1940
// from their corresponding freelists. Mark them as invalid.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1941
// - This does not correct the occupancy map.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1942
// - This does not adjust the counters in ChunkManager.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1943
// - Does not adjust container count counter in containing VirtualSpaceNode
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1944
// Returns number of chunks removed.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1945
int ChunkManager::remove_chunks_in_area(MetaWord* p, size_t word_size) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1946
  assert(p != NULL && word_size > 0, "Invalid range.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1947
  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
  1948
  assert_is_aligned(word_size, smallest_chunk_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1949
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1950
  Metachunk* const start = (Metachunk*) p;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1951
  const Metachunk* const end = (Metachunk*)(p + word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1952
  Metachunk* cur = start;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1953
  int num_removed = 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1954
  while (cur < end) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1955
    Metachunk* next = (Metachunk*)(((MetaWord*)cur) + cur->word_size());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1956
    DEBUG_ONLY(do_verify_chunk(cur));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1957
    assert(cur->get_chunk_type() != HumongousIndex, "Unexpected humongous chunk found at %p.", cur);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1958
    assert(cur->is_tagged_free(), "Chunk expected to be free (%p)", cur);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1959
    log_trace(gc, metaspace, freelist)("%s: removing chunk %p, size " SIZE_FORMAT_HEX ".",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1960
      (is_class() ? "class space" : "metaspace"),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1961
      cur, cur->word_size() * sizeof(MetaWord));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1962
    cur->remove_sentinel();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1963
    // Note: cannot call ChunkManager::remove_chunk, because that
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1964
    // modifies the counters in ChunkManager, which we do not want. So
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1965
    // we call remove_chunk on the freelist directly (see also the
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1966
    // splitting function which does the same).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1967
    ChunkList* const list = free_chunks(list_index(cur->word_size()));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1968
    list->remove_chunk(cur);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1969
    num_removed ++;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1970
    cur = next;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1971
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1972
  return num_removed;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1973
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1974
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1975
// Walk the list of VirtualSpaceNodes and delete
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1976
// nodes with a 0 container_count.  Remove Metachunks in
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1977
// the node from their respective freelists.
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1978
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
  1979
  assert(SafepointSynchronize::is_at_safepoint(), "must be called at safepoint for contains to work");
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  1980
  assert_lock_strong(MetaspaceExpand_lock);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1981
  // Don't use a VirtualSpaceListIterator because this
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1982
  // 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
  1983
  VirtualSpaceNode* purged_vsl = NULL;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1984
  VirtualSpaceNode* prev_vsl = virtual_space_list();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1985
  VirtualSpaceNode* next_vsl = prev_vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1986
  while (next_vsl != NULL) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1987
    VirtualSpaceNode* vsl = next_vsl;
36177
b2b76aba8e42 8149643: Remove check of counters in VirtualSpaceNode::inc_container_count
jmasa
parents: 35905
diff changeset
  1988
    DEBUG_ONLY(vsl->verify_container_count();)
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1989
    next_vsl = vsl->next();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1990
    // Don't free the current virtual space since it will likely
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1991
    // be needed soon.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1992
    if (vsl->container_count() == 0 && vsl != current_virtual_space()) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1993
      log_trace(gc, metaspace, freelist)("Purging VirtualSpaceNode " PTR_FORMAT " (capacity: " SIZE_FORMAT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  1994
                                         ", 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
  1995
      // Unlink it from the list
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1996
      if (prev_vsl == vsl) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1997
        // 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
  1998
        assert(vsl == virtual_space_list(), "Expected to be the first node");
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1999
        set_virtual_space_list(vsl->next());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2000
      } else {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2001
        prev_vsl->set_next(vsl->next());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2002
      }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2003
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2004
      vsl->purge(chunk_manager);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2005
      dec_reserved_words(vsl->reserved_words());
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2006
      dec_committed_words(vsl->committed_words());
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2007
      dec_virtual_space_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2008
      purged_vsl = vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2009
      delete vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2010
    } else {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2011
      prev_vsl = vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2012
    }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2013
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2014
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2015
  if (purged_vsl != NULL) {
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2016
    // 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
  2017
    VirtualSpaceListIterator iter(virtual_space_list());
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2018
    while (iter.repeat()) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2019
      VirtualSpaceNode* vsl = iter.get_next();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2020
      assert(vsl != purged_vsl, "Purge of vsl failed");
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2021
    }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2022
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2023
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2024
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2025
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2026
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2027
// 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
  2028
// 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
  2029
// unloading time during a safepoint.
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2030
bool VirtualSpaceList::contains(const void* ptr) {
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2031
  // 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
  2032
  // 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
  2033
  VirtualSpaceListIterator iter(virtual_space_list());
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2034
  while (iter.repeat()) {
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2035
    VirtualSpaceNode* vsn = iter.get_next();
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2036
    if (vsn->contains(ptr)) {
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2037
      return true;
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2038
    }
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2039
  }
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2040
  return false;
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2041
}
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  2042
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2043
void VirtualSpaceList::retire_current_virtual_space() {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2044
  assert_lock_strong(MetaspaceExpand_lock);
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2045
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2046
  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
  2047
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2048
  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
  2049
                                  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
  2050
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2051
  vsn->retire(cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2052
}
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2053
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2054
void VirtualSpaceNode::retire(ChunkManager* chunk_manager) {
36177
b2b76aba8e42 8149643: Remove check of counters in VirtualSpaceNode::inc_container_count
jmasa
parents: 35905
diff changeset
  2055
  DEBUG_ONLY(verify_container_count();)
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2056
  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
  2057
  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
  2058
    ChunkIndex index = (ChunkIndex)i;
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2059
    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
  2060
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2061
    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
  2062
      Metachunk* chunk = get_chunk_vs(chunk_size);
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2063
      // Chunk will be allocated aligned, so allocation may require
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2064
      // additional padding chunks. That may cause above allocation to
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2065
      // fail. Just ignore the failed allocation and continue with the
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2066
      // next smaller chunk size. As the VirtualSpaceNode comitted
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2067
      // size should be a multiple of the smallest chunk size, we
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2068
      // should always be able to fill the VirtualSpace completely.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2069
      if (chunk == NULL) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2070
        break;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2071
      }
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2072
      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
  2073
    }
36177
b2b76aba8e42 8149643: Remove check of counters in VirtualSpaceNode::inc_container_count
jmasa
parents: 35905
diff changeset
  2074
    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
  2075
  }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2076
  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
  2077
}
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2078
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2079
VirtualSpaceList::VirtualSpaceList(size_t word_size) :
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2080
                                   _is_class(false),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2081
                                   _virtual_space_list(NULL),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2082
                                   _current_virtual_space(NULL),
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2083
                                   _reserved_words(0),
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2084
                                   _committed_words(0),
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2085
                                   _virtual_space_count(0) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2086
  MutexLockerEx cl(MetaspaceExpand_lock,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2087
                   Mutex::_no_safepoint_check_flag);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2088
  create_new_virtual_space(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2089
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2090
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2091
VirtualSpaceList::VirtualSpaceList(ReservedSpace rs) :
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2092
                                   _is_class(true),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2093
                                   _virtual_space_list(NULL),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2094
                                   _current_virtual_space(NULL),
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2095
                                   _reserved_words(0),
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2096
                                   _committed_words(0),
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2097
                                   _virtual_space_count(0) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2098
  MutexLockerEx cl(MetaspaceExpand_lock,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2099
                   Mutex::_no_safepoint_check_flag);
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2100
  VirtualSpaceNode* class_entry = new VirtualSpaceNode(is_class(), rs);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2101
  bool succeeded = class_entry->initialize();
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2102
  if (succeeded) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2103
    link_vs(class_entry);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2104
  }
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
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2107
size_t VirtualSpaceList::free_bytes() {
47543
198cb8e20aef 8187331: VirtualSpaceList tracks free space on wrong node
zgu
parents: 47216
diff changeset
  2108
  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
  2109
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2110
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2111
// 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
  2112
bool VirtualSpaceList::create_new_virtual_space(size_t vs_word_size) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2113
  assert_lock_strong(MetaspaceExpand_lock);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2114
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2115
  if (is_class()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2116
    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
  2117
                  " 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
  2118
                  " 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
  2119
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2120
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2121
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2122
  if (vs_word_size == 0) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2123
    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
  2124
    return false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2125
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2126
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2127
  // Reserve the space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2128
  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
  2129
  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
  2130
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2131
  // Allocate the meta virtual space and initialize it.
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2132
  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
  2133
  if (!new_entry->initialize()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2134
    delete new_entry;
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
  } else {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2137
    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
  2138
        "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
  2139
    // 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
  2140
    OrderAccess::storestore();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2141
    link_vs(new_entry);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2142
    return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2143
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2144
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2145
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2146
void VirtualSpaceList::link_vs(VirtualSpaceNode* new_entry) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2147
  if (virtual_space_list() == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2148
      set_virtual_space_list(new_entry);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2149
  } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2150
    current_virtual_space()->set_next(new_entry);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2151
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2152
  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
  2153
  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
  2154
  inc_committed_words(new_entry->committed_words());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2155
  inc_virtual_space_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2156
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2157
  new_entry->mangle();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2158
#endif
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2159
  LogTarget(Trace, gc, metaspace) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2160
  if (lt.is_enabled()) {
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2161
    LogStream ls(lt);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2162
    VirtualSpaceNode* vsl = current_virtual_space();
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2163
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2164
    vsl->print_on(&ls);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2165
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2166
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2167
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2168
bool VirtualSpaceList::expand_node_by(VirtualSpaceNode* node,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2169
                                      size_t min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2170
                                      size_t preferred_words) {
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2171
  size_t before = node->committed_words();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2172
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2173
  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
  2174
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2175
  size_t after = node->committed_words();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2176
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2177
  // 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
  2178
  assert(after >= before, "Inconsistency");
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2179
  inc_committed_words(after - before);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2180
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2181
  return result;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2182
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
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_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
  2185
  assert_is_aligned(min_words,       Metaspace::commit_alignment_words());
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  2186
  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
  2187
  assert(min_words <= preferred_words, "Invalid arguments");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2188
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2189
  const char* const class_or_not = (is_class() ? "class" : "non-class");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2190
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2191
  if (!MetaspaceGC::can_expand(min_words, this->is_class())) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2192
    log_trace(gc, metaspace, freelist)("Cannot expand %s virtual space list.",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2193
              class_or_not);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2194
    return  false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2195
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2196
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2197
  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
  2198
  if (allowed_expansion_words < min_words) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2199
    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
  2200
              class_or_not);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2201
    return false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2202
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2203
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2204
  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
  2205
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2206
  // 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
  2207
  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
  2208
                                    min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2209
                                    max_expansion_words);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2210
  if (vs_expanded) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2211
     log_trace(gc, metaspace, freelist)("Expanded %s virtual space list.",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2212
               class_or_not);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2213
     return true;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2214
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2215
  log_trace(gc, metaspace, freelist)("%s virtual space list: retire current node.",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2216
            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
  2217
  retire_current_virtual_space();
20406
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
  // Get another virtual space.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2220
  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
  2221
  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
  2222
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2223
  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
  2224
    if (current_virtual_space()->is_pre_committed()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2225
      // 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
  2226
      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
  2227
          "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
  2228
          "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
  2229
      return true;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2230
    }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2231
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2232
    return expand_node_by(current_virtual_space(),
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2233
                          min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2234
                          max_expansion_words);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2235
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2236
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2237
  return false;
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
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2240
// Given a chunk, calculate the largest possible padding space which
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2241
// could be required when allocating it.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2242
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
  2243
  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
  2244
  if (chunk_type != HumongousIndex) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2245
    // Normal, non-humongous chunks are allocated at chunk size
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2246
    // boundaries, so the largest padding space required would be that
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2247
    // minus the smallest chunk size.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2248
    const size_t smallest_chunk_size = is_class ? ClassSpecializedChunk : SpecializedChunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2249
    return chunk_word_size - smallest_chunk_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2250
  } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2251
    // Humongous chunks are allocated at smallest-chunksize
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2252
    // boundaries, so there is no padding required.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2253
    return 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2254
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2255
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2256
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2257
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2258
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
  2259
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2260
  // Allocate a chunk out of the current virtual space.
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2261
  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
  2262
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2263
  if (next != NULL) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2264
    return next;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2265
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2266
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2267
  // 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
  2268
  // 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
  2269
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2270
  // We must have enough space for the requested size and any
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2271
  // additional reqired padding chunks.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2272
  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
  2273
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2274
  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
  2275
  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
  2276
  if (min_word_size >= preferred_word_size) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2277
    // Can happen when humongous chunks are allocated.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2278
    preferred_word_size = min_word_size;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2279
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2280
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2281
  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
  2282
  if (expanded) {
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2283
    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
  2284
    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
  2285
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2286
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2287
   return next;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2288
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2289
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2290
void VirtualSpaceList::print_on(outputStream* st) const {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2291
  VirtualSpaceListIterator iter(virtual_space_list());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2292
  while (iter.repeat()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2293
    VirtualSpaceNode* node = iter.get_next();
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2294
    node->print_on(st);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2295
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2296
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2297
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2298
void VirtualSpaceList::print_map(outputStream* st) const {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2299
  VirtualSpaceNode* list = virtual_space_list();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2300
  VirtualSpaceListIterator iter(list);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2301
  unsigned i = 0;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2302
  while (iter.repeat()) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2303
    st->print_cr("Node %u:", i);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2304
    VirtualSpaceNode* node = iter.get_next();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2305
    node->print_map(st, this->is_class());
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2306
    i ++;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2307
  }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2308
}
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2309
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2310
// MetaspaceGC methods
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
// VM_CollectForMetadataAllocation is the vm operation used to GC.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2313
// 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
  2314
// 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
  2315
// 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
  2316
// 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
  2317
// gen had bounds, MinMetaspaceExpansion and MaxMetaspaceExpansion.  The
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2318
// 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
  2319
//
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2320
// 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
  2321
// 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
  2322
// 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
  2323
// 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
  2324
// 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
  2325
// 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
  2326
// 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
  2327
// 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
  2328
// the HWM.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2329
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2330
// 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
  2331
// Increase by a minimum amount (MinMetaspaceExpansion) so that
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2332
// 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
  2333
// 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
  2334
// 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
  2335
// plus some.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2336
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
  2337
  size_t min_delta = MinMetaspaceExpansion;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2338
  size_t max_delta = MaxMetaspaceExpansion;
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  2339
  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
  2340
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2341
  if (delta <= min_delta) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2342
    delta = min_delta;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2343
  } else if (delta <= max_delta) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2344
    // 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
  2345
    // allocation so make the delta greater than just enough
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2346
    // for this allocation.
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2347
    delta = max_delta;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2348
  } else {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2349
    // 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
  2350
    // so increase by the minimum.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2351
    delta = delta + min_delta;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2352
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2353
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  2354
  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
  2355
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2356
  return delta;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2357
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2358
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2359
size_t MetaspaceGC::capacity_until_GC() {
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  2360
  size_t value = OrderAccess::load_acquire(&_capacity_until_GC);
27693
3eee985a97e7 8059492: Wrong spelling in assert: "Not initialied properly?"
aharlap
parents: 27683
diff changeset
  2361
  assert(value >= MetaspaceSize, "Not initialized properly?");
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2362
  return value;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2363
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2364
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2365
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
  2366
  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
  2367
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  2368
  intptr_t capacity_until_GC = _capacity_until_GC;
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  2369
  intptr_t new_value = capacity_until_GC + v;
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2370
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2371
  if (new_value < capacity_until_GC) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2372
    // 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
  2373
    new_value = align_down(max_uintx, Metaspace::commit_alignment());
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2374
  }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2375
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  2376
  intptr_t expected = _capacity_until_GC;
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  2377
  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
  2378
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2379
  if (expected != actual) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2380
    return false;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2381
  }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2382
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2383
  if (new_cap_until_GC != NULL) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2384
    *new_cap_until_GC = new_value;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2385
  }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2386
  if (old_cap_until_GC != NULL) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2387
    *old_cap_until_GC = capacity_until_GC;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2388
  }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2389
  return true;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2390
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2391
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2392
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
  2393
  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
  2394
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  2395
  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
  2396
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2397
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2398
void MetaspaceGC::initialize() {
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2399
  // 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
  2400
  // we can't do a GC during initialization.
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2401
  _capacity_until_GC = MaxMetaspaceSize;
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2402
}
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2403
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2404
void MetaspaceGC::post_initialize() {
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2405
  // Reset the high-water mark once the VM initialization is done.
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  2406
  _capacity_until_GC = MAX2(MetaspaceUtils::committed_bytes(), MetaspaceSize);
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2407
}
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2408
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2409
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
  2410
  // 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
  2411
  if (is_class && Metaspace::using_class_space()) {
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  2412
    size_t class_committed = MetaspaceUtils::committed_bytes(Metaspace::ClassType);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2413
    if (class_committed + word_size * BytesPerWord > CompressedClassSpaceSize) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2414
      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
  2415
                (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
  2416
      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
  2417
    }
16391
7bf8a7699f5f 8004241: NPG: Metaspace occupies more memory than specified by -XX:MaxMetaspaceSize option
mgerdin
parents: 16387
diff changeset
  2418
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2419
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2420
  // Check if the user has imposed a limit on the metaspace memory.
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  2421
  size_t committed_bytes = MetaspaceUtils::committed_bytes();
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2422
  if (committed_bytes + word_size * BytesPerWord > MaxMetaspaceSize) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2423
    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
  2424
              (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
  2425
    return false;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2426
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2427
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2428
  return true;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2429
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2430
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2431
size_t MetaspaceGC::allowed_expansion() {
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  2432
  size_t committed_bytes = MetaspaceUtils::committed_bytes();
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2433
  size_t capacity_until_gc = capacity_until_GC();
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2434
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2435
  assert(capacity_until_gc >= committed_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2436
         "capacity_until_gc: " SIZE_FORMAT " < committed_bytes: " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2437
         capacity_until_gc, committed_bytes);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2438
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2439
  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
  2440
  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
  2441
  size_t left_to_commit = MIN2(left_until_GC, left_until_max);
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2442
  log_trace(gc, metaspace, freelist)("allowed expansion words: " SIZE_FORMAT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2443
            " (left_until_max: " SIZE_FORMAT ", left_until_GC: " SIZE_FORMAT ".",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2444
            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
  2445
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2446
  return left_to_commit / BytesPerWord;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2447
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2448
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2449
void MetaspaceGC::compute_new_size() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2450
  assert(_shrink_factor <= 100, "invalid shrink factor");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2451
  uint current_shrink_factor = _shrink_factor;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2452
  _shrink_factor = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2453
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2454
  // 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
  2455
  // 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
  2456
  // un-fragmented chunk free list is available for future allocations.
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  2457
  // 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
  2458
  // 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
  2459
  // 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
  2460
  // 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
  2461
  // shrink below committed_bytes() and this has caused serious bugs in the past.
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  2462
  const size_t used_after_gc = MetaspaceUtils::committed_bytes();
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2463
  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
  2464
15610
528d799702c7 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 15488
diff changeset
  2465
  const double minimum_free_percentage = MinMetaspaceFreeRatio / 100.0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2466
  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
  2467
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2468
  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
  2469
  size_t minimum_desired_capacity =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2470
    (size_t)MIN2(min_tmp, double(max_uintx));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2471
  // Don't shrink less than the initial generation size
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2472
  minimum_desired_capacity = MAX2(minimum_desired_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2473
                                  MetaspaceSize);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2474
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2475
  log_trace(gc, metaspace)("MetaspaceGC::compute_new_size: ");
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2476
  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
  2477
                           minimum_free_percentage, maximum_used_percentage);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2478
  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
  2479
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2480
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2481
  size_t shrink_bytes = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2482
  if (capacity_until_GC < minimum_desired_capacity) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2483
    // 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
  2484
    // increment the HWM.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2485
    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
  2486
    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
  2487
    // Don't expand unless it's significant
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2488
    if (expand_bytes >= MinMetaspaceExpansion) {
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2489
      size_t new_capacity_until_GC = 0;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2490
      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
  2491
      assert(succeeded, "Should always succesfully increment HWM when at safepoint");
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  2492
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  2493
      Metaspace::tracer()->report_gc_threshold(capacity_until_GC,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  2494
                                               new_capacity_until_GC,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  2495
                                               MetaspaceGCThresholdUpdater::ComputeNewSize);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2496
      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
  2497
                               minimum_desired_capacity / (double) K,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2498
                               expand_bytes / (double) K,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2499
                               MinMetaspaceExpansion / (double) K,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2500
                               new_capacity_until_GC / (double) K);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2501
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2502
    return;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2503
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2504
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2505
  // No expansion, now see if we want to shrink
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2506
  // We would never want to shrink more than this
22499
33777708d0fc 8031779: Assert in MetaspaceGC is always true
ehelin
parents: 22248
diff changeset
  2507
  assert(capacity_until_GC >= minimum_desired_capacity,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2508
         SIZE_FORMAT " >= " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2509
         capacity_until_GC, minimum_desired_capacity);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2510
  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
  2511
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2512
  // Should shrinking be considered?
15610
528d799702c7 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 15488
diff changeset
  2513
  if (MaxMetaspaceFreeRatio < 100) {
528d799702c7 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 15488
diff changeset
  2514
    const double maximum_free_percentage = MaxMetaspaceFreeRatio / 100.0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2515
    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
  2516
    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
  2517
    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
  2518
    maximum_desired_capacity = MAX2(maximum_desired_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2519
                                    MetaspaceSize);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2520
    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
  2521
                             maximum_free_percentage, minimum_used_percentage);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2522
    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
  2523
                             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
  2524
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2525
    assert(minimum_desired_capacity <= maximum_desired_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2526
           "sanity check");
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
    if (capacity_until_GC > maximum_desired_capacity) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2529
      // Capacity too large, compute shrinking size
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2530
      shrink_bytes = capacity_until_GC - maximum_desired_capacity;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2531
      // 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
  2532
      // 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
  2533
      // 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
  2534
      // 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
  2535
      // 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
  2536
      // 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
  2537
      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
  2538
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  2539
      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
  2540
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2541
      assert(shrink_bytes <= max_shrink_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2542
             "invalid shrink size " SIZE_FORMAT " not <= " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2543
             shrink_bytes, max_shrink_bytes);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2544
      if (current_shrink_factor == 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2545
        _shrink_factor = 10;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2546
      } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2547
        _shrink_factor = MIN2(current_shrink_factor * 4, (uint) 100);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2548
      }
37151
bcda1fb89431 8151845: Comment in globals.hpp for MetaspaceSize is incorrect.
jmasa
parents: 37139
diff changeset
  2549
      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
  2550
                               MetaspaceSize / (double) K, maximum_desired_capacity / (double) K);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2551
      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
  2552
                               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
  2553
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2554
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2555
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2556
  // 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
  2557
  if (shrink_bytes >= MinMetaspaceExpansion &&
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2558
      ((capacity_until_GC - shrink_bytes) >= MetaspaceSize)) {
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  2559
    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
  2560
    Metaspace::tracer()->report_gc_threshold(capacity_until_GC,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  2561
                                             new_capacity_until_GC,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  2562
                                             MetaspaceGCThresholdUpdater::ComputeNewSize);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2563
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2564
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2565
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2566
// Metadebug methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2567
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2568
void Metadebug::init_allocation_fail_alot_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2569
  if (MetadataAllocationFailALot) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2570
    _allocation_fail_alot_count =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2571
      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
  2572
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2573
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2574
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2575
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2576
bool Metadebug::test_metadata_failure() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2577
  if (MetadataAllocationFailALot &&
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2578
      Threads::is_vm_complete()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2579
    if (_allocation_fail_alot_count > 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2580
      _allocation_fail_alot_count--;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2581
    } else {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2582
      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
  2583
      init_allocation_fail_alot_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2584
      return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2585
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2586
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2587
  return false;
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
#endif
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
// ChunkManager methods
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2592
size_t ChunkManager::free_chunks_total_words() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2593
  return _free_chunks_total;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2594
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2595
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2596
size_t ChunkManager::free_chunks_total_bytes() {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2597
  return free_chunks_total_words() * BytesPerWord;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2598
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2599
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2600
// Update internal accounting after a chunk was added
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2601
void ChunkManager::account_for_added_chunk(const Metachunk* c) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2602
  assert_lock_strong(MetaspaceExpand_lock);
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2603
  _free_chunks_count ++;
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2604
  _free_chunks_total += c->word_size();
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2605
}
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2606
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2607
// Update internal accounting after a chunk was removed
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2608
void ChunkManager::account_for_removed_chunk(const Metachunk* c) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2609
  assert_lock_strong(MetaspaceExpand_lock);
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2610
  assert(_free_chunks_count >= 1,
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2611
    "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
  2612
  assert(_free_chunks_total >= c->word_size(),
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2613
    "ChunkManager::_free_chunks_total: about to go negative"
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2614
     "(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
  2615
  _free_chunks_count --;
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2616
  _free_chunks_total -= c->word_size();
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2617
}
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2618
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2619
size_t ChunkManager::free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2620
#ifdef ASSERT
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2621
  if (!UseConcMarkSweepGC && !MetaspaceExpand_lock->is_locked()) {
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2622
    MutexLockerEx cl(MetaspaceExpand_lock,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2623
                     Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2624
    // 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
  2625
    // 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
  2626
    slow_locked_verify_free_chunks_count();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2627
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2628
#endif
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2629
  return _free_chunks_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2630
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2631
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2632
ChunkIndex ChunkManager::list_index(size_t size) {
49453
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  2633
  return get_chunk_type_by_size(size, is_class());
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2634
}
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2635
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2636
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
  2637
  index_bounds_check(index);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2638
  assert(index != HumongousIndex, "Do not call for humongous chunks.");
49453
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  2639
  return get_size_for_nonhumongous_chunktype(index, is_class());
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2640
}
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2641
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2642
void ChunkManager::locked_verify_free_chunks_total() {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2643
  assert_lock_strong(MetaspaceExpand_lock);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2644
  assert(sum_free_chunks() == _free_chunks_total,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2645
         "_free_chunks_total " SIZE_FORMAT " is not the"
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2646
         " same as sum " SIZE_FORMAT, _free_chunks_total,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2647
         sum_free_chunks());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2648
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2649
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2650
void ChunkManager::verify_free_chunks_total() {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2651
  MutexLockerEx cl(MetaspaceExpand_lock,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2652
                     Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2653
  locked_verify_free_chunks_total();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2654
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2655
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2656
void ChunkManager::locked_verify_free_chunks_count() {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2657
  assert_lock_strong(MetaspaceExpand_lock);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2658
  assert(sum_free_chunks_count() == _free_chunks_count,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2659
         "_free_chunks_count " SIZE_FORMAT " is not the"
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2660
         " same as sum " SIZE_FORMAT, _free_chunks_count,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2661
         sum_free_chunks_count());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2662
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2663
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2664
void ChunkManager::verify_free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2665
#ifdef ASSERT
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2666
  MutexLockerEx cl(MetaspaceExpand_lock,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2667
                     Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2668
  locked_verify_free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2669
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2670
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2671
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2672
void ChunkManager::verify() {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2673
  MutexLockerEx cl(MetaspaceExpand_lock,
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2674
                     Mutex::_no_safepoint_check_flag);
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2675
  locked_verify();
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::locked_verify() {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2679
  locked_verify_free_chunks_count();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2680
  locked_verify_free_chunks_total();
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2681
  for (ChunkIndex i = ZeroIndex; i < NumberOfFreeLists; i = next_chunk_index(i)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2682
    ChunkList* list = free_chunks(i);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2683
    if (list != NULL) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2684
      Metachunk* chunk = list->head();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2685
      while (chunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2686
        DEBUG_ONLY(do_verify_chunk(chunk);)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2687
        assert(chunk->is_tagged_free(), "Chunk should be tagged as free.");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2688
        chunk = chunk->next();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2689
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2690
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2691
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2692
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2693
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2694
void ChunkManager::locked_print_free_chunks(outputStream* st) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2695
  assert_lock_strong(MetaspaceExpand_lock);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2696
  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
  2697
                _free_chunks_total, _free_chunks_count);
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::locked_print_sum_free_chunks(outputStream* st) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2701
  assert_lock_strong(MetaspaceExpand_lock);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2702
  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
  2703
                sum_free_chunks(), sum_free_chunks_count());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2704
}
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  2705
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2706
ChunkList* ChunkManager::free_chunks(ChunkIndex index) {
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  2707
  assert(index == SpecializedIndex || index == SmallIndex || index == MediumIndex,
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  2708
         "Bad index: %d", (int)index);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  2709
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2710
  return &_free_chunks[index];
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2711
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2712
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2713
// 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
  2714
// methods that are used in product builds.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2715
size_t ChunkManager::sum_free_chunks() {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2716
  assert_lock_strong(MetaspaceExpand_lock);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2717
  size_t result = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2718
  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
  2719
    ChunkList* list = free_chunks(i);
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
    if (list == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2722
      continue;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2723
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2724
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2725
    result = result + list->count() * list->size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2726
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2727
  result = result + humongous_dictionary()->total_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2728
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2729
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2730
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2731
size_t ChunkManager::sum_free_chunks_count() {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2732
  assert_lock_strong(MetaspaceExpand_lock);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2733
  size_t count = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2734
  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
  2735
    ChunkList* list = free_chunks(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2736
    if (list == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2737
      continue;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2738
    }
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2739
    count = count + list->count();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2740
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2741
  count = count + humongous_dictionary()->total_free_blocks();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2742
  return count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2743
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2744
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2745
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
  2746
  ChunkIndex index = list_index(word_size);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2747
  assert(index < HumongousIndex, "No humongous list");
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2748
  return free_chunks(index);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2749
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2750
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2751
// 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
  2752
// 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
  2753
// the target chunk of target chunk size. The smaller chunks, including the target
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2754
// 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
  2755
// 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
  2756
Metachunk* ChunkManager::split_chunk(size_t target_chunk_word_size, Metachunk* larger_chunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2757
  assert(larger_chunk->word_size() > target_chunk_word_size, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2758
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2759
  const ChunkIndex larger_chunk_index = larger_chunk->get_chunk_type();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2760
  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
  2761
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2762
  MetaWord* const region_start = (MetaWord*)larger_chunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2763
  const size_t region_word_len = larger_chunk->word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2764
  MetaWord* const region_end = region_start + region_word_len;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2765
  VirtualSpaceNode* const vsn = larger_chunk->container();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2766
  OccupancyMap* const ocmap = vsn->occupancy_map();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2767
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2768
  // 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
  2769
  // 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
  2770
  // at an address suitable to place the smaller target chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2771
  assert_is_aligned(region_start, target_chunk_word_size);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2772
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2773
  // Remove old chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2774
  free_chunks(larger_chunk_index)->remove_chunk(larger_chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2775
  larger_chunk->remove_sentinel();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2776
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2777
  // Prevent access to the old chunk from here on.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2778
  larger_chunk = NULL;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2779
  // ... and wipe it.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2780
  DEBUG_ONLY(memset(region_start, 0xfe, region_word_len * BytesPerWord));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2781
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2782
  // In its place create first the target chunk...
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2783
  MetaWord* p = region_start;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2784
  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
  2785
  assert(target_chunk == (Metachunk*)p, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2786
  target_chunk->set_origin(origin_split);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2787
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2788
  // Note: we do not need to mark its start in the occupancy map
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2789
  // because it coincides with the old chunk start.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2790
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2791
  // Mark chunk as free and return to the freelist.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2792
  do_update_in_use_info_for_chunk(target_chunk, false);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2793
  free_chunks(target_chunk_index)->return_chunk_at_head(target_chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2794
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2795
  // This chunk should now be valid and can be verified.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2796
  DEBUG_ONLY(do_verify_chunk(target_chunk));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2797
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2798
  // In the remaining space create the remainder chunks.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2799
  p += target_chunk->word_size();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2800
  assert(p < region_end, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2801
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2802
  while (p < region_end) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2803
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2804
    // Find the largest chunk size which fits the alignment requirements at address p.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2805
    ChunkIndex this_chunk_index = prev_chunk_index(larger_chunk_index);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2806
    size_t this_chunk_word_size = 0;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2807
    for(;;) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2808
      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
  2809
      if (is_aligned(p, this_chunk_word_size * BytesPerWord)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2810
        break;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2811
      } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2812
        this_chunk_index = prev_chunk_index(this_chunk_index);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2813
        assert(this_chunk_index >= target_chunk_index, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2814
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2815
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2816
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2817
    assert(this_chunk_word_size >= target_chunk_word_size, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2818
    assert(is_aligned(p, this_chunk_word_size * BytesPerWord), "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2819
    assert(p + this_chunk_word_size <= region_end, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2820
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2821
    // Create splitting chunk.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2822
    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
  2823
    assert(this_chunk == (Metachunk*)p, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2824
    this_chunk->set_origin(origin_split);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2825
    ocmap->set_chunk_starts_at_address(p, true);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2826
    do_update_in_use_info_for_chunk(this_chunk, false);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2827
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2828
    // This chunk should be valid and can be verified.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2829
    DEBUG_ONLY(do_verify_chunk(this_chunk));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2830
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2831
    // Return this chunk to freelist and correct counter.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2832
    free_chunks(this_chunk_index)->return_chunk_at_head(this_chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2833
    _free_chunks_count ++;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2834
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2835
    log_trace(gc, metaspace, freelist)("Created chunk at " PTR_FORMAT ", word size "
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2836
      SIZE_FORMAT_HEX " (%s), in split region [" PTR_FORMAT "..." PTR_FORMAT ").",
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2837
      p2i(this_chunk), this_chunk->word_size(), chunk_size_name(this_chunk_index),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2838
      p2i(region_start), p2i(region_end));
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2839
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2840
    p += this_chunk_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2841
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
  return target_chunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2845
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2846
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2847
Metachunk* ChunkManager::free_chunks_get(size_t word_size) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2848
  assert_lock_strong(MetaspaceExpand_lock);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2849
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2850
  slow_locked_verify();
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2851
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2852
  Metachunk* chunk = NULL;
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2853
  bool we_did_split_a_chunk = false;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2854
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2855
  if (list_index(word_size) != HumongousIndex) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2856
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2857
    ChunkList* free_list = find_free_chunks_list(word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2858
    assert(free_list != NULL, "Sanity check");
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2859
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2860
    chunk = free_list->head();
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2861
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2862
    if (chunk == NULL) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2863
      // 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
  2864
      // This is the counterpart of the coalescing-upon-chunk-return.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2865
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2866
      ChunkIndex target_chunk_index = get_chunk_type_by_size(word_size, is_class());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2867
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2868
      // Is there a larger chunk we could split?
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2869
      Metachunk* larger_chunk = NULL;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2870
      ChunkIndex larger_chunk_index = next_chunk_index(target_chunk_index);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2871
      while (larger_chunk == NULL && larger_chunk_index < NumberOfFreeLists) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2872
        larger_chunk = free_chunks(larger_chunk_index)->head();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2873
        if (larger_chunk == NULL) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2874
          larger_chunk_index = next_chunk_index(larger_chunk_index);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2875
        }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2876
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2877
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2878
      if (larger_chunk != NULL) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2879
        assert(larger_chunk->word_size() > word_size, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2880
        assert(larger_chunk->get_chunk_type() == larger_chunk_index, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2881
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2882
        // We found a larger chunk. Lets split it up:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2883
        // - remove old chunk
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2884
        // - in its place, create new smaller chunks, with at least one chunk
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2885
        //   being of target size, the others sized as large as possible. This
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2886
        //   is to make sure the resulting chunks are "as coalesced as possible"
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2887
        //   (similar to VirtualSpaceNode::retire()).
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2888
        // Note: during this operation both ChunkManager and VirtualSpaceNode
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2889
        //  are temporarily invalid, so be careful with asserts.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2890
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2891
        log_trace(gc, metaspace, freelist)("%s: splitting chunk " PTR_FORMAT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2892
           ", 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
  2893
          (is_class() ? "class space" : "metaspace"), p2i(larger_chunk), larger_chunk->word_size(),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2894
          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
  2895
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2896
        chunk = split_chunk(word_size, larger_chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2897
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2898
        // This should have worked.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2899
        assert(chunk != NULL, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2900
        assert(chunk->word_size() == word_size, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2901
        assert(chunk->is_tagged_free(), "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2902
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2903
        we_did_split_a_chunk = true;
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
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2907
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2908
    if (chunk == NULL) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2909
      return NULL;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2910
    }
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2911
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2912
    // 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
  2913
    free_list->remove_chunk(chunk);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2914
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2915
    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
  2916
                                       p2i(free_list), free_list->count());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2917
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2918
  } else {
46674
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46625
diff changeset
  2919
    chunk = humongous_dictionary()->get_chunk(word_size);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2920
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2921
    if (chunk == NULL) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2922
      return NULL;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2923
    }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2924
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2925
    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
  2926
                                    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
  2927
  }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2928
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2929
  // Chunk has been removed from the chunk manager; update counters.
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2930
  account_for_removed_chunk(chunk);
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2931
  do_update_in_use_info_for_chunk(chunk, true);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2932
  chunk->container()->inc_container_count();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2933
  chunk->inc_use_count();
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2934
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2935
  // 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
  2936
  chunk->set_next(NULL);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2937
  chunk->set_prev(NULL);
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2938
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2939
  // Run some verifications (some more if we did a chunk split)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2940
#ifdef ASSERT
49405
e88237c5ac83 8199656: Make slow metaspace verifications switchable in debug builds
stuefe
parents: 49402
diff changeset
  2941
  if (VerifyMetaspace) {
49386
d89e98d85841 8199518: test/hotspot/jtreg/runtime/SelectionResolution tests take a lot longer to run with fastdebug after JDK-8198423
stuefe
parents: 49372
diff changeset
  2942
    locked_verify();
d89e98d85841 8199518: test/hotspot/jtreg/runtime/SelectionResolution tests take a lot longer to run with fastdebug after JDK-8198423
stuefe
parents: 49372
diff changeset
  2943
    VirtualSpaceNode* const vsn = chunk->container();
d89e98d85841 8199518: test/hotspot/jtreg/runtime/SelectionResolution tests take a lot longer to run with fastdebug after JDK-8198423
stuefe
parents: 49372
diff changeset
  2944
    vsn->verify();
d89e98d85841 8199518: test/hotspot/jtreg/runtime/SelectionResolution tests take a lot longer to run with fastdebug after JDK-8198423
stuefe
parents: 49372
diff changeset
  2945
    if (we_did_split_a_chunk) {
d89e98d85841 8199518: test/hotspot/jtreg/runtime/SelectionResolution tests take a lot longer to run with fastdebug after JDK-8198423
stuefe
parents: 49372
diff changeset
  2946
      vsn->verify_free_chunks_are_ideally_merged();
d89e98d85841 8199518: test/hotspot/jtreg/runtime/SelectionResolution tests take a lot longer to run with fastdebug after JDK-8198423
stuefe
parents: 49372
diff changeset
  2947
    }
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2948
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2949
#endif
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2950
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2951
  return chunk;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2952
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2953
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2954
Metachunk* ChunkManager::chunk_freelist_allocate(size_t word_size) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2955
  assert_lock_strong(MetaspaceExpand_lock);
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2956
  slow_locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2957
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2958
  // Take from the beginning of the list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2959
  Metachunk* chunk = free_chunks_get(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2960
  if (chunk == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2961
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2962
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2963
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2964
  assert((word_size <= chunk->word_size()) ||
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  2965
         (list_index(chunk->word_size()) == HumongousIndex),
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2966
         "Non-humongous variable sized chunk");
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2967
  LogTarget(Debug, gc, metaspace, freelist) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2968
  if (lt.is_enabled()) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2969
    size_t list_count;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2970
    if (list_index(word_size) < HumongousIndex) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2971
      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
  2972
      list_count = list->count();
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2973
    } else {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2974
      list_count = humongous_dictionary()->total_count();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2975
    }
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2976
    LogStream ls(lt);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2977
    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
  2978
             p2i(this), p2i(chunk), chunk->word_size(), list_count);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2979
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2980
    locked_print_free_chunks(&ls);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2981
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2982
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2983
  return chunk;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2984
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2985
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2986
void ChunkManager::return_single_chunk(ChunkIndex index, Metachunk* chunk) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  2987
  assert_lock_strong(MetaspaceExpand_lock);
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2988
  DEBUG_ONLY(do_verify_chunk(chunk);)
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  2989
  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
  2990
  assert(chunk != NULL, "Expected chunk.");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2991
  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
  2992
  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
  2993
  index_bounds_check(index);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2994
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2995
  // 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
  2996
  // 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
  2997
  // 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
  2998
  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
  2999
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3000
  if (index != HumongousIndex) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3001
    // 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
  3002
    ChunkList* list = free_chunks(index);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3003
    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
  3004
    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
  3005
    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
  3006
        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
  3007
  } else {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3008
    // Return humongous chunk to dictionary.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3009
    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
  3010
    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
  3011
           "Humongous chunk has wrong alignment.");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3012
    _humongous_dictionary.return_chunk(chunk);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3013
    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
  3014
        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
  3015
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3016
  chunk->container()->dec_container_count();
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3017
  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
  3018
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  3019
  // Chunk has been added; update counters.
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  3020
  account_for_added_chunk(chunk);
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  3021
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3022
  // Attempt coalesce returned chunks with its neighboring chunks:
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3023
  // 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
  3024
  if (index == SmallIndex || index == SpecializedIndex) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3025
    if (!attempt_to_coalesce_around_chunk(chunk, MediumIndex)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3026
      // 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
  3027
      if (index == SpecializedIndex) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3028
        if (!attempt_to_coalesce_around_chunk(chunk, SmallIndex)) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3029
          // give up.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3030
        }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3031
      }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3032
    }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3033
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3034
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3035
}
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3036
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3037
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
  3038
  index_bounds_check(index);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3039
  if (chunks == NULL) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3040
    return;
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
  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
  3043
  if (log.is_enabled()) { // tracing
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3044
    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
  3045
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3046
  unsigned num_chunks_returned = 0;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3047
  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
  3048
  Metachunk* cur = chunks;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3049
  while (cur != NULL) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3050
    // 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
  3051
    // 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
  3052
    Metachunk* next = cur->next();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3053
    if (log.is_enabled()) { // tracing
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3054
      num_chunks_returned ++;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3055
      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
  3056
    }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3057
    return_single_chunk(index, cur);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3058
    cur = next;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3059
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3060
  if (log.is_enabled()) { // tracing
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3061
    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
  3062
        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
  3063
    if (index != HumongousIndex) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3064
      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
  3065
    } else {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3066
      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
  3067
    }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3068
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3069
}
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3070
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3071
void ChunkManager::print_on(outputStream* out) const {
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3072
  _humongous_dictionary.report_statistics(out);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3073
}
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3074
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3075
void ChunkManager::locked_get_statistics(ChunkManagerStatistics* stat) const {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  3076
  assert_lock_strong(MetaspaceExpand_lock);
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3077
  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
  3078
    stat->num_by_type[i] = num_free_chunks(i);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3079
    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
  3080
    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
  3081
  }
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3082
  stat->num_humongous_chunks = num_free_chunks(HumongousIndex);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3083
  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
  3084
}
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3085
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3086
void ChunkManager::get_statistics(ChunkManagerStatistics* stat) const {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  3087
  MutexLockerEx cl(MetaspaceExpand_lock,
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3088
                   Mutex::_no_safepoint_check_flag);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3089
  locked_get_statistics(stat);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3090
}
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3091
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3092
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
  3093
  size_t total = 0;
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3094
  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
  3095
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3096
  const char* unit = scale_unit(scale);
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3097
  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
  3098
    out->print("  " SIZE_FORMAT " %s (" SIZE_FORMAT " bytes) chunks, total ",
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3099
                   stat->num_by_type[i], chunk_size_name(i),
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3100
                   stat->single_size_by_type[i]);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3101
    if (scale == 1) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3102
      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
  3103
    } else {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3104
      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
  3105
    }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3106
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3107
    total += stat->total_size_by_type[i];
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3108
  }
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3109
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3110
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3111
  total += stat->total_size_humongous_chunks;
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3112
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3113
  if (scale == 1) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3114
    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
  3115
    stat->num_humongous_chunks, stat->total_size_humongous_chunks);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3116
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3117
    out->print_cr("  total size: " SIZE_FORMAT " bytes.", total);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3118
  } else {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3119
    out->print_cr("  " SIZE_FORMAT " humongous chunks, total %.2f%s",
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3120
    stat->num_humongous_chunks,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3121
    (float)stat->total_size_humongous_chunks / scale, unit);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3122
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3123
    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
  3124
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3125
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3126
}
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3127
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3128
void ChunkManager::print_all_chunkmanagers(outputStream* out, size_t scale) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3129
  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
  3130
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3131
  // 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
  3132
  // out of lock protection
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3133
  ChunkManagerStatistics stat;
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3134
  out->print_cr("Chunkmanager (non-class):");
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3135
  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
  3136
  if (non_class_cm != NULL) {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3137
    non_class_cm->get_statistics(&stat);
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3138
    ChunkManager::print_statistics(&stat, out, scale);
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3139
  } else {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3140
    out->print_cr("unavailable.");
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3141
  }
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3142
  out->print_cr("Chunkmanager (class):");
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3143
  const ChunkManager* const class_cm = Metaspace::chunk_manager_class();
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3144
  if (class_cm != NULL) {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3145
    class_cm->get_statistics(&stat);
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3146
    ChunkManager::print_statistics(&stat, out, scale);
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3147
  } else {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3148
    out->print_cr("unavailable.");
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  3149
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3150
}
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3151
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3152
// SpaceManager methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3153
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3154
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
  3155
  size_t chunk_sizes[] = {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3156
      specialized_chunk_size(is_class_space),
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3157
      small_chunk_size(is_class_space),
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3158
      medium_chunk_size(is_class_space)
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3159
  };
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3160
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3161
  // Adjust up to one of the fixed chunk sizes ...
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3162
  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
  3163
    if (requested <= chunk_sizes[i]) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3164
      return chunk_sizes[i];
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3165
    }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3166
  }
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3167
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3168
  // ... or return the size as a humongous chunk.
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3169
  return requested;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3170
}
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3171
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3172
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
  3173
  return adjust_initial_chunk_size(requested, is_class());
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3174
}
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3175
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3176
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
  3177
  size_t requested;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3178
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3179
  if (is_class()) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3180
    switch (type) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3181
    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
  3182
    case Metaspace::AnonymousMetaspaceType:  requested = ClassSpecializedChunk; break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3183
    case Metaspace::ReflectionMetaspaceType: requested = ClassSpecializedChunk; break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3184
    default:                                 requested = ClassSmallChunk; break;
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
  } else {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3187
    switch (type) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3188
    case Metaspace::BootMetaspaceType:       requested = Metaspace::first_chunk_word_size(); break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3189
    case Metaspace::AnonymousMetaspaceType:  requested = SpecializedChunk; break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3190
    case Metaspace::ReflectionMetaspaceType: requested = SpecializedChunk; break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3191
    default:                                 requested = SmallChunk; break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3192
    }
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
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3195
  // Adjust to one of the fixed chunk sizes (unless humongous)
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3196
  const size_t adjusted = adjust_initial_chunk_size(requested);
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
  assert(adjusted != 0, "Incorrect initial chunk size. Requested: "
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3199
         SIZE_FORMAT " adjusted: " SIZE_FORMAT, requested, adjusted);
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
  return adjusted;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3202
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3203
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3204
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
  3205
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3206
  size_t free = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3207
  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
  3208
    Metachunk* chunk = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3209
    while (chunk != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3210
      free += chunk->free_word_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3211
      chunk = chunk->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3212
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3213
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3214
  return free;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3215
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3216
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3217
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
  3218
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3219
  size_t result = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3220
  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
  3221
   result += sum_waste_in_chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3222
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3223
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3224
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3225
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3226
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3227
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
  3228
  size_t result = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3229
  Metachunk* chunk = chunks_in_use(index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3230
  // 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
  3231
  // 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
  3232
  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
  3233
    if (chunk != current_chunk()) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3234
      result += chunk->free_word_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3235
    }
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
  3236
    chunk = chunk->next();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3237
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3238
  return result;
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
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3241
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
  3242
  // 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
  3243
  // 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
  3244
  // 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
  3245
  // 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
  3246
  // 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
  3247
  // 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
  3248
  // 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
  3249
  // answer.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3250
  if (UseConcMarkSweepGC) {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3251
    return allocated_chunks_words();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3252
  } else {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3253
    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
  3254
    size_t sum = 0;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3255
    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
  3256
      Metachunk* chunk = chunks_in_use(i);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3257
      while (chunk != NULL) {
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3258
        sum += chunk->word_size();
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3259
        chunk = chunk->next();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3260
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3261
    }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3262
  return sum;
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
}
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
size_t SpaceManager::sum_count_in_chunks_in_use() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3267
  size_t count = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3268
  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
  3269
    count = count + sum_count_in_chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3270
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3271
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3272
  return count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3273
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3274
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3275
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
  3276
  size_t count = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3277
  Metachunk* chunk = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3278
  while (chunk != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3279
    count++;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3280
    chunk = chunk->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3281
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3282
  return count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3283
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3284
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3285
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3286
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
  3287
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3288
  size_t used = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3289
  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
  3290
    Metachunk* chunk = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3291
    while (chunk != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3292
      used += chunk->used_word_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3293
      chunk = chunk->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3294
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3295
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3296
  return used;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3297
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3298
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3299
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
  3300
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3301
  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
  3302
    Metachunk* chunk = chunks_in_use(i);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3303
    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
  3304
                 chunk_size_name(i), p2i(chunk));
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3305
    if (chunk != NULL) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3306
      st->print_cr(" free " SIZE_FORMAT,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3307
                   chunk->free_word_size());
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3308
    } else {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24351
diff changeset
  3309
      st->cr();
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3310
    }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3311
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3312
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3313
  chunk_manager()->locked_print_free_chunks(st);
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3314
  chunk_manager()->locked_print_sum_free_chunks(st);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3315
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3316
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3317
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
  3318
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3319
  // 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
  3320
  // _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
  3321
  // After that a medium chunk is preferred.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3322
  size_t chunk_word_size;
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3323
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3324
  // Special case for anonymous metadata space.
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3325
  // 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
  3326
  // rarely about 4K (64-bits JVM).
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3327
  // Instead of jumping to SmallChunk after initial chunk exhausted, keeping allocation
49395
c382614abe59 8191924: Adjust DelegatingClassLoader's metadata space sizing algorithm
zgu
parents: 49389
diff changeset
  3328
  // from SpecializeChunk up to _anon_or_delegating_metadata_specialize_chunk_limit (4)
c382614abe59 8191924: Adjust DelegatingClassLoader's metadata space sizing algorithm
zgu
parents: 49389
diff changeset
  3329
  // reduces space waste from 60+% to around 30%.
c382614abe59 8191924: Adjust DelegatingClassLoader's metadata space sizing algorithm
zgu
parents: 49389
diff changeset
  3330
  if ((_space_type == Metaspace::AnonymousMetaspaceType || _space_type == Metaspace::ReflectionMetaspaceType) &&
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3331
      _mdtype == Metaspace::NonClassType &&
49395
c382614abe59 8191924: Adjust DelegatingClassLoader's metadata space sizing algorithm
zgu
parents: 49389
diff changeset
  3332
      sum_count_in_chunks_in_use(SpecializedIndex) < _anon_and_delegating_metadata_specialize_chunk_limit &&
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3333
      word_size + Metachunk::overhead() <= SpecializedChunk) {
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3334
    return SpecializedChunk;
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3335
  }
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3336
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3337
  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
  3338
      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
  3339
    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
  3340
    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
  3341
      chunk_word_size = medium_chunk_size();
13728
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
  } else {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3344
    chunk_word_size = medium_chunk_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3345
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3346
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3347
  // 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
  3348
  // 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
  3349
  // the smallest chunk size.
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3350
  size_t if_humongous_sized_chunk =
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  3351
    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
  3352
                  smallest_chunk_size());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3353
  chunk_word_size =
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3354
    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
  3355
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3356
  assert(!SpaceManager::is_humongous(word_size) ||
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3357
         chunk_word_size == if_humongous_sized_chunk,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3358
         "Size calculation is wrong, word_size " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3359
         " chunk_word_size " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3360
         word_size, chunk_word_size);
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37151
diff changeset
  3361
  Log(gc, metaspace, alloc) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3362
  if (log.is_debug() && SpaceManager::is_humongous(word_size)) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3363
    log.debug("Metadata humongous allocation:");
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3364
    log.debug("  word_size " PTR_FORMAT, word_size);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3365
    log.debug("  chunk_word_size " PTR_FORMAT, chunk_word_size);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3366
    log.debug("    chunk overhead " PTR_FORMAT, Metachunk::overhead());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3367
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3368
  return chunk_word_size;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3369
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3370
20407
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3371
void SpaceManager::track_metaspace_memory_usage() {
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3372
  if (is_init_completed()) {
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3373
    if (is_class()) {
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3374
      MemoryService::track_compressed_class_memory_usage();
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3375
    }
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3376
    MemoryService::track_metaspace_memory_usage();
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3377
  }
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3378
}
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3379
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3380
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
  3381
  assert(vs_list()->current_virtual_space() != NULL,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3382
         "Should have been set");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3383
  assert(current_chunk() == NULL ||
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3384
         current_chunk()->allocate(word_size) == NULL,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3385
         "Don't need to expand");
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  3386
  MutexLockerEx cl(MetaspaceExpand_lock, Mutex::_no_safepoint_check_flag);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3387
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3388
  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
  3389
    size_t words_left = 0;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3390
    size_t words_used = 0;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3391
    if (current_chunk() != NULL) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3392
      words_left = current_chunk()->free_word_size();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3393
      words_used = current_chunk()->used_word_size();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3394
    }
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3395
    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
  3396
                                       word_size, words_used, words_left);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3397
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3398
31028
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  3399
  // Get another chunk
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3400
  size_t chunk_word_size = calc_chunk_size(word_size);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3401
  Metachunk* next = get_new_chunk(chunk_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3402
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3403
  MetaWord* mem = NULL;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3404
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3405
  // 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
  3406
  // and do an allocation from it.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3407
  if (next != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3408
    // 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
  3409
    add_chunk(next, false);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3410
    mem = next->allocate(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3411
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3412
20407
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3413
  // Track metaspace memory usage statistic.
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3414
  track_metaspace_memory_usage();
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  3415
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3416
  return mem;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3417
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3418
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3419
void SpaceManager::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3420
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3421
  for (ChunkIndex i = ZeroIndex;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3422
       i < NumberOfInUseLists ;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3423
       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
  3424
    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
  3425
                 p2i(chunks_in_use(i)),
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3426
                 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
  3427
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3428
  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
  3429
               " Humongous " SIZE_FORMAT,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3430
               sum_waste_in_chunks_in_use(SmallIndex),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3431
               sum_waste_in_chunks_in_use(MediumIndex),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3432
               sum_waste_in_chunks_in_use(HumongousIndex));
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3433
  // block free lists
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3434
  if (block_freelists() != NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3435
    st->print_cr("total in block free lists " SIZE_FORMAT,
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3436
      block_freelists()->total_size());
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3437
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3438
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3439
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3440
SpaceManager::SpaceManager(Metaspace::MetadataType mdtype,
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3441
                           Metaspace::MetaspaceType space_type,
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3442
                           Mutex* lock) :
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3443
  _mdtype(mdtype),
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3444
  _space_type(space_type),
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3445
  _allocated_blocks_words(0),
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3446
  _allocated_chunks_words(0),
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3447
  _allocated_chunks_count(0),
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3448
  _block_freelists(NULL),
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3449
  _lock(lock)
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3450
{
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3451
  initialize();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3452
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3453
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3454
void SpaceManager::inc_size_metrics(size_t words) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  3455
  assert_lock_strong(MetaspaceExpand_lock);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3456
  // 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
  3457
  // for each SpaceManager
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3458
  _allocated_chunks_words = _allocated_chunks_words + words;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3459
  _allocated_chunks_count++;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3460
  // Global total of capacity in allocated Metachunks
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3461
  MetaspaceUtils::inc_capacity(mdtype(), words);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3462
  // Global total of allocated Metablocks.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3463
  // 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
  3464
  // 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
  3465
  // 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
  3466
  // Metachunk).
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3467
  MetaspaceUtils::inc_used(mdtype(), Metachunk::overhead());
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3468
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3469
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3470
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
  3471
  // Add to the per SpaceManager total
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  3472
  Atomic::add(words, &_allocated_blocks_words);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3473
  // Add to the global total
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3474
  MetaspaceUtils::inc_used(mdtype(), words);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3475
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3476
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3477
void SpaceManager::dec_total_from_size_metrics() {
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3478
  MetaspaceUtils::dec_capacity(mdtype(), allocated_chunks_words());
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3479
  MetaspaceUtils::dec_used(mdtype(), allocated_blocks_words());
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3480
  // Also deduct the overhead per Metachunk
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3481
  MetaspaceUtils::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
  3482
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3483
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3484
void SpaceManager::initialize() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3485
  Metadebug::init_allocation_fail_alot_count();
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3486
  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
  3487
    _chunks_in_use[i] = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3488
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3489
  _current_chunk = NULL;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3490
  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
  3491
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3492
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3493
SpaceManager::~SpaceManager() {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  3494
  // This call this->_lock which can't be done while holding MetaspaceExpand_lock
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3495
  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
  3496
         "sum_capacity_in_chunks_in_use() " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3497
         " allocated_chunks_words() " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3498
         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
  3499
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  3500
  MutexLockerEx fcl(MetaspaceExpand_lock,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3501
                    Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3502
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3503
  assert(sum_count_in_chunks_in_use() == allocated_chunks_count(),
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3504
         "sum_count_in_chunks_in_use() " SIZE_FORMAT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3505
         " allocated_chunks_count() " SIZE_FORMAT,
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3506
         sum_count_in_chunks_in_use(), allocated_chunks_count());
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  3507
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3508
  chunk_manager()->slow_locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3509
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3510
  dec_total_from_size_metrics();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3511
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37151
diff changeset
  3512
  Log(gc, metaspace, freelist) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3513
  if (log.is_trace()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3514
    log.trace("~SpaceManager(): " PTR_FORMAT, p2i(this));
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3515
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3516
    LogStream ls(log.trace());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3517
    locked_print_chunks_in_use_on(&ls);
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3518
    if (block_freelists() != NULL) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3519
      block_freelists()->print_on(&ls);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3520
    }
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3521
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3522
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3523
  // 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
  3524
  // to the global list of free chunks.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3525
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3526
  // 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
  3527
  // free lists.  Each list is NULL terminated.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3528
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  3529
  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
  3530
    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
  3531
    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
  3532
    set_chunks_in_use(i, NULL);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3533
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3534
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3535
  chunk_manager()->slow_locked_verify();
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3536
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3537
  if (_block_freelists != NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3538
    delete _block_freelists;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3539
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3540
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3541
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3542
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
  3543
  assert_lock_strong(_lock);
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3544
  // Allocations and deallocations are in raw_word_size
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3545
  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
  3546
  // Lazily create a block_freelist
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3547
  if (block_freelists() == NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3548
    _block_freelists = new BlockFreelist();
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3549
  }
18987
a1b541fe1159 8019845: Memory leak during class redefinition
fparain
parents: 18492
diff changeset
  3550
  block_freelists()->return_block(p, raw_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3551
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3552
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3553
// 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
  3554
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
  3555
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3556
  assert(new_chunk != NULL, "Should not be NULL");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3557
  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
  3558
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3559
  new_chunk->reset_empty();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3560
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3561
  // Find the correct list and and set the current
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3562
  // chunk for that list.
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  3563
  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
  3564
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3565
  if (index != HumongousIndex) {
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3566
    retire_current_chunk();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3567
    set_current_chunk(new_chunk);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3568
    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
  3569
    set_chunks_in_use(index, new_chunk);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3570
  } else {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3571
    // 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
  3572
    // 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
  3573
    // chunk.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3574
    if (make_current) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3575
      // 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
  3576
      set_current_chunk(new_chunk);
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
    // 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
  3579
    // 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
  3580
    // 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
  3581
    // of the humongous chunks list.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3582
    new_chunk->set_next(chunks_in_use(HumongousIndex));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3583
    set_chunks_in_use(HumongousIndex, new_chunk);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3584
15087
8849ea877278 8005486: NPG: Incorrect assertion in ChunkManager::list_index()
jmasa
parents: 15086
diff changeset
  3585
    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
  3586
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3587
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3588
  // Add to the running sum of capacity
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3589
  inc_size_metrics(new_chunk->word_size());
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3590
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3591
  assert(new_chunk->is_empty(), "Not ready for reuse");
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37151
diff changeset
  3592
  Log(gc, metaspace, freelist) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3593
  if (log.is_trace()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3594
    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
  3595
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3596
    LogStream ls(log.trace());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3597
    new_chunk->print_on(&ls);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3598
    chunk_manager()->locked_print_free_chunks(&ls);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3599
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3600
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3601
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3602
void SpaceManager::retire_current_chunk() {
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3603
  if (current_chunk() != NULL) {
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3604
    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
  3605
    if (remaining_words >= BlockFreelist::min_dictionary_size()) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3606
      MetaWord* ptr = current_chunk()->allocate(remaining_words);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3607
      deallocate(ptr, remaining_words);
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3608
      inc_used_metrics(remaining_words);
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3609
    }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3610
  }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3611
}
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  3612
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3613
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
  3614
  // Get a chunk from the chunk freelist
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3615
  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
  3616
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3617
  if (next == NULL) {
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3618
    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
  3619
                                    medium_chunk_bunch());
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3620
  }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3621
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37151
diff changeset
  3622
  Log(gc, metaspace, alloc) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3623
  if (log.is_debug() && next != NULL &&
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3624
      SpaceManager::is_humongous(next->word_size())) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3625
    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
  3626
  }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3627
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3628
  return next;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3629
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3630
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3631
MetaWord* SpaceManager::allocate(size_t word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3632
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3633
  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
  3634
  BlockFreelist* fl =  block_freelists();
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3635
  MetaWord* p = NULL;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3636
  // 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
  3637
  // 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
  3638
  // 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
  3639
  // 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
  3640
  // for allocations.  Do some profiling.  JJJ
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3641
  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
  3642
    p = fl->get_block(raw_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3643
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3644
  if (p == NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3645
    p = allocate_work(raw_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3646
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3647
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3648
  return p;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3649
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3650
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3651
// Returns the address of spaced allocated for "word_size".
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3652
// This methods does not know about blocks (Metablocks)
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3653
MetaWord* SpaceManager::allocate_work(size_t word_size) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3654
  assert_lock_strong(_lock);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3655
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3656
  if (Metadebug::test_metadata_failure()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3657
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3658
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3659
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3660
  // Is there space in the current chunk?
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3661
  MetaWord* result = NULL;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3662
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3663
  if (current_chunk() != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3664
    result = current_chunk()->allocate(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3665
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3666
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3667
  if (result == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3668
    result = grow_and_allocate(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3669
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3670
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3671
  if (result != NULL) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3672
    inc_used_metrics(word_size);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3673
    assert(result != (MetaWord*) chunks_in_use(MediumIndex),
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3674
           "Head of the list is being allocated");
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
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3678
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3679
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3680
void SpaceManager::verify() {
49402
64156c70746c 8199432: metaspace: fix wrong comment and condition in SpaceManager::verify()
stuefe
parents: 49401
diff changeset
  3681
  for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
64156c70746c 8199432: metaspace: fix wrong comment and condition in SpaceManager::verify()
stuefe
parents: 49401
diff changeset
  3682
    Metachunk* curr = chunks_in_use(i);
64156c70746c 8199432: metaspace: fix wrong comment and condition in SpaceManager::verify()
stuefe
parents: 49401
diff changeset
  3683
    while (curr != NULL) {
64156c70746c 8199432: metaspace: fix wrong comment and condition in SpaceManager::verify()
stuefe
parents: 49401
diff changeset
  3684
      DEBUG_ONLY(do_verify_chunk(curr);)
64156c70746c 8199432: metaspace: fix wrong comment and condition in SpaceManager::verify()
stuefe
parents: 49401
diff changeset
  3685
      assert(curr->is_tagged_free() == false, "Chunk should be tagged as in use.");
64156c70746c 8199432: metaspace: fix wrong comment and condition in SpaceManager::verify()
stuefe
parents: 49401
diff changeset
  3686
      curr = curr->next();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3687
    }
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
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3690
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  3691
void SpaceManager::verify_chunk_size(Metachunk* chunk) {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  3692
  assert(is_humongous(chunk->word_size()) ||
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3693
         chunk->word_size() == medium_chunk_size() ||
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3694
         chunk->word_size() == small_chunk_size() ||
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3695
         chunk->word_size() == specialized_chunk_size(),
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  3696
         "Chunk size is wrong");
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  3697
  return;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  3698
}
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  3699
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3700
#ifdef ASSERT
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3701
void SpaceManager::verify_allocated_blocks_words() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3702
  // 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
  3703
  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
  3704
    "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
  3705
  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
  3706
         "allocation total is not consistent " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3707
         " vs " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3708
         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
  3709
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3710
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3711
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3712
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3713
void SpaceManager::dump(outputStream* const out) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3714
  size_t curr_total = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3715
  size_t waste = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3716
  uint i = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3717
  size_t used = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3718
  size_t capacity = 0;
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
  // 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
  3721
  for (ChunkIndex index = ZeroIndex;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3722
       index < NumberOfInUseLists;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3723
       index = next_chunk_index(index)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3724
    for (Metachunk* curr = chunks_in_use(index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3725
         curr != NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3726
         curr = curr->next()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3727
      out->print("%d) ", i++);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3728
      curr->print_on(out);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3729
      curr_total += curr->word_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3730
      used += curr->used_word_size();
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3731
      capacity += curr->word_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3732
      waste += curr->free_word_size() + curr->overhead();;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3733
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3734
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3735
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3736
  if (log_is_enabled(Trace, gc, metaspace, freelist)) {
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3737
    if (block_freelists() != NULL) block_freelists()->print_on(out);
19992
ecae893d6947 8024751: Fix bugs in TraceMetadata
stefank
parents: 19990
diff changeset
  3738
  }
ecae893d6947 8024751: Fix bugs in TraceMetadata
stefank
parents: 19990
diff changeset
  3739
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3740
  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
  3741
  // Free space isn't wasted.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3742
  waste -= free;
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
  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
  3745
                " free " SIZE_FORMAT " capacity " SIZE_FORMAT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3746
                " waste " SIZE_FORMAT, curr_total, used, free, capacity, waste);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3747
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3748
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3749
// MetaspaceUtils
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3750
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3751
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3752
size_t MetaspaceUtils::_capacity_words[] = {0, 0};
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3753
volatile size_t MetaspaceUtils::_used_words[] = {0, 0};
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3754
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3755
size_t MetaspaceUtils::free_bytes(Metaspace::MetadataType mdtype) {
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  3756
  VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  3757
  return list == NULL ? 0 : list->free_bytes();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  3758
}
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  3759
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3760
size_t MetaspaceUtils::free_bytes() {
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  3761
  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
  3762
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3763
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3764
void MetaspaceUtils::dec_capacity(Metaspace::MetadataType mdtype, size_t words) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  3765
  assert_lock_strong(MetaspaceExpand_lock);
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3766
  assert(words <= capacity_words(mdtype),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3767
         "About to decrement below 0: words " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3768
         " is greater than _capacity_words[%u] " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3769
         words, mdtype, capacity_words(mdtype));
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3770
  _capacity_words[mdtype] -= words;
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3771
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3772
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3773
void MetaspaceUtils::inc_capacity(Metaspace::MetadataType mdtype, size_t words) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  3774
  assert_lock_strong(MetaspaceExpand_lock);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3775
  // Needs to be atomic
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3776
  _capacity_words[mdtype] += words;
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3777
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3778
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3779
void MetaspaceUtils::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
  3780
  assert(words <= used_words(mdtype),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3781
         "About to decrement below 0: words " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3782
         " is greater than _used_words[%u] " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3783
         words, mdtype, used_words(mdtype));
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3784
  // For CMS deallocation of the Metaspaces occurs during the
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  3785
  // sweep which is a concurrent phase.  Protection by the MetaspaceExpand_lock
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3786
  // 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
  3787
  // and protected by the Metaspace lock.
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  3788
  Atomic::sub(words, &_used_words[mdtype]);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3789
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3790
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3791
void MetaspaceUtils::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
  3792
  // _used_words tracks allocations for
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3793
  // each piece of metadata.  Those allocations are
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3794
  // generally done concurrently by different application
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3795
  // threads so must be done atomically.
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  3796
  Atomic::add(words, &_used_words[mdtype]);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3797
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3798
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3799
size_t MetaspaceUtils::used_bytes_slow(Metaspace::MetadataType mdtype) {
13733
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3800
  size_t used = 0;
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3801
  ClassLoaderDataGraphMetaspaceIterator iter;
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3802
  while (iter.repeat()) {
49401
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  3803
    ClassLoaderMetaspace* msp = iter.get_next();
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3804
    // Sum allocated_blocks_words for each metaspace
13733
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3805
    if (msp != NULL) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3806
      used += msp->used_words_slow(mdtype);
13733
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3807
    }
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3808
  }
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3809
  return used * BytesPerWord;
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3810
}
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  3811
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3812
size_t MetaspaceUtils::free_bytes_slow(Metaspace::MetadataType mdtype) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3813
  size_t free = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3814
  ClassLoaderDataGraphMetaspaceIterator iter;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3815
  while (iter.repeat()) {
49401
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  3816
    ClassLoaderMetaspace* msp = iter.get_next();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3817
    if (msp != NULL) {
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3818
      free += msp->free_words_slow(mdtype);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3819
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3820
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3821
  return free * BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3822
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3823
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3824
size_t MetaspaceUtils::capacity_bytes_slow(Metaspace::MetadataType mdtype) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3825
  if ((mdtype == Metaspace::ClassType) && !Metaspace::using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3826
    return 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3827
  }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3828
  // 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
  3829
  // added to the capacity calculation as needed.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3830
  size_t capacity = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3831
  ClassLoaderDataGraphMetaspaceIterator iter;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3832
  while (iter.repeat()) {
49401
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  3833
    ClassLoaderMetaspace* msp = iter.get_next();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3834
    if (msp != NULL) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3835
      capacity += msp->capacity_words_slow(mdtype);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3836
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3837
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3838
  return capacity * BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3839
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3840
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3841
size_t MetaspaceUtils::capacity_bytes_slow() {
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3842
#ifdef PRODUCT
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3843
  // Use capacity_bytes() in PRODUCT instead of this function.
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3844
  guarantee(false, "Should not call capacity_bytes_slow() in the PRODUCT");
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3845
#endif
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3846
  size_t class_capacity = capacity_bytes_slow(Metaspace::ClassType);
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3847
  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
  3848
  assert(capacity_bytes() == class_capacity + non_class_capacity,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3849
         "bad accounting: capacity_bytes() " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3850
         " class_capacity + non_class_capacity " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3851
         " class_capacity " SIZE_FORMAT " non_class_capacity " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3852
         capacity_bytes(), class_capacity + non_class_capacity,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3853
         class_capacity, non_class_capacity);
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3854
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3855
  return class_capacity + non_class_capacity;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3856
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3857
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3858
size_t MetaspaceUtils::reserved_bytes(Metaspace::MetadataType mdtype) {
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3859
  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
  3860
  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
  3861
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3862
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3863
size_t MetaspaceUtils::committed_bytes(Metaspace::MetadataType mdtype) {
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3864
  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
  3865
  return list == NULL ? 0 : list->committed_bytes();
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3866
}
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3867
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3868
size_t MetaspaceUtils::min_chunk_size_words() { return Metaspace::first_chunk_word_size(); }
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3869
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3870
size_t MetaspaceUtils::free_chunks_total_words(Metaspace::MetadataType mdtype) {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3871
  ChunkManager* chunk_manager = Metaspace::get_chunk_manager(mdtype);
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3872
  if (chunk_manager == NULL) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3873
    return 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3874
  }
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3875
  chunk_manager->slow_verify();
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3876
  return chunk_manager->free_chunks_total_words();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3877
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3878
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3879
size_t MetaspaceUtils::free_chunks_total_bytes(Metaspace::MetadataType mdtype) {
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3880
  return free_chunks_total_words(mdtype) * BytesPerWord;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3881
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3882
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3883
size_t MetaspaceUtils::free_chunks_total_words() {
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3884
  return free_chunks_total_words(Metaspace::ClassType) +
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3885
         free_chunks_total_words(Metaspace::NonClassType);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3886
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3887
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3888
size_t MetaspaceUtils::free_chunks_total_bytes() {
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3889
  return free_chunks_total_words() * BytesPerWord;
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3890
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3891
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3892
bool MetaspaceUtils::has_chunk_free_list(Metaspace::MetadataType mdtype) {
23470
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3893
  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
  3894
}
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3895
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3896
MetaspaceChunkFreeListSummary MetaspaceUtils::chunk_free_list_summary(Metaspace::MetadataType mdtype) {
23470
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3897
  if (!has_chunk_free_list(mdtype)) {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3898
    return MetaspaceChunkFreeListSummary();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3899
  }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3900
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3901
  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
  3902
  return cm->chunk_free_list_summary();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3903
}
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3904
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3905
void MetaspaceUtils::print_metaspace_change(size_t prev_metadata_used) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3906
  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
  3907
                          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
  3908
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3909
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3910
void MetaspaceUtils::print_on(outputStream* out) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3911
  Metaspace::MetadataType nct = Metaspace::NonClassType;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3912
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3913
  out->print_cr(" Metaspace       "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3914
                "used "      SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3915
                "capacity "  SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3916
                "committed " SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3917
                "reserved "  SIZE_FORMAT "K",
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3918
                used_bytes()/K,
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3919
                capacity_bytes()/K,
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3920
                committed_bytes()/K,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3921
                reserved_bytes()/K);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3922
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3923
  if (Metaspace::using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3924
    Metaspace::MetadataType ct = Metaspace::ClassType;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3925
    out->print_cr("  class space    "
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3926
                  "used "      SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3927
                  "capacity "  SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3928
                  "committed " SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3929
                  "reserved "  SIZE_FORMAT "K",
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3930
                  used_bytes(ct)/K,
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3931
                  capacity_bytes(ct)/K,
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3932
                  committed_bytes(ct)/K,
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3933
                  reserved_bytes(ct)/K);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3934
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3935
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3936
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3937
// Print information for class space and data space separately.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3938
// This is almost the same as above.
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3939
void MetaspaceUtils::print_on(outputStream* out, Metaspace::MetadataType mdtype) {
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3940
  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
  3941
  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
  3942
  size_t used_bytes = used_bytes_slow(mdtype);
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3943
  size_t free_bytes = free_bytes_slow(mdtype);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3944
  size_t used_and_free = used_bytes + free_bytes +
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3945
                           free_chunks_capacity_bytes;
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3946
  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
  3947
             "K + unused in chunks " SIZE_FORMAT "K  + "
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3948
             " 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
  3949
             "K  capacity in allocated chunks " SIZE_FORMAT "K",
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3950
             used_bytes / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3951
             free_bytes / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3952
             free_chunks_capacity_bytes / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3953
             used_and_free / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3954
             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
  3955
  // 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
  3956
  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
  3957
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3958
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3959
// Print total fragmentation for class metaspaces
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3960
void MetaspaceUtils::print_class_waste(outputStream* out) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3961
  assert(Metaspace::using_class_space(), "class metaspace not used");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3962
  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
  3963
  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
  3964
  ClassLoaderDataGraphMetaspaceIterator iter;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3965
  while (iter.repeat()) {
49401
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  3966
    ClassLoaderMetaspace* msp = iter.get_next();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3967
    if (msp != NULL) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3968
      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
  3969
      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
  3970
      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
  3971
      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
  3972
      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
  3973
      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
  3974
      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
  3975
    }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3976
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3977
  out->print_cr(" class: " SIZE_FORMAT " specialized(s) " SIZE_FORMAT ", "
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3978
                SIZE_FORMAT " small(s) " SIZE_FORMAT ", "
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3979
                SIZE_FORMAT " medium(s) " SIZE_FORMAT ", "
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3980
                "large count " SIZE_FORMAT,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3981
                cls_specialized_count, cls_specialized_waste,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3982
                cls_small_count, cls_small_waste,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3983
                cls_medium_count, cls_medium_waste, cls_humongous_count);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3984
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3985
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3986
// Print total fragmentation for data and class metaspaces separately
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  3987
void MetaspaceUtils::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
  3988
  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
  3989
  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
  3990
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3991
  ClassLoaderDataGraphMetaspaceIterator iter;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3992
  while (iter.repeat()) {
49401
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  3993
    ClassLoaderMetaspace* msp = iter.get_next();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3994
    if (msp != NULL) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3995
      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
  3996
      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
  3997
      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
  3998
      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
  3999
      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
  4000
      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
  4001
      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
  4002
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4003
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4004
  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
  4005
  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
  4006
                        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
  4007
                        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
  4008
                        "large count " SIZE_FORMAT,
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4009
             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
  4010
             small_waste, medium_count, medium_waste, humongous_count);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4011
  if (Metaspace::using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4012
    print_class_waste(out);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4013
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4014
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4015
49364
601146c66cad 8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents: 49348
diff changeset
  4016
class MetadataStats {
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4017
private:
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4018
  size_t _capacity;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4019
  size_t _used;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4020
  size_t _free;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4021
  size_t _waste;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4022
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4023
public:
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4024
  MetadataStats() : _capacity(0), _used(0), _free(0), _waste(0) { }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4025
  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
  4026
  : _capacity(capacity), _used(used), _free(free), _waste(waste) { }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4027
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4028
  void add(const MetadataStats& stats) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4029
    _capacity += stats.capacity();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4030
    _used += stats.used();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4031
    _free += stats.free();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4032
    _waste += stats.waste();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4033
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4034
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4035
  size_t capacity() const { return _capacity; }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4036
  size_t used() const     { return _used; }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4037
  size_t free() const     { return _free; }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4038
  size_t waste() const    { return _waste; }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4039
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4040
  void print_on(outputStream* out, size_t scale) const;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4041
};
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4042
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4043
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4044
void MetadataStats::print_on(outputStream* out, size_t scale) const {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4045
  const char* unit = scale_unit(scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4046
  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
  4047
    (float)capacity() / scale, unit,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4048
    (float)used() / scale, unit,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4049
    (float)free() / scale, unit,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4050
    (float)waste() / scale, unit);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4051
}
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4052
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4053
class PrintCLDMetaspaceInfoClosure : public CLDClosure {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4054
private:
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4055
  outputStream*  _out;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4056
  size_t         _scale;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4057
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4058
  size_t         _total_count;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4059
  MetadataStats  _total_metadata;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4060
  MetadataStats  _total_class;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4061
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4062
  size_t         _total_anon_count;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4063
  MetadataStats  _total_anon_metadata;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4064
  MetadataStats  _total_anon_class;
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
public:
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4067
  PrintCLDMetaspaceInfoClosure(outputStream* out, size_t scale = K)
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4068
  : _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
  4069
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4070
  ~PrintCLDMetaspaceInfoClosure() {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4071
    print_summary();
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
  void do_cld(ClassLoaderData* cld) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4075
    assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4076
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4077
    if (cld->is_unloading()) return;
49401
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4078
    ClassLoaderMetaspace* msp = cld->metaspace_or_null();
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4079
    if (msp == NULL) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4080
      return;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4081
    }
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
    bool anonymous = false;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4084
    if (cld->is_anonymous()) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4085
      _out->print_cr("ClassLoader: for anonymous class");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4086
      anonymous = true;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4087
    } else {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4088
      ResourceMark rm;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4089
      _out->print_cr("ClassLoader: %s", cld->loader_name());
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4090
    }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4091
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4092
    print_metaspace(msp, anonymous);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4093
    _out->cr();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4094
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4095
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4096
private:
49401
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4097
  void print_metaspace(ClassLoaderMetaspace* msp, bool anonymous);
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4098
  void print_summary() const;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4099
};
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4100
49401
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4101
void PrintCLDMetaspaceInfoClosure::print_metaspace(ClassLoaderMetaspace* msp, bool anonymous){
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4102
  assert(msp != NULL, "Sanity");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4103
  SpaceManager* vsm = msp->vsm();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4104
  const char* unit = scale_unit(_scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4105
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4106
  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
  4107
  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
  4108
  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
  4109
  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
  4110
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4111
  _total_count ++;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4112
  MetadataStats metadata_stats(capacity, used, free, waste);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4113
  _total_metadata.add(metadata_stats);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4114
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4115
  if (anonymous) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4116
    _total_anon_count ++;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4117
    _total_anon_metadata.add(metadata_stats);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4118
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4119
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4120
  _out->print("  Metadata   ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4121
  metadata_stats.print_on(_out, _scale);
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
  if (Metaspace::using_class_space()) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4124
    vsm = msp->class_vsm();
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
    capacity = vsm->sum_capacity_in_chunks_in_use() * BytesPerWord;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4127
    used = vsm->sum_used_in_chunks_in_use() * BytesPerWord;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4128
    free = vsm->sum_free_in_chunks_in_use() * BytesPerWord;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4129
    waste = vsm->sum_waste_in_chunks_in_use() * BytesPerWord;
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
    MetadataStats class_stats(capacity, used, free, waste);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4132
    _total_class.add(class_stats);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4133
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4134
    if (anonymous) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4135
      _total_anon_class.add(class_stats);
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
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4138
    _out->print("  Class data ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4139
    class_stats.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4140
  }
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
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4143
void PrintCLDMetaspaceInfoClosure::print_summary() const {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4144
  const char* unit = scale_unit(_scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4145
  _out->cr();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4146
  _out->print_cr("Summary:");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4147
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4148
  MetadataStats total;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4149
  total.add(_total_metadata);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4150
  total.add(_total_class);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4151
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4152
  _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
  4153
  total.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4154
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4155
  _out->print("                    Metadata ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4156
  _total_metadata.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4157
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4158
  if (Metaspace::using_class_space()) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4159
    _out->print("                  Class data ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4160
    _total_class.print_on(_out, _scale);
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
  _out->cr();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4163
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4164
  MetadataStats total_anon;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4165
  total_anon.add(_total_anon_metadata);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4166
  total_anon.add(_total_anon_class);
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
  _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
  4169
  total_anon.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4170
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4171
  _out->print("                    Metadata ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4172
  _total_anon_metadata.print_on(_out, _scale);
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
  if (Metaspace::using_class_space()) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4175
    _out->print("                  Class data ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4176
    _total_anon_class.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4177
  }
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
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  4180
void MetaspaceUtils::print_metadata_for_nmt(outputStream* out, size_t scale) {
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4181
  const char* unit = scale_unit(scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4182
  out->print_cr("Metaspaces:");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4183
  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
  4184
    reserved_bytes(Metaspace::NonClassType) / scale, unit,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4185
    committed_bytes(Metaspace::NonClassType) / scale, unit);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4186
  if (Metaspace::using_class_space()) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4187
    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
  4188
    reserved_bytes(Metaspace::ClassType) / scale, unit,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4189
    committed_bytes(Metaspace::ClassType) / scale, unit);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4190
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4191
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4192
  out->cr();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4193
  ChunkManager::print_all_chunkmanagers(out, scale);
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
  out->cr();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4196
  out->print_cr("Per-classloader metadata:");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4197
  out->cr();
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
  PrintCLDMetaspaceInfoClosure cl(out, scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4200
  ClassLoaderDataGraph::cld_do(&cl);
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
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  4203
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4204
// Dump global metaspace things from the end of ClassLoaderDataGraph
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  4205
void MetaspaceUtils::dump(outputStream* out) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4206
  out->print_cr("All Metaspace:");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4207
  out->print("data space: "); print_on(out, Metaspace::NonClassType);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4208
  out->print("class space: "); print_on(out, Metaspace::ClassType);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4209
  print_waste(out);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4210
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4211
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4212
// Prints an ASCII representation of the given space.
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  4213
void MetaspaceUtils::print_metaspace_map(outputStream* out, Metaspace::MetadataType mdtype) {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  4214
  MutexLockerEx cl(MetaspaceExpand_lock, Mutex::_no_safepoint_check_flag);
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4215
  const bool for_class = mdtype == Metaspace::ClassType ? true : false;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4216
  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
  4217
  if (vsl != NULL) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4218
    if (for_class) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4219
      if (!Metaspace::using_class_space()) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4220
        out->print_cr("No Class Space.");
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4221
        return;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4222
      }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4223
      out->print_raw("---- Metaspace Map (Class Space) ----");
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4224
    } else {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4225
      out->print_raw("---- Metaspace Map (Non-Class Space) ----");
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4226
    }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4227
    // Print legend:
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4228
    out->cr();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4229
    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
  4230
    out->cr();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4231
    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
  4232
    vsl->print_map(out);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4233
    out->cr();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4234
  }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4235
}
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4236
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  4237
void MetaspaceUtils::verify_free_chunks() {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4238
  Metaspace::chunk_manager_metadata()->verify();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4239
  if (Metaspace::using_class_space()) {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4240
    Metaspace::chunk_manager_class()->verify();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4241
  }
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  4242
}
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  4243
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  4244
void MetaspaceUtils::verify_capacity() {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4245
#ifdef ASSERT
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  4246
  size_t running_sum_capacity_bytes = capacity_bytes();
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4247
  // 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
  4248
  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
  4249
  assert(running_sum_capacity_bytes == capacity_in_use_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4250
         "capacity_words() * BytesPerWord " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4251
         " capacity_bytes_slow()" SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4252
         running_sum_capacity_bytes, capacity_in_use_bytes);
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4253
  for (Metaspace::MetadataType i = Metaspace::ClassType;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4254
       i < Metaspace:: MetadataTypeCount;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4255
       i = (Metaspace::MetadataType)(i + 1)) {
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4256
    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
  4257
    assert(capacity_bytes(i) == capacity_in_use_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4258
           "capacity_bytes(%u) " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4259
           " capacity_bytes_slow(%u)" SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4260
           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
  4261
  }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4262
#endif
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4263
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4264
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  4265
void MetaspaceUtils::verify_used() {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4266
#ifdef ASSERT
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  4267
  size_t running_sum_used_bytes = used_bytes();
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4268
  // 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
  4269
  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
  4270
  assert(used_bytes() == used_in_use_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4271
         "used_bytes() " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4272
         " used_bytes_slow()" SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4273
         used_bytes(), used_in_use_bytes);
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4274
  for (Metaspace::MetadataType i = Metaspace::ClassType;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4275
       i < Metaspace:: MetadataTypeCount;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4276
       i = (Metaspace::MetadataType)(i + 1)) {
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  4277
    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
  4278
    assert(used_bytes(i) == used_in_use_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4279
           "used_bytes(%u) " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4280
           " used_bytes_slow(%u)" SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4281
           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
  4282
  }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4283
#endif
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4284
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4285
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  4286
void MetaspaceUtils::verify_metrics() {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4287
  verify_capacity();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4288
  verify_used();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4289
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4290
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  4291
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4292
// Metaspace methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4293
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4294
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
  4295
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
  4296
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4297
size_t Metaspace::_commit_alignment = 0;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4298
size_t Metaspace::_reserve_alignment = 0;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4299
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4300
VirtualSpaceList* Metaspace::_space_list = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4301
VirtualSpaceList* Metaspace::_class_space_list = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4302
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4303
ChunkManager* Metaspace::_chunk_manager_metadata = NULL;
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4304
ChunkManager* Metaspace::_chunk_manager_class = NULL;
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4305
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4306
#define VIRTUALSPACEMULTIPLIER 2
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4307
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4308
#ifdef _LP64
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4309
static const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1);
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4310
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4311
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
  4312
  assert(!DumpSharedSpaces, "narrow_klass is set by MetaspaceShared class.");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4313
  // 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
  4314
  // 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
  4315
  // (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
  4316
  // between the lower base and higher address.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4317
  address lower_base;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4318
  address higher_address;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4319
#if INCLUDE_CDS
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4320
  if (UseSharedSpaces) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4321
    higher_address = MAX2((address)(cds_base + MetaspaceShared::core_spaces_size()),
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4322
                          (address)(metaspace_base + compressed_class_space_size()));
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4323
    lower_base = MIN2(metaspace_base, cds_base);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4324
  } else
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4325
#endif
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4326
  {
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4327
    higher_address = metaspace_base + compressed_class_space_size();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4328
    lower_base = metaspace_base;
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4329
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4330
    uint64_t klass_encoding_max = UnscaledClassSpaceMax << LogKlassAlignmentInBytes;
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4331
    // 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
  4332
    if (higher_address <= (address)klass_encoding_max) {
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22499
diff changeset
  4333
      lower_base = 0; // Effectively lower base is zero.
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4334
    }
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4335
  }
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4336
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4337
  Universe::set_narrow_klass_base(lower_base);
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4338
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4339
  // 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
  4340
  // 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
  4341
  // 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
  4342
  // 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
  4343
  // 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
  4344
  // 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
  4345
  if (!UseSharedSpaces
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4346
      && (uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4347
    Universe::set_narrow_klass_shift(0);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4348
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4349
    Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4350
  }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 42621
diff changeset
  4351
  AOTLoader::set_narrow_klass_shift();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4352
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4353
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4354
#if INCLUDE_CDS
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4355
// 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
  4356
// to work with compressed klass pointers.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4357
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
  4358
  assert(cds_base != 0 && UseSharedSpaces, "Only use with CDS");
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  4359
  assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4360
  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
  4361
  address higher_address = MAX2((address)(cds_base + MetaspaceShared::core_spaces_size()),
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4362
                                (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
  4363
  return ((uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4364
}
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4365
#endif
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4366
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4367
// Try to allocate the metaspace at the requested addr.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4368
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
  4369
  assert(!DumpSharedSpaces, "compress klass space is allocated by MetaspaceShared class.");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4370
  assert(using_class_space(), "called improperly");
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  4371
  assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4372
  assert(compressed_class_space_size() < KlassEncodingMetaspaceMax,
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4373
         "Metaspace size is too big");
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4374
  assert_is_aligned(requested_addr, _reserve_alignment);
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4375
  assert_is_aligned(cds_base, _reserve_alignment);
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4376
  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
  4377
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4378
  // 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
  4379
  bool large_pages = false;
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4380
39229
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4381
#if !(defined(AARCH64) || defined(AIX))
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4382
  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
  4383
                                             _reserve_alignment,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4384
                                             large_pages,
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28163
diff changeset
  4385
                                             requested_addr);
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4386
#else // AARCH64
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4387
  ReservedSpace metaspace_rs;
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4388
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4389
  // Our compressed klass pointers may fit nicely into the lower 32
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4390
  // bits.
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4391
  if ((uint64_t)requested_addr + compressed_class_space_size() < 4*G) {
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4392
    metaspace_rs = ReservedSpace(compressed_class_space_size(),
39229
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4393
                                 _reserve_alignment,
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4394
                                 large_pages,
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4395
                                 requested_addr);
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4396
  }
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4397
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4398
  if (! metaspace_rs.is_reserved()) {
39229
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4399
    // 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
  4400
    // 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
  4401
    // 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
  4402
    // 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
  4403
    // the base, 4G alignment is helpful, too.
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4404
    size_t increment = AARCH64_ONLY(4*)G;
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4405
    for (char *a = align_up(requested_addr, increment);
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4406
         a < (char*)(1024*G);
39229
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4407
         a += increment) {
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4408
      if (a == (char *)(32*G)) {
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4409
        // 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
  4410
        increment = 4*G;
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  4411
      }
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4412
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4413
#if INCLUDE_CDS
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4414
      if (UseSharedSpaces
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4415
          && ! can_use_cds_with_metaspace_addr(a, cds_base)) {
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4416
        // We failed to find an aligned base that will reach.  Fall
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4417
        // back to using our requested addr.
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4418
        metaspace_rs = ReservedSpace(compressed_class_space_size(),
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4419
                                     _reserve_alignment,
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4420
                                     large_pages,
29187
b3e445e08548 8071563: AARCH64 staging fail to build
enevill
parents: 29185
diff changeset
  4421
                                     requested_addr);
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4422
        break;
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4423
      }
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4424
#endif
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4425
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4426
      metaspace_rs = ReservedSpace(compressed_class_space_size(),
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4427
                                   _reserve_alignment,
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4428
                                   large_pages,
29187
b3e445e08548 8071563: AARCH64 staging fail to build
enevill
parents: 29185
diff changeset
  4429
                                   a);
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4430
      if (metaspace_rs.is_reserved())
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4431
        break;
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4432
    }
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4433
  }
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4434
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4435
#endif // AARCH64
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  4436
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4437
  if (!metaspace_rs.is_reserved()) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4438
#if INCLUDE_CDS
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4439
    if (UseSharedSpaces) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4440
      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
  4441
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4442
      // Keep trying to allocate the metaspace, increasing the requested_addr
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4443
      // 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
  4444
      // use of CDS with compressed klass pointers.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4445
      char *addr = requested_addr;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4446
      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
  4447
             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
  4448
        addr = addr + increment;
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4449
        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
  4450
                                     _reserve_alignment, large_pages, addr);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4451
      }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4452
    }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4453
#endif
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4454
    // 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
  4455
    // 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
  4456
    // metaspace as if UseCompressedClassPointers is off because too much
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  4457
    // initialization has happened that depends on UseCompressedClassPointers.
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  4458
    // So, UseCompressedClassPointers cannot be turned off at this point.
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4459
    if (!metaspace_rs.is_reserved()) {
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  4460
      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
  4461
                                   _reserve_alignment, large_pages);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4462
      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
  4463
        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
  4464
                                              compressed_class_space_size()));
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4465
      }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4466
    }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4467
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4468
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4469
  // If we got here then the metaspace got allocated.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4470
  MemTracker::record_virtual_memory_type((address)metaspace_rs.base(), mtClass);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4471
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4472
#if INCLUDE_CDS
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4473
  // Verify that we can use shared spaces.  Otherwise, turn off CDS.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4474
  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
  4475
    FileMapInfo::stop_sharing_and_unmap(
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4476
        "Could not allocate metaspace at a compatible address");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4477
  }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  4478
#endif
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4479
  set_narrow_klass_base_and_shift((address)metaspace_rs.base(),
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4480
                                  UseSharedSpaces ? (address)cds_base : 0);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4481
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4482
  initialize_class_space(metaspace_rs);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4483
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  4484
  LogTarget(Trace, gc, metaspace) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  4485
  if (lt.is_enabled()) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  4486
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  4487
    LogStream ls(lt);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  4488
    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
  4489
  }
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4490
}
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4491
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4492
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
  4493
  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
  4494
               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
  4495
  if (_class_space_list != NULL) {
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4496
    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
  4497
    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
  4498
                 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
  4499
    if (requested_addr != 0) {
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4500
      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
  4501
    }
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  4502
    st->cr();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4503
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4504
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4505
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  4506
// 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
  4507
// 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
  4508
void Metaspace::initialize_class_space(ReservedSpace rs) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4509
  // 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
  4510
  assert(rs.size() >= CompressedClassSpaceSize,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4511
         SIZE_FORMAT " != " SIZE_FORMAT, rs.size(), CompressedClassSpaceSize);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4512
  assert(using_class_space(), "Must be using class space");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4513
  _class_space_list = new VirtualSpaceList(rs);
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4514
  _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
  4515
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4516
  if (!_class_space_list->initialization_succeeded()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4517
    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
  4518
  }
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4519
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4520
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4521
#endif
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4522
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4523
void Metaspace::ergo_initialize() {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4524
  if (DumpSharedSpaces) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4525
    // 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
  4526
    FLAG_SET_ERGO(bool, UseLargePagesInMetaspace, false);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4527
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4528
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4529
  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
  4530
  if (UseLargePages && UseLargePagesInMetaspace) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4531
    page_size = os::large_page_size();
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4532
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4533
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4534
  _commit_alignment  = page_size;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4535
  _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
  4536
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4537
  // 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
  4538
  // 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
  4539
  // 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
  4540
  // java.lang.management.MemoryUsage API.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4541
  //
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4542
  // 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
  4543
  // 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
  4544
  // alignment depends on other flags being parsed.
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4545
  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
  4546
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4547
  if (MetaspaceSize > MaxMetaspaceSize) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4548
    MetaspaceSize = MaxMetaspaceSize;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4549
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4550
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4551
  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
  4552
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4553
  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
  4554
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4555
  MinMetaspaceExpansion = align_down_bounded(MinMetaspaceExpansion, _commit_alignment);
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4556
  MaxMetaspaceExpansion = align_down_bounded(MaxMetaspaceExpansion, _commit_alignment);
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4557
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4558
  CompressedClassSpaceSize = align_down_bounded(CompressedClassSpaceSize, _reserve_alignment);
47654
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4559
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4560
  // 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
  4561
  size_t min_metaspace_sz =
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4562
      VIRTUALSPACEMULTIPLIER * InitialBootClassLoaderMetaspaceSize;
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4563
  if (UseCompressedClassPointers) {
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4564
    if ((min_metaspace_sz + CompressedClassSpaceSize) >  MaxMetaspaceSize) {
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4565
      if (min_metaspace_sz >= MaxMetaspaceSize) {
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4566
        vm_exit_during_initialization("MaxMetaspaceSize is too small.");
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4567
      } else {
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4568
        FLAG_SET_ERGO(size_t, CompressedClassSpaceSize,
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4569
                      MaxMetaspaceSize - min_metaspace_sz);
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4570
      }
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4571
    }
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4572
  } else if (min_metaspace_sz >= MaxMetaspaceSize) {
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4573
    FLAG_SET_ERGO(size_t, InitialBootClassLoaderMetaspaceSize,
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4574
                  min_metaspace_sz);
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4575
  }
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  4576
48387
7daebcef2e0d 8193386: CompressedClassSize too large with MaxMetaspace
coleenp
parents: 48148
diff changeset
  4577
  set_compressed_class_space_size(CompressedClassSpaceSize);
20406
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
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4580
void Metaspace::global_initialize() {
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  4581
  MetaspaceGC::initialize();
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  4582
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4583
#if INCLUDE_CDS
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4584
  if (DumpSharedSpaces) {
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4585
    MetaspaceShared::initialize_dumptime_shared_and_meta_spaces();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4586
  } else if (UseSharedSpaces) {
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4587
    // 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
  4588
    // 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
  4589
    // (!DumpSharedSpaces && !UseSharedSpaces) case to set up class
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4590
    // metaspace.
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4591
    MetaspaceShared::initialize_runtime_shared_and_meta_spaces();
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4592
  }
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4593
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4594
  if (!DumpSharedSpaces && !UseSharedSpaces)
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4595
#endif // INCLUDE_CDS
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4596
  {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4597
#ifdef _LP64
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4598
    if (using_class_space()) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4599
      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
  4600
      allocate_metaspace_compressed_klass_ptrs(base, 0);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4601
    }
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  4602
#endif // _LP64
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4603
  }
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4604
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4605
  // Initialize these before initializing the VirtualSpaceList
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4606
  _first_chunk_word_size = InitialBootClassLoaderMetaspaceSize / BytesPerWord;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4607
  _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
  4608
  // 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
  4609
  // 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
  4610
  // from there.  This size calculated by -version.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4611
  _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
  4612
                                     (CompressedClassSpaceSize/BytesPerWord)*2);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4613
  _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
  4614
  // Arbitrarily set the initial virtual space to a multiple
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4615
  // of the boot class loader size.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4616
  size_t word_size = VIRTUALSPACEMULTIPLIER * _first_chunk_word_size;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4617
  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
  4618
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4619
  // Initialize the list of virtual spaces.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4620
  _space_list = new VirtualSpaceList(word_size);
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4621
  _chunk_manager_metadata = new ChunkManager(false/*metaspace*/);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4622
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4623
  if (!_space_list->initialization_succeeded()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4624
    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
  4625
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4626
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  4627
  _tracer = new MetaspaceTracer();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4628
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4629
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  4630
void Metaspace::post_initialize() {
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  4631
  MetaspaceGC::post_initialize();
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  4632
}
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  4633
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4634
void Metaspace::verify_global_initialization() {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4635
  assert(space_list() != NULL, "Metadata VirtualSpaceList has not been initialized");
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4636
  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
  4637
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4638
  if (using_class_space()) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4639
    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
  4640
    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
  4641
  }
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4642
}
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4643
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4644
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
  4645
  size_t byte_size = word_size * wordSize;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4646
  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
  4647
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  4648
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  4649
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
  4650
                              MetaspaceObj::Type type, TRAPS) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  4651
  assert(!_frozen, "sanity");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4652
  if (HAS_PENDING_EXCEPTION) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4653
    assert(false, "Should not allocate with exception pending");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4654
    return NULL;  // caller does a CHECK_NULL too
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4655
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4656
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4657
  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
  4658
        "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
  4659
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4660
  MetadataType mdtype = (type == MetaspaceObj::ClassType) ? ClassType : NonClassType;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4661
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4662
  // Try to allocate metadata.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4663
  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
  4664
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4665
  if (result == NULL) {
49372
3bb8b00832d0 8196626: [Graal] runtime/appcds/UseAppCDS.java crashes with "VM thread using lock Heap_lock (not allowed to block on)"
ccheung
parents: 49366
diff changeset
  4666
    if (DumpSharedSpaces && THREAD->is_VM_thread()) {
3bb8b00832d0 8196626: [Graal] runtime/appcds/UseAppCDS.java crashes with "VM thread using lock Heap_lock (not allowed to block on)"
ccheung
parents: 49366
diff changeset
  4667
      tty->print_cr("Failed allocating metaspace object type %s of size " SIZE_FORMAT ". CDS dump aborted.",
3bb8b00832d0 8196626: [Graal] runtime/appcds/UseAppCDS.java crashes with "VM thread using lock Heap_lock (not allowed to block on)"
ccheung
parents: 49366
diff changeset
  4668
          MetaspaceObj::type_name(type), word_size * BytesPerWord);
3bb8b00832d0 8196626: [Graal] runtime/appcds/UseAppCDS.java crashes with "VM thread using lock Heap_lock (not allowed to block on)"
ccheung
parents: 49366
diff changeset
  4669
      vm_exit(1);
3bb8b00832d0 8196626: [Graal] runtime/appcds/UseAppCDS.java crashes with "VM thread using lock Heap_lock (not allowed to block on)"
ccheung
parents: 49366
diff changeset
  4670
    }
3bb8b00832d0 8196626: [Graal] runtime/appcds/UseAppCDS.java crashes with "VM thread using lock Heap_lock (not allowed to block on)"
ccheung
parents: 49366
diff changeset
  4671
23468
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4672
    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
  4673
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4674
    // Allocation failed.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4675
    if (is_init_completed()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4676
      // 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
  4677
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4678
      // Try to clean out some memory and retry.
49045
9b556b613a07 8198509: Move satisfy_failed_metadata_allocation out from CollectorPolicy
stefank
parents: 48971
diff changeset
  4679
      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
  4680
    }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4681
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4682
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4683
  if (result == NULL) {
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4684
    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
  4685
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4686
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  4687
  // 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
  4688
  Copy::fill_to_words((HeapWord*)result, word_size, 0);
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  4689
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  4690
  return result;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4691
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4692
23469
0a4d02776968 8036701: Add trace event when a metaspace throws out of memory error
ehelin
parents: 23468
diff changeset
  4693
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
  4694
  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
  4695
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4696
  // If result is still null, we are out of memory.
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37151
diff changeset
  4697
  Log(gc, metaspace, freelist) log;
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  4698
  if (log.is_info()) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  4699
    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
  4700
             is_class_space_allocation(mdtype) ? "class" : "data", word_size);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  4701
    ResourceMark rm;
46723
5c418c5fcade 8185262: Keep default logging for Metaspace OOM short and concise
stuefe
parents: 46709
diff changeset
  4702
    if (log.is_debug()) {
5c418c5fcade 8185262: Keep default logging for Metaspace OOM short and concise
stuefe
parents: 46709
diff changeset
  4703
      if (loader_data->metaspace_or_null() != NULL) {
5c418c5fcade 8185262: Keep default logging for Metaspace OOM short and concise
stuefe
parents: 46709
diff changeset
  4704
        LogStream ls(log.debug());
49348
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49045
diff changeset
  4705
        loader_data->print_value_on(&ls);
46723
5c418c5fcade 8185262: Keep default logging for Metaspace OOM short and concise
stuefe
parents: 46709
diff changeset
  4706
      }
5c418c5fcade 8185262: Keep default logging for Metaspace OOM short and concise
stuefe
parents: 46709
diff changeset
  4707
    }
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  4708
    LogStream ls(log.info());
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  4709
    MetaspaceUtils::dump(&ls);
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  4710
    MetaspaceUtils::print_metaspace_map(&ls, mdtype);
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  4711
    ChunkManager::print_all_chunkmanagers(&ls);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4712
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4713
21186
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4714
  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
  4715
  if (is_class_space_allocation(mdtype)) {
49401
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4716
    ClassLoaderMetaspace* metaspace = loader_data->metaspace_non_null();
21186
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4717
    out_of_compressed_class_space =
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  4718
      MetaspaceUtils::committed_bytes(Metaspace::ClassType) +
21186
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4719
      (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
  4720
      CompressedClassSpaceSize;
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4721
  }
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4722
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4723
  // -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
  4724
  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
  4725
    "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
  4726
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4727
  report_java_out_of_memory(space_string);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4728
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4729
  if (JvmtiExport::should_post_resource_exhausted()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4730
    JvmtiExport::post_resource_exhausted(
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4731
        JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4732
        space_string);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4733
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4734
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4735
  if (!is_init_completed()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4736
    vm_exit_during_initialization("OutOfMemoryError", space_string);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4737
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4738
21186
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4739
  if (out_of_compressed_class_space) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4740
    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
  4741
  } else {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4742
    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
  4743
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4744
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4745
23468
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4746
const char* Metaspace::metadata_type_name(Metaspace::MetadataType mdtype) {
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4747
  switch (mdtype) {
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4748
    case Metaspace::ClassType: return "Class";
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4749
    case Metaspace::NonClassType: return "Metadata";
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4750
    default:
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4751
      assert(false, "Got bad mdtype: %d", (int) mdtype);
23468
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4752
      return NULL;
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4753
  }
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4754
}
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4755
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4756
void Metaspace::purge(MetadataType mdtype) {
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4757
  get_space_list(mdtype)->purge(get_chunk_manager(mdtype));
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4758
}
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4759
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  4760
void Metaspace::purge() {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  4761
  MutexLockerEx cl(MetaspaceExpand_lock,
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  4762
                   Mutex::_no_safepoint_check_flag);
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4763
  purge(NonClassType);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4764
  if (using_class_space()) {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4765
    purge(ClassType);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4766
  }
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  4767
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  4768
22201
9c2ccfa3a5fe 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 21569
diff changeset
  4769
bool Metaspace::contains(const void* ptr) {
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48387
diff changeset
  4770
  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
  4771
    return true;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4772
  }
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 42650
diff changeset
  4773
  return contains_non_shared(ptr);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 42650
diff changeset
  4774
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 42650
diff changeset
  4775
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 42650
diff changeset
  4776
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
  4777
  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
  4778
     return true;
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  4779
  }
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  4780
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  4781
  return get_space_list(NonClassType)->contains(ptr);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4782
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4783
49401
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4784
// ClassLoaderMetaspace
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4785
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4786
ClassLoaderMetaspace::ClassLoaderMetaspace(Mutex* lock, Metaspace::MetaspaceType type) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4787
  initialize(lock, type);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4788
}
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4789
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4790
ClassLoaderMetaspace::~ClassLoaderMetaspace() {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4791
  delete _vsm;
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4792
  if (Metaspace::using_class_space()) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4793
    delete _class_vsm;
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4794
  }
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4795
}
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4796
void ClassLoaderMetaspace::initialize_first_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4797
  Metachunk* chunk = get_initialization_chunk(type, mdtype);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4798
  if (chunk != NULL) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4799
    // Add to this manager's list of chunks in use and current_chunk().
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4800
    get_space_manager(mdtype)->add_chunk(chunk, true);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4801
  }
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4802
}
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4803
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4804
Metachunk* ClassLoaderMetaspace::get_initialization_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4805
  size_t chunk_word_size = get_space_manager(mdtype)->get_initial_chunk_size(type);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4806
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4807
  // Get a chunk from the chunk freelist
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4808
  Metachunk* chunk = Metaspace::get_chunk_manager(mdtype)->chunk_freelist_allocate(chunk_word_size);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4809
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4810
  if (chunk == NULL) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4811
    chunk = Metaspace::get_space_list(mdtype)->get_new_chunk(chunk_word_size,
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4812
                                                  get_space_manager(mdtype)->medium_chunk_bunch());
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4813
  }
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4814
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4815
  return chunk;
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4816
}
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4817
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4818
void ClassLoaderMetaspace::initialize(Mutex* lock, Metaspace::MetaspaceType type) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4819
  Metaspace::verify_global_initialization();
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4820
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4821
  // Allocate SpaceManager for metadata objects.
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4822
  _vsm = new SpaceManager(Metaspace::NonClassType, type, lock);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4823
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4824
  if (Metaspace::using_class_space()) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4825
    // Allocate SpaceManager for classes.
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4826
    _class_vsm = new SpaceManager(Metaspace::ClassType, type, lock);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4827
  }
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4828
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  4829
  MutexLockerEx cl(MetaspaceExpand_lock, Mutex::_no_safepoint_check_flag);
49401
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4830
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4831
  // Allocate chunk for metadata objects
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4832
  initialize_first_chunk(type, Metaspace::NonClassType);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4833
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4834
  // Allocate chunk for class metadata objects
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4835
  if (Metaspace::using_class_space()) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4836
    initialize_first_chunk(type, Metaspace::ClassType);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4837
  }
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4838
}
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4839
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4840
MetaWord* ClassLoaderMetaspace::allocate(size_t word_size, Metaspace::MetadataType mdtype) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4841
  Metaspace::assert_not_frozen();
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4842
  // Don't use class_vsm() unless UseCompressedClassPointers is true.
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4843
  if (Metaspace::is_class_space_allocation(mdtype)) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4844
    return  class_vsm()->allocate(word_size);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4845
  } else {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4846
    return  vsm()->allocate(word_size);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4847
  }
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4848
}
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4849
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4850
MetaWord* ClassLoaderMetaspace::expand_and_allocate(size_t word_size, Metaspace::MetadataType mdtype) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4851
  Metaspace::assert_not_frozen();
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4852
  size_t delta_bytes = MetaspaceGC::delta_capacity_until_GC(word_size * BytesPerWord);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4853
  assert(delta_bytes > 0, "Must be");
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4854
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4855
  size_t before = 0;
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4856
  size_t after = 0;
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4857
  MetaWord* res;
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4858
  bool incremented;
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4859
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4860
  // Each thread increments the HWM at most once. Even if the thread fails to increment
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4861
  // the HWM, an allocation is still attempted. This is because another thread must then
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4862
  // have incremented the HWM and therefore the allocation might still succeed.
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4863
  do {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4864
    incremented = MetaspaceGC::inc_capacity_until_GC(delta_bytes, &after, &before);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4865
    res = allocate(word_size, mdtype);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4866
  } while (!incremented && res == NULL);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4867
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4868
  if (incremented) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4869
    Metaspace::tracer()->report_gc_threshold(before, after,
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4870
                                  MetaspaceGCThresholdUpdater::ExpandAndAllocate);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4871
    log_trace(gc, metaspace)("Increase capacity to GC from " SIZE_FORMAT " to " SIZE_FORMAT, before, after);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4872
  }
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4873
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4874
  return res;
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4875
}
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4876
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4877
size_t ClassLoaderMetaspace::used_words_slow(Metaspace::MetadataType mdtype) const {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4878
  if (mdtype == Metaspace::ClassType) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4879
    return Metaspace::using_class_space() ? class_vsm()->sum_used_in_chunks_in_use() : 0;
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4880
  } else {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4881
    return vsm()->sum_used_in_chunks_in_use();  // includes overhead!
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4882
  }
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4883
}
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4884
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4885
size_t ClassLoaderMetaspace::free_words_slow(Metaspace::MetadataType mdtype) const {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4886
  Metaspace::assert_not_frozen();
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4887
  if (mdtype == Metaspace::ClassType) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4888
    return Metaspace::using_class_space() ? class_vsm()->sum_free_in_chunks_in_use() : 0;
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4889
  } else {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4890
    return vsm()->sum_free_in_chunks_in_use();
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4891
  }
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4892
}
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4893
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4894
// Space capacity in the Metaspace.  It includes
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4895
// space in the list of chunks from which allocations
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4896
// have been made. Don't include space in the global freelist and
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4897
// in the space available in the dictionary which
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4898
// is already counted in some chunk.
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4899
size_t ClassLoaderMetaspace::capacity_words_slow(Metaspace::MetadataType mdtype) const {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4900
  if (mdtype == Metaspace::ClassType) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4901
    return Metaspace::using_class_space() ? class_vsm()->sum_capacity_in_chunks_in_use() : 0;
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4902
  } else {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4903
    return vsm()->sum_capacity_in_chunks_in_use();
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4904
  }
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4905
}
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4906
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4907
size_t ClassLoaderMetaspace::used_bytes_slow(Metaspace::MetadataType mdtype) const {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4908
  return used_words_slow(mdtype) * BytesPerWord;
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4909
}
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4910
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4911
size_t ClassLoaderMetaspace::capacity_bytes_slow(Metaspace::MetadataType mdtype) const {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4912
  return capacity_words_slow(mdtype) * BytesPerWord;
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4913
}
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4914
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4915
size_t ClassLoaderMetaspace::allocated_blocks_bytes() const {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4916
  return vsm()->allocated_blocks_bytes() +
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4917
      (Metaspace::using_class_space() ? class_vsm()->allocated_blocks_bytes() : 0);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4918
}
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4919
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4920
size_t ClassLoaderMetaspace::allocated_chunks_bytes() const {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4921
  return vsm()->allocated_chunks_bytes() +
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4922
      (Metaspace::using_class_space() ? class_vsm()->allocated_chunks_bytes() : 0);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4923
}
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4924
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4925
void ClassLoaderMetaspace::deallocate(MetaWord* ptr, size_t word_size, bool is_class) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4926
  Metaspace::assert_not_frozen();
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4927
  assert(!SafepointSynchronize::is_at_safepoint()
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4928
         || Thread::current()->is_VM_thread(), "should be the VM thread");
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4929
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4930
  MutexLockerEx ml(vsm()->lock(), Mutex::_no_safepoint_check_flag);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4931
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4932
  if (is_class && Metaspace::using_class_space()) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4933
    class_vsm()->deallocate(ptr, word_size);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4934
  } else {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4935
    vsm()->deallocate(ptr, word_size);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4936
  }
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4937
}
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4938
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4939
size_t ClassLoaderMetaspace::class_chunk_size(size_t word_size) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4940
  assert(Metaspace::using_class_space(), "Has to use class space");
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4941
  return class_vsm()->calc_chunk_size(word_size);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4942
}
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4943
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4944
void ClassLoaderMetaspace::print_on(outputStream* out) const {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4945
  // Print both class virtual space counts and metaspace.
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4946
  if (Verbose) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4947
    vsm()->print_on(out);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4948
    if (Metaspace::using_class_space()) {
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4949
      class_vsm()->print_on(out);
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4950
    }
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4951
  }
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4952
}
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4953
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4954
void ClassLoaderMetaspace::verify() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4955
  vsm()->verify();
49401
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4956
  if (Metaspace::using_class_space()) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4957
    class_vsm()->verify();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4958
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4959
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4960
49401
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4961
void ClassLoaderMetaspace::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
  4962
  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
  4963
  vsm()->dump(out);
49401
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4964
  if (Metaspace::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
  4965
    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
  4966
    class_vsm()->dump(out);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4967
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4968
}
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4969
49401
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4970
0c71baee49a7 8199431: Split up class Metaspace into a static and a non-static part
stuefe
parents: 49395
diff changeset
  4971
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4972
#ifdef ASSERT
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4973
static void do_verify_chunk(Metachunk* chunk) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4974
  guarantee(chunk != NULL, "Sanity");
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4975
  // Verify chunk itself; then verify that it is consistent with the
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4976
  // occupany map of its containing node.
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4977
  chunk->verify();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4978
  VirtualSpaceNode* const vsn = chunk->container();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4979
  OccupancyMap* const ocmap = vsn->occupancy_map();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4980
  ocmap->verify_for_chunk(chunk);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4981
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4982
#endif
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4983
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4984
static void do_update_in_use_info_for_chunk(Metachunk* chunk, bool inuse) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4985
  chunk->set_is_tagged_free(!inuse);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4986
  OccupancyMap* const ocmap = chunk->container()->occupancy_map();
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4987
  ocmap->set_region_in_use((MetaWord*)chunk, chunk->word_size(), inuse);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4988
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  4989
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4990
/////////////// Unit tests ///////////////
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4991
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4992
#ifndef PRODUCT
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4993
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  4994
class TestMetaspaceUtilsTest : AllStatic {
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4995
 public:
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4996
  static void test_reserved() {
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  4997
    size_t reserved = MetaspaceUtils::reserved_bytes();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4998
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4999
    assert(reserved > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5000
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  5001
    size_t committed  = MetaspaceUtils::committed_bytes();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5002
    assert(committed <= reserved, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5003
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  5004
    size_t reserved_metadata = MetaspaceUtils::reserved_bytes(Metaspace::NonClassType);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5005
    assert(reserved_metadata > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5006
    assert(reserved_metadata <= reserved, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5007
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5008
    if (UseCompressedClassPointers) {
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  5009
      size_t reserved_class    = MetaspaceUtils::reserved_bytes(Metaspace::ClassType);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5010
      assert(reserved_class > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5011
      assert(reserved_class < reserved, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5012
    }
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
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5015
  static void test_committed() {
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  5016
    size_t committed = MetaspaceUtils::committed_bytes();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5017
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5018
    assert(committed > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5019
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  5020
    size_t reserved  = MetaspaceUtils::reserved_bytes();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5021
    assert(committed <= reserved, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5022
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  5023
    size_t committed_metadata = MetaspaceUtils::committed_bytes(Metaspace::NonClassType);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5024
    assert(committed_metadata > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5025
    assert(committed_metadata <= committed, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5026
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5027
    if (UseCompressedClassPointers) {
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  5028
      size_t committed_class    = MetaspaceUtils::committed_bytes(Metaspace::ClassType);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5029
      assert(committed_class > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5030
      assert(committed_class < committed, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5031
    }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5032
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5033
20084
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5034
  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
  5035
    VirtualSpaceList* vs_list = new VirtualSpaceList(os::vm_allocation_granularity());
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  5036
    MutexLockerEx cl(MetaspaceExpand_lock, Mutex::_no_safepoint_check_flag);
20084
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5037
    // 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
  5038
    // vm_allocation_granularity aligned on Windows.
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5039
    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
  5040
    large_size += (os::vm_page_size()/BytesPerWord);
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5041
    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
  5042
  }
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5043
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5044
  static void test() {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5045
    test_reserved();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5046
    test_committed();
20084
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  5047
    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
  5048
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5049
};
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  5050
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  5051
void TestMetaspaceUtils_test() {
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49386
diff changeset
  5052
  TestMetaspaceUtilsTest::test();
19989
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
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5055
class TestVirtualSpaceNodeTest {
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5056
  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
  5057
                                          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
  5058
                                          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
  5059
    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
  5060
    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
  5061
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5062
    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
  5063
    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
  5064
    // 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
  5065
    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
  5066
    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
  5067
  }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5068
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5069
 public:
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5070
  static void test() {
49601
bfc70d5d291a 8198760: Move global lock SpaceManager::_expand_lock to MutexLocker.cpp
coleenp
parents: 49594
diff changeset
  5071
    MutexLockerEx ml(MetaspaceExpand_lock, Mutex::_no_safepoint_check_flag);
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5072
    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
  5073
    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
  5074
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5075
    // 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
  5076
    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
  5077
    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
  5078
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5079
    { // No committed memory in VSN
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5080
      ChunkManager cm(false);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5081
      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
  5082
      vsn.initialize();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5083
      vsn.retire(&cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5084
      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
  5085
    }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5086
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5087
    { // All of VSN is committed, half is used by chunks
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5088
      ChunkManager cm(false);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5089
      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
  5090
      vsn.initialize();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5091
      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
  5092
      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
  5093
      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
  5094
      vsn.retire(&cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5095
      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
  5096
      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
  5097
    }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5098
28497
a7aecf0ffb6b 8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents: 28372
diff changeset
  5099
    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
  5100
    // 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
  5101
    if (page_chunks < MediumChunk) {
a7aecf0ffb6b 8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents: 28372
diff changeset
  5102
      // 4 pages of VSN is committed, some is used by chunks
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5103
      ChunkManager cm(false);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5104
      VirtualSpaceNode vsn(false, vsn_test_size_bytes);
28497
a7aecf0ffb6b 8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents: 28372
diff changeset
  5105
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5106
      vsn.initialize();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5107
      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
  5108
      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
  5109
      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
  5110
      vsn.retire(&cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5111
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5112
      // 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
  5113
      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
  5114
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5115
      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
  5116
      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
  5117
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5118
      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
  5119
      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
  5120
      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
  5121
    }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5122
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5123
    { // Half of VSN is committed, a humongous chunk is used
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5124
      ChunkManager cm(false);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5125
      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
  5126
      vsn.initialize();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5127
      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
  5128
      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
  5129
      vsn.retire(&cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5130
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5131
      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
  5132
      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
  5133
      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
  5134
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5135
      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
  5136
      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
  5137
      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
  5138
    }
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
  }
22222
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5141
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5142
#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
  5143
  assert(vsn.is_available(word_size), \
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  5144
         #word_size ": " PTR_FORMAT " bytes were not available in " \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  5145
         "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  5146
         (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
  5147
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5148
#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
  5149
  assert(!vsn.is_available(word_size), \
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  5150
         #word_size ": " PTR_FORMAT " bytes should not be available in " \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  5151
         "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  5152
         (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
  5153
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5154
  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
  5155
    // Reserve some memory.
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5156
    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
  5157
    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
  5158
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5159
    // Commit some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5160
    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
  5161
    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
  5162
    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
  5163
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5164
    // 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
  5165
    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
  5166
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5167
    // 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
  5168
    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
  5169
    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
  5170
  }
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5171
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5172
  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
  5173
    // Reserve some memory.
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5174
    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
  5175
    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
  5176
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5177
    // Commit some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5178
    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
  5179
    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
  5180
    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
  5181
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5182
    // 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
  5183
    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
  5184
    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
  5185
  }
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5186
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5187
  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
  5188
    // Reserve some memory.
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5189
    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
  5190
    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
  5191
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5192
    // Commit some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5193
    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
  5194
    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
  5195
    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
  5196
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5197
    // 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
  5198
    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
  5199
    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
  5200
    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
  5201
    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
  5202
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5203
    // 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
  5204
    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
  5205
  }
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5206
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  5207
  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
  5208
    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
  5209
    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
  5210
    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
  5211
  }
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5212
};
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  5213
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5214
// 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
  5215
// 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
  5216
void ChunkManager_test_list_index() {
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5217
  {
49453
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5218
    // Test previous bug where a query for a humongous class metachunk,
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5219
    // incorrectly matched the non-class medium metachunk size.
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5220
    {
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5221
      ChunkManager manager(true);
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5222
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5223
      assert(MediumChunk > ClassMediumChunk, "Precondition for test");
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5224
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5225
      ChunkIndex index = manager.list_index(MediumChunk);
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5226
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5227
      assert(index == HumongousIndex,
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5228
          "Requested size is larger than ClassMediumChunk,"
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5229
          " so should return HumongousIndex. Got index: %d", (int)index);
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5230
    }
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5231
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5232
    // Check the specified sizes as well.
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5233
    {
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5234
      ChunkManager manager(true);
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5235
      assert(manager.list_index(ClassSpecializedChunk) == SpecializedIndex, "sanity");
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5236
      assert(manager.list_index(ClassSmallChunk) == SmallIndex, "sanity");
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5237
      assert(manager.list_index(ClassMediumChunk) == MediumIndex, "sanity");
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5238
      assert(manager.list_index(ClassMediumChunk + ClassSpecializedChunk) == HumongousIndex, "sanity");
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5239
    }
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5240
    {
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5241
      ChunkManager manager(false);
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5242
      assert(manager.list_index(SpecializedChunk) == SpecializedIndex, "sanity");
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5243
      assert(manager.list_index(SmallChunk) == SmallIndex, "sanity");
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5244
      assert(manager.list_index(MediumChunk) == MediumIndex, "sanity");
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5245
      assert(manager.list_index(MediumChunk + SpecializedChunk) == HumongousIndex, "sanity");
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5246
    }
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5247
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5248
  }
c8ab058dcf1f 8199667: Unify metaspace list index handling and reinstantiate ChunkManager listindex gtest
stuefe
parents: 49405
diff changeset
  5249
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5250
}
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5251
46602
f63ae85597f1 8183228: Fix optimized build after JDK-8170933
stuefe
parents: 46587
diff changeset
  5252
#endif // !PRODUCT
f63ae85597f1 8183228: Fix optimized build after JDK-8170933
stuefe
parents: 46587
diff changeset
  5253
f63ae85597f1 8183228: Fix optimized build after JDK-8170933
stuefe
parents: 46587
diff changeset
  5254
#ifdef ASSERT
f63ae85597f1 8183228: Fix optimized build after JDK-8170933
stuefe
parents: 46587
diff changeset
  5255
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  5256
// 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
  5257
// 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
  5258
class SpaceManagerTest : AllStatic {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5259
  friend void SpaceManager_test_adjust_initial_chunk_size();
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5260
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5261
  static void test_adjust_initial_chunk_size(bool is_class) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5262
    const size_t smallest = SpaceManager::smallest_chunk_size(is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5263
    const size_t normal   = SpaceManager::small_chunk_size(is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5264
    const size_t medium   = SpaceManager::medium_chunk_size(is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5265
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5266
#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
  5267
    do {                                                                         \
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5268
      size_t v = value;                                                          \
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5269
      size_t e = expected;                                                       \
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5270
      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
  5271
             "Expected: " SIZE_FORMAT " got: " SIZE_FORMAT, e, v);               \
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5272
    } while (0)
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5273
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5274
    // Smallest (specialized)
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5275
    test_adjust_initial_chunk_size(1,            smallest, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5276
    test_adjust_initial_chunk_size(smallest - 1, smallest, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5277
    test_adjust_initial_chunk_size(smallest,     smallest, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5278
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5279
    // Small
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5280
    test_adjust_initial_chunk_size(smallest + 1, normal, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5281
    test_adjust_initial_chunk_size(normal - 1,   normal, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5282
    test_adjust_initial_chunk_size(normal,       normal, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5283
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5284
    // Medium
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5285
    test_adjust_initial_chunk_size(normal + 1, medium, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5286
    test_adjust_initial_chunk_size(medium - 1, medium, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5287
    test_adjust_initial_chunk_size(medium,     medium, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5288
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5289
    // Humongous
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5290
    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
  5291
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5292
#undef test_adjust_initial_chunk_size
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
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5295
  static void test_adjust_initial_chunk_size() {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5296
    test_adjust_initial_chunk_size(false);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5297
    test_adjust_initial_chunk_size(true);
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
};
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5300
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5301
void SpaceManager_test_adjust_initial_chunk_size() {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  5302
  SpaceManagerTest::test_adjust_initial_chunk_size();
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
46602
f63ae85597f1 8183228: Fix optimized build after JDK-8170933
stuefe
parents: 46587
diff changeset
  5305
#endif // ASSERT
49365
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5306
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5307
struct chunkmanager_statistics_t {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5308
  int num_specialized_chunks;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5309
  int num_small_chunks;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5310
  int num_medium_chunks;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5311
  int num_humongous_chunks;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5312
};
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5313
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5314
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
  5315
  ChunkManager* const chunk_manager = Metaspace::get_chunk_manager(mdType);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5316
  ChunkManager::ChunkManagerStatistics stat;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5317
  chunk_manager->get_statistics(&stat);
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5318
  out->num_specialized_chunks = (int)stat.num_by_type[SpecializedIndex];
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5319
  out->num_small_chunks = (int)stat.num_by_type[SmallIndex];
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5320
  out->num_medium_chunks = (int)stat.num_by_type[MediumIndex];
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5321
  out->num_humongous_chunks = (int)stat.num_humongous_chunks;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5322
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5323
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5324
struct chunk_geometry_t {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5325
  size_t specialized_chunk_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5326
  size_t small_chunk_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5327
  size_t medium_chunk_word_size;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5328
};
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5329
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5330
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
  5331
  if (mdType == Metaspace::NonClassType) {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5332
    out->specialized_chunk_word_size = SpecializedChunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5333
    out->small_chunk_word_size = SmallChunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5334
    out->medium_chunk_word_size = MediumChunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5335
  } else {
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5336
    out->specialized_chunk_word_size = ClassSpecializedChunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5337
    out->small_chunk_word_size = ClassSmallChunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5338
    out->medium_chunk_word_size = ClassMediumChunk;
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5339
  }
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5340
}
825f006619e5 8198423: Improve metaspace chunk allocation
stuefe
parents: 49045
diff changeset
  5341