src/hotspot/share/memory/metaspace.cpp
author stefank
Thu, 22 Feb 2018 18:35:04 +0100
changeset 49045 9b556b613a07
parent 48971 b2bb70f5effd
child 49348 fde3feaaa4ed
child 49365 825f006619e5
permissions -rw-r--r--
8198509: Move satisfy_failed_metadata_allocation out from CollectorPolicy Reviewed-by: sjohanss, pliden
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     1
/*
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48387
diff changeset
     2
 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     4
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     8
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    13
 * accompanied this code).
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    14
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    18
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    21
 * questions.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    22
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    23
 */
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    24
#include "precompiled.hpp"
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 42621
diff changeset
    25
#include "aot/aotLoader.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30580
diff changeset
    26
#include "gc/shared/collectedHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30580
diff changeset
    27
#include "gc/shared/collectorPolicy.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30580
diff changeset
    28
#include "gc/shared/gcLocker.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
    29
#include "logging/log.hpp"
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
    30
#include "logging/logStream.hpp"
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
    31
#include "memory/allocation.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    32
#include "memory/binaryTreeDictionary.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    33
#include "memory/filemap.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    34
#include "memory/freeList.hpp"
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
    35
#include "memory/metachunk.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    36
#include "memory/metaspace.hpp"
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
    37
#include "memory/metaspaceGCThresholdUpdater.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    38
#include "memory/metaspaceShared.hpp"
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
    39
#include "memory/metaspaceTracer.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    40
#include "memory/resourceArea.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    41
#include "memory/universe.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39986
diff changeset
    42
#include "runtime/atomic.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    43
#include "runtime/globals.hpp"
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
    44
#include "runtime/init.hpp"
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
    45
#include "runtime/java.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    46
#include "runtime/mutex.hpp"
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 23854
diff changeset
    47
#include "runtime/orderAccess.inline.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    48
#include "services/memTracker.hpp"
20407
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
    49
#include "services/memoryService.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    50
#include "utilities/align.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    51
#include "utilities/copy.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    52
#include "utilities/debug.hpp"
27683
1d5707553fff 8064580: Move INCLUDE_CDS include section to the end of the include list
stefank
parents: 27404
diff changeset
    53
#include "utilities/macros.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    54
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
    55
typedef BinaryTreeDictionary<Metablock, FreeList<Metablock> > BlockTreeDictionary;
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
    56
typedef BinaryTreeDictionary<Metachunk, FreeList<Metachunk> > ChunkTreeDictionary;
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
    57
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
    58
// Set this constant to enable slow integrity checking of the free chunk lists
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
    59
const bool metaspace_slow_verify = false;
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
    60
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
    61
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
    62
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    63
MetaWord* last_allocated = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    64
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
    65
size_t Metaspace::_compressed_class_space_size;
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
    66
const MetaspaceTracer* Metaspace::_tracer = NULL;
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
    67
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
    68
DEBUG_ONLY(bool Metaspace::_frozen = false;)
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
    69
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    70
// Used in declarations in SpaceManager and ChunkManager
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    71
enum ChunkIndex {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    72
  ZeroIndex = 0,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    73
  SpecializedIndex = ZeroIndex,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    74
  SmallIndex = SpecializedIndex + 1,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    75
  MediumIndex = SmallIndex + 1,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    76
  HumongousIndex = MediumIndex + 1,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    77
  NumberOfFreeLists = 3,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    78
  NumberOfInUseLists = 4
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    79
};
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    80
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
    81
// Helper, returns a descriptive name for the given index.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
    82
static const char* chunk_size_name(ChunkIndex index) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
    83
  switch (index) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
    84
    case SpecializedIndex:
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
    85
      return "specialized";
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
    86
    case SmallIndex:
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
    87
      return "small";
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
    88
    case MediumIndex:
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
    89
      return "medium";
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
    90
    case HumongousIndex:
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
    91
      return "humongous";
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
    92
    default:
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
    93
      return "Invalid index";
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
    94
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
    95
}
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
    96
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    97
enum ChunkSizes {    // in words.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    98
  ClassSpecializedChunk = 128,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    99
  SpecializedChunk = 128,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   100
  ClassSmallChunk = 256,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   101
  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
   102
  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
   103
  MediumChunk = 8 * K
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   104
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   105
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   106
static ChunkIndex next_chunk_index(ChunkIndex i) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   107
  assert(i < NumberOfInUseLists, "Out of bound");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   108
  return (ChunkIndex) (i+1);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   109
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   110
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   111
static const char* scale_unit(size_t scale) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   112
  switch(scale) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   113
    case 1: return "BYTES";
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   114
    case K: return "KB";
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   115
    case M: return "MB";
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   116
    case G: return "GB";
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   117
    default:
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   118
      ShouldNotReachHere();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   119
      return NULL;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   120
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   121
}
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   122
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   123
volatile intptr_t MetaspaceGC::_capacity_until_GC = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   124
uint MetaspaceGC::_shrink_factor = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   125
bool MetaspaceGC::_should_concurrent_collect = false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   126
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
   127
typedef class FreeList<Metachunk> ChunkList;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   128
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   129
// Manages the global free lists of chunks.
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   130
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
   131
  friend class TestVirtualSpaceNodeTest;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   132
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   133
  // Free list of chunks of different sizes.
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   134
  //   SpecializedChunk
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   135
  //   SmallChunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   136
  //   MediumChunk
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   137
  ChunkList _free_chunks[NumberOfFreeLists];
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   138
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   139
  // 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
   140
  ChunkList* free_chunks(ChunkIndex index);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   141
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   142
  // 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
   143
  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
   144
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   145
  //   HumongousChunk
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   146
  ChunkTreeDictionary _humongous_dictionary;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   147
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   148
  // Returns the humongous chunk dictionary.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   149
  ChunkTreeDictionary* humongous_dictionary() {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   150
    return &_humongous_dictionary;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   151
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   152
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
   153
  // 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
   154
  size_t _free_chunks_total;
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
   155
  // Number of chunks in this ChunkManager
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   156
  size_t _free_chunks_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   157
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
   158
  // Update counters after a chunk was added or removed removed.
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
   159
  void account_for_added_chunk(const Metachunk* c);
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
   160
  void account_for_removed_chunk(const Metachunk* c);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   161
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   162
  // Debug support
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   163
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   164
  size_t sum_free_chunks();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   165
  size_t sum_free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   166
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   167
  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
   168
  void slow_locked_verify_free_chunks_total() {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   169
    if (metaspace_slow_verify) {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   170
      locked_verify_free_chunks_total();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   171
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   172
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   173
  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
   174
  void slow_locked_verify_free_chunks_count() {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   175
    if (metaspace_slow_verify) {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   176
      locked_verify_free_chunks_count();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   177
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   178
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   179
  void verify_free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   180
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   181
  struct ChunkManagerStatistics {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   182
    size_t num_by_type[NumberOfFreeLists];
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   183
    size_t single_size_by_type[NumberOfFreeLists];
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   184
    size_t total_size_by_type[NumberOfFreeLists];
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   185
    size_t num_humongous_chunks;
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   186
    size_t total_size_humongous_chunks;
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   187
  };
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   188
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   189
  void locked_get_statistics(ChunkManagerStatistics* stat) const;
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   190
  void get_statistics(ChunkManagerStatistics* stat) const;
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   191
  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
   192
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   193
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   194
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   195
  ChunkManager(size_t specialized_size, size_t small_size, size_t medium_size)
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   196
      : _free_chunks_total(0), _free_chunks_count(0) {
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   197
    _free_chunks[SpecializedIndex].set_size(specialized_size);
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   198
    _free_chunks[SmallIndex].set_size(small_size);
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   199
    _free_chunks[MediumIndex].set_size(medium_size);
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   200
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   201
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   202
  // add or delete (return) a chunk to the global freelist.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   203
  Metachunk* chunk_freelist_allocate(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   204
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   205
  // 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
   206
  // 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
   207
  ChunkIndex list_index(size_t size);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   208
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   209
  // Map a given index to the chunk size.
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   210
  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
   211
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   212
  // 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
   213
  // 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
   214
  // humongous).
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   215
  void remove_chunk(Metachunk* chunk);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   216
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   217
  // 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
   218
  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
   219
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
   220
  // 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
   221
  // of type index.
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
   222
  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
   223
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   224
  // Total of the space in the free chunks list
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
   225
  size_t free_chunks_total_words();
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
   226
  size_t free_chunks_total_bytes();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   227
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   228
  // Number of chunks in the free chunks list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   229
  size_t free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   230
20733
8dead86921fe 8026715: Remove the MetaDataDeallocateALot develop flag
stefank
parents: 20729
diff changeset
   231
  // 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
   232
  Metachunk* free_chunks_get(size_t chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   233
23470
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   234
#define index_bounds_check(index)                                         \
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   235
  assert(index == SpecializedIndex ||                                     \
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   236
         index == SmallIndex ||                                           \
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   237
         index == MediumIndex ||                                          \
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
   238
         index == HumongousIndex, "Bad index: %d", (int) index)
23470
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   239
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   240
  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
   241
    index_bounds_check(index);
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   242
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   243
    if (index == HumongousIndex) {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   244
      return _humongous_dictionary.total_free_blocks();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   245
    }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   246
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   247
    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
   248
    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
   249
  }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   250
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   251
  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
   252
    index_bounds_check(index);
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   253
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   254
    size_t word_size = 0;
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   255
    if (index == HumongousIndex) {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   256
      word_size = _humongous_dictionary.total_size();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   257
    } else {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   258
      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
   259
      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
   260
    }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   261
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   262
    return word_size * BytesPerWord;
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   263
  }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   264
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   265
  MetaspaceChunkFreeListSummary chunk_free_list_summary() const {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   266
    return MetaspaceChunkFreeListSummary(num_free_chunks(SpecializedIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   267
                                         num_free_chunks(SmallIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   268
                                         num_free_chunks(MediumIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   269
                                         num_free_chunks(HumongousIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   270
                                         size_free_chunks_in_bytes(SpecializedIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   271
                                         size_free_chunks_in_bytes(SmallIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   272
                                         size_free_chunks_in_bytes(MediumIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   273
                                         size_free_chunks_in_bytes(HumongousIndex));
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   274
  }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   275
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   276
  // Debug support
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   277
  void verify();
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   278
  void slow_verify() {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   279
    if (metaspace_slow_verify) {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   280
      verify();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   281
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   282
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   283
  void locked_verify();
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   284
  void slow_locked_verify() {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   285
    if (metaspace_slow_verify) {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   286
      locked_verify();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   287
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   288
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   289
  void verify_free_chunks_total();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   290
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   291
  void locked_print_free_chunks(outputStream* st);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   292
  void locked_print_sum_free_chunks(outputStream* st);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   293
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   294
  void print_on(outputStream* st) const;
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   295
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   296
  // Prints composition for both non-class and (if available)
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
   297
  // class chunk manager.
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
   298
  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
   299
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   300
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   301
class SmallBlocks : public CHeapObj<mtClass> {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   302
  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
   303
  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
   304
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   305
 private:
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   306
  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
   307
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   308
  FreeList<Metablock>& list_at(size_t word_size) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   309
    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
   310
    return _small_lists[word_size - _small_block_min_size];
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   311
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   312
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   313
 public:
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   314
  SmallBlocks() {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   315
    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
   316
      uint k = i - _small_block_min_size;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   317
      _small_lists[k].set_size(i);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   318
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   319
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   320
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   321
  size_t total_size() const {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   322
    size_t result = 0;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   323
    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
   324
      uint k = i - _small_block_min_size;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   325
      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
   326
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   327
    return result;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   328
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   329
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   330
  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
   331
  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
   332
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   333
  MetaWord* get_block(size_t word_size) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   334
    if (list_at(word_size).count() > 0) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   335
      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
   336
      return new_block;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   337
    } else {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   338
      return NULL;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   339
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   340
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   341
  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
   342
    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
   343
    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
   344
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   345
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   346
  void print_on(outputStream* st) const {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   347
    st->print_cr("SmallBlocks:");
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   348
    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
   349
      uint k = i - _small_block_min_size;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   350
      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
   351
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   352
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   353
};
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   354
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   355
// 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
   356
// to the allocation of a quantum of metadata).
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   357
class BlockFreelist : public CHeapObj<mtClass> {
30580
394471b86a83 8079091: Remove dictionary NULL check on common path of BlockFreeList methods
jwha
parents: 29806
diff changeset
   358
  BlockTreeDictionary* const _dictionary;
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   359
  SmallBlocks* _small_blocks;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   360
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   361
  // 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
   362
  // 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
   363
  const static int WasteMultiplier = 4;
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   364
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   365
  // Accessors
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   366
  BlockTreeDictionary* dictionary() const { return _dictionary; }
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   367
  SmallBlocks* small_blocks() {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   368
    if (_small_blocks == NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   369
      _small_blocks = new SmallBlocks();
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   370
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   371
    return _small_blocks;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   372
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   373
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   374
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   375
  BlockFreelist();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   376
  ~BlockFreelist();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   377
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   378
  // Get and return a block to the free list
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   379
  MetaWord* get_block(size_t word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   380
  void return_block(MetaWord* p, size_t word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   381
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   382
  size_t total_size() const  {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   383
    size_t result = dictionary()->total_size();
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   384
    if (_small_blocks != NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   385
      result = result + _small_blocks->total_size();
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   386
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   387
    return result;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   388
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   389
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   390
  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
   391
  void print_on(outputStream* st) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   392
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   393
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   394
// A VirtualSpaceList node.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   395
class VirtualSpaceNode : public CHeapObj<mtClass> {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   396
  friend class VirtualSpaceList;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   397
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   398
  // Link to next VirtualSpaceNode
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   399
  VirtualSpaceNode* _next;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   400
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   401
  // total in the VirtualSpace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   402
  MemRegion _reserved;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   403
  ReservedSpace _rs;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   404
  VirtualSpace _virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   405
  MetaWord* _top;
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   406
  // count of chunks contained in this VirtualSpace
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   407
  uintx _container_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   408
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   409
  // Convenience functions to access the _virtual_space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   410
  char* low()  const { return virtual_space()->low(); }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   411
  char* high() const { return virtual_space()->high(); }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   412
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   413
  // The first Metachunk will be allocated at the bottom of the
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   414
  // VirtualSpace
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   415
  Metachunk* first_chunk() { return (Metachunk*) bottom(); }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   416
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   417
  // 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
   418
  size_t free_words_in_vs() const;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   419
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   420
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   421
  VirtualSpaceNode(size_t byte_size);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   422
  VirtualSpaceNode(ReservedSpace rs) : _top(NULL), _next(NULL), _rs(rs), _container_count(0) {}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   423
  ~VirtualSpaceNode();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   424
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   425
  // Convenience functions for logical bottom and end
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   426
  MetaWord* bottom() const { return (MetaWord*) _virtual_space.low(); }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   427
  MetaWord* end() const { return (MetaWord*) _virtual_space.high(); }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   428
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
   429
  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
   430
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   431
  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
   432
  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
   433
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   434
  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
   435
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   436
  // address of next available space in _virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   437
  // Accessors
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   438
  VirtualSpaceNode* next() { return _next; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   439
  void set_next(VirtualSpaceNode* v) { _next = v; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   440
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   441
  void set_reserved(MemRegion const v) { _reserved = v; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   442
  void set_top(MetaWord* v) { _top = v; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   443
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   444
  // Accessors
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   445
  MemRegion* reserved() { return &_reserved; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   446
  VirtualSpace* virtual_space() const { return (VirtualSpace*) &_virtual_space; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   447
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   448
  // 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
   449
  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
   450
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   451
  MetaWord* top() const { return _top; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   452
  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
   453
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   454
  uintx container_count() { return _container_count; }
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   455
  void inc_container_count();
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   456
  void dec_container_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   457
#ifdef ASSERT
29806
64aa40385bdd 8076173: VirtualSpaceNode container_count() and container_count_slow() have different return types
david
parents: 29800
diff changeset
   458
  uintx container_count_slow();
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   459
  void verify_container_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   460
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   461
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   462
  // 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
   463
  size_t used_words_in_vs() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   464
  size_t capacity_words_in_vs() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   465
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   466
  bool initialize();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   467
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   468
  // get space from the virtual space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   469
  Metachunk* take_from_committed(size_t chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   470
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   471
  // 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
   472
  Metachunk* get_chunk_vs(size_t chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   473
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   474
  // 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
   475
  // to Virtualspace
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   476
  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
   477
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   478
  // In preparation for deleting this node, remove all the chunks
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   479
  // in the node from any freelist.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   480
  void purge(ChunkManager* chunk_manager);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   481
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   482
  // 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
   483
  // 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
   484
  // 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
   485
  // 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
   486
  // 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
   487
  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
   488
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
   489
#ifdef ASSERT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   490
  // Debug support
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   491
  void mangle();
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
   492
#endif
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   493
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   494
  void print_on(outputStream* st) const;
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   495
  void print_map(outputStream* st, bool is_class) const;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   496
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   497
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   498
#define assert_is_aligned(value, alignment)                  \
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   499
  assert(is_aligned((value), (alignment)),                   \
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   500
         SIZE_FORMAT_HEX " is not aligned to "               \
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   501
         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
   502
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   503
// 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
   504
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
   505
  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
   506
    size_t words = bytes / BytesPerWord;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   507
    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
   508
    if (MetaspaceGC::can_expand(words, is_class) &&
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   509
        MetaspaceGC::allowed_expansion() >= words) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   510
      return true;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   511
    }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   512
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   513
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   514
  return false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   515
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   516
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   517
  // byte_size is the size of the associated virtualspace.
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   518
VirtualSpaceNode::VirtualSpaceNode(size_t bytes) : _top(NULL), _next(NULL), _rs(), _container_count(0) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   519
  assert_is_aligned(bytes, Metaspace::reserve_alignment());
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
   520
  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
   521
  _rs = ReservedSpace(bytes, Metaspace::reserve_alignment(), large_pages);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   522
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   523
  if (_rs.is_reserved()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   524
    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
   525
    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
   526
    assert_is_aligned(_rs.base(), Metaspace::reserve_alignment());
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   527
    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
   528
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   529
    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
   530
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   531
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   532
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   533
void VirtualSpaceNode::purge(ChunkManager* chunk_manager) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   534
  Metachunk* chunk = first_chunk();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   535
  Metachunk* invalid_chunk = (Metachunk*) top();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   536
  while (chunk < invalid_chunk ) {
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   537
    assert(chunk->is_tagged_free(), "Should be tagged free");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   538
    MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   539
    chunk_manager->remove_chunk(chunk);
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   540
    assert(chunk->next() == NULL &&
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   541
           chunk->prev() == NULL,
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   542
           "Was not removed from its list");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   543
    chunk = (Metachunk*) next;
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   544
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   545
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   546
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   547
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
   548
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   549
  // Format:
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   550
  // <ptr>
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   551
  // <ptr>  . .. .               .  ..
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   552
  //        SSxSSMMMMMMMMMMMMMMMMsssXX
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   553
  //        112114444444444444444
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   554
  // <ptr>  . .. .               .  ..
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   555
  //        SSxSSMMMMMMMMMMMMMMMMsssXX
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   556
  //        112114444444444444444
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   557
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   558
  if (bottom() == top()) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   559
    return;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   560
  }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   561
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   562
  // First line: dividers for every med-chunk-sized interval
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   563
  // Second line: a dot for the start of a chunk
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   564
  // Third line: a letter per chunk type (x,s,m,h), uppercase if in use.
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   565
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   566
  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
   567
  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
   568
  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
   569
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   570
  int line_len = 100;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   571
  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
   572
  line_len = (int)(section_len / spec_chunk_size);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   573
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   574
  char* line1 = (char*)os::malloc(line_len, mtInternal);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   575
  char* line2 = (char*)os::malloc(line_len, mtInternal);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   576
  char* line3 = (char*)os::malloc(line_len, mtInternal);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   577
  int pos = 0;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   578
  const MetaWord* p = bottom();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   579
  const Metachunk* chunk = (const Metachunk*)p;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   580
  const MetaWord* chunk_end = p + chunk->word_size();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   581
  while (p < top()) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   582
    if (pos == line_len) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   583
      pos = 0;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   584
      st->fill_to(22);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   585
      st->print_raw(line1, line_len);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   586
      st->cr();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   587
      st->fill_to(22);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   588
      st->print_raw(line2, line_len);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   589
      st->cr();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   590
    }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   591
    if (pos == 0) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   592
      st->print(PTR_FORMAT ":", p2i(p));
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   593
    }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   594
    if (p == chunk_end) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   595
      chunk = (Metachunk*)p;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   596
      chunk_end = p + chunk->word_size();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   597
    }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   598
    if (p == (const MetaWord*)chunk) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   599
      // chunk starts.
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   600
      line1[pos] = '.';
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   601
    } else {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   602
      line1[pos] = ' ';
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   603
    }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   604
    // 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
   605
    // chunk is in use.
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   606
    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
   607
    if (chunk->word_size() == spec_chunk_size) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   608
      line2[pos] = chunk_is_free ? 'x' : 'X';
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   609
    } else if (chunk->word_size() == small_chunk_size) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   610
      line2[pos] = chunk_is_free ? 's' : 'S';
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   611
    } else if (chunk->word_size() == med_chunk_size) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   612
      line2[pos] = chunk_is_free ? 'm' : 'M';
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   613
   } else if (chunk->word_size() > med_chunk_size) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   614
      line2[pos] = chunk_is_free ? 'h' : 'H';
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   615
    } else {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   616
      ShouldNotReachHere();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   617
    }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   618
    p += spec_chunk_size;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   619
    pos ++;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   620
  }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   621
  if (pos > 0) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   622
    st->fill_to(22);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   623
    st->print_raw(line1, pos);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   624
    st->cr();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   625
    st->fill_to(22);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   626
    st->print_raw(line2, pos);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   627
    st->cr();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   628
  }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   629
  os::free(line1);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   630
  os::free(line2);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   631
  os::free(line3);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   632
}
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   633
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   634
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   635
#ifdef ASSERT
29806
64aa40385bdd 8076173: VirtualSpaceNode container_count() and container_count_slow() have different return types
david
parents: 29800
diff changeset
   636
uintx VirtualSpaceNode::container_count_slow() {
64aa40385bdd 8076173: VirtualSpaceNode container_count() and container_count_slow() have different return types
david
parents: 29800
diff changeset
   637
  uintx count = 0;
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   638
  Metachunk* chunk = first_chunk();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   639
  Metachunk* invalid_chunk = (Metachunk*) top();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   640
  while (chunk < invalid_chunk ) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   641
    MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   642
    // Don't count the chunks on the free lists.  Those are
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   643
    // still part of the VirtualSpaceNode but not currently
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   644
    // counted.
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   645
    if (!chunk->is_tagged_free()) {
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   646
      count++;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   647
    }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   648
    chunk = (Metachunk*) next;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   649
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   650
  return count;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   651
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   652
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   653
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   654
// List of VirtualSpaces for metadata allocation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   655
class VirtualSpaceList : public CHeapObj<mtClass> {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   656
  friend class VirtualSpaceNode;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   657
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   658
  enum VirtualSpaceSizes {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   659
    VirtualSpaceSize = 256 * K
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   660
  };
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   661
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   662
  // Head of the list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   663
  VirtualSpaceNode* _virtual_space_list;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   664
  // virtual space currently being used for allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   665
  VirtualSpaceNode* _current_virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   666
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   667
  // 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
   668
  bool _is_class;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   669
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   670
  // 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
   671
  size_t _reserved_words;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   672
  size_t _committed_words;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   673
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   674
  // Number of virtual spaces
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   675
  size_t _virtual_space_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   676
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   677
  ~VirtualSpaceList();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   678
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   679
  VirtualSpaceNode* virtual_space_list() const { return _virtual_space_list; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   680
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   681
  void set_virtual_space_list(VirtualSpaceNode* v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   682
    _virtual_space_list = v;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   683
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   684
  void set_current_virtual_space(VirtualSpaceNode* v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   685
    _current_virtual_space = v;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   686
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   687
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   688
  void link_vs(VirtualSpaceNode* new_entry);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   689
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   690
  // 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
   691
  // 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
   692
  // 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
   693
  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
   694
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   695
  // 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
   696
  // 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
   697
  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
   698
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   699
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   700
  VirtualSpaceList(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   701
  VirtualSpaceList(ReservedSpace rs);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   702
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   703
  size_t free_bytes();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   704
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
   705
  Metachunk* get_new_chunk(size_t chunk_word_size,
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
   706
                           size_t suggested_commit_granularity);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   707
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   708
  bool expand_node_by(VirtualSpaceNode* node,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   709
                      size_t min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   710
                      size_t preferred_words);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   711
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   712
  bool expand_by(size_t min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   713
                 size_t preferred_words);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   714
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   715
  VirtualSpaceNode* current_virtual_space() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   716
    return _current_virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   717
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   718
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   719
  bool is_class() const { return _is_class; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   720
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   721
  bool initialization_succeeded() { return _virtual_space_list != NULL; }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   722
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   723
  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
   724
  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
   725
  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
   726
  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
   727
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   728
  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
   729
  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
   730
  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
   731
  void dec_committed_words(size_t v);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   732
  void inc_virtual_space_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   733
  void dec_virtual_space_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   734
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
   735
  bool contains(const void* ptr);
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
   736
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   737
  // Unlink empty VirtualSpaceNodes and free it.
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   738
  void purge(ChunkManager* chunk_manager);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   739
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   740
  void print_on(outputStream* st) const;
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
   741
  void print_map(outputStream* st) const;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   742
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   743
  class VirtualSpaceListIterator : public StackObj {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   744
    VirtualSpaceNode* _virtual_spaces;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   745
   public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   746
    VirtualSpaceListIterator(VirtualSpaceNode* virtual_spaces) :
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   747
      _virtual_spaces(virtual_spaces) {}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   748
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   749
    bool repeat() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   750
      return _virtual_spaces != NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   751
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   752
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   753
    VirtualSpaceNode* get_next() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   754
      VirtualSpaceNode* result = _virtual_spaces;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   755
      if (_virtual_spaces != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   756
        _virtual_spaces = _virtual_spaces->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   757
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   758
      return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   759
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   760
  };
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   761
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   762
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   763
class Metadebug : AllStatic {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   764
  // Debugging support for Metaspaces
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   765
  static int _allocation_fail_alot_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   766
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   767
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   768
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   769
  static void init_allocation_fail_alot_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   770
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   771
  static bool test_metadata_failure();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   772
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   773
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   774
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   775
int Metadebug::_allocation_fail_alot_count = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   776
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   777
//  SpaceManager - used by Metaspace to handle allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   778
class SpaceManager : public CHeapObj<mtClass> {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   779
  friend class Metaspace;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   780
  friend class Metadebug;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   781
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   782
 private:
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   783
22201
9c2ccfa3a5fe 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 21569
diff changeset
   784
  // protects allocations
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   785
  Mutex* const _lock;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   786
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
   787
  // Type of metadata allocated.
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
   788
  const Metaspace::MetadataType   _mdtype;
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
   789
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
   790
  // Type of metaspace
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
   791
  const Metaspace::MetaspaceType  _space_type;
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
   792
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   793
  // List of chunks in use by this SpaceManager.  Allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   794
  // 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
   795
  // chunks when the SpaceManager is freed.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   796
  Metachunk* _chunks_in_use[NumberOfInUseLists];
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   797
  Metachunk* _current_chunk;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   798
31028
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
   799
  // 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
   800
  static uint const _small_chunk_limit;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   801
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
   802
  // Maximum number of specialize chunks to allocate for anonymous
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
   803
  // metadata space to a SpaceManager
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
   804
  static uint const _anon_metadata_specialize_chunk_limit;
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
   805
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   806
  // 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
   807
  size_t _allocated_blocks_words;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   808
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   809
  // Sum of all allocated chunks
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   810
  size_t _allocated_chunks_words;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   811
  size_t _allocated_chunks_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   812
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   813
  // Free lists of blocks are per SpaceManager since they
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   814
  // 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
   815
  // 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
   816
  // the class loader using the SpaceManager is collected.
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   817
  BlockFreelist* _block_freelists;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   818
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   819
  // protects virtualspace and chunk expansions
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   820
  static const char*  _expand_lock_name;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   821
  static const int    _expand_lock_rank;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   822
  static Mutex* const _expand_lock;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   823
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   824
 private:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   825
  // Accessors
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   826
  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
   827
  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
   828
    _chunks_in_use[index] = v;
9c2ccfa3a5fe 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 21569
diff changeset
   829
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   830
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   831
  BlockFreelist* block_freelists() const { return _block_freelists; }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   832
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
   833
  Metaspace::MetadataType mdtype() { return _mdtype; }
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   834
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   835
  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
   836
  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
   837
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   838
  Metachunk* current_chunk() const { return _current_chunk; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   839
  void set_current_chunk(Metachunk* v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   840
    _current_chunk = v;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   841
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   842
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   843
  Metachunk* find_current_chunk(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   844
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   845
  // Add chunk to the list of chunks in use
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   846
  void add_chunk(Metachunk* v, bool make_current);
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   847
  void retire_current_chunk();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   848
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   849
  Mutex* lock() const { return _lock; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   850
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   851
 protected:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   852
  void initialize();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   853
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   854
 public:
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
   855
  SpaceManager(Metaspace::MetadataType mdtype,
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
   856
               Metaspace::MetaspaceType space_type,
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   857
               Mutex* lock);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   858
  ~SpaceManager();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   859
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   860
  enum ChunkMultiples {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   861
    MediumChunkMultiple = 4
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   862
  };
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   863
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
   864
  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
   865
  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
   866
  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
   867
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
   868
  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
   869
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   870
  // Accessors
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
   871
  bool is_class() const { return _mdtype == Metaspace::ClassType; }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
   872
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
   873
  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
   874
  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
   875
  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
   876
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
   877
  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
   878
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
   879
  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
   880
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   881
  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
   882
  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
   883
  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
   884
  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
   885
  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
   886
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   887
  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
   888
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   889
  static Mutex* expand_lock() { return _expand_lock; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   890
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   891
  // 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
   892
  // 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
   893
  // the in-use list.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   894
  void inc_size_metrics(size_t words);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   895
  // 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
   896
  // 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
   897
  void inc_used_metrics(size_t words);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   898
  // 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
   899
  // 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
   900
  // 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
   901
  void dec_total_from_size_metrics();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   902
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
   903
  // 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
   904
  // 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
   905
  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
   906
  size_t adjust_initial_chunk_size(size_t requested) const;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
   907
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
   908
  // Get the initial chunks size for this metaspace type.
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
   909
  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
   910
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   911
  size_t sum_capacity_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   912
  size_t sum_used_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   913
  size_t sum_free_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   914
  size_t sum_waste_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   915
  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
   916
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   917
  size_t sum_count_in_chunks_in_use();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   918
  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
   919
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
   920
  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
   921
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   922
  // Block allocation and deallocation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   923
  // Allocates a block from the current chunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   924
  MetaWord* allocate(size_t word_size);
31028
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
   925
  // Allocates a block from a small chunk
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
   926
  MetaWord* get_small_chunk_and_allocate(size_t word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   927
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   928
  // Helper for allocations
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   929
  MetaWord* allocate_work(size_t word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   930
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   931
  // Returns a block to the per manager freelist
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   932
  void deallocate(MetaWord* p, size_t word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   933
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   934
  // 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
   935
  // returned chunk size (for expanding space for chunk allocation).
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   936
  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
   937
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   938
  // Called when an allocation from the current chunk fails.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   939
  // 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
   940
  // and allocates from that chunk.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   941
  MetaWord* grow_and_allocate(size_t word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   942
20407
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
   943
  // Notify memory usage to MemoryService.
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
   944
  void track_metaspace_memory_usage();
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
   945
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   946
  // debugging support.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   947
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   948
  void dump(outputStream* const out) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   949
  void print_on(outputStream* st) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   950
  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
   951
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   952
  void verify();
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
   953
  void verify_chunk_size(Metachunk* chunk);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   954
#ifdef ASSERT
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   955
  void verify_allocated_blocks_words();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   956
#endif
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   957
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
   958
  // 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
   959
  // 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
   960
  size_t get_allocation_word_size(size_t word_size) {
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   961
    size_t byte_size = word_size * BytesPerWord;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   962
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   963
    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
   964
    raw_bytes_size = align_up(raw_bytes_size, Metachunk::object_alignment());
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   965
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   966
    size_t raw_word_size = raw_bytes_size / BytesPerWord;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   967
    assert(raw_word_size * BytesPerWord == raw_bytes_size, "Size problem");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   968
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   969
    return raw_word_size;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   970
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   971
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   972
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   973
uint const SpaceManager::_small_chunk_limit = 4;
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
   974
uint const SpaceManager::_anon_metadata_specialize_chunk_limit = 4;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   975
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   976
const char* SpaceManager::_expand_lock_name =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   977
  "SpaceManager chunk allocation lock";
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   978
const int SpaceManager::_expand_lock_rank = Monitor::leaf - 1;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   979
Mutex* const SpaceManager::_expand_lock =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   980
  new Mutex(SpaceManager::_expand_lock_rank,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   981
            SpaceManager::_expand_lock_name,
28163
322d55d167be 8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents: 28023
diff changeset
   982
            Mutex::_allow_vm_block_flag,
322d55d167be 8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents: 28023
diff changeset
   983
            Monitor::_safepoint_check_never);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   984
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   985
void VirtualSpaceNode::inc_container_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   986
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   987
  _container_count++;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   988
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   989
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   990
void VirtualSpaceNode::dec_container_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   991
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   992
  _container_count--;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   993
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   994
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   995
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   996
void VirtualSpaceNode::verify_container_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   997
  assert(_container_count == container_count_slow(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
   998
         "Inconsistency in container_count _container_count " UINTX_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
   999
         " container_count_slow() " UINTX_FORMAT, _container_count, container_count_slow());
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1000
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1001
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1002
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1003
// BlockFreelist methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1004
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1005
BlockFreelist::BlockFreelist() : _dictionary(new BlockTreeDictionary()), _small_blocks(NULL) {}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1006
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1007
BlockFreelist::~BlockFreelist() {
30580
394471b86a83 8079091: Remove dictionary NULL check on common path of BlockFreeList methods
jwha
parents: 29806
diff changeset
  1008
  delete _dictionary;
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1009
  if (_small_blocks != NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1010
    delete _small_blocks;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1011
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1012
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1013
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1014
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
  1015
  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
  1016
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  1017
  Metablock* free_chunk = ::new (p) Metablock(word_size);
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1018
  if (word_size < SmallBlocks::small_block_max_size()) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1019
    small_blocks()->return_block(free_chunk, word_size);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1020
  } else {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1021
  dictionary()->return_chunk(free_chunk);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1022
}
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1023
  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
  1024
            SIZE_FORMAT, p2i(free_chunk), word_size);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1025
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1026
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1027
MetaWord* BlockFreelist::get_block(size_t word_size) {
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1028
  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
  1029
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1030
  // Try small_blocks first.
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1031
  if (word_size < SmallBlocks::small_block_max_size()) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1032
    // 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
  1033
    // this space manager.
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1034
    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
  1035
    if (new_block != NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1036
      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
  1037
              p2i(new_block), word_size);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1038
      return new_block;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1039
    }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1040
  }
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1041
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1042
  if (word_size < BlockFreelist::min_dictionary_size()) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1043
    // 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
  1044
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1045
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1046
46674
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46625
diff changeset
  1047
  Metablock* free_block = dictionary()->get_chunk(word_size);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1048
  if (free_block == NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1049
    return NULL;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1050
  }
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1051
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1052
  const size_t block_size = free_block->size();
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1053
  if (block_size > WasteMultiplier * word_size) {
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1054
    return_block((MetaWord*)free_block, block_size);
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1055
    return NULL;
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1056
  }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1057
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1058
  MetaWord* new_block = (MetaWord*)free_block;
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1059
  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
  1060
  const size_t unused = block_size - word_size;
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1061
  if (unused >= SmallBlocks::small_block_min_size()) {
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1062
    return_block(new_block + word_size, unused);
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1063
  }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1064
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1065
  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
  1066
            p2i(new_block), word_size);
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  1067
  return new_block;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1068
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1069
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1070
void BlockFreelist::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1071
  dictionary()->print_free_lists(st);
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1072
  if (_small_blocks != NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1073
    _small_blocks->print_on(st);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  1074
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1075
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1076
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1077
// VirtualSpaceNode methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1078
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1079
VirtualSpaceNode::~VirtualSpaceNode() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1080
  _rs.release();
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1081
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1082
  size_t word_size = sizeof(*this) / BytesPerWord;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1083
  Copy::fill_to_words((HeapWord*) this, word_size, 0xf1f1f1f1);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1084
#endif
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1085
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1086
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1087
size_t VirtualSpaceNode::used_words_in_vs() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1088
  return pointer_delta(top(), bottom(), sizeof(MetaWord));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1089
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1090
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1091
// Space committed in the VirtualSpace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1092
size_t VirtualSpaceNode::capacity_words_in_vs() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1093
  return pointer_delta(end(), bottom(), sizeof(MetaWord));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1094
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1095
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1096
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
  1097
  return pointer_delta(end(), top(), sizeof(MetaWord));
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1098
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1099
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1100
// Allocates the chunk from the virtual space only.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1101
// 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
  1102
// chunks removed here are necessarily used for allocation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1103
Metachunk* VirtualSpaceNode::take_from_committed(size_t chunk_word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1104
  // Bottom of the new chunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1105
  MetaWord* chunk_limit = top();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1106
  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
  1107
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1108
  // 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
  1109
  // commit granularity to enforce the following condition.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1110
  // 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
  1111
  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
  1112
      "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
  1113
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1114
  if (!is_available(chunk_word_size)) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1115
    LogTarget(Debug, gc, metaspace, freelist) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1116
    if (lt.is_enabled()) {
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1117
      LogStream ls(lt);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1118
      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
  1119
      // 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
  1120
      print_on(&ls);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1121
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1122
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1123
  }
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
  // 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
  1126
  inc_top(chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1127
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1128
  // Initialize the chunk
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1129
  Metachunk* result = ::new (chunk_limit) Metachunk(chunk_word_size, this);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1130
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1131
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1132
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1133
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1134
// 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
  1135
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
  1136
  size_t min_bytes = min_words * BytesPerWord;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1137
  size_t preferred_bytes = preferred_words * BytesPerWord;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1138
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1139
  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
  1140
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1141
  if (uncommitted < min_bytes) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1142
    return false;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1143
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1144
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1145
  size_t commit = MIN2(preferred_bytes, uncommitted);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1146
  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
  1147
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1148
  assert(result, "Failed to commit memory");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1149
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1150
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1151
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1152
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1153
Metachunk* VirtualSpaceNode::get_chunk_vs(size_t chunk_word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1154
  assert_lock_strong(SpaceManager::expand_lock());
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1155
  Metachunk* result = take_from_committed(chunk_word_size);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1156
  if (result != NULL) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1157
    inc_container_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1158
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1159
  return result;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1160
}
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
bool VirtualSpaceNode::initialize() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1163
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1164
  if (!_rs.is_reserved()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1165
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1166
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1167
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1168
  // 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
  1169
  // 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
  1170
  // 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
  1171
  assert_is_aligned(_rs.base(), Metaspace::commit_alignment());
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1172
  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
  1173
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1174
  // 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
  1175
  // 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
  1176
  // committed_size and actual_committed_size agrees.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1177
  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
  1178
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1179
  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
  1180
                                            Metaspace::commit_alignment());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1181
  if (result) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1182
    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
  1183
        "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
  1184
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1185
    set_top((MetaWord*)virtual_space()->low());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1186
    set_reserved(MemRegion((HeapWord*)_rs.base(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1187
                 (HeapWord*)(_rs.base() + _rs.size())));
13729
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
  1188
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
  1189
    assert(reserved()->start() == (HeapWord*) _rs.base(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1190
           "Reserved start was not set properly " PTR_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1191
           " != " PTR_FORMAT, p2i(reserved()->start()), p2i(_rs.base()));
13729
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
  1192
    assert(reserved()->word_size() == _rs.size() / BytesPerWord,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1193
           "Reserved size was not set properly " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1194
           " != " SIZE_FORMAT, reserved()->word_size(),
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1195
           _rs.size() / BytesPerWord);
13728
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
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1198
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1199
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1200
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1201
void VirtualSpaceNode::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1202
  size_t used = used_words_in_vs();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1203
  size_t capacity = capacity_words_in_vs();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1204
  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
  1205
  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
  1206
           "[" PTR_FORMAT ", " PTR_FORMAT ", "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1207
           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
  1208
           p2i(vs), capacity / K,
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1209
           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
  1210
           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
  1211
           p2i(vs->high_boundary()));
13728
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
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
  1214
#ifdef ASSERT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1215
void VirtualSpaceNode::mangle() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1216
  size_t word_size = capacity_words_in_vs();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1217
  Copy::fill_to_words((HeapWord*) low(), word_size, 0xf1f1f1f1);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1218
}
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
  1219
#endif // ASSERT
13728
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
// VirtualSpaceList methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1222
// Space allocated from the VirtualSpace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1223
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1224
VirtualSpaceList::~VirtualSpaceList() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1225
  VirtualSpaceListIterator iter(virtual_space_list());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1226
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1227
    VirtualSpaceNode* vsl = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1228
    delete vsl;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1229
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1230
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1231
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1232
void VirtualSpaceList::inc_reserved_words(size_t v) {
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1233
  assert_lock_strong(SpaceManager::expand_lock());
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1234
  _reserved_words = _reserved_words + v;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1235
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1236
void VirtualSpaceList::dec_reserved_words(size_t v) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1237
  assert_lock_strong(SpaceManager::expand_lock());
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1238
  _reserved_words = _reserved_words - v;
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1239
}
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1240
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1241
#define assert_committed_below_limit()                        \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1242
  assert(MetaspaceAux::committed_bytes() <= MaxMetaspaceSize, \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1243
         "Too much committed memory. Committed: " SIZE_FORMAT \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1244
         " limit (MaxMetaspaceSize): " SIZE_FORMAT,           \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1245
         MetaspaceAux::committed_bytes(), MaxMetaspaceSize);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1246
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1247
void VirtualSpaceList::inc_committed_words(size_t v) {
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1248
  assert_lock_strong(SpaceManager::expand_lock());
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1249
  _committed_words = _committed_words + v;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1250
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1251
  assert_committed_below_limit();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1252
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1253
void VirtualSpaceList::dec_committed_words(size_t v) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1254
  assert_lock_strong(SpaceManager::expand_lock());
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1255
  _committed_words = _committed_words - v;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1256
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1257
  assert_committed_below_limit();
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1258
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1259
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1260
void VirtualSpaceList::inc_virtual_space_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1261
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1262
  _virtual_space_count++;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1263
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1264
void VirtualSpaceList::dec_virtual_space_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1265
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1266
  _virtual_space_count--;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1267
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1268
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1269
void ChunkManager::remove_chunk(Metachunk* chunk) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1270
  size_t word_size = chunk->word_size();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1271
  ChunkIndex index = list_index(word_size);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1272
  if (index != HumongousIndex) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1273
    free_chunks(index)->remove_chunk(chunk);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1274
  } else {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1275
    humongous_dictionary()->remove_chunk(chunk);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1276
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1277
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1278
  // Chunk has been removed from the chunks free list, update counters.
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1279
  account_for_removed_chunk(chunk);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1280
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1281
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1282
// Walk the list of VirtualSpaceNodes and delete
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1283
// nodes with a 0 container_count.  Remove Metachunks in
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1284
// the node from their respective freelists.
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1285
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
  1286
  assert(SafepointSynchronize::is_at_safepoint(), "must be called at safepoint for contains to work");
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1287
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1288
  // Don't use a VirtualSpaceListIterator because this
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1289
  // 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
  1290
  VirtualSpaceNode* purged_vsl = NULL;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1291
  VirtualSpaceNode* prev_vsl = virtual_space_list();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1292
  VirtualSpaceNode* next_vsl = prev_vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1293
  while (next_vsl != NULL) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1294
    VirtualSpaceNode* vsl = next_vsl;
36177
b2b76aba8e42 8149643: Remove check of counters in VirtualSpaceNode::inc_container_count
jmasa
parents: 35905
diff changeset
  1295
    DEBUG_ONLY(vsl->verify_container_count();)
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1296
    next_vsl = vsl->next();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1297
    // Don't free the current virtual space since it will likely
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1298
    // be needed soon.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1299
    if (vsl->container_count() == 0 && vsl != current_virtual_space()) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1300
      // Unlink it from the list
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1301
      if (prev_vsl == vsl) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1302
        // 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
  1303
        assert(vsl == virtual_space_list(), "Expected to be the first node");
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1304
        set_virtual_space_list(vsl->next());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1305
      } else {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1306
        prev_vsl->set_next(vsl->next());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1307
      }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1308
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1309
      vsl->purge(chunk_manager);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1310
      dec_reserved_words(vsl->reserved_words());
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1311
      dec_committed_words(vsl->committed_words());
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1312
      dec_virtual_space_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1313
      purged_vsl = vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1314
      delete vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1315
    } else {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1316
      prev_vsl = vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1317
    }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1318
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1319
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1320
  if (purged_vsl != NULL) {
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1321
    // 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
  1322
    VirtualSpaceListIterator iter(virtual_space_list());
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1323
    while (iter.repeat()) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1324
      VirtualSpaceNode* vsl = iter.get_next();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1325
      assert(vsl != purged_vsl, "Purge of vsl failed");
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1326
    }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1327
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1328
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1329
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1330
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1331
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1332
// 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
  1333
// 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
  1334
// unloading time during a safepoint.
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1335
bool VirtualSpaceList::contains(const void* ptr) {
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1336
  // 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
  1337
  // 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
  1338
  VirtualSpaceListIterator iter(virtual_space_list());
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1339
  while (iter.repeat()) {
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1340
    VirtualSpaceNode* vsn = iter.get_next();
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1341
    if (vsn->contains(ptr)) {
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1342
      return true;
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1343
    }
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1344
  }
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1345
  return false;
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1346
}
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1347
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1348
void VirtualSpaceList::retire_current_virtual_space() {
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1349
  assert_lock_strong(SpaceManager::expand_lock());
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1350
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1351
  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
  1352
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1353
  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
  1354
                                  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
  1355
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1356
  vsn->retire(cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1357
}
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1358
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1359
void VirtualSpaceNode::retire(ChunkManager* chunk_manager) {
36177
b2b76aba8e42 8149643: Remove check of counters in VirtualSpaceNode::inc_container_count
jmasa
parents: 35905
diff changeset
  1360
  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
  1361
  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
  1362
    ChunkIndex index = (ChunkIndex)i;
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1363
    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
  1364
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1365
    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
  1366
      Metachunk* chunk = get_chunk_vs(chunk_size);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1367
      assert(chunk != NULL, "allocation should have been successful");
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1368
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1369
      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
  1370
    }
36177
b2b76aba8e42 8149643: Remove check of counters in VirtualSpaceNode::inc_container_count
jmasa
parents: 35905
diff changeset
  1371
    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
  1372
  }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1373
  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
  1374
}
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1375
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1376
VirtualSpaceList::VirtualSpaceList(size_t word_size) :
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1377
                                   _is_class(false),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1378
                                   _virtual_space_list(NULL),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1379
                                   _current_virtual_space(NULL),
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1380
                                   _reserved_words(0),
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1381
                                   _committed_words(0),
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1382
                                   _virtual_space_count(0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1383
  MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1384
                   Mutex::_no_safepoint_check_flag);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1385
  create_new_virtual_space(word_size);
13728
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
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1388
VirtualSpaceList::VirtualSpaceList(ReservedSpace rs) :
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1389
                                   _is_class(true),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1390
                                   _virtual_space_list(NULL),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1391
                                   _current_virtual_space(NULL),
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1392
                                   _reserved_words(0),
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1393
                                   _committed_words(0),
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1394
                                   _virtual_space_count(0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1395
  MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1396
                   Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1397
  VirtualSpaceNode* class_entry = new VirtualSpaceNode(rs);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1398
  bool succeeded = class_entry->initialize();
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1399
  if (succeeded) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1400
    link_vs(class_entry);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1401
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1402
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1403
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1404
size_t VirtualSpaceList::free_bytes() {
47543
198cb8e20aef 8187331: VirtualSpaceList tracks free space on wrong node
zgu
parents: 47216
diff changeset
  1405
  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
  1406
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1407
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1408
// 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
  1409
bool VirtualSpaceList::create_new_virtual_space(size_t vs_word_size) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1410
  assert_lock_strong(SpaceManager::expand_lock());
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1411
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1412
  if (is_class()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1413
    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
  1414
                  " 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
  1415
                  " 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
  1416
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1417
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1418
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1419
  if (vs_word_size == 0) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1420
    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
  1421
    return false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1422
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1423
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1424
  // Reserve the space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1425
  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
  1426
  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
  1427
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1428
  // Allocate the meta virtual space and initialize it.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1429
  VirtualSpaceNode* new_entry = new VirtualSpaceNode(vs_byte_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1430
  if (!new_entry->initialize()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1431
    delete new_entry;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1432
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1433
  } else {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1434
    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
  1435
        "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
  1436
    // 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
  1437
    OrderAccess::storestore();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1438
    link_vs(new_entry);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1439
    return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1440
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1441
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1442
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1443
void VirtualSpaceList::link_vs(VirtualSpaceNode* new_entry) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1444
  if (virtual_space_list() == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1445
      set_virtual_space_list(new_entry);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1446
  } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1447
    current_virtual_space()->set_next(new_entry);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1448
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1449
  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
  1450
  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
  1451
  inc_committed_words(new_entry->committed_words());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1452
  inc_virtual_space_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1453
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1454
  new_entry->mangle();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1455
#endif
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1456
  LogTarget(Trace, gc, metaspace) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1457
  if (lt.is_enabled()) {
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1458
    LogStream ls(lt);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1459
    VirtualSpaceNode* vsl = current_virtual_space();
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  1460
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  1461
    vsl->print_on(&ls);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1462
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1463
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1464
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1465
bool VirtualSpaceList::expand_node_by(VirtualSpaceNode* node,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1466
                                      size_t min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1467
                                      size_t preferred_words) {
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1468
  size_t before = node->committed_words();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1469
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1470
  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
  1471
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1472
  size_t after = node->committed_words();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1473
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1474
  // 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
  1475
  assert(after >= before, "Inconsistency");
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1476
  inc_committed_words(after - before);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1477
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1478
  return result;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1479
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1480
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1481
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
  1482
  assert_is_aligned(min_words,       Metaspace::commit_alignment_words());
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1483
  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
  1484
  assert(min_words <= preferred_words, "Invalid arguments");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1485
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1486
  if (!MetaspaceGC::can_expand(min_words, this->is_class())) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1487
    return  false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1488
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1489
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1490
  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
  1491
  if (allowed_expansion_words < min_words) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1492
    return false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1493
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1494
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1495
  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
  1496
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1497
  // 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
  1498
  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
  1499
                                    min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1500
                                    max_expansion_words);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1501
  if (vs_expanded) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1502
    return true;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1503
  }
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1504
  retire_current_virtual_space();
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1505
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1506
  // Get another virtual space.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1507
  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
  1508
  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
  1509
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1510
  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
  1511
    if (current_virtual_space()->is_pre_committed()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1512
      // 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
  1513
      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
  1514
          "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
  1515
          "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
  1516
      return true;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1517
    }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1518
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1519
    return expand_node_by(current_virtual_space(),
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1520
                          min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1521
                          max_expansion_words);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1522
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1523
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1524
  return false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1525
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1526
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1527
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
  1528
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1529
  // Allocate a chunk out of the current virtual space.
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1530
  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
  1531
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1532
  if (next != NULL) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1533
    return next;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1534
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1535
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1536
  // 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
  1537
  // 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
  1538
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1539
  size_t min_word_size       = align_up(chunk_word_size,              Metaspace::commit_alignment_words());
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1540
  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
  1541
  if (min_word_size >= preferred_word_size) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1542
    // Can happen when humongous chunks are allocated.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1543
    preferred_word_size = min_word_size;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1544
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1545
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1546
  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
  1547
  if (expanded) {
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  1548
    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
  1549
    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
  1550
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1551
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1552
   return next;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1553
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1554
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1555
void VirtualSpaceList::print_on(outputStream* st) const {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  1556
  VirtualSpaceListIterator iter(virtual_space_list());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  1557
  while (iter.repeat()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  1558
    VirtualSpaceNode* node = iter.get_next();
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  1559
    node->print_on(st);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1560
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1561
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1562
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1563
void VirtualSpaceList::print_map(outputStream* st) const {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1564
  VirtualSpaceNode* list = virtual_space_list();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1565
  VirtualSpaceListIterator iter(list);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1566
  unsigned i = 0;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1567
  while (iter.repeat()) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1568
    st->print_cr("Node %u:", i);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1569
    VirtualSpaceNode* node = iter.get_next();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1570
    node->print_map(st, this->is_class());
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1571
    i ++;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1572
  }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1573
}
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  1574
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1575
// MetaspaceGC methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1576
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1577
// VM_CollectForMetadataAllocation is the vm operation used to GC.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1578
// 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
  1579
// 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
  1580
// 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
  1581
// 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
  1582
// gen had bounds, MinMetaspaceExpansion and MaxMetaspaceExpansion.  The
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1583
// 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
  1584
//
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1585
// 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
  1586
// 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
  1587
// 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
  1588
// 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
  1589
// 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
  1590
// 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
  1591
// 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
  1592
// 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
  1593
// the HWM.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1594
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1595
// 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
  1596
// Increase by a minimum amount (MinMetaspaceExpansion) so that
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1597
// 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
  1598
// 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
  1599
// 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
  1600
// plus some.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1601
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
  1602
  size_t min_delta = MinMetaspaceExpansion;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1603
  size_t max_delta = MaxMetaspaceExpansion;
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1604
  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
  1605
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1606
  if (delta <= min_delta) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1607
    delta = min_delta;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1608
  } else if (delta <= max_delta) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1609
    // 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
  1610
    // allocation so make the delta greater than just enough
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1611
    // for this allocation.
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1612
    delta = max_delta;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1613
  } else {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1614
    // 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
  1615
    // so increase by the minimum.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1616
    delta = delta + min_delta;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1617
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1618
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1619
  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
  1620
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1621
  return delta;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1622
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1623
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1624
size_t MetaspaceGC::capacity_until_GC() {
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  1625
  size_t value = OrderAccess::load_acquire(&_capacity_until_GC);
27693
3eee985a97e7 8059492: Wrong spelling in assert: "Not initialied properly?"
aharlap
parents: 27683
diff changeset
  1626
  assert(value >= MetaspaceSize, "Not initialized properly?");
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1627
  return value;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1628
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1629
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1630
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
  1631
  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
  1632
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  1633
  intptr_t capacity_until_GC = _capacity_until_GC;
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  1634
  intptr_t new_value = capacity_until_GC + v;
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1635
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1636
  if (new_value < capacity_until_GC) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1637
    // 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
  1638
    new_value = align_down(max_uintx, Metaspace::commit_alignment());
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1639
  }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1640
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  1641
  intptr_t expected = _capacity_until_GC;
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  1642
  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
  1643
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1644
  if (expected != actual) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1645
    return false;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1646
  }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1647
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1648
  if (new_cap_until_GC != NULL) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1649
    *new_cap_until_GC = new_value;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1650
  }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1651
  if (old_cap_until_GC != NULL) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1652
    *old_cap_until_GC = capacity_until_GC;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1653
  }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1654
  return true;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1655
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1656
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1657
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
  1658
  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
  1659
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  1660
  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
  1661
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1662
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1663
void MetaspaceGC::initialize() {
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1664
  // 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
  1665
  // we can't do a GC during initialization.
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1666
  _capacity_until_GC = MaxMetaspaceSize;
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1667
}
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1668
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1669
void MetaspaceGC::post_initialize() {
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1670
  // Reset the high-water mark once the VM initialization is done.
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1671
  _capacity_until_GC = MAX2(MetaspaceAux::committed_bytes(), MetaspaceSize);
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1672
}
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1673
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1674
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
  1675
  // 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
  1676
  if (is_class && Metaspace::using_class_space()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1677
    size_t class_committed = MetaspaceAux::committed_bytes(Metaspace::ClassType);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1678
    if (class_committed + word_size * BytesPerWord > CompressedClassSpaceSize) {
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
  1679
      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
  1680
    }
16391
7bf8a7699f5f 8004241: NPG: Metaspace occupies more memory than specified by -XX:MaxMetaspaceSize option
mgerdin
parents: 16387
diff changeset
  1681
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1682
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1683
  // Check if the user has imposed a limit on the metaspace memory.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1684
  size_t committed_bytes = MetaspaceAux::committed_bytes();
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1685
  if (committed_bytes + word_size * BytesPerWord > MaxMetaspaceSize) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1686
    return false;
13728
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
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1689
  return true;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1690
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1691
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1692
size_t MetaspaceGC::allowed_expansion() {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1693
  size_t committed_bytes = MetaspaceAux::committed_bytes();
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1694
  size_t capacity_until_gc = capacity_until_GC();
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1695
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1696
  assert(capacity_until_gc >= committed_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1697
         "capacity_until_gc: " SIZE_FORMAT " < committed_bytes: " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1698
         capacity_until_gc, committed_bytes);
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 left_until_max  = MaxMetaspaceSize - committed_bytes;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1701
  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
  1702
  size_t left_to_commit = MIN2(left_until_GC, left_until_max);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1703
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1704
  return left_to_commit / BytesPerWord;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1705
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1706
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1707
void MetaspaceGC::compute_new_size() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1708
  assert(_shrink_factor <= 100, "invalid shrink factor");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1709
  uint current_shrink_factor = _shrink_factor;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1710
  _shrink_factor = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1711
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1712
  // 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
  1713
  // 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
  1714
  // un-fragmented chunk free list is available for future allocations.
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1715
  // 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
  1716
  // 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
  1717
  // 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
  1718
  // 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
  1719
  // shrink below committed_bytes() and this has caused serious bugs in the past.
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1720
  const size_t used_after_gc = MetaspaceAux::committed_bytes();
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1721
  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
  1722
15610
528d799702c7 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 15488
diff changeset
  1723
  const double minimum_free_percentage = MinMetaspaceFreeRatio / 100.0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1724
  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
  1725
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1726
  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
  1727
  size_t minimum_desired_capacity =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1728
    (size_t)MIN2(min_tmp, double(max_uintx));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1729
  // Don't shrink less than the initial generation size
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1730
  minimum_desired_capacity = MAX2(minimum_desired_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1731
                                  MetaspaceSize);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1732
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  1733
  log_trace(gc, metaspace)("MetaspaceGC::compute_new_size: ");
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  1734
  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
  1735
                           minimum_free_percentage, maximum_used_percentage);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  1736
  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
  1737
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1738
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1739
  size_t shrink_bytes = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1740
  if (capacity_until_GC < minimum_desired_capacity) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1741
    // 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
  1742
    // increment the HWM.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1743
    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
  1744
    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
  1745
    // Don't expand unless it's significant
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1746
    if (expand_bytes >= MinMetaspaceExpansion) {
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1747
      size_t new_capacity_until_GC = 0;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1748
      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
  1749
      assert(succeeded, "Should always succesfully increment HWM when at safepoint");
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1750
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1751
      Metaspace::tracer()->report_gc_threshold(capacity_until_GC,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1752
                                               new_capacity_until_GC,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1753
                                               MetaspaceGCThresholdUpdater::ComputeNewSize);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  1754
      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
  1755
                               minimum_desired_capacity / (double) K,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  1756
                               expand_bytes / (double) K,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  1757
                               MinMetaspaceExpansion / (double) K,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  1758
                               new_capacity_until_GC / (double) K);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1759
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1760
    return;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1761
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1762
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1763
  // No expansion, now see if we want to shrink
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1764
  // We would never want to shrink more than this
22499
33777708d0fc 8031779: Assert in MetaspaceGC is always true
ehelin
parents: 22248
diff changeset
  1765
  assert(capacity_until_GC >= minimum_desired_capacity,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1766
         SIZE_FORMAT " >= " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1767
         capacity_until_GC, minimum_desired_capacity);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1768
  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
  1769
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1770
  // Should shrinking be considered?
15610
528d799702c7 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 15488
diff changeset
  1771
  if (MaxMetaspaceFreeRatio < 100) {
528d799702c7 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 15488
diff changeset
  1772
    const double maximum_free_percentage = MaxMetaspaceFreeRatio / 100.0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1773
    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
  1774
    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
  1775
    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
  1776
    maximum_desired_capacity = MAX2(maximum_desired_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1777
                                    MetaspaceSize);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  1778
    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
  1779
                             maximum_free_percentage, minimum_used_percentage);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  1780
    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
  1781
                             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
  1782
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1783
    assert(minimum_desired_capacity <= maximum_desired_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1784
           "sanity check");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1785
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1786
    if (capacity_until_GC > maximum_desired_capacity) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1787
      // Capacity too large, compute shrinking size
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1788
      shrink_bytes = capacity_until_GC - maximum_desired_capacity;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1789
      // 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
  1790
      // 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
  1791
      // 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
  1792
      // 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
  1793
      // 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
  1794
      // 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
  1795
      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
  1796
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1797
      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
  1798
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1799
      assert(shrink_bytes <= max_shrink_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1800
             "invalid shrink size " SIZE_FORMAT " not <= " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1801
             shrink_bytes, max_shrink_bytes);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1802
      if (current_shrink_factor == 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1803
        _shrink_factor = 10;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1804
      } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1805
        _shrink_factor = MIN2(current_shrink_factor * 4, (uint) 100);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1806
      }
37151
bcda1fb89431 8151845: Comment in globals.hpp for MetaspaceSize is incorrect.
jmasa
parents: 37139
diff changeset
  1807
      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
  1808
                               MetaspaceSize / (double) K, maximum_desired_capacity / (double) K);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  1809
      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
  1810
                               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
  1811
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1812
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1813
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1814
  // 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
  1815
  if (shrink_bytes >= MinMetaspaceExpansion &&
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1816
      ((capacity_until_GC - shrink_bytes) >= MetaspaceSize)) {
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1817
    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
  1818
    Metaspace::tracer()->report_gc_threshold(capacity_until_GC,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1819
                                             new_capacity_until_GC,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1820
                                             MetaspaceGCThresholdUpdater::ComputeNewSize);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1821
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1822
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1823
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1824
// Metadebug methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1825
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1826
void Metadebug::init_allocation_fail_alot_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1827
  if (MetadataAllocationFailALot) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1828
    _allocation_fail_alot_count =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1829
      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
  1830
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1831
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1832
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1833
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1834
bool Metadebug::test_metadata_failure() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1835
  if (MetadataAllocationFailALot &&
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1836
      Threads::is_vm_complete()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1837
    if (_allocation_fail_alot_count > 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1838
      _allocation_fail_alot_count--;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1839
    } else {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  1840
      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
  1841
      init_allocation_fail_alot_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1842
      return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1843
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1844
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1845
  return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1846
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1847
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1848
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1849
// ChunkManager methods
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  1850
size_t ChunkManager::free_chunks_total_words() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1851
  return _free_chunks_total;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1852
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1853
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  1854
size_t ChunkManager::free_chunks_total_bytes() {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  1855
  return free_chunks_total_words() * BytesPerWord;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1856
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1857
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1858
// Update internal accounting after a chunk was added
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1859
void ChunkManager::account_for_added_chunk(const Metachunk* c) {
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1860
  assert_lock_strong(SpaceManager::expand_lock());
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1861
  _free_chunks_count ++;
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1862
  _free_chunks_total += c->word_size();
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1863
}
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1864
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1865
// Update internal accounting after a chunk was removed
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1866
void ChunkManager::account_for_removed_chunk(const Metachunk* c) {
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1867
  assert_lock_strong(SpaceManager::expand_lock());
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1868
  assert(_free_chunks_count >= 1,
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1869
    "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
  1870
  assert(_free_chunks_total >= c->word_size(),
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1871
    "ChunkManager::_free_chunks_total: about to go negative"
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1872
     "(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
  1873
  _free_chunks_count --;
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1874
  _free_chunks_total -= c->word_size();
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1875
}
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  1876
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1877
size_t ChunkManager::free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1878
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1879
  if (!UseConcMarkSweepGC && !SpaceManager::expand_lock()->is_locked()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1880
    MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1881
                     Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1882
    // 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
  1883
    // 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
  1884
    slow_locked_verify_free_chunks_count();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1885
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1886
#endif
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1887
  return _free_chunks_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1888
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1889
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1890
ChunkIndex ChunkManager::list_index(size_t size) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1891
  if (size_by_index(SpecializedIndex) == size) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1892
    return SpecializedIndex;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1893
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1894
  if (size_by_index(SmallIndex) == size) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1895
    return SmallIndex;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1896
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1897
  const size_t med_size = size_by_index(MediumIndex);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1898
  if (med_size == size) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1899
    return MediumIndex;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1900
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1901
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1902
  assert(size > med_size, "Not a humongous chunk");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1903
  return HumongousIndex;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1904
}
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1905
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  1906
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
  1907
  index_bounds_check(index);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1908
  assert(index != HumongousIndex, "Do not call for humongous chunks.");
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  1909
  return _free_chunks[index].size();
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1910
}
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  1911
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1912
void ChunkManager::locked_verify_free_chunks_total() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1913
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1914
  assert(sum_free_chunks() == _free_chunks_total,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1915
         "_free_chunks_total " SIZE_FORMAT " is not the"
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1916
         " same as sum " SIZE_FORMAT, _free_chunks_total,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1917
         sum_free_chunks());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1918
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1919
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1920
void ChunkManager::verify_free_chunks_total() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1921
  MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1922
                     Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1923
  locked_verify_free_chunks_total();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1924
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1925
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1926
void ChunkManager::locked_verify_free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1927
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1928
  assert(sum_free_chunks_count() == _free_chunks_count,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1929
         "_free_chunks_count " SIZE_FORMAT " is not the"
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1930
         " same as sum " SIZE_FORMAT, _free_chunks_count,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  1931
         sum_free_chunks_count());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1932
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1933
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1934
void ChunkManager::verify_free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1935
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1936
  MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1937
                     Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1938
  locked_verify_free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1939
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1940
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1941
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1942
void ChunkManager::verify() {
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1943
  MutexLockerEx cl(SpaceManager::expand_lock(),
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1944
                     Mutex::_no_safepoint_check_flag);
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1945
  locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1946
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1947
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1948
void ChunkManager::locked_verify() {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1949
  locked_verify_free_chunks_count();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1950
  locked_verify_free_chunks_total();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1951
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1952
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1953
void ChunkManager::locked_print_free_chunks(outputStream* st) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1954
  assert_lock_strong(SpaceManager::expand_lock());
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1955
  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
  1956
                _free_chunks_total, _free_chunks_count);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1957
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1958
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1959
void ChunkManager::locked_print_sum_free_chunks(outputStream* st) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1960
  assert_lock_strong(SpaceManager::expand_lock());
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1961
  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
  1962
                sum_free_chunks(), sum_free_chunks_count());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1963
}
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  1964
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1965
ChunkList* ChunkManager::free_chunks(ChunkIndex index) {
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  1966
  assert(index == SpecializedIndex || index == SmallIndex || index == MediumIndex,
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  1967
         "Bad index: %d", (int)index);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  1968
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1969
  return &_free_chunks[index];
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1970
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1971
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1972
// 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
  1973
// methods that are used in product builds.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1974
size_t ChunkManager::sum_free_chunks() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1975
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1976
  size_t result = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1977
  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
  1978
    ChunkList* list = free_chunks(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1979
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1980
    if (list == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1981
      continue;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1982
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1983
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  1984
    result = result + list->count() * list->size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1985
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1986
  result = result + humongous_dictionary()->total_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1987
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1988
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1989
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1990
size_t ChunkManager::sum_free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1991
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1992
  size_t count = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1993
  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
  1994
    ChunkList* list = free_chunks(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1995
    if (list == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1996
      continue;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1997
    }
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  1998
    count = count + list->count();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1999
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2000
  count = count + humongous_dictionary()->total_free_blocks();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2001
  return count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2002
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2003
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2004
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
  2005
  ChunkIndex index = list_index(word_size);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2006
  assert(index < HumongousIndex, "No humongous list");
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2007
  return free_chunks(index);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2008
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2009
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2010
Metachunk* ChunkManager::free_chunks_get(size_t word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2011
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2012
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2013
  slow_locked_verify();
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2014
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2015
  Metachunk* chunk = NULL;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2016
  if (list_index(word_size) != HumongousIndex) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2017
    ChunkList* free_list = find_free_chunks_list(word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2018
    assert(free_list != NULL, "Sanity check");
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2019
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2020
    chunk = free_list->head();
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2021
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2022
    if (chunk == NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2023
      return NULL;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2024
    }
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2025
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2026
    // 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
  2027
    free_list->remove_chunk(chunk);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2028
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2029
    log_trace(gc, metaspace, freelist)("ChunkManager::free_chunks_get: free_list " PTR_FORMAT " head " PTR_FORMAT " size " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2030
                                       p2i(free_list), p2i(chunk), chunk->word_size());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2031
  } else {
46674
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46625
diff changeset
  2032
    chunk = humongous_dictionary()->get_chunk(word_size);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2033
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2034
    if (chunk == NULL) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2035
      return NULL;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2036
    }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2037
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2038
    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
  2039
                                    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
  2040
  }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2041
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2042
  // Chunk has been removed from the chunk manager; update counters.
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2043
  account_for_removed_chunk(chunk);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2044
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2045
  // 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
  2046
  chunk->set_next(NULL);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2047
  chunk->set_prev(NULL);
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2048
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2049
  // Chunk is no longer on any freelist. Setting to false make container_count_slow()
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2050
  // work.
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  2051
  chunk->set_is_tagged_free(false);
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2052
  chunk->container()->inc_container_count();
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2053
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2054
  slow_locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2055
  return chunk;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2056
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2057
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2058
Metachunk* ChunkManager::chunk_freelist_allocate(size_t word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2059
  assert_lock_strong(SpaceManager::expand_lock());
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2060
  slow_locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2061
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2062
  // Take from the beginning of the list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2063
  Metachunk* chunk = free_chunks_get(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2064
  if (chunk == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2065
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2066
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2067
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2068
  assert((word_size <= chunk->word_size()) ||
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  2069
         (list_index(chunk->word_size()) == HumongousIndex),
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2070
         "Non-humongous variable sized chunk");
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2071
  LogTarget(Debug, gc, metaspace, freelist) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2072
  if (lt.is_enabled()) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2073
    size_t list_count;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2074
    if (list_index(word_size) < HumongousIndex) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2075
      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
  2076
      list_count = list->count();
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2077
    } else {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2078
      list_count = humongous_dictionary()->total_count();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2079
    }
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2080
    LogStream ls(lt);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2081
    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
  2082
             p2i(this), p2i(chunk), chunk->word_size(), list_count);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2083
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2084
    locked_print_free_chunks(&ls);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2085
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2086
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2087
  return chunk;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2088
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2089
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2090
void ChunkManager::return_single_chunk(ChunkIndex index, Metachunk* chunk) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2091
  assert_lock_strong(SpaceManager::expand_lock());
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2092
  assert(chunk != NULL, "Expected chunk.");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2093
  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
  2094
  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
  2095
  index_bounds_check(index);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2096
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2097
  // 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
  2098
  // 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
  2099
  // keeps tree node pointers in the chunk payload area which mangle will overwrite.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2100
  NOT_PRODUCT(chunk->mangle(badMetaWordVal);)
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2101
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2102
  if (index != HumongousIndex) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2103
    // 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
  2104
    ChunkList* list = free_chunks(index);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2105
    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
  2106
    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
  2107
    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
  2108
        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
  2109
  } else {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2110
    // Return humongous chunk to dictionary.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2111
    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
  2112
    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
  2113
           "Humongous chunk has wrong alignment.");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2114
    _humongous_dictionary.return_chunk(chunk);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2115
    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
  2116
        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
  2117
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2118
  chunk->container()->dec_container_count();
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  2119
  chunk->set_is_tagged_free(true);
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2120
46360
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2121
  // Chunk has been added; update counters.
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2122
  account_for_added_chunk(chunk);
c753322134b0 8170520: Make Metaspace ChunkManager counters non-atomic
stuefe
parents: 46333
diff changeset
  2123
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2124
}
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2125
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2126
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
  2127
  index_bounds_check(index);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2128
  if (chunks == NULL) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2129
    return;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2130
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2131
  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
  2132
  if (log.is_enabled()) { // tracing
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2133
    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
  2134
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2135
  unsigned num_chunks_returned = 0;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2136
  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
  2137
  Metachunk* cur = chunks;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2138
  while (cur != NULL) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2139
    // 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
  2140
    // 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
  2141
    Metachunk* next = cur->next();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2142
    if (log.is_enabled()) { // tracing
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2143
      num_chunks_returned ++;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2144
      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
  2145
    }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2146
    return_single_chunk(index, cur);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2147
    cur = next;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2148
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2149
  if (log.is_enabled()) { // tracing
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2150
    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
  2151
        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
  2152
    if (index != HumongousIndex) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2153
      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
  2154
    } else {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2155
      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
  2156
    }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2157
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2158
}
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2159
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2160
void ChunkManager::print_on(outputStream* out) const {
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2161
  _humongous_dictionary.report_statistics(out);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2162
}
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2163
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2164
void ChunkManager::locked_get_statistics(ChunkManagerStatistics* stat) const {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2165
  assert_lock_strong(SpaceManager::expand_lock());
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2166
  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
  2167
    stat->num_by_type[i] = num_free_chunks(i);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2168
    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
  2169
    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
  2170
  }
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2171
  stat->num_humongous_chunks = num_free_chunks(HumongousIndex);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2172
  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
  2173
}
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2174
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2175
void ChunkManager::get_statistics(ChunkManagerStatistics* stat) const {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2176
  MutexLockerEx cl(SpaceManager::expand_lock(),
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2177
                   Mutex::_no_safepoint_check_flag);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2178
  locked_get_statistics(stat);
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2179
}
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2180
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2181
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
  2182
  size_t total = 0;
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2183
  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
  2184
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2185
  const char* unit = scale_unit(scale);
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2186
  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
  2187
    out->print("  " SIZE_FORMAT " %s (" SIZE_FORMAT " bytes) chunks, total ",
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2188
                   stat->num_by_type[i], chunk_size_name(i),
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2189
                   stat->single_size_by_type[i]);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2190
    if (scale == 1) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2191
      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
  2192
    } else {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2193
      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
  2194
    }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2195
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2196
    total += stat->total_size_by_type[i];
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2197
  }
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2198
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2199
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2200
  total += stat->total_size_humongous_chunks;
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2201
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2202
  if (scale == 1) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2203
    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
  2204
    stat->num_humongous_chunks, stat->total_size_humongous_chunks);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2205
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2206
    out->print_cr("  total size: " SIZE_FORMAT " bytes.", total);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2207
  } else {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2208
    out->print_cr("  " SIZE_FORMAT " humongous chunks, total %.2f%s",
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2209
    stat->num_humongous_chunks,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2210
    (float)stat->total_size_humongous_chunks / scale, unit);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2211
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2212
    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
  2213
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2214
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2215
}
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2216
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2217
void ChunkManager::print_all_chunkmanagers(outputStream* out, size_t scale) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2218
  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
  2219
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2220
  // 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
  2221
  // out of lock protection
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2222
  ChunkManagerStatistics stat;
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2223
  out->print_cr("Chunkmanager (non-class):");
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2224
  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
  2225
  if (non_class_cm != NULL) {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2226
    non_class_cm->get_statistics(&stat);
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2227
    ChunkManager::print_statistics(&stat, out, scale);
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2228
  } else {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2229
    out->print_cr("unavailable.");
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2230
  }
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2231
  out->print_cr("Chunkmanager (class):");
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2232
  const ChunkManager* const class_cm = Metaspace::chunk_manager_class();
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2233
  if (class_cm != NULL) {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2234
    class_cm->get_statistics(&stat);
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  2235
    ChunkManager::print_statistics(&stat, out, scale);
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2236
  } else {
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2237
    out->print_cr("unavailable.");
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  2238
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2239
}
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2240
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2241
// SpaceManager methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2242
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2243
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
  2244
  size_t chunk_sizes[] = {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2245
      specialized_chunk_size(is_class_space),
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2246
      small_chunk_size(is_class_space),
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2247
      medium_chunk_size(is_class_space)
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2248
  };
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2249
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2250
  // Adjust up to one of the fixed chunk sizes ...
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2251
  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
  2252
    if (requested <= chunk_sizes[i]) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2253
      return chunk_sizes[i];
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2254
    }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2255
  }
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2256
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2257
  // ... or return the size as a humongous chunk.
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2258
  return requested;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2259
}
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2260
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2261
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
  2262
  return adjust_initial_chunk_size(requested, is_class());
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2263
}
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2264
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2265
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
  2266
  size_t requested;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2267
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2268
  if (is_class()) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2269
    switch (type) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2270
    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
  2271
    case Metaspace::AnonymousMetaspaceType:  requested = ClassSpecializedChunk; break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2272
    case Metaspace::ReflectionMetaspaceType: requested = ClassSpecializedChunk; break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2273
    default:                                 requested = ClassSmallChunk; break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2274
    }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2275
  } else {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2276
    switch (type) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2277
    case Metaspace::BootMetaspaceType:       requested = Metaspace::first_chunk_word_size(); break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2278
    case Metaspace::AnonymousMetaspaceType:  requested = SpecializedChunk; break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2279
    case Metaspace::ReflectionMetaspaceType: requested = SpecializedChunk; break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2280
    default:                                 requested = SmallChunk; break;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2281
    }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2282
  }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2283
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2284
  // Adjust to one of the fixed chunk sizes (unless humongous)
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2285
  const size_t adjusted = adjust_initial_chunk_size(requested);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2286
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2287
  assert(adjusted != 0, "Incorrect initial chunk size. Requested: "
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2288
         SIZE_FORMAT " adjusted: " SIZE_FORMAT, requested, adjusted);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2289
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2290
  return adjusted;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2291
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2292
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2293
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
  2294
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2295
  size_t free = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2296
  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
  2297
    Metachunk* chunk = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2298
    while (chunk != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2299
      free += chunk->free_word_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2300
      chunk = chunk->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2301
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2302
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2303
  return free;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2304
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2305
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2306
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
  2307
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2308
  size_t result = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2309
  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
  2310
   result += sum_waste_in_chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2311
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2312
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2313
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2314
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2315
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2316
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
  2317
  size_t result = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2318
  Metachunk* chunk = chunks_in_use(index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2319
  // 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
  2320
  // 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
  2321
  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
  2322
    if (chunk != current_chunk()) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2323
      result += chunk->free_word_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2324
    }
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
  2325
    chunk = chunk->next();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2326
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2327
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2328
}
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
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
  2331
  // 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
  2332
  // 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
  2333
  // 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
  2334
  // 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
  2335
  // 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
  2336
  // 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
  2337
  // 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
  2338
  // answer.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2339
  if (UseConcMarkSweepGC) {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2340
    return allocated_chunks_words();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2341
  } else {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2342
    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
  2343
    size_t sum = 0;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2344
    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
  2345
      Metachunk* chunk = chunks_in_use(i);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2346
      while (chunk != NULL) {
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  2347
        sum += chunk->word_size();
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2348
        chunk = chunk->next();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2349
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2350
    }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2351
  return sum;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2352
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2353
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2354
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2355
size_t SpaceManager::sum_count_in_chunks_in_use() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2356
  size_t count = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2357
  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
  2358
    count = count + sum_count_in_chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2359
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2360
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2361
  return count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2362
}
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
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
  2365
  size_t count = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2366
  Metachunk* chunk = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2367
  while (chunk != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2368
    count++;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2369
    chunk = chunk->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2370
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2371
  return count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2372
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2373
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2374
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2375
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
  2376
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2377
  size_t used = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2378
  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
  2379
    Metachunk* chunk = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2380
    while (chunk != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2381
      used += chunk->used_word_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2382
      chunk = chunk->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2383
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2384
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2385
  return used;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2386
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2387
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2388
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
  2389
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2390
  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
  2391
    Metachunk* chunk = chunks_in_use(i);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2392
    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
  2393
                 chunk_size_name(i), p2i(chunk));
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2394
    if (chunk != NULL) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2395
      st->print_cr(" free " SIZE_FORMAT,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2396
                   chunk->free_word_size());
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2397
    } else {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24351
diff changeset
  2398
      st->cr();
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2399
    }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2400
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2401
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2402
  chunk_manager()->locked_print_free_chunks(st);
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2403
  chunk_manager()->locked_print_sum_free_chunks(st);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2404
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2405
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2406
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
  2407
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2408
  // 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
  2409
  // _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
  2410
  // After that a medium chunk is preferred.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2411
  size_t chunk_word_size;
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  2412
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  2413
  // Special case for anonymous metadata space.
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  2414
  // 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
  2415
  // rarely about 4K (64-bits JVM).
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  2416
  // Instead of jumping to SmallChunk after initial chunk exhausted, keeping allocation
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  2417
  // from SpecializeChunk up to _anon_metadata_specialize_chunk_limit (4) reduces space waste
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  2418
  // from 60+% to around 30%.
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  2419
  if (_space_type == Metaspace::AnonymousMetaspaceType &&
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  2420
      _mdtype == Metaspace::NonClassType &&
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  2421
      sum_count_in_chunks_in_use(SpecializedIndex) < _anon_metadata_specialize_chunk_limit &&
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  2422
      word_size + Metachunk::overhead() <= SpecializedChunk) {
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  2423
    return SpecializedChunk;
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  2424
  }
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  2425
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2426
  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
  2427
      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
  2428
    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
  2429
    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
  2430
      chunk_word_size = medium_chunk_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2431
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2432
  } else {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2433
    chunk_word_size = medium_chunk_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2434
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2435
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2436
  // 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
  2437
  // 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
  2438
  // the smallest chunk size.
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2439
  size_t if_humongous_sized_chunk =
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  2440
    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
  2441
                  smallest_chunk_size());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2442
  chunk_word_size =
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2443
    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
  2444
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2445
  assert(!SpaceManager::is_humongous(word_size) ||
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2446
         chunk_word_size == if_humongous_sized_chunk,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2447
         "Size calculation is wrong, word_size " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2448
         " chunk_word_size " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2449
         word_size, chunk_word_size);
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37151
diff changeset
  2450
  Log(gc, metaspace, alloc) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2451
  if (log.is_debug() && SpaceManager::is_humongous(word_size)) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2452
    log.debug("Metadata humongous allocation:");
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2453
    log.debug("  word_size " PTR_FORMAT, word_size);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2454
    log.debug("  chunk_word_size " PTR_FORMAT, chunk_word_size);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2455
    log.debug("    chunk overhead " PTR_FORMAT, Metachunk::overhead());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2456
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2457
  return chunk_word_size;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2458
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2459
20407
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2460
void SpaceManager::track_metaspace_memory_usage() {
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2461
  if (is_init_completed()) {
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2462
    if (is_class()) {
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2463
      MemoryService::track_compressed_class_memory_usage();
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2464
    }
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2465
    MemoryService::track_metaspace_memory_usage();
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2466
  }
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2467
}
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2468
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2469
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
  2470
  assert(vs_list()->current_virtual_space() != NULL,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2471
         "Should have been set");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2472
  assert(current_chunk() == NULL ||
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2473
         current_chunk()->allocate(word_size) == NULL,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2474
         "Don't need to expand");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2475
  MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2476
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2477
  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
  2478
    size_t words_left = 0;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2479
    size_t words_used = 0;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2480
    if (current_chunk() != NULL) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2481
      words_left = current_chunk()->free_word_size();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2482
      words_used = current_chunk()->used_word_size();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2483
    }
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2484
    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
  2485
                                       word_size, words_used, words_left);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2486
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2487
31028
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2488
  // Get another chunk
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2489
  size_t chunk_word_size = calc_chunk_size(word_size);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2490
  Metachunk* next = get_new_chunk(chunk_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2491
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2492
  MetaWord* mem = NULL;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2493
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2494
  // 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
  2495
  // and do an allocation from it.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2496
  if (next != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2497
    // 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
  2498
    add_chunk(next, false);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2499
    mem = next->allocate(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2500
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2501
20407
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2502
  // Track metaspace memory usage statistic.
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2503
  track_metaspace_memory_usage();
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2504
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2505
  return mem;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2506
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2507
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2508
void SpaceManager::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2509
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2510
  for (ChunkIndex i = ZeroIndex;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2511
       i < NumberOfInUseLists ;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2512
       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
  2513
    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
  2514
                 p2i(chunks_in_use(i)),
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2515
                 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
  2516
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2517
  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
  2518
               " Humongous " SIZE_FORMAT,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2519
               sum_waste_in_chunks_in_use(SmallIndex),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2520
               sum_waste_in_chunks_in_use(MediumIndex),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2521
               sum_waste_in_chunks_in_use(HumongousIndex));
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2522
  // block free lists
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2523
  if (block_freelists() != NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2524
    st->print_cr("total in block free lists " SIZE_FORMAT,
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2525
      block_freelists()->total_size());
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2526
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2527
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2528
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2529
SpaceManager::SpaceManager(Metaspace::MetadataType mdtype,
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  2530
                           Metaspace::MetaspaceType space_type,
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2531
                           Mutex* lock) :
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2532
  _mdtype(mdtype),
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  2533
  _space_type(space_type),
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2534
  _allocated_blocks_words(0),
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2535
  _allocated_chunks_words(0),
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2536
  _allocated_chunks_count(0),
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2537
  _block_freelists(NULL),
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2538
  _lock(lock)
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2539
{
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2540
  initialize();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2541
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2542
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2543
void SpaceManager::inc_size_metrics(size_t words) {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2544
  assert_lock_strong(SpaceManager::expand_lock());
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2545
  // 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
  2546
  // for each SpaceManager
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2547
  _allocated_chunks_words = _allocated_chunks_words + words;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2548
  _allocated_chunks_count++;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2549
  // Global total of capacity in allocated Metachunks
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2550
  MetaspaceAux::inc_capacity(mdtype(), words);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2551
  // Global total of allocated Metablocks.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2552
  // 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
  2553
  // 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
  2554
  // 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
  2555
  // Metachunk).
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2556
  MetaspaceAux::inc_used(mdtype(), Metachunk::overhead());
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2557
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2558
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2559
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
  2560
  // Add to the per SpaceManager total
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  2561
  Atomic::add(words, &_allocated_blocks_words);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2562
  // Add to the global total
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2563
  MetaspaceAux::inc_used(mdtype(), words);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2564
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2565
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2566
void SpaceManager::dec_total_from_size_metrics() {
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2567
  MetaspaceAux::dec_capacity(mdtype(), allocated_chunks_words());
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2568
  MetaspaceAux::dec_used(mdtype(), allocated_blocks_words());
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2569
  // Also deduct the overhead per Metachunk
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2570
  MetaspaceAux::dec_used(mdtype(), allocated_chunks_count() * Metachunk::overhead());
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2571
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2572
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2573
void SpaceManager::initialize() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2574
  Metadebug::init_allocation_fail_alot_count();
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2575
  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
  2576
    _chunks_in_use[i] = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2577
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2578
  _current_chunk = NULL;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2579
  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
  2580
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2581
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2582
SpaceManager::~SpaceManager() {
16385
4a05c6d94b04 8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents: 15954
diff changeset
  2583
  // This call this->_lock which can't be done while holding expand_lock()
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2584
  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
  2585
         "sum_capacity_in_chunks_in_use() " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2586
         " allocated_chunks_words() " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2587
         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
  2588
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2589
  MutexLockerEx fcl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2590
                    Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2591
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2592
  chunk_manager()->slow_locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2593
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2594
  dec_total_from_size_metrics();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2595
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37151
diff changeset
  2596
  Log(gc, metaspace, freelist) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2597
  if (log.is_trace()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2598
    log.trace("~SpaceManager(): " PTR_FORMAT, p2i(this));
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2599
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2600
    LogStream ls(log.trace());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2601
    locked_print_chunks_in_use_on(&ls);
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2602
    if (block_freelists() != NULL) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2603
      block_freelists()->print_on(&ls);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2604
    }
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2605
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2606
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2607
  // 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
  2608
  // to the global list of free chunks.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2609
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2610
  // 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
  2611
  // free lists.  Each list is NULL terminated.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2612
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  2613
  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
  2614
    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
  2615
    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
  2616
    set_chunks_in_use(i, NULL);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2617
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2618
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2619
  chunk_manager()->slow_locked_verify();
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2620
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2621
  if (_block_freelists != NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2622
    delete _block_freelists;
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2623
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2624
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2625
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2626
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
  2627
  assert_lock_strong(_lock);
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2628
  // Allocations and deallocations are in raw_word_size
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2629
  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
  2630
  // Lazily create a block_freelist
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2631
  if (block_freelists() == NULL) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2632
    _block_freelists = new BlockFreelist();
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2633
  }
18987
a1b541fe1159 8019845: Memory leak during class redefinition
fparain
parents: 18492
diff changeset
  2634
  block_freelists()->return_block(p, raw_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2635
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2636
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2637
// 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
  2638
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
  2639
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2640
  assert(new_chunk != NULL, "Should not be NULL");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2641
  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
  2642
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2643
  new_chunk->reset_empty();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2644
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2645
  // Find the correct list and and set the current
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2646
  // chunk for that list.
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  2647
  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
  2648
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2649
  if (index != HumongousIndex) {
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2650
    retire_current_chunk();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2651
    set_current_chunk(new_chunk);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2652
    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
  2653
    set_chunks_in_use(index, new_chunk);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2654
  } else {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2655
    // 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
  2656
    // 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
  2657
    // chunk.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2658
    if (make_current) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2659
      // 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
  2660
      set_current_chunk(new_chunk);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2661
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2662
    // 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
  2663
    // 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
  2664
    // 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
  2665
    // of the humongous chunks list.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2666
    new_chunk->set_next(chunks_in_use(HumongousIndex));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2667
    set_chunks_in_use(HumongousIndex, new_chunk);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2668
15087
8849ea877278 8005486: NPG: Incorrect assertion in ChunkManager::list_index()
jmasa
parents: 15086
diff changeset
  2669
    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
  2670
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2671
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2672
  // Add to the running sum of capacity
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2673
  inc_size_metrics(new_chunk->word_size());
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2674
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2675
  assert(new_chunk->is_empty(), "Not ready for reuse");
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37151
diff changeset
  2676
  Log(gc, metaspace, freelist) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2677
  if (log.is_trace()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2678
    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
  2679
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2680
    LogStream ls(log.trace());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2681
    new_chunk->print_on(&ls);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  2682
    chunk_manager()->locked_print_free_chunks(&ls);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2683
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2684
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2685
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2686
void SpaceManager::retire_current_chunk() {
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2687
  if (current_chunk() != NULL) {
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2688
    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
  2689
    if (remaining_words >= BlockFreelist::min_dictionary_size()) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2690
      MetaWord* ptr = current_chunk()->allocate(remaining_words);
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2691
      deallocate(ptr, remaining_words);
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2692
      inc_used_metrics(remaining_words);
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2693
    }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2694
  }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2695
}
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2696
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2697
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
  2698
  // Get a chunk from the chunk freelist
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2699
  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
  2700
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2701
  if (next == NULL) {
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  2702
    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
  2703
                                    medium_chunk_bunch());
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2704
  }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2705
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37151
diff changeset
  2706
  Log(gc, metaspace, alloc) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2707
  if (log.is_debug() && next != NULL &&
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2708
      SpaceManager::is_humongous(next->word_size())) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2709
    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
  2710
  }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2711
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2712
  return next;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2713
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2714
31028
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2715
/*
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2716
 * The policy is to allocate up to _small_chunk_limit small chunks
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2717
 * after which only medium chunks are allocated.  This is done to
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2718
 * reduce fragmentation.  In some cases, this can result in a lot
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2719
 * of small chunks being allocated to the point where it's not
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2720
 * possible to expand.  If this happens, there may be no medium chunks
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2721
 * available and OOME would be thrown.  Instead of doing that,
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2722
 * if the allocation request size fits in a small chunk, an attempt
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2723
 * will be made to allocate a small chunk.
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2724
 */
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2725
MetaWord* SpaceManager::get_small_chunk_and_allocate(size_t word_size) {
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2726
  size_t raw_word_size = get_allocation_word_size(word_size);
31374
9280d10f1f26 8085987: Vm crash "not long aligned" in nsk/stress/metaspace/jck60/jck6* tests
jprovino
parents: 31362
diff changeset
  2727
9280d10f1f26 8085987: Vm crash "not long aligned" in nsk/stress/metaspace/jck60/jck6* tests
jprovino
parents: 31362
diff changeset
  2728
  if (raw_word_size + Metachunk::overhead() > small_chunk_size()) {
31028
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2729
    return NULL;
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2730
  }
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2731
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2732
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2733
  MutexLockerEx cl1(expand_lock(), Mutex::_no_safepoint_check_flag);
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2734
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2735
  Metachunk* chunk = chunk_manager()->chunk_freelist_allocate(small_chunk_size());
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2736
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2737
  MetaWord* mem = NULL;
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2738
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2739
  if (chunk != NULL) {
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2740
    // Add chunk to the in-use chunk list and do an allocation from it.
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2741
    // Add to this manager's list of chunks in use.
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2742
    add_chunk(chunk, false);
31374
9280d10f1f26 8085987: Vm crash "not long aligned" in nsk/stress/metaspace/jck60/jck6* tests
jprovino
parents: 31362
diff changeset
  2743
    mem = chunk->allocate(raw_word_size);
9280d10f1f26 8085987: Vm crash "not long aligned" in nsk/stress/metaspace/jck60/jck6* tests
jprovino
parents: 31362
diff changeset
  2744
9280d10f1f26 8085987: Vm crash "not long aligned" in nsk/stress/metaspace/jck60/jck6* tests
jprovino
parents: 31362
diff changeset
  2745
    inc_used_metrics(raw_word_size);
31028
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2746
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2747
    // Track metaspace memory usage statistic.
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2748
    track_metaspace_memory_usage();
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2749
  }
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2750
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2751
  return mem;
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2752
}
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  2753
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2754
MetaWord* SpaceManager::allocate(size_t word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2755
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2756
  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
  2757
  BlockFreelist* fl =  block_freelists();
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2758
  MetaWord* p = NULL;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2759
  // 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
  2760
  // 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
  2761
  // 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
  2762
  // 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
  2763
  // for allocations.  Do some profiling.  JJJ
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2764
  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
  2765
    p = fl->get_block(raw_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2766
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2767
  if (p == NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2768
    p = allocate_work(raw_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2769
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2770
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2771
  return p;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2772
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2773
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2774
// Returns the address of spaced allocated for "word_size".
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2775
// This methods does not know about blocks (Metablocks)
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2776
MetaWord* SpaceManager::allocate_work(size_t word_size) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2777
  assert_lock_strong(_lock);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2778
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2779
  if (Metadebug::test_metadata_failure()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2780
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2781
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2782
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2783
  // Is there space in the current chunk?
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2784
  MetaWord* result = NULL;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2785
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2786
  if (current_chunk() != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2787
    result = current_chunk()->allocate(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2788
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2789
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2790
  if (result == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2791
    result = grow_and_allocate(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2792
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2793
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2794
  if (result != NULL) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2795
    inc_used_metrics(word_size);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2796
    assert(result != (MetaWord*) chunks_in_use(MediumIndex),
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2797
           "Head of the list is being allocated");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2798
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2799
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2800
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2801
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2802
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2803
void SpaceManager::verify() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2804
  // If there are blocks in the dictionary, then
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22499
diff changeset
  2805
  // verification of chunks does not work since
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2806
  // being in the dictionary alters a chunk.
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2807
  if (block_freelists() != NULL && block_freelists()->total_size() == 0) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2808
    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
  2809
      Metachunk* curr = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2810
      while (curr != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2811
        curr->verify();
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2812
        verify_chunk_size(curr);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2813
        curr = curr->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2814
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2815
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2816
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2817
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2818
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2819
void SpaceManager::verify_chunk_size(Metachunk* chunk) {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2820
  assert(is_humongous(chunk->word_size()) ||
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2821
         chunk->word_size() == medium_chunk_size() ||
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2822
         chunk->word_size() == small_chunk_size() ||
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2823
         chunk->word_size() == specialized_chunk_size(),
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2824
         "Chunk size is wrong");
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2825
  return;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2826
}
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2827
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2828
#ifdef ASSERT
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2829
void SpaceManager::verify_allocated_blocks_words() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2830
  // 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
  2831
  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
  2832
    "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
  2833
  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
  2834
         "allocation total is not consistent " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2835
         " vs " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2836
         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
  2837
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2838
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2839
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2840
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2841
void SpaceManager::dump(outputStream* const out) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2842
  size_t curr_total = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2843
  size_t waste = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2844
  uint i = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2845
  size_t used = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2846
  size_t capacity = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2847
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2848
  // 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
  2849
  for (ChunkIndex index = ZeroIndex;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2850
       index < NumberOfInUseLists;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2851
       index = next_chunk_index(index)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2852
    for (Metachunk* curr = chunks_in_use(index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2853
         curr != NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2854
         curr = curr->next()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2855
      out->print("%d) ", i++);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2856
      curr->print_on(out);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2857
      curr_total += curr->word_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2858
      used += curr->used_word_size();
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  2859
      capacity += curr->word_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2860
      waste += curr->free_word_size() + curr->overhead();;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2861
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2862
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2863
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  2864
  if (log_is_enabled(Trace, gc, metaspace, freelist)) {
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  2865
    if (block_freelists() != NULL) block_freelists()->print_on(out);
19992
ecae893d6947 8024751: Fix bugs in TraceMetadata
stefank
parents: 19990
diff changeset
  2866
  }
ecae893d6947 8024751: Fix bugs in TraceMetadata
stefank
parents: 19990
diff changeset
  2867
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2868
  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
  2869
  // Free space isn't wasted.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2870
  waste -= free;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2871
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2872
  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
  2873
                " free " SIZE_FORMAT " capacity " SIZE_FORMAT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2874
                " waste " SIZE_FORMAT, curr_total, used, free, capacity, waste);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2875
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2876
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2877
// MetaspaceAux
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2878
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2879
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2880
size_t MetaspaceAux::_capacity_words[] = {0, 0};
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47543
diff changeset
  2881
volatile size_t MetaspaceAux::_used_words[] = {0, 0};
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2882
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2883
size_t MetaspaceAux::free_bytes(Metaspace::MetadataType mdtype) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2884
  VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2885
  return list == NULL ? 0 : list->free_bytes();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2886
}
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2887
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2888
size_t MetaspaceAux::free_bytes() {
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2889
  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
  2890
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2891
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2892
void MetaspaceAux::dec_capacity(Metaspace::MetadataType mdtype, size_t words) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2893
  assert_lock_strong(SpaceManager::expand_lock());
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2894
  assert(words <= capacity_words(mdtype),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2895
         "About to decrement below 0: words " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2896
         " is greater than _capacity_words[%u] " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2897
         words, mdtype, capacity_words(mdtype));
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2898
  _capacity_words[mdtype] -= words;
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2899
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2900
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2901
void MetaspaceAux::inc_capacity(Metaspace::MetadataType mdtype, size_t words) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2902
  assert_lock_strong(SpaceManager::expand_lock());
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2903
  // Needs to be atomic
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2904
  _capacity_words[mdtype] += words;
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2905
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2906
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2907
void MetaspaceAux::dec_used(Metaspace::MetadataType mdtype, size_t words) {
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2908
  assert(words <= used_words(mdtype),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2909
         "About to decrement below 0: words " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2910
         " is greater than _used_words[%u] " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2911
         words, mdtype, used_words(mdtype));
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2912
  // For CMS deallocation of the Metaspaces occurs during the
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2913
  // sweep which is a concurrent phase.  Protection by the expand_lock()
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2914
  // 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
  2915
  // and protected by the Metaspace lock.
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  2916
  Atomic::sub(words, &_used_words[mdtype]);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2917
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2918
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2919
void MetaspaceAux::inc_used(Metaspace::MetadataType mdtype, size_t words) {
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2920
  // _used_words tracks allocations for
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2921
  // each piece of metadata.  Those allocations are
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2922
  // generally done concurrently by different application
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2923
  // threads so must be done atomically.
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47599
diff changeset
  2924
  Atomic::add(words, &_used_words[mdtype]);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2925
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2926
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2927
size_t MetaspaceAux::used_bytes_slow(Metaspace::MetadataType mdtype) {
13733
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2928
  size_t used = 0;
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2929
  ClassLoaderDataGraphMetaspaceIterator iter;
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2930
  while (iter.repeat()) {
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2931
    Metaspace* msp = iter.get_next();
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2932
    // Sum allocated_blocks_words for each metaspace
13733
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2933
    if (msp != NULL) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2934
      used += msp->used_words_slow(mdtype);
13733
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2935
    }
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2936
  }
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2937
  return used * BytesPerWord;
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2938
}
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2939
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2940
size_t MetaspaceAux::free_bytes_slow(Metaspace::MetadataType mdtype) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2941
  size_t free = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2942
  ClassLoaderDataGraphMetaspaceIterator iter;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2943
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2944
    Metaspace* msp = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2945
    if (msp != NULL) {
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2946
      free += msp->free_words_slow(mdtype);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2947
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2948
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2949
  return free * BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2950
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2951
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2952
size_t MetaspaceAux::capacity_bytes_slow(Metaspace::MetadataType mdtype) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2953
  if ((mdtype == Metaspace::ClassType) && !Metaspace::using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2954
    return 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2955
  }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2956
  // 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
  2957
  // added to the capacity calculation as needed.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2958
  size_t capacity = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2959
  ClassLoaderDataGraphMetaspaceIterator iter;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2960
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2961
    Metaspace* msp = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2962
    if (msp != NULL) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2963
      capacity += msp->capacity_words_slow(mdtype);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2964
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2965
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2966
  return capacity * BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2967
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2968
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2969
size_t MetaspaceAux::capacity_bytes_slow() {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2970
#ifdef PRODUCT
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2971
  // Use capacity_bytes() in PRODUCT instead of this function.
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2972
  guarantee(false, "Should not call capacity_bytes_slow() in the PRODUCT");
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2973
#endif
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2974
  size_t class_capacity = capacity_bytes_slow(Metaspace::ClassType);
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2975
  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
  2976
  assert(capacity_bytes() == class_capacity + non_class_capacity,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2977
         "bad accounting: capacity_bytes() " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2978
         " class_capacity + non_class_capacity " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2979
         " class_capacity " SIZE_FORMAT " non_class_capacity " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2980
         capacity_bytes(), class_capacity + non_class_capacity,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  2981
         class_capacity, non_class_capacity);
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2982
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2983
  return class_capacity + non_class_capacity;
13728
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
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2986
size_t MetaspaceAux::reserved_bytes(Metaspace::MetadataType mdtype) {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2987
  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
  2988
  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
  2989
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2990
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2991
size_t MetaspaceAux::committed_bytes(Metaspace::MetadataType mdtype) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2992
  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
  2993
  return list == NULL ? 0 : list->committed_bytes();
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2994
}
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2995
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2996
size_t MetaspaceAux::min_chunk_size_words() { return Metaspace::first_chunk_word_size(); }
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2997
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2998
size_t MetaspaceAux::free_chunks_total_words(Metaspace::MetadataType mdtype) {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2999
  ChunkManager* chunk_manager = Metaspace::get_chunk_manager(mdtype);
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3000
  if (chunk_manager == NULL) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3001
    return 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3002
  }
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3003
  chunk_manager->slow_verify();
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3004
  return chunk_manager->free_chunks_total_words();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3005
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3006
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3007
size_t MetaspaceAux::free_chunks_total_bytes(Metaspace::MetadataType mdtype) {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3008
  return free_chunks_total_words(mdtype) * BytesPerWord;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3009
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3010
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3011
size_t MetaspaceAux::free_chunks_total_words() {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3012
  return free_chunks_total_words(Metaspace::ClassType) +
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3013
         free_chunks_total_words(Metaspace::NonClassType);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3014
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3015
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3016
size_t MetaspaceAux::free_chunks_total_bytes() {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3017
  return free_chunks_total_words() * BytesPerWord;
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3018
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3019
23470
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3020
bool MetaspaceAux::has_chunk_free_list(Metaspace::MetadataType mdtype) {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3021
  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
  3022
}
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3023
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3024
MetaspaceChunkFreeListSummary MetaspaceAux::chunk_free_list_summary(Metaspace::MetadataType mdtype) {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3025
  if (!has_chunk_free_list(mdtype)) {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3026
    return MetaspaceChunkFreeListSummary();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3027
  }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3028
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3029
  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
  3030
  return cm->chunk_free_list_summary();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3031
}
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  3032
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3033
void MetaspaceAux::print_metaspace_change(size_t prev_metadata_used) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3034
  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
  3035
                          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
  3036
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3037
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3038
void MetaspaceAux::print_on(outputStream* out) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3039
  Metaspace::MetadataType nct = Metaspace::NonClassType;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3040
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3041
  out->print_cr(" Metaspace       "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3042
                "used "      SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3043
                "capacity "  SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3044
                "committed " SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3045
                "reserved "  SIZE_FORMAT "K",
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3046
                used_bytes()/K,
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3047
                capacity_bytes()/K,
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3048
                committed_bytes()/K,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3049
                reserved_bytes()/K);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3050
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3051
  if (Metaspace::using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3052
    Metaspace::MetadataType ct = Metaspace::ClassType;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3053
    out->print_cr("  class space    "
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3054
                  "used "      SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3055
                  "capacity "  SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3056
                  "committed " SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3057
                  "reserved "  SIZE_FORMAT "K",
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3058
                  used_bytes(ct)/K,
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3059
                  capacity_bytes(ct)/K,
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3060
                  committed_bytes(ct)/K,
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3061
                  reserved_bytes(ct)/K);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3062
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3063
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3064
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3065
// Print information for class space and data space separately.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3066
// This is almost the same as above.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3067
void MetaspaceAux::print_on(outputStream* out, Metaspace::MetadataType mdtype) {
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3068
  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
  3069
  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
  3070
  size_t used_bytes = used_bytes_slow(mdtype);
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3071
  size_t free_bytes = free_bytes_slow(mdtype);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3072
  size_t used_and_free = used_bytes + free_bytes +
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3073
                           free_chunks_capacity_bytes;
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3074
  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
  3075
             "K + unused in chunks " SIZE_FORMAT "K  + "
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3076
             " 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
  3077
             "K  capacity in allocated chunks " SIZE_FORMAT "K",
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3078
             used_bytes / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3079
             free_bytes / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3080
             free_chunks_capacity_bytes / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3081
             used_and_free / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3082
             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
  3083
  // 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
  3084
  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
  3085
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3086
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3087
// Print total fragmentation for class metaspaces
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3088
void MetaspaceAux::print_class_waste(outputStream* out) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3089
  assert(Metaspace::using_class_space(), "class metaspace not used");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3090
  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
  3091
  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
  3092
  ClassLoaderDataGraphMetaspaceIterator iter;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3093
  while (iter.repeat()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3094
    Metaspace* msp = iter.get_next();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3095
    if (msp != NULL) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3096
      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
  3097
      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
  3098
      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
  3099
      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
  3100
      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
  3101
      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
  3102
      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
  3103
    }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3104
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3105
  out->print_cr(" class: " SIZE_FORMAT " specialized(s) " SIZE_FORMAT ", "
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3106
                SIZE_FORMAT " small(s) " SIZE_FORMAT ", "
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3107
                SIZE_FORMAT " medium(s) " SIZE_FORMAT ", "
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3108
                "large count " SIZE_FORMAT,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3109
                cls_specialized_count, cls_specialized_waste,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3110
                cls_small_count, cls_small_waste,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3111
                cls_medium_count, cls_medium_waste, cls_humongous_count);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3112
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3113
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3114
// Print total fragmentation for data and class metaspaces separately
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3115
void MetaspaceAux::print_waste(outputStream* out) {
18491
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  3116
  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
  3117
  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
  3118
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3119
  ClassLoaderDataGraphMetaspaceIterator iter;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3120
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3121
    Metaspace* msp = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3122
    if (msp != NULL) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3123
      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
  3124
      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
  3125
      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
  3126
      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
  3127
      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
  3128
      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
  3129
      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
  3130
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3131
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3132
  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
  3133
  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
  3134
                        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
  3135
                        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
  3136
                        "large count " SIZE_FORMAT,
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3137
             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
  3138
             small_waste, medium_count, medium_waste, humongous_count);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3139
  if (Metaspace::using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3140
    print_class_waste(out);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3141
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3142
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3143
47802
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3144
class MetadataStats VALUE_OBJ_CLASS_SPEC {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3145
private:
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3146
  size_t _capacity;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3147
  size_t _used;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3148
  size_t _free;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3149
  size_t _waste;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3150
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3151
public:
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3152
  MetadataStats() : _capacity(0), _used(0), _free(0), _waste(0) { }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3153
  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
  3154
  : _capacity(capacity), _used(used), _free(free), _waste(waste) { }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3155
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3156
  void add(const MetadataStats& stats) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3157
    _capacity += stats.capacity();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3158
    _used += stats.used();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3159
    _free += stats.free();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3160
    _waste += stats.waste();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3161
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3162
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3163
  size_t capacity() const { return _capacity; }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3164
  size_t used() const     { return _used; }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3165
  size_t free() const     { return _free; }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3166
  size_t waste() const    { return _waste; }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3167
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3168
  void print_on(outputStream* out, size_t scale) const;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3169
};
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3170
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3171
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3172
void MetadataStats::print_on(outputStream* out, size_t scale) const {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3173
  const char* unit = scale_unit(scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3174
  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
  3175
    (float)capacity() / scale, unit,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3176
    (float)used() / scale, unit,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3177
    (float)free() / scale, unit,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3178
    (float)waste() / scale, unit);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3179
}
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3180
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3181
class PrintCLDMetaspaceInfoClosure : public CLDClosure {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3182
private:
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3183
  outputStream*  _out;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3184
  size_t         _scale;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3185
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3186
  size_t         _total_count;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3187
  MetadataStats  _total_metadata;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3188
  MetadataStats  _total_class;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3189
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3190
  size_t         _total_anon_count;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3191
  MetadataStats  _total_anon_metadata;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3192
  MetadataStats  _total_anon_class;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3193
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3194
public:
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3195
  PrintCLDMetaspaceInfoClosure(outputStream* out, size_t scale = K)
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3196
  : _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
  3197
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3198
  ~PrintCLDMetaspaceInfoClosure() {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3199
    print_summary();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3200
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3201
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3202
  void do_cld(ClassLoaderData* cld) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3203
    assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3204
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3205
    if (cld->is_unloading()) return;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3206
    Metaspace* msp = cld->metaspace_or_null();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3207
    if (msp == NULL) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3208
      return;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3209
    }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3210
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3211
    bool anonymous = false;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3212
    if (cld->is_anonymous()) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3213
      _out->print_cr("ClassLoader: for anonymous class");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3214
      anonymous = true;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3215
    } else {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3216
      ResourceMark rm;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3217
      _out->print_cr("ClassLoader: %s", cld->loader_name());
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3218
    }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3219
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3220
    print_metaspace(msp, anonymous);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3221
    _out->cr();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3222
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3223
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3224
private:
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3225
  void print_metaspace(Metaspace* msp, bool anonymous);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3226
  void print_summary() const;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3227
};
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3228
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3229
void PrintCLDMetaspaceInfoClosure::print_metaspace(Metaspace* msp, bool anonymous){
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3230
  assert(msp != NULL, "Sanity");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3231
  SpaceManager* vsm = msp->vsm();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3232
  const char* unit = scale_unit(_scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3233
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3234
  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
  3235
  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
  3236
  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
  3237
  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
  3238
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3239
  _total_count ++;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3240
  MetadataStats metadata_stats(capacity, used, free, waste);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3241
  _total_metadata.add(metadata_stats);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3242
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3243
  if (anonymous) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3244
    _total_anon_count ++;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3245
    _total_anon_metadata.add(metadata_stats);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3246
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3247
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3248
  _out->print("  Metadata   ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3249
  metadata_stats.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3250
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3251
  if (Metaspace::using_class_space()) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3252
    vsm = msp->class_vsm();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3253
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3254
    capacity = vsm->sum_capacity_in_chunks_in_use() * BytesPerWord;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3255
    used = vsm->sum_used_in_chunks_in_use() * BytesPerWord;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3256
    free = vsm->sum_free_in_chunks_in_use() * BytesPerWord;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3257
    waste = vsm->sum_waste_in_chunks_in_use() * BytesPerWord;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3258
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3259
    MetadataStats class_stats(capacity, used, free, waste);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3260
    _total_class.add(class_stats);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3261
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3262
    if (anonymous) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3263
      _total_anon_class.add(class_stats);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3264
    }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3265
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3266
    _out->print("  Class data ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3267
    class_stats.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3268
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3269
}
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3270
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3271
void PrintCLDMetaspaceInfoClosure::print_summary() const {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3272
  const char* unit = scale_unit(_scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3273
  _out->cr();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3274
  _out->print_cr("Summary:");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3275
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3276
  MetadataStats total;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3277
  total.add(_total_metadata);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3278
  total.add(_total_class);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3279
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3280
  _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
  3281
  total.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3282
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3283
  _out->print("                    Metadata ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3284
  _total_metadata.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3285
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3286
  if (Metaspace::using_class_space()) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3287
    _out->print("                  Class data ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3288
    _total_class.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3289
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3290
  _out->cr();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3291
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3292
  MetadataStats total_anon;
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3293
  total_anon.add(_total_anon_metadata);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3294
  total_anon.add(_total_anon_class);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3295
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3296
  _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
  3297
  total_anon.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3298
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3299
  _out->print("                    Metadata ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3300
  _total_anon_metadata.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3301
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3302
  if (Metaspace::using_class_space()) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3303
    _out->print("                  Class data ");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3304
    _total_anon_class.print_on(_out, _scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3305
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3306
}
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3307
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3308
void MetaspaceAux::print_metadata_for_nmt(outputStream* out, size_t scale) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3309
  const char* unit = scale_unit(scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3310
  out->print_cr("Metaspaces:");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3311
  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
  3312
    reserved_bytes(Metaspace::NonClassType) / scale, unit,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3313
    committed_bytes(Metaspace::NonClassType) / scale, unit);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3314
  if (Metaspace::using_class_space()) {
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3315
    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
  3316
    reserved_bytes(Metaspace::ClassType) / scale, unit,
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3317
    committed_bytes(Metaspace::ClassType) / scale, unit);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3318
  }
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3319
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3320
  out->cr();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3321
  ChunkManager::print_all_chunkmanagers(out, scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3322
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3323
  out->cr();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3324
  out->print_cr("Per-classloader metadata:");
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3325
  out->cr();
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3326
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3327
  PrintCLDMetaspaceInfoClosure cl(out, scale);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3328
  ClassLoaderDataGraph::cld_do(&cl);
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3329
}
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3330
18dccdc438d7 8189688: NMT: Report per-class load metadata information
zgu
parents: 47654
diff changeset
  3331
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3332
// Dump global metaspace things from the end of ClassLoaderDataGraph
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3333
void MetaspaceAux::dump(outputStream* out) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3334
  out->print_cr("All Metaspace:");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3335
  out->print("data space: "); print_on(out, Metaspace::NonClassType);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3336
  out->print("class space: "); print_on(out, Metaspace::ClassType);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3337
  print_waste(out);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3338
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3339
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3340
// Prints an ASCII representation of the given space.
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3341
void MetaspaceAux::print_metaspace_map(outputStream* out, Metaspace::MetadataType mdtype) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3342
  MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3343
  const bool for_class = mdtype == Metaspace::ClassType ? true : false;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3344
  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
  3345
  if (vsl != NULL) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3346
    if (for_class) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3347
      if (!Metaspace::using_class_space()) {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3348
        out->print_cr("No Class Space.");
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3349
        return;
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3350
      }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3351
      out->print_raw("---- Metaspace Map (Class Space) ----");
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3352
    } else {
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3353
      out->print_raw("---- Metaspace Map (Non-Class Space) ----");
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3354
    }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3355
    // Print legend:
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3356
    out->cr();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3357
    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
  3358
    out->cr();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3359
    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
  3360
    vsl->print_map(out);
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3361
    out->cr();
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3362
  }
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3363
}
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  3364
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  3365
void MetaspaceAux::verify_free_chunks() {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3366
  Metaspace::chunk_manager_metadata()->verify();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3367
  if (Metaspace::using_class_space()) {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3368
    Metaspace::chunk_manager_class()->verify();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3369
  }
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  3370
}
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  3371
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3372
void MetaspaceAux::verify_capacity() {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3373
#ifdef ASSERT
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3374
  size_t running_sum_capacity_bytes = capacity_bytes();
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3375
  // 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
  3376
  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
  3377
  assert(running_sum_capacity_bytes == capacity_in_use_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3378
         "capacity_words() * BytesPerWord " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3379
         " capacity_bytes_slow()" SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3380
         running_sum_capacity_bytes, capacity_in_use_bytes);
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3381
  for (Metaspace::MetadataType i = Metaspace::ClassType;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3382
       i < Metaspace:: MetadataTypeCount;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3383
       i = (Metaspace::MetadataType)(i + 1)) {
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3384
    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
  3385
    assert(capacity_bytes(i) == capacity_in_use_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3386
           "capacity_bytes(%u) " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3387
           " capacity_bytes_slow(%u)" SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3388
           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
  3389
  }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3390
#endif
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3391
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3392
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3393
void MetaspaceAux::verify_used() {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3394
#ifdef ASSERT
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  3395
  size_t running_sum_used_bytes = used_bytes();
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3396
  // 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
  3397
  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
  3398
  assert(used_bytes() == used_in_use_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3399
         "used_bytes() " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3400
         " used_bytes_slow()" SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3401
         used_bytes(), used_in_use_bytes);
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3402
  for (Metaspace::MetadataType i = Metaspace::ClassType;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3403
       i < Metaspace:: MetadataTypeCount;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3404
       i = (Metaspace::MetadataType)(i + 1)) {
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  3405
    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
  3406
    assert(used_bytes(i) == used_in_use_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3407
           "used_bytes(%u) " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3408
           " used_bytes_slow(%u)" SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3409
           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
  3410
  }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3411
#endif
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3412
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3413
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3414
void MetaspaceAux::verify_metrics() {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3415
  verify_capacity();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3416
  verify_used();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3417
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3418
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3419
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3420
// Metaspace methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3421
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3422
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
  3423
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
  3424
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3425
size_t Metaspace::_commit_alignment = 0;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3426
size_t Metaspace::_reserve_alignment = 0;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3427
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3428
Metaspace::Metaspace(Mutex* lock, MetaspaceType type) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3429
  initialize(lock, type);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3430
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3431
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3432
Metaspace::~Metaspace() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3433
  delete _vsm;
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3434
  if (using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3435
    delete _class_vsm;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3436
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3437
}
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
VirtualSpaceList* Metaspace::_space_list = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3440
VirtualSpaceList* Metaspace::_class_space_list = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3441
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3442
ChunkManager* Metaspace::_chunk_manager_metadata = NULL;
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3443
ChunkManager* Metaspace::_chunk_manager_class = NULL;
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3444
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3445
#define VIRTUALSPACEMULTIPLIER 2
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3446
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3447
#ifdef _LP64
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3448
static const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1);
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3449
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3450
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
  3451
  assert(!DumpSharedSpaces, "narrow_klass is set by MetaspaceShared class.");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3452
  // 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
  3453
  // 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
  3454
  // (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
  3455
  // between the lower base and higher address.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3456
  address lower_base;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3457
  address higher_address;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3458
#if INCLUDE_CDS
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3459
  if (UseSharedSpaces) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3460
    higher_address = MAX2((address)(cds_base + MetaspaceShared::core_spaces_size()),
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3461
                          (address)(metaspace_base + compressed_class_space_size()));
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3462
    lower_base = MIN2(metaspace_base, cds_base);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3463
  } else
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3464
#endif
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3465
  {
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3466
    higher_address = metaspace_base + compressed_class_space_size();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3467
    lower_base = metaspace_base;
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3468
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3469
    uint64_t klass_encoding_max = UnscaledClassSpaceMax << LogKlassAlignmentInBytes;
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3470
    // 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
  3471
    if (higher_address <= (address)klass_encoding_max) {
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22499
diff changeset
  3472
      lower_base = 0; // Effectively lower base is zero.
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3473
    }
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3474
  }
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3475
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3476
  Universe::set_narrow_klass_base(lower_base);
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3477
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  3478
  // 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
  3479
  // 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
  3480
  // 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
  3481
  // 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
  3482
  // 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
  3483
  // 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
  3484
  if (!UseSharedSpaces
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  3485
      && (uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3486
    Universe::set_narrow_klass_shift(0);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3487
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3488
    Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3489
  }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 42621
diff changeset
  3490
  AOTLoader::set_narrow_klass_shift();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3491
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3492
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3493
#if INCLUDE_CDS
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3494
// 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
  3495
// to work with compressed klass pointers.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3496
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
  3497
  assert(cds_base != 0 && UseSharedSpaces, "Only use with CDS");
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3498
  assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3499
  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
  3500
  address higher_address = MAX2((address)(cds_base + MetaspaceShared::core_spaces_size()),
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3501
                                (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
  3502
  return ((uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3503
}
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3504
#endif
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3505
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3506
// Try to allocate the metaspace at the requested addr.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3507
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
  3508
  assert(!DumpSharedSpaces, "compress klass space is allocated by MetaspaceShared class.");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3509
  assert(using_class_space(), "called improperly");
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3510
  assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3511
  assert(compressed_class_space_size() < KlassEncodingMetaspaceMax,
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3512
         "Metaspace size is too big");
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  3513
  assert_is_aligned(requested_addr, _reserve_alignment);
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  3514
  assert_is_aligned(cds_base, _reserve_alignment);
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  3515
  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
  3516
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3517
  // 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
  3518
  bool large_pages = false;
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3519
39229
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  3520
#if !(defined(AARCH64) || defined(AIX))
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3521
  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
  3522
                                             _reserve_alignment,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3523
                                             large_pages,
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28163
diff changeset
  3524
                                             requested_addr);
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3525
#else // AARCH64
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3526
  ReservedSpace metaspace_rs;
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3527
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3528
  // Our compressed klass pointers may fit nicely into the lower 32
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3529
  // bits.
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3530
  if ((uint64_t)requested_addr + compressed_class_space_size() < 4*G) {
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3531
    metaspace_rs = ReservedSpace(compressed_class_space_size(),
39229
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  3532
                                 _reserve_alignment,
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  3533
                                 large_pages,
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  3534
                                 requested_addr);
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3535
  }
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3536
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3537
  if (! metaspace_rs.is_reserved()) {
39229
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  3538
    // 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
  3539
    // 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
  3540
    // 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
  3541
    // 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
  3542
    // the base, 4G alignment is helpful, too.
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  3543
    size_t increment = AARCH64_ONLY(4*)G;
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  3544
    for (char *a = align_up(requested_addr, increment);
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3545
         a < (char*)(1024*G);
39229
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  3546
         a += increment) {
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  3547
      if (a == (char *)(32*G)) {
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  3548
        // 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
  3549
        increment = 4*G;
8bfc00dd44b6 8159056: [aix] Compressed class space not allocated in lower regions
goetz
parents: 37267
diff changeset
  3550
      }
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3551
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3552
#if INCLUDE_CDS
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3553
      if (UseSharedSpaces
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3554
          && ! can_use_cds_with_metaspace_addr(a, cds_base)) {
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3555
        // We failed to find an aligned base that will reach.  Fall
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3556
        // back to using our requested addr.
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3557
        metaspace_rs = ReservedSpace(compressed_class_space_size(),
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3558
                                     _reserve_alignment,
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3559
                                     large_pages,
29187
b3e445e08548 8071563: AARCH64 staging fail to build
enevill
parents: 29185
diff changeset
  3560
                                     requested_addr);
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3561
        break;
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3562
      }
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3563
#endif
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3564
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3565
      metaspace_rs = ReservedSpace(compressed_class_space_size(),
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3566
                                   _reserve_alignment,
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3567
                                   large_pages,
29187
b3e445e08548 8071563: AARCH64 staging fail to build
enevill
parents: 29185
diff changeset
  3568
                                   a);
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3569
      if (metaspace_rs.is_reserved())
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3570
        break;
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3571
    }
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3572
  }
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3573
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3574
#endif // AARCH64
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3575
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3576
  if (!metaspace_rs.is_reserved()) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3577
#if INCLUDE_CDS
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3578
    if (UseSharedSpaces) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  3579
      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
  3580
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3581
      // Keep trying to allocate the metaspace, increasing the requested_addr
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3582
      // 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
  3583
      // use of CDS with compressed klass pointers.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3584
      char *addr = requested_addr;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3585
      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
  3586
             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
  3587
        addr = addr + increment;
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3588
        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
  3589
                                     _reserve_alignment, large_pages, addr);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3590
      }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3591
    }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3592
#endif
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3593
    // 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
  3594
    // 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
  3595
    // metaspace as if UseCompressedClassPointers is off because too much
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3596
    // initialization has happened that depends on UseCompressedClassPointers.
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3597
    // So, UseCompressedClassPointers cannot be turned off at this point.
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3598
    if (!metaspace_rs.is_reserved()) {
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3599
      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
  3600
                                   _reserve_alignment, large_pages);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3601
      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
  3602
        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
  3603
                                              compressed_class_space_size()));
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3604
      }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3605
    }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3606
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3607
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3608
  // If we got here then the metaspace got allocated.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3609
  MemTracker::record_virtual_memory_type((address)metaspace_rs.base(), mtClass);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3610
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3611
#if INCLUDE_CDS
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3612
  // Verify that we can use shared spaces.  Otherwise, turn off CDS.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3613
  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
  3614
    FileMapInfo::stop_sharing_and_unmap(
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3615
        "Could not allocate metaspace at a compatible address");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3616
  }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3617
#endif
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3618
  set_narrow_klass_base_and_shift((address)metaspace_rs.base(),
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3619
                                  UseSharedSpaces ? (address)cds_base : 0);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3620
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3621
  initialize_class_space(metaspace_rs);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3622
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3623
  LogTarget(Trace, gc, metaspace) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3624
  if (lt.is_enabled()) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3625
    ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3626
    LogStream ls(lt);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  3627
    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
  3628
  }
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  3629
}
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  3630
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  3631
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
  3632
  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
  3633
               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
  3634
  if (_class_space_list != NULL) {
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  3635
    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
  3636
    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
  3637
                 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
  3638
    if (requested_addr != 0) {
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  3639
      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
  3640
    }
60081f497e75 8035074: hs_err improvement: Add time zone information in the hs_err file
coleenp
parents: 31028
diff changeset
  3641
    st->cr();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3642
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3643
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3644
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3645
// 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
  3646
// 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
  3647
void Metaspace::initialize_class_space(ReservedSpace rs) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3648
  // 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
  3649
  assert(rs.size() >= CompressedClassSpaceSize,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  3650
         SIZE_FORMAT " != " SIZE_FORMAT, rs.size(), CompressedClassSpaceSize);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3651
  assert(using_class_space(), "Must be using class space");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3652
  _class_space_list = new VirtualSpaceList(rs);
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3653
  _chunk_manager_class = new ChunkManager(ClassSpecializedChunk, ClassSmallChunk, ClassMediumChunk);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3654
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3655
  if (!_class_space_list->initialization_succeeded()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3656
    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
  3657
  }
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3658
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3659
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3660
#endif
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3661
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3662
void Metaspace::ergo_initialize() {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3663
  if (DumpSharedSpaces) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3664
    // 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
  3665
    FLAG_SET_ERGO(bool, UseLargePagesInMetaspace, false);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3666
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3667
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3668
  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
  3669
  if (UseLargePages && UseLargePagesInMetaspace) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3670
    page_size = os::large_page_size();
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3671
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3672
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3673
  _commit_alignment  = page_size;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3674
  _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
  3675
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3676
  // 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
  3677
  // 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
  3678
  // 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
  3679
  // java.lang.management.MemoryUsage API.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3680
  //
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3681
  // 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
  3682
  // 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
  3683
  // alignment depends on other flags being parsed.
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  3684
  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
  3685
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3686
  if (MetaspaceSize > MaxMetaspaceSize) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3687
    MetaspaceSize = MaxMetaspaceSize;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3688
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3689
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  3690
  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
  3691
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3692
  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
  3693
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  3694
  MinMetaspaceExpansion = align_down_bounded(MinMetaspaceExpansion, _commit_alignment);
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  3695
  MaxMetaspaceExpansion = align_down_bounded(MaxMetaspaceExpansion, _commit_alignment);
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  3696
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  3697
  CompressedClassSpaceSize = align_down_bounded(CompressedClassSpaceSize, _reserve_alignment);
47654
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  3698
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  3699
  // 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
  3700
  size_t min_metaspace_sz =
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  3701
      VIRTUALSPACEMULTIPLIER * InitialBootClassLoaderMetaspaceSize;
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  3702
  if (UseCompressedClassPointers) {
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  3703
    if ((min_metaspace_sz + CompressedClassSpaceSize) >  MaxMetaspaceSize) {
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  3704
      if (min_metaspace_sz >= MaxMetaspaceSize) {
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  3705
        vm_exit_during_initialization("MaxMetaspaceSize is too small.");
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  3706
      } else {
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  3707
        FLAG_SET_ERGO(size_t, CompressedClassSpaceSize,
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  3708
                      MaxMetaspaceSize - min_metaspace_sz);
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  3709
      }
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  3710
    }
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  3711
  } else if (min_metaspace_sz >= MaxMetaspaceSize) {
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  3712
    FLAG_SET_ERGO(size_t, InitialBootClassLoaderMetaspaceSize,
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  3713
                  min_metaspace_sz);
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  3714
  }
dbd1f4f276ba 8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
ysuenaga
parents: 47634
diff changeset
  3715
48387
7daebcef2e0d 8193386: CompressedClassSize too large with MaxMetaspace
coleenp
parents: 48148
diff changeset
  3716
  set_compressed_class_space_size(CompressedClassSpaceSize);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3717
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3718
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3719
void Metaspace::global_initialize() {
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  3720
  MetaspaceGC::initialize();
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  3721
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3722
#if INCLUDE_CDS
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3723
  if (DumpSharedSpaces) {
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  3724
    MetaspaceShared::initialize_dumptime_shared_and_meta_spaces();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3725
  } else if (UseSharedSpaces) {
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  3726
    // 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
  3727
    // 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
  3728
    // (!DumpSharedSpaces && !UseSharedSpaces) case to set up class
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  3729
    // metaspace.
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  3730
    MetaspaceShared::initialize_runtime_shared_and_meta_spaces();
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  3731
  }
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  3732
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  3733
  if (!DumpSharedSpaces && !UseSharedSpaces)
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  3734
#endif // INCLUDE_CDS
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  3735
  {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3736
#ifdef _LP64
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  3737
    if (using_class_space()) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  3738
      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
  3739
      allocate_metaspace_compressed_klass_ptrs(base, 0);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3740
    }
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47553
diff changeset
  3741
#endif // _LP64
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3742
  }
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3743
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3744
  // Initialize these before initializing the VirtualSpaceList
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3745
  _first_chunk_word_size = InitialBootClassLoaderMetaspaceSize / BytesPerWord;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3746
  _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
  3747
  // 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
  3748
  // 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
  3749
  // from there.  This size calculated by -version.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3750
  _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
  3751
                                     (CompressedClassSpaceSize/BytesPerWord)*2);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3752
  _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
  3753
  // Arbitrarily set the initial virtual space to a multiple
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3754
  // of the boot class loader size.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3755
  size_t word_size = VIRTUALSPACEMULTIPLIER * _first_chunk_word_size;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3756
  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
  3757
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3758
  // Initialize the list of virtual spaces.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3759
  _space_list = new VirtualSpaceList(word_size);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3760
  _chunk_manager_metadata = new ChunkManager(SpecializedChunk, SmallChunk, MediumChunk);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3761
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3762
  if (!_space_list->initialization_succeeded()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3763
    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
  3764
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3765
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  3766
  _tracer = new MetaspaceTracer();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3767
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3768
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  3769
void Metaspace::post_initialize() {
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  3770
  MetaspaceGC::post_initialize();
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  3771
}
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  3772
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3773
void Metaspace::initialize_first_chunk(MetaspaceType type, MetadataType mdtype) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3774
  Metachunk* chunk = get_initialization_chunk(type, mdtype);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3775
  if (chunk != NULL) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3776
    // Add to this manager's list of chunks in use and current_chunk().
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3777
    get_space_manager(mdtype)->add_chunk(chunk, true);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3778
  }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3779
}
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3780
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3781
Metachunk* Metaspace::get_initialization_chunk(MetaspaceType type, MetadataType mdtype) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3782
  size_t chunk_word_size = get_space_manager(mdtype)->get_initial_chunk_size(type);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3783
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3784
  // Get a chunk from the chunk freelist
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3785
  Metachunk* chunk = get_chunk_manager(mdtype)->chunk_freelist_allocate(chunk_word_size);
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3786
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3787
  if (chunk == NULL) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3788
    chunk = get_space_list(mdtype)->get_new_chunk(chunk_word_size,
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3789
                                                  get_space_manager(mdtype)->medium_chunk_bunch());
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3790
  }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3791
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3792
  return chunk;
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3793
}
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3794
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3795
void Metaspace::verify_global_initialization() {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3796
  assert(space_list() != NULL, "Metadata VirtualSpaceList has not been initialized");
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3797
  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
  3798
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3799
  if (using_class_space()) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3800
    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
  3801
    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
  3802
  }
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3803
}
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3804
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3805
void Metaspace::initialize(Mutex* lock, MetaspaceType type) {
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3806
  verify_global_initialization();
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3807
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3808
  // Allocate SpaceManager for metadata objects.
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3809
  _vsm = new SpaceManager(NonClassType, type, lock);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3810
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3811
  if (using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3812
    // Allocate SpaceManager for classes.
48148
385bed268108 8190729: Adjustment to anonymous metadata space chunk allocation algorithm
zgu
parents: 47808
diff changeset
  3813
    _class_vsm = new SpaceManager(ClassType, type, lock);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3814
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3815
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3816
  MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3817
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3818
  // Allocate chunk for metadata objects
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3819
  initialize_first_chunk(type, NonClassType);
13728
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
  // Allocate chunk for class metadata objects
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3822
  if (using_class_space()) {
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  3823
    initialize_first_chunk(type, ClassType);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3824
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3825
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3826
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3827
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
  3828
  size_t byte_size = word_size * wordSize;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3829
  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
  3830
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3831
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3832
MetaWord* Metaspace::allocate(size_t word_size, MetadataType mdtype) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3833
  assert(!_frozen, "sanity");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3834
  // Don't use class_vsm() unless UseCompressedClassPointers is true.
20306
f6805e2a0dd8 8025279: metaspace/flags/maxMetaspaceSize throws OOM: out of Compressed Klass space
mgerdin
parents: 20084
diff changeset
  3835
  if (is_class_space_allocation(mdtype)) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3836
    return  class_vsm()->allocate(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3837
  } else {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3838
    return  vsm()->allocate(word_size);
13728
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
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3841
13755
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3842
MetaWord* Metaspace::expand_and_allocate(size_t word_size, MetadataType mdtype) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3843
  assert(!_frozen, "sanity");
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3844
  size_t delta_bytes = MetaspaceGC::delta_capacity_until_GC(word_size * BytesPerWord);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3845
  assert(delta_bytes > 0, "Must be");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3846
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3847
  size_t before = 0;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3848
  size_t after = 0;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3849
  MetaWord* res;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3850
  bool incremented;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3851
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3852
  // Each thread increments the HWM at most once. Even if the thread fails to increment
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3853
  // the HWM, an allocation is still attempted. This is because another thread must then
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3854
  // have incremented the HWM and therefore the allocation might still succeed.
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3855
  do {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3856
    incremented = MetaspaceGC::inc_capacity_until_GC(delta_bytes, &after, &before);
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3857
    res = allocate(word_size, mdtype);
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3858
  } while (!incremented && res == NULL);
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3859
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3860
  if (incremented) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3861
    tracer()->report_gc_threshold(before, after,
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3862
                                  MetaspaceGCThresholdUpdater::ExpandAndAllocate);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3863
    log_trace(gc, metaspace)("Increase capacity to GC from " SIZE_FORMAT " to " SIZE_FORMAT, before, after);
13755
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3864
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3865
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3866
  return res;
13755
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3867
}
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3868
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3869
size_t Metaspace::used_words_slow(MetadataType mdtype) const {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3870
  if (mdtype == ClassType) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3871
    return using_class_space() ? class_vsm()->sum_used_in_chunks_in_use() : 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3872
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3873
    return vsm()->sum_used_in_chunks_in_use();  // includes overhead!
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3874
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3875
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3876
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3877
size_t Metaspace::free_words_slow(MetadataType mdtype) const {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3878
  assert(!_frozen, "sanity");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3879
  if (mdtype == ClassType) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3880
    return using_class_space() ? class_vsm()->sum_free_in_chunks_in_use() : 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3881
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3882
    return vsm()->sum_free_in_chunks_in_use();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3883
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3884
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3885
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3886
// Space capacity in the Metaspace.  It includes
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3887
// space in the list of chunks from which allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3888
// have been made. Don't include space in the global freelist and
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3889
// in the space available in the dictionary which
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3890
// is already counted in some chunk.
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3891
size_t Metaspace::capacity_words_slow(MetadataType mdtype) const {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3892
  if (mdtype == ClassType) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3893
    return using_class_space() ? class_vsm()->sum_capacity_in_chunks_in_use() : 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3894
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3895
    return vsm()->sum_capacity_in_chunks_in_use();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3896
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3897
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3898
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3899
size_t Metaspace::used_bytes_slow(MetadataType mdtype) const {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3900
  return used_words_slow(mdtype) * BytesPerWord;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3901
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3902
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3903
size_t Metaspace::capacity_bytes_slow(MetadataType mdtype) const {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3904
  return capacity_words_slow(mdtype) * BytesPerWord;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3905
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3906
25051
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3907
size_t Metaspace::allocated_blocks_bytes() const {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3908
  return vsm()->allocated_blocks_bytes() +
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3909
      (using_class_space() ? class_vsm()->allocated_blocks_bytes() : 0);
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3910
}
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3911
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3912
size_t Metaspace::allocated_chunks_bytes() const {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3913
  return vsm()->allocated_chunks_bytes() +
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3914
      (using_class_space() ? class_vsm()->allocated_chunks_bytes() : 0);
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3915
}
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3916
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3917
void Metaspace::deallocate(MetaWord* ptr, size_t word_size, bool is_class) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3918
  assert(!_frozen, "sanity");
23503
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3919
  assert(!SafepointSynchronize::is_at_safepoint()
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3920
         || Thread::current()->is_VM_thread(), "should be the VM thread");
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3921
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3922
  MutexLockerEx ml(vsm()->lock(), Mutex::_no_safepoint_check_flag);
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3923
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3924
  if (is_class && using_class_space()) {
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3925
    class_vsm()->deallocate(ptr, word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3926
  } else {
23503
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3927
    vsm()->deallocate(ptr, word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3928
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3929
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3930
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3931
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
  3932
                              MetaspaceObj::Type type, TRAPS) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46723
diff changeset
  3933
  assert(!_frozen, "sanity");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3934
  if (HAS_PENDING_EXCEPTION) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3935
    assert(false, "Should not allocate with exception pending");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3936
    return NULL;  // caller does a CHECK_NULL too
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3937
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3938
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3939
  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
  3940
        "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
  3941
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3942
  MetadataType mdtype = (type == MetaspaceObj::ClassType) ? ClassType : NonClassType;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3943
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3944
  // Try to allocate metadata.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3945
  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
  3946
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3947
  if (result == NULL) {
23468
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  3948
    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
  3949
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3950
    // Allocation failed.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3951
    if (is_init_completed()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3952
      // 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
  3953
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3954
      // Try to clean out some memory and retry.
49045
9b556b613a07 8198509: Move satisfy_failed_metadata_allocation out from CollectorPolicy
stefank
parents: 48971
diff changeset
  3955
      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
  3956
    }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3957
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3958
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3959
  if (result == NULL) {
31028
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  3960
    SpaceManager* sm;
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  3961
    if (is_class_space_allocation(mdtype)) {
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  3962
      sm = loader_data->metaspace_non_null()->class_vsm();
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  3963
    } else {
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  3964
      sm = loader_data->metaspace_non_null()->vsm();
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  3965
    }
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  3966
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  3967
    result = sm->get_small_chunk_and_allocate(word_size);
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  3968
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  3969
    if (result == NULL) {
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  3970
      report_metadata_oome(loader_data, word_size, type, mdtype, CHECK_NULL);
8c5b4d489c41 8081508: metaspace/shrink_grow/CompressedClassSpaceSize fails with OOM: Compressed class space
jprovino
parents: 30764
diff changeset
  3971
    }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3972
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3973
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3974
  // 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
  3975
  Copy::fill_to_words((HeapWord*)result, word_size, 0);
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3976
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3977
  return result;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3978
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3979
21186
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  3980
size_t Metaspace::class_chunk_size(size_t word_size) {
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  3981
  assert(using_class_space(), "Has to use class space");
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  3982
  return class_vsm()->calc_chunk_size(word_size);
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  3983
}
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  3984
23469
0a4d02776968 8036701: Add trace event when a metaspace throws out of memory error
ehelin
parents: 23468
diff changeset
  3985
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
  3986
  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
  3987
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3988
  // If result is still null, we are out of memory.
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37151
diff changeset
  3989
  Log(gc, metaspace, freelist) log;
41727
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3990
  if (log.is_info()) {
f1658e76a682 8164921: Memory leaked when instrumentation.retransformClasses() is called repeatedly
coleenp
parents: 41182
diff changeset
  3991
    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
  3992
             is_class_space_allocation(mdtype) ? "class" : "data", word_size);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34242
diff changeset
  3993
    ResourceMark rm;
46723
5c418c5fcade 8185262: Keep default logging for Metaspace OOM short and concise
stuefe
parents: 46709
diff changeset
  3994
    if (log.is_debug()) {
5c418c5fcade 8185262: Keep default logging for Metaspace OOM short and concise
stuefe
parents: 46709
diff changeset
  3995
      if (loader_data->metaspace_or_null() != NULL) {
5c418c5fcade 8185262: Keep default logging for Metaspace OOM short and concise
stuefe
parents: 46709
diff changeset
  3996
        LogStream ls(log.debug());
5c418c5fcade 8185262: Keep default logging for Metaspace OOM short and concise
stuefe
parents: 46709
diff changeset
  3997
        loader_data->dump(&ls);
5c418c5fcade 8185262: Keep default logging for Metaspace OOM short and concise
stuefe
parents: 46709
diff changeset
  3998
      }
5c418c5fcade 8185262: Keep default logging for Metaspace OOM short and concise
stuefe
parents: 46709
diff changeset
  3999
    }
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  4000
    LogStream ls(log.info());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
  4001
    MetaspaceAux::dump(&ls);
47808
57752bd5d1b4 8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents: 47802
diff changeset
  4002
    MetaspaceAux::print_metaspace_map(&ls, mdtype);
46709
adaac4b80549 8185033: On Metaspace OOM, ChunkManager composition should be logged.
stuefe
parents: 46701
diff changeset
  4003
    ChunkManager::print_all_chunkmanagers(&ls);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4004
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4005
21186
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4006
  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
  4007
  if (is_class_space_allocation(mdtype)) {
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4008
    Metaspace* metaspace = loader_data->metaspace_non_null();
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4009
    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
  4010
      MetaspaceAux::committed_bytes(Metaspace::ClassType) +
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4011
      (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
  4012
      CompressedClassSpaceSize;
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4013
  }
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4014
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4015
  // -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
  4016
  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
  4017
    "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
  4018
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4019
  report_java_out_of_memory(space_string);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4020
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4021
  if (JvmtiExport::should_post_resource_exhausted()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4022
    JvmtiExport::post_resource_exhausted(
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4023
        JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4024
        space_string);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4025
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4026
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4027
  if (!is_init_completed()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4028
    vm_exit_during_initialization("OutOfMemoryError", space_string);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4029
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4030
21186
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  4031
  if (out_of_compressed_class_space) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4032
    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
  4033
  } else {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  4034
    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
  4035
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4036
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4037
23468
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4038
const char* Metaspace::metadata_type_name(Metaspace::MetadataType mdtype) {
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4039
  switch (mdtype) {
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4040
    case Metaspace::ClassType: return "Class";
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4041
    case Metaspace::NonClassType: return "Metadata";
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4042
    default:
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4043
      assert(false, "Got bad mdtype: %d", (int) mdtype);
23468
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4044
      return NULL;
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4045
  }
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4046
}
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  4047
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4048
void Metaspace::purge(MetadataType mdtype) {
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4049
  get_space_list(mdtype)->purge(get_chunk_manager(mdtype));
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4050
}
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4051
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  4052
void Metaspace::purge() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  4053
  MutexLockerEx cl(SpaceManager::expand_lock(),
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  4054
                   Mutex::_no_safepoint_check_flag);
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4055
  purge(NonClassType);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4056
  if (using_class_space()) {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  4057
    purge(ClassType);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4058
  }
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  4059
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  4060
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4061
void Metaspace::print_on(outputStream* out) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4062
  // Print both class virtual space counts and metaspace.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4063
  if (Verbose) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4064
    vsm()->print_on(out);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4065
    if (using_class_space()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4066
      class_vsm()->print_on(out);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4067
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4068
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4069
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4070
22201
9c2ccfa3a5fe 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 21569
diff changeset
  4071
bool Metaspace::contains(const void* ptr) {
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48387
diff changeset
  4072
  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
  4073
    return true;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4074
  }
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 42650
diff changeset
  4075
  return contains_non_shared(ptr);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 42650
diff changeset
  4076
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 42650
diff changeset
  4077
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 42650
diff changeset
  4078
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
  4079
  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
  4080
     return true;
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  4081
  }
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  4082
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  4083
  return get_space_list(NonClassType)->contains(ptr);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4084
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4085
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4086
void Metaspace::verify() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4087
  vsm()->verify();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4088
  if (using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4089
    class_vsm()->verify();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4090
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4091
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4092
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4093
void Metaspace::dump(outputStream* const out) const {
29800
fa5f7a2bf717 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29697
diff changeset
  4094
  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
  4095
  vsm()->dump(out);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4096
  if (using_class_space()) {
29800
fa5f7a2bf717 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29697
diff changeset
  4097
    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
  4098
    class_vsm()->dump(out);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  4099
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  4100
}
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4101
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4102
/////////////// Unit tests ///////////////
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4103
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4104
#ifndef PRODUCT
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4105
20084
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  4106
class TestMetaspaceAuxTest : AllStatic {
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4107
 public:
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4108
  static void test_reserved() {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4109
    size_t reserved = MetaspaceAux::reserved_bytes();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4110
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4111
    assert(reserved > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4112
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4113
    size_t committed  = MetaspaceAux::committed_bytes();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4114
    assert(committed <= reserved, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4115
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4116
    size_t reserved_metadata = MetaspaceAux::reserved_bytes(Metaspace::NonClassType);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4117
    assert(reserved_metadata > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4118
    assert(reserved_metadata <= reserved, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4119
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4120
    if (UseCompressedClassPointers) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4121
      size_t reserved_class    = MetaspaceAux::reserved_bytes(Metaspace::ClassType);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4122
      assert(reserved_class > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4123
      assert(reserved_class < reserved, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4124
    }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4125
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4126
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4127
  static void test_committed() {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4128
    size_t committed = MetaspaceAux::committed_bytes();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4129
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4130
    assert(committed > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4131
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4132
    size_t reserved  = MetaspaceAux::reserved_bytes();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4133
    assert(committed <= reserved, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4134
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4135
    size_t committed_metadata = MetaspaceAux::committed_bytes(Metaspace::NonClassType);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4136
    assert(committed_metadata > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4137
    assert(committed_metadata <= committed, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4138
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4139
    if (UseCompressedClassPointers) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4140
      size_t committed_class    = MetaspaceAux::committed_bytes(Metaspace::ClassType);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4141
      assert(committed_class > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4142
      assert(committed_class < committed, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4143
    }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4144
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4145
20084
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  4146
  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
  4147
    VirtualSpaceList* vs_list = new VirtualSpaceList(os::vm_allocation_granularity());
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  4148
    MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  4149
    // 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
  4150
    // vm_allocation_granularity aligned on Windows.
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  4151
    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
  4152
    large_size += (os::vm_page_size()/BytesPerWord);
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4153
    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
  4154
  }
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  4155
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4156
  static void test() {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4157
    test_reserved();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4158
    test_committed();
20084
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  4159
    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
  4160
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4161
};
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4162
20084
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  4163
void TestMetaspaceAux_test() {
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  4164
  TestMetaspaceAuxTest::test();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4165
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4166
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4167
class TestVirtualSpaceNodeTest {
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4168
  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
  4169
                                          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
  4170
                                          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
  4171
    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
  4172
    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
  4173
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4174
    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
  4175
    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
  4176
    // 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
  4177
    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
  4178
    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
  4179
  }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4180
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4181
 public:
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4182
  static void test() {
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4183
    MutexLockerEx ml(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4184
    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
  4185
    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
  4186
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4187
    // 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
  4188
    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
  4189
    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
  4190
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4191
    { // No committed memory in VSN
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4192
      ChunkManager cm(SpecializedChunk, SmallChunk, MediumChunk);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4193
      VirtualSpaceNode vsn(vsn_test_size_bytes);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4194
      vsn.initialize();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4195
      vsn.retire(&cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4196
      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
  4197
    }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4198
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4199
    { // All of VSN is committed, half is used by chunks
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4200
      ChunkManager cm(SpecializedChunk, SmallChunk, MediumChunk);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4201
      VirtualSpaceNode vsn(vsn_test_size_bytes);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4202
      vsn.initialize();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4203
      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
  4204
      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
  4205
      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
  4206
      vsn.retire(&cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4207
      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
  4208
      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
  4209
    }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4210
28497
a7aecf0ffb6b 8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents: 28372
diff changeset
  4211
    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
  4212
    // 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
  4213
    if (page_chunks < MediumChunk) {
a7aecf0ffb6b 8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents: 28372
diff changeset
  4214
      // 4 pages of VSN is committed, some is used by chunks
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4215
      ChunkManager cm(SpecializedChunk, SmallChunk, MediumChunk);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4216
      VirtualSpaceNode vsn(vsn_test_size_bytes);
28497
a7aecf0ffb6b 8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents: 28372
diff changeset
  4217
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4218
      vsn.initialize();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4219
      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
  4220
      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
  4221
      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
  4222
      vsn.retire(&cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4223
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4224
      // 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
  4225
      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
  4226
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4227
      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
  4228
      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
  4229
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4230
      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
  4231
      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
  4232
      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
  4233
    }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4234
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4235
    { // Half of VSN is committed, a humongous chunk is used
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4236
      ChunkManager cm(SpecializedChunk, SmallChunk, MediumChunk);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4237
      VirtualSpaceNode vsn(vsn_test_size_bytes);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4238
      vsn.initialize();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4239
      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
  4240
      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
  4241
      vsn.retire(&cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4242
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4243
      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
  4244
      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
  4245
      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
  4246
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4247
      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
  4248
      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
  4249
      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
  4250
    }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4251
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4252
  }
22222
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4253
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4254
#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
  4255
  assert(vsn.is_available(word_size), \
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4256
         #word_size ": " PTR_FORMAT " bytes were not available in " \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4257
         "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4258
         (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
  4259
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4260
#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
  4261
  assert(!vsn.is_available(word_size), \
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4262
         #word_size ": " PTR_FORMAT " bytes should not be available in " \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4263
         "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31374
diff changeset
  4264
         (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
  4265
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4266
  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
  4267
    // Reserve some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4268
    VirtualSpaceNode vsn(os::vm_allocation_granularity());
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4269
    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
  4270
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4271
    // Commit some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4272
    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
  4273
    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
  4274
    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
  4275
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4276
    // 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
  4277
    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
  4278
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4279
    // 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
  4280
    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
  4281
    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
  4282
  }
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4283
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4284
  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
  4285
    // Reserve some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4286
    VirtualSpaceNode vsn(os::vm_allocation_granularity());
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4287
    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
  4288
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4289
    // Commit some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4290
    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
  4291
    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
  4292
    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
  4293
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4294
    // 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
  4295
    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
  4296
    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
  4297
  }
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4298
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4299
  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
  4300
    // Reserve some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4301
    VirtualSpaceNode vsn(os::vm_allocation_granularity());
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4302
    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
  4303
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4304
    // Commit some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4305
    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
  4306
    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
  4307
    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
  4308
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4309
    // 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
  4310
    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
  4311
    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
  4312
    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
  4313
    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
  4314
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4315
    // 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
  4316
    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
  4317
  }
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4318
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4319
  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
  4320
    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
  4321
    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
  4322
    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
  4323
  }
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4324
};
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4325
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4326
void TestVirtualSpaceNode_test() {
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4327
  TestVirtualSpaceNodeTest::test();
22222
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4328
  TestVirtualSpaceNodeTest::test_is_available();
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4329
}
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4330
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4331
// 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
  4332
// 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
  4333
void ChunkManager_test_list_index() {
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4334
  ChunkManager manager(ClassSpecializedChunk, ClassSmallChunk, ClassMediumChunk);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4335
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4336
  // Test previous bug where a query for a humongous class metachunk,
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4337
  // incorrectly matched the non-class medium metachunk size.
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4338
  {
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4339
    assert(MediumChunk > ClassMediumChunk, "Precondition for test");
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4340
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4341
    ChunkIndex index = manager.list_index(MediumChunk);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4342
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4343
    assert(index == HumongousIndex,
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4344
           "Requested size is larger than ClassMediumChunk,"
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4345
           " so should return HumongousIndex. Got index: %d", (int)index);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4346
  }
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4347
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4348
  // Check the specified sizes as well.
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4349
  {
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4350
    ChunkIndex index = manager.list_index(ClassSpecializedChunk);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4351
    assert(index == SpecializedIndex, "Wrong index returned. Got index: %d", (int)index);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4352
  }
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4353
  {
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4354
    ChunkIndex index = manager.list_index(ClassSmallChunk);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4355
    assert(index == SmallIndex, "Wrong index returned. Got index: %d", (int)index);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4356
  }
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4357
  {
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4358
    ChunkIndex index = manager.list_index(ClassMediumChunk);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4359
    assert(index == MediumIndex, "Wrong index returned. Got index: %d", (int)index);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4360
  }
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4361
  {
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4362
    ChunkIndex index = manager.list_index(ClassMediumChunk + 1);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4363
    assert(index == HumongousIndex, "Wrong index returned. Got index: %d", (int)index);
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4364
  }
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4365
}
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4366
46602
f63ae85597f1 8183228: Fix optimized build after JDK-8170933
stuefe
parents: 46587
diff changeset
  4367
#endif // !PRODUCT
f63ae85597f1 8183228: Fix optimized build after JDK-8170933
stuefe
parents: 46587
diff changeset
  4368
f63ae85597f1 8183228: Fix optimized build after JDK-8170933
stuefe
parents: 46587
diff changeset
  4369
#ifdef ASSERT
f63ae85597f1 8183228: Fix optimized build after JDK-8170933
stuefe
parents: 46587
diff changeset
  4370
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4371
// ChunkManagerReturnTest stresses taking/returning chunks from the ChunkManager. It takes and
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4372
// returns chunks from/to the ChunkManager while keeping track of the expected ChunkManager
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4373
// content.
48971
b2bb70f5effd 8197772: metaspace uses global operator new/delete for gtest testing
coleenp
parents: 48794
diff changeset
  4374
class ChunkManagerReturnTestImpl : public CHeapObj<mtClass> {
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4375
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4376
  VirtualSpaceNode _vsn;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4377
  ChunkManager _cm;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4378
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4379
  // The expected content of the chunk manager.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4380
  unsigned _chunks_in_chunkmanager;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4381
  size_t _words_in_chunkmanager;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4382
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4383
  // A fixed size pool of chunks. Chunks may be in the chunk manager (free) or not (in use).
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4384
  static const int num_chunks = 256;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4385
  Metachunk* _pool[num_chunks];
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4386
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4387
  // Helper, return a random position into the chunk pool.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4388
  static int get_random_position() {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4389
    return os::random() % num_chunks;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4390
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4391
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4392
  // Asserts that ChunkManager counters match expectations.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4393
  void assert_counters() {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4394
    assert(_vsn.container_count() == num_chunks - _chunks_in_chunkmanager, "vsn counter mismatch.");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4395
    assert(_cm.free_chunks_count() == _chunks_in_chunkmanager, "cm counter mismatch.");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4396
    assert(_cm.free_chunks_total_words() == _words_in_chunkmanager, "cm counter mismatch.");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4397
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4398
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4399
  // Get a random chunk size. Equal chance to get spec/med/small chunk size or
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4400
  // a humongous chunk size. The latter itself is random in the range of [med+spec..4*med).
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4401
  size_t get_random_chunk_size() {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4402
    const size_t sizes [] = { SpecializedChunk, SmallChunk, MediumChunk };
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4403
    const int rand = os::random() % 4;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4404
    if (rand < 3) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4405
      return sizes[rand];
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4406
    } else {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4407
      // Note: this affects the max. size of space (see _vsn initialization in ctor).
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4408
      return align_up(MediumChunk + 1 + (os::random() % (MediumChunk * 4)), SpecializedChunk);
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4409
    }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4410
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4411
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4412
  // Starting at pool index <start>+1, find the next chunk tagged as either free or in use, depending
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4413
  // on <is_free>. Search wraps. Returns its position, or -1 if no matching chunk was found.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4414
  int next_matching_chunk(int start, bool is_free) const {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4415
    assert(start >= 0 && start < num_chunks, "invalid parameter");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4416
    int pos = start;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4417
    do {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4418
      if (++pos == num_chunks) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4419
        pos = 0;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4420
      }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4421
      if (_pool[pos]->is_tagged_free() == is_free) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4422
        return pos;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4423
      }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4424
    } while (pos != start);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4425
    return -1;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4426
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4427
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4428
  // A structure to keep information about a chunk list including which
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4429
  // chunks are part of this list. This is needed to keep information about a chunk list
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4430
  // we will to return to the ChunkManager, because the original list will be destroyed.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4431
  struct AChunkList {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4432
    Metachunk* head;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4433
    Metachunk* all[num_chunks];
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4434
    size_t size;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4435
    int num;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4436
    ChunkIndex index;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4437
  };
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4438
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4439
  // Assemble, from the in-use chunks (not in the chunk manager) in the pool,
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4440
  // a random chunk list of max. length <list_size> of chunks with the same
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4441
  // ChunkIndex (chunk size).
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4442
  // Returns false if list cannot be assembled. List is returned in the <out>
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4443
  // structure. Returned list may be smaller than <list_size>.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4444
  bool assemble_random_chunklist(AChunkList* out, int list_size) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4445
    // Choose a random in-use chunk from the pool...
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4446
    const int headpos = next_matching_chunk(get_random_position(), false);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4447
    if (headpos == -1) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4448
      return false;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4449
    }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4450
    Metachunk* const head = _pool[headpos];
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4451
    out->all[0] = head;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4452
    assert(head->is_tagged_free() == false, "Chunk state mismatch");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4453
    // ..then go from there, chain it up with up to list_size - 1 number of other
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4454
    // in-use chunks of the same index.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4455
    const ChunkIndex index = _cm.list_index(head->word_size());
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4456
    int num_added = 1;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4457
    size_t size_added = head->word_size();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4458
    int pos = headpos;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4459
    Metachunk* tail = head;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4460
    do {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4461
      pos = next_matching_chunk(pos, false);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4462
      if (pos != headpos) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4463
        Metachunk* c = _pool[pos];
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4464
        assert(c->is_tagged_free() == false, "Chunk state mismatch");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4465
        if (index == _cm.list_index(c->word_size())) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4466
          tail->set_next(c);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4467
          c->set_prev(tail);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4468
          tail = c;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4469
          out->all[num_added] = c;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4470
          num_added ++;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4471
          size_added += c->word_size();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4472
        }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4473
      }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4474
    } while (num_added < list_size && pos != headpos);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4475
    out->head = head;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4476
    out->index = index;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4477
    out->size = size_added;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4478
    out->num = num_added;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4479
    return true;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4480
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4481
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4482
  // Take a single random chunk from the ChunkManager.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4483
  bool take_single_random_chunk_from_chunkmanager() {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4484
    assert_counters();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4485
    _cm.locked_verify();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4486
    int pos = next_matching_chunk(get_random_position(), true);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4487
    if (pos == -1) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4488
      return false;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4489
    }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4490
    Metachunk* c = _pool[pos];
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4491
    assert(c->is_tagged_free(), "Chunk state mismatch");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4492
    // Note: instead of using ChunkManager::remove_chunk on this one chunk, we call
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4493
    // ChunkManager::free_chunks_get() with this chunk's word size. We really want
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4494
    // to exercise ChunkManager::free_chunks_get() because that one gets called for
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4495
    // normal chunk allocation.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4496
    Metachunk* c2 = _cm.free_chunks_get(c->word_size());
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4497
    assert(c2 != NULL, "Unexpected.");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4498
    assert(!c2->is_tagged_free(), "Chunk state mismatch");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4499
    assert(c2->next() == NULL && c2->prev() == NULL, "Chunk should be outside of a list.");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4500
    _chunks_in_chunkmanager --;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4501
    _words_in_chunkmanager -= c->word_size();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4502
    assert_counters();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4503
    _cm.locked_verify();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4504
    return true;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4505
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4506
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4507
  // Returns a single random chunk to the chunk manager. Returns false if that
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4508
  // was not possible (all chunks are already in the chunk manager).
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4509
  bool return_single_random_chunk_to_chunkmanager() {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4510
    assert_counters();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4511
    _cm.locked_verify();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4512
    int pos = next_matching_chunk(get_random_position(), false);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4513
    if (pos == -1) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4514
      return false;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4515
    }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4516
    Metachunk* c = _pool[pos];
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4517
    assert(c->is_tagged_free() == false, "wrong chunk information");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4518
    _cm.return_single_chunk(_cm.list_index(c->word_size()), c);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4519
    _chunks_in_chunkmanager ++;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4520
    _words_in_chunkmanager += c->word_size();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4521
    assert(c->is_tagged_free() == true, "wrong chunk information");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4522
    assert_counters();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4523
    _cm.locked_verify();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4524
    return true;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4525
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4526
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4527
  // Return a random chunk list to the chunk manager. Returns the length of the
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4528
  // returned list.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4529
  int return_random_chunk_list_to_chunkmanager(int list_size) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4530
    assert_counters();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4531
    _cm.locked_verify();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4532
    AChunkList aChunkList;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4533
    if (!assemble_random_chunklist(&aChunkList, list_size)) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4534
      return 0;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4535
    }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4536
    // Before returning chunks are returned, they should be tagged in use.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4537
    for (int i = 0; i < aChunkList.num; i ++) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4538
      assert(!aChunkList.all[i]->is_tagged_free(), "chunk state mismatch.");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4539
    }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4540
    _cm.return_chunk_list(aChunkList.index, aChunkList.head);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4541
    _chunks_in_chunkmanager += aChunkList.num;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4542
    _words_in_chunkmanager += aChunkList.size;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4543
    // After all chunks are returned, check that they are now tagged free.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4544
    for (int i = 0; i < aChunkList.num; i ++) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4545
      assert(aChunkList.all[i]->is_tagged_free(), "chunk state mismatch.");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4546
    }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4547
    assert_counters();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4548
    _cm.locked_verify();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4549
    return aChunkList.num;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4550
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4551
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4552
public:
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4553
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4554
  ChunkManagerReturnTestImpl()
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  4555
    : _vsn(align_up(MediumChunk * num_chunks * 5 * sizeof(MetaWord), Metaspace::reserve_alignment()))
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4556
    , _cm(SpecializedChunk, SmallChunk, MediumChunk)
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4557
    , _chunks_in_chunkmanager(0)
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4558
    , _words_in_chunkmanager(0)
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4559
  {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4560
    MutexLockerEx ml(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4561
    // Allocate virtual space and allocate random chunks. Keep these chunks in the _pool. These chunks are
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4562
    // "in use", because not yet added to any chunk manager.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4563
    _vsn.initialize();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4564
    _vsn.expand_by(_vsn.reserved_words(), _vsn.reserved_words());
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4565
    for (int i = 0; i < num_chunks; i ++) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4566
      const size_t size = get_random_chunk_size();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4567
      _pool[i] = _vsn.get_chunk_vs(size);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4568
      assert(_pool[i] != NULL, "allocation failed");
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4569
    }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4570
    assert_counters();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4571
    _cm.locked_verify();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4572
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4573
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4574
  // Test entry point.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4575
  // Return some chunks to the chunk manager (return phase). Take some chunks out (take phase). Repeat.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4576
  // Chunks are choosen randomly. Number of chunks to return or taken are choosen randomly, but affected
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4577
  // by the <phase_length_factor> argument: a factor of 0.0 will cause the test to quickly alternate between
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4578
  // returning and taking, whereas a factor of 1.0 will take/return all chunks from/to the
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4579
  // chunks manager, thereby emptying or filling it completely.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4580
  void do_test(float phase_length_factor) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4581
    MutexLockerEx ml(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4582
    assert_counters();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4583
    // Execute n operations, and operation being the move of a single chunk to/from the chunk manager.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4584
    const int num_max_ops = num_chunks * 100;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4585
    int num_ops = num_max_ops;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4586
    const int average_phase_length = (int)(phase_length_factor * num_chunks);
46587
6c97f34cb194 8182554: Code for os::random() assumes long is 32 bits
coleenp
parents: 46522
diff changeset
  4587
    int num_ops_until_switch = MAX2(1, (average_phase_length + os::random() % 8 - 4));
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4588
    bool return_phase = true;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4589
    while (num_ops > 0) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4590
      int chunks_moved = 0;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4591
      if (return_phase) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4592
        // Randomly switch between returning a single chunk or a random length chunk list.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4593
        if (os::random() % 2 == 0) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4594
          if (return_single_random_chunk_to_chunkmanager()) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4595
            chunks_moved = 1;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4596
          }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4597
        } else {
46587
6c97f34cb194 8182554: Code for os::random() assumes long is 32 bits
coleenp
parents: 46522
diff changeset
  4598
          const int list_length = MAX2(1, (os::random() % num_ops_until_switch));
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4599
          chunks_moved = return_random_chunk_list_to_chunkmanager(list_length);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4600
        }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4601
      } else {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4602
        // Breath out.
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4603
        if (take_single_random_chunk_from_chunkmanager()) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4604
          chunks_moved = 1;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4605
        }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4606
      }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4607
      num_ops -= chunks_moved;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4608
      num_ops_until_switch -= chunks_moved;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4609
      if (chunks_moved == 0 || num_ops_until_switch <= 0) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4610
        return_phase = !return_phase;
46587
6c97f34cb194 8182554: Code for os::random() assumes long is 32 bits
coleenp
parents: 46522
diff changeset
  4611
        num_ops_until_switch = MAX2(1, (average_phase_length + os::random() % 8 - 4));
46333
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4612
      }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4613
    }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4614
  }
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4615
};
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4616
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4617
void* setup_chunkmanager_returntests() {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4618
  ChunkManagerReturnTestImpl* p = new ChunkManagerReturnTestImpl();
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4619
  return p;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4620
}
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4621
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4622
void teardown_chunkmanager_returntests(void* p) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4623
  delete (ChunkManagerReturnTestImpl*) p;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4624
}
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4625
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4626
void run_chunkmanager_returntests(void* p, float phase_length) {
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4627
  ChunkManagerReturnTestImpl* test = (ChunkManagerReturnTestImpl*) p;
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4628
  test->do_test(phase_length);
cef2c78aaa56 8170933: Cleanup Metaspace Chunk manager: Unify treatment of humongous and non-humongous chunks
stuefe
parents: 46324
diff changeset
  4629
}
42621
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4630
f2598e832afa 8170358: [REDO] 8k class metaspace chunks misallocated from 4k chunk freelist
stefank
parents: 42615
diff changeset
  4631
// 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
  4632
// 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
  4633
class SpaceManagerTest : AllStatic {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4634
  friend void SpaceManager_test_adjust_initial_chunk_size();
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4635
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4636
  static void test_adjust_initial_chunk_size(bool is_class) {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4637
    const size_t smallest = SpaceManager::smallest_chunk_size(is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4638
    const size_t normal   = SpaceManager::small_chunk_size(is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4639
    const size_t medium   = SpaceManager::medium_chunk_size(is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4640
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4641
#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
  4642
    do {                                                                         \
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4643
      size_t v = value;                                                          \
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4644
      size_t e = expected;                                                       \
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4645
      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
  4646
             "Expected: " SIZE_FORMAT " got: " SIZE_FORMAT, e, v);               \
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4647
    } while (0)
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4648
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4649
    // Smallest (specialized)
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4650
    test_adjust_initial_chunk_size(1,            smallest, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4651
    test_adjust_initial_chunk_size(smallest - 1, smallest, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4652
    test_adjust_initial_chunk_size(smallest,     smallest, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4653
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4654
    // Small
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4655
    test_adjust_initial_chunk_size(smallest + 1, normal, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4656
    test_adjust_initial_chunk_size(normal - 1,   normal, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4657
    test_adjust_initial_chunk_size(normal,       normal, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4658
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4659
    // Medium
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4660
    test_adjust_initial_chunk_size(normal + 1, medium, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4661
    test_adjust_initial_chunk_size(medium - 1, medium, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4662
    test_adjust_initial_chunk_size(medium,     medium, is_class);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4663
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4664
    // Humongous
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4665
    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
  4666
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4667
#undef test_adjust_initial_chunk_size
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4668
  }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4669
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4670
  static void test_adjust_initial_chunk_size() {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4671
    test_adjust_initial_chunk_size(false);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4672
    test_adjust_initial_chunk_size(true);
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4673
  }
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4674
};
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4675
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4676
void SpaceManager_test_adjust_initial_chunk_size() {
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4677
  SpaceManagerTest::test_adjust_initial_chunk_size();
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4678
}
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents: 42602
diff changeset
  4679
46602
f63ae85597f1 8183228: Fix optimized build after JDK-8170933
stuefe
parents: 46587
diff changeset
  4680
#endif // ASSERT