hotspot/src/share/vm/memory/metaspace.cpp
author kvn
Tue, 20 Jan 2015 15:24:58 -0800
changeset 29185 41cf0610fedf
parent 28504 64e071ba6d1d
parent 29181 89beae49867c
child 29187 b3e445e08548
permissions -rw-r--r--
Merge
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
/*
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28163
diff changeset
     2
 * Copyright (c) 2011, 2015, 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"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    25
#include "gc_interface/collectedHeap.hpp"
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
    26
#include "memory/allocation.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    27
#include "memory/binaryTreeDictionary.hpp"
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
    28
#include "memory/freeList.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    29
#include "memory/collectorPolicy.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    30
#include "memory/filemap.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    31
#include "memory/freeList.hpp"
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
    32
#include "memory/gcLocker.hpp"
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
    33
#include "memory/metachunk.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    34
#include "memory/metaspace.hpp"
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
    35
#include "memory/metaspaceGCThresholdUpdater.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    36
#include "memory/metaspaceShared.hpp"
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
    37
#include "memory/metaspaceTracer.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    38
#include "memory/resourceArea.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    39
#include "memory/universe.hpp"
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
    40
#include "runtime/atomic.inline.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    41
#include "runtime/globals.hpp"
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
    42
#include "runtime/init.hpp"
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
    43
#include "runtime/java.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    44
#include "runtime/mutex.hpp"
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 23854
diff changeset
    45
#include "runtime/orderAccess.inline.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    46
#include "services/memTracker.hpp"
20407
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
    47
#include "services/memoryService.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    48
#include "utilities/copy.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    49
#include "utilities/debug.hpp"
27683
1d5707553fff 8064580: Move INCLUDE_CDS include section to the end of the include list
stefank
parents: 27404
diff changeset
    50
#include "utilities/macros.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    51
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24351
diff changeset
    52
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24351
diff changeset
    53
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
    54
typedef BinaryTreeDictionary<Metablock, FreeList<Metablock> > BlockTreeDictionary;
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
    55
typedef BinaryTreeDictionary<Metachunk, FreeList<Metachunk> > ChunkTreeDictionary;
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
    56
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
    57
// 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
    58
const bool metaspace_slow_verify = false;
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
    59
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
    60
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
    61
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    62
MetaWord* last_allocated = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    63
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
    64
size_t Metaspace::_compressed_class_space_size;
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
    65
const MetaspaceTracer* Metaspace::_tracer = NULL;
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
    66
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    67
// Used in declarations in SpaceManager and ChunkManager
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    68
enum ChunkIndex {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    69
  ZeroIndex = 0,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    70
  SpecializedIndex = ZeroIndex,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    71
  SmallIndex = SpecializedIndex + 1,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    72
  MediumIndex = SmallIndex + 1,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    73
  HumongousIndex = MediumIndex + 1,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    74
  NumberOfFreeLists = 3,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    75
  NumberOfInUseLists = 4
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    76
};
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    77
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    78
enum ChunkSizes {    // in words.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    79
  ClassSpecializedChunk = 128,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    80
  SpecializedChunk = 128,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    81
  ClassSmallChunk = 256,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    82
  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
    83
  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
    84
  MediumChunk = 8 * K
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    85
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    86
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    87
static ChunkIndex next_chunk_index(ChunkIndex i) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
    88
  assert(i < NumberOfInUseLists, "Out of bound");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    89
  return (ChunkIndex) (i+1);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    90
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    91
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
    92
volatile intptr_t MetaspaceGC::_capacity_until_GC = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    93
uint MetaspaceGC::_shrink_factor = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    94
bool MetaspaceGC::_should_concurrent_collect = false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    95
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
    96
typedef class FreeList<Metachunk> ChunkList;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    97
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    98
// Manages the global free lists of chunks.
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
    99
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
   100
  friend class TestVirtualSpaceNodeTest;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   101
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   102
  // Free list of chunks of different sizes.
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   103
  //   SpecializedChunk
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   104
  //   SmallChunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   105
  //   MediumChunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   106
  //   HumongousChunk
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   107
  ChunkList _free_chunks[NumberOfFreeLists];
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   108
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   109
  //   HumongousChunk
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   110
  ChunkTreeDictionary _humongous_dictionary;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   111
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   112
  // ChunkManager in all lists of this type
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   113
  size_t _free_chunks_total;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   114
  size_t _free_chunks_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   115
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   116
  void dec_free_chunks_total(size_t v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   117
    assert(_free_chunks_count > 0 &&
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   118
             _free_chunks_total > 0,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   119
             "About to go negative");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   120
    Atomic::add_ptr(-1, &_free_chunks_count);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   121
    jlong minus_v = (jlong) - (jlong) v;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   122
    Atomic::add_ptr(minus_v, &_free_chunks_total);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   123
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   124
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   125
  // Debug support
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   126
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   127
  size_t sum_free_chunks();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   128
  size_t sum_free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   129
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   130
  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
   131
  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
   132
    if (metaspace_slow_verify) {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   133
      locked_verify_free_chunks_total();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   134
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   135
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   136
  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
   137
  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
   138
    if (metaspace_slow_verify) {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   139
      locked_verify_free_chunks_count();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   140
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   141
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   142
  void verify_free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   143
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   144
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   145
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   146
  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
   147
      : _free_chunks_total(0), _free_chunks_count(0) {
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   148
    _free_chunks[SpecializedIndex].set_size(specialized_size);
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   149
    _free_chunks[SmallIndex].set_size(small_size);
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   150
    _free_chunks[MediumIndex].set_size(medium_size);
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   151
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   152
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   153
  // 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
   154
  Metachunk* chunk_freelist_allocate(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   155
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   156
  // 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
   157
  // for special, small, medium, and humongous chunks.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   158
  static ChunkIndex list_index(size_t size);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   159
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   160
  // Remove the chunk from its freelist.  It is
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   161
  // expected to be on one of the _free_chunks[] lists.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   162
  void remove_chunk(Metachunk* chunk);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   163
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
   164
  // 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
   165
  // of type index.
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
   166
  void return_chunks(ChunkIndex index, Metachunk* chunks);
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
   167
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   168
  // Total of the space in the free chunks list
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
   169
  size_t free_chunks_total_words();
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
   170
  size_t free_chunks_total_bytes();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   171
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   172
  // Number of chunks in the free chunks list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   173
  size_t free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   174
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   175
  void inc_free_chunks_total(size_t v, size_t count = 1) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   176
    Atomic::add_ptr(count, &_free_chunks_count);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   177
    Atomic::add_ptr(v, &_free_chunks_total);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   178
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   179
  ChunkTreeDictionary* humongous_dictionary() {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   180
    return &_humongous_dictionary;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   181
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   182
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   183
  ChunkList* free_chunks(ChunkIndex index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   184
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   185
  // Returns the list for the given chunk word size.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   186
  ChunkList* find_free_chunks_list(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   187
20733
8dead86921fe 8026715: Remove the MetaDataDeallocateALot develop flag
stefank
parents: 20729
diff changeset
   188
  // 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
   189
  Metachunk* free_chunks_get(size_t chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   190
23470
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   191
#define index_bounds_check(index)                                         \
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   192
  assert(index == SpecializedIndex ||                                     \
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   193
         index == SmallIndex ||                                           \
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   194
         index == MediumIndex ||                                          \
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   195
         index == HumongousIndex, err_msg("Bad index: %d", (int) index))
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   196
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   197
  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
   198
    index_bounds_check(index);
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   199
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   200
    if (index == HumongousIndex) {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   201
      return _humongous_dictionary.total_free_blocks();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   202
    }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   203
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   204
    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
   205
    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
   206
  }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   207
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   208
  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
   209
    index_bounds_check(index);
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   210
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   211
    size_t word_size = 0;
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   212
    if (index == HumongousIndex) {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   213
      word_size = _humongous_dictionary.total_size();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   214
    } else {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   215
      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
   216
      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
   217
    }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   218
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   219
    return word_size * BytesPerWord;
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   220
  }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   221
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   222
  MetaspaceChunkFreeListSummary chunk_free_list_summary() const {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   223
    return MetaspaceChunkFreeListSummary(num_free_chunks(SpecializedIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   224
                                         num_free_chunks(SmallIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   225
                                         num_free_chunks(MediumIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   226
                                         num_free_chunks(HumongousIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   227
                                         size_free_chunks_in_bytes(SpecializedIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   228
                                         size_free_chunks_in_bytes(SmallIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   229
                                         size_free_chunks_in_bytes(MediumIndex),
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   230
                                         size_free_chunks_in_bytes(HumongousIndex));
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   231
  }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
   232
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   233
  // Debug support
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   234
  void verify();
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   235
  void slow_verify() {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   236
    if (metaspace_slow_verify) {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   237
      verify();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   238
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   239
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   240
  void locked_verify();
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   241
  void slow_locked_verify() {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   242
    if (metaspace_slow_verify) {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   243
      locked_verify();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   244
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   245
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   246
  void verify_free_chunks_total();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   247
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   248
  void locked_print_free_chunks(outputStream* st);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   249
  void locked_print_sum_free_chunks(outputStream* st);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   250
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   251
  void print_on(outputStream* st) const;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   252
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   253
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   254
// 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
   255
// to the allocation of a quantum of metadata).
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   256
class BlockFreelist VALUE_OBJ_CLASS_SPEC {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   257
  BlockTreeDictionary* _dictionary;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   258
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   259
  // 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
   260
  // 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
   261
  const static int WasteMultiplier = 4;
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   262
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   263
  // Accessors
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   264
  BlockTreeDictionary* dictionary() const { return _dictionary; }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   265
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   266
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   267
  BlockFreelist();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   268
  ~BlockFreelist();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   269
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   270
  // Get and return a block to the free list
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   271
  MetaWord* get_block(size_t word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   272
  void return_block(MetaWord* p, size_t word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   273
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   274
  size_t total_size() {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   275
  if (dictionary() == NULL) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   276
    return 0;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   277
  } else {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   278
    return dictionary()->total_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   279
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   280
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   281
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   282
  void print_on(outputStream* st) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   283
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   284
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   285
// A VirtualSpaceList node.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   286
class VirtualSpaceNode : public CHeapObj<mtClass> {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   287
  friend class VirtualSpaceList;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   288
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   289
  // Link to next VirtualSpaceNode
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   290
  VirtualSpaceNode* _next;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   291
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   292
  // total in the VirtualSpace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   293
  MemRegion _reserved;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   294
  ReservedSpace _rs;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   295
  VirtualSpace _virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   296
  MetaWord* _top;
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   297
  // count of chunks contained in this VirtualSpace
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   298
  uintx _container_count;
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
  // Convenience functions to access the _virtual_space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   301
  char* low()  const { return virtual_space()->low(); }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   302
  char* high() const { return virtual_space()->high(); }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   303
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   304
  // The first Metachunk will be allocated at the bottom of the
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   305
  // VirtualSpace
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   306
  Metachunk* first_chunk() { return (Metachunk*) bottom(); }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   307
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   308
  // 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
   309
  size_t free_words_in_vs() const;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   310
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   311
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   312
  VirtualSpaceNode(size_t byte_size);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   313
  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
   314
  ~VirtualSpaceNode();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   315
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   316
  // Convenience functions for logical bottom and end
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   317
  MetaWord* bottom() const { return (MetaWord*) _virtual_space.low(); }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   318
  MetaWord* end() const { return (MetaWord*) _virtual_space.high(); }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   319
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
   320
  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
   321
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   322
  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
   323
  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
   324
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   325
  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
   326
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   327
  // address of next available space in _virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   328
  // Accessors
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   329
  VirtualSpaceNode* next() { return _next; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   330
  void set_next(VirtualSpaceNode* v) { _next = v; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   331
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   332
  void set_reserved(MemRegion const v) { _reserved = v; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   333
  void set_top(MetaWord* v) { _top = v; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   334
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   335
  // Accessors
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   336
  MemRegion* reserved() { return &_reserved; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   337
  VirtualSpace* virtual_space() const { return (VirtualSpace*) &_virtual_space; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   338
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   339
  // 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
   340
  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
   341
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   342
  MetaWord* top() const { return _top; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   343
  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
   344
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   345
  uintx container_count() { return _container_count; }
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   346
  void inc_container_count();
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   347
  void dec_container_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   348
#ifdef ASSERT
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   349
  uint container_count_slow();
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   350
  void verify_container_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   351
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   352
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   353
  // 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
   354
  size_t used_words_in_vs() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   355
  size_t capacity_words_in_vs() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   356
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   357
  bool initialize();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   358
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   359
  // get space from the virtual space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   360
  Metachunk* take_from_committed(size_t chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   361
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   362
  // 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
   363
  Metachunk* get_chunk_vs(size_t chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   364
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   365
  // 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
   366
  // to Virtualspace
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   367
  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
   368
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   369
  // In preparation for deleting this node, remove all the chunks
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   370
  // in the node from any freelist.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   371
  void purge(ChunkManager* chunk_manager);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   372
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   373
  // 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
   374
  // 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
   375
  // 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
   376
  // 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
   377
  // 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
   378
  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
   379
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
   380
#ifdef ASSERT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   381
  // Debug support
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   382
  void mangle();
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
   383
#endif
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   384
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   385
  void print_on(outputStream* st) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   386
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   387
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   388
#define assert_is_ptr_aligned(ptr, alignment) \
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   389
  assert(is_ptr_aligned(ptr, alignment),      \
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   390
    err_msg(PTR_FORMAT " is not aligned to "  \
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   391
      SIZE_FORMAT, ptr, alignment))
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   392
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   393
#define assert_is_size_aligned(size, alignment) \
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   394
  assert(is_size_aligned(size, alignment),      \
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   395
    err_msg(SIZE_FORMAT " is not aligned to "   \
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   396
       SIZE_FORMAT, size, alignment))
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   397
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   398
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   399
// 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
   400
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
   401
  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
   402
    size_t words = bytes / BytesPerWord;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   403
    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
   404
    if (MetaspaceGC::can_expand(words, is_class) &&
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   405
        MetaspaceGC::allowed_expansion() >= words) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   406
      return true;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   407
    }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   408
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   409
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   410
  return false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   411
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   412
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   413
  // 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
   414
VirtualSpaceNode::VirtualSpaceNode(size_t bytes) : _top(NULL), _next(NULL), _rs(), _container_count(0) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   415
  assert_is_size_aligned(bytes, Metaspace::reserve_alignment());
16353
d9984db1bba2 8009614: nsk/split_verifier/stress/ifelse/ifelse002_30 fails with 'assert((size & (granularity - 1)) == 0) failed: size not aligned to os::vm_allocation_granularity()
zgu
parents: 15928
diff changeset
   416
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
   417
#if INCLUDE_CDS
16430
882cddc35bec 8008217: CDS: Class data sharing limits the malloc heap on Solaris
coleenp
parents: 16355
diff changeset
   418
  // This allocates memory with mmap.  For DumpSharedspaces, try to reserve
882cddc35bec 8008217: CDS: Class data sharing limits the malloc heap on Solaris
coleenp
parents: 16355
diff changeset
   419
  // configurable address, generally at the top of the Java heap so other
882cddc35bec 8008217: CDS: Class data sharing limits the malloc heap on Solaris
coleenp
parents: 16355
diff changeset
   420
  // memory addresses don't conflict.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   421
  if (DumpSharedSpaces) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   422
    bool large_pages = false; // No large pages when dumping the CDS archive.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   423
    char* shared_base = (char*)align_ptr_up((char*)SharedBaseAddress, Metaspace::reserve_alignment());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   424
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28163
diff changeset
   425
    _rs = ReservedSpace(bytes, Metaspace::reserve_alignment(), large_pages, shared_base);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   426
    if (_rs.is_reserved()) {
16430
882cddc35bec 8008217: CDS: Class data sharing limits the malloc heap on Solaris
coleenp
parents: 16355
diff changeset
   427
      assert(shared_base == 0 || _rs.base() == shared_base, "should match");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   428
    } else {
16430
882cddc35bec 8008217: CDS: Class data sharing limits the malloc heap on Solaris
coleenp
parents: 16355
diff changeset
   429
      // Get a mmap region anywhere if the SharedBaseAddress fails.
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   430
      _rs = ReservedSpace(bytes, Metaspace::reserve_alignment(), large_pages);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   431
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   432
    MetaspaceShared::set_shared_rs(&_rs);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
   433
  } else
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
   434
#endif
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
   435
  {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   436
    bool large_pages = should_commit_large_pages_when_reserving(bytes);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   437
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   438
    _rs = ReservedSpace(bytes, Metaspace::reserve_alignment(), large_pages);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   439
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   440
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   441
  if (_rs.is_reserved()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   442
    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
   443
    assert(_rs.size() != 0, "Catch if we get a 0 size");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   444
    assert_is_ptr_aligned(_rs.base(), Metaspace::reserve_alignment());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   445
    assert_is_size_aligned(_rs.size(), Metaspace::reserve_alignment());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   446
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   447
    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
   448
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   449
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   450
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   451
void VirtualSpaceNode::purge(ChunkManager* chunk_manager) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   452
  Metachunk* chunk = first_chunk();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   453
  Metachunk* invalid_chunk = (Metachunk*) top();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   454
  while (chunk < invalid_chunk ) {
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   455
    assert(chunk->is_tagged_free(), "Should be tagged free");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   456
    MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   457
    chunk_manager->remove_chunk(chunk);
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   458
    assert(chunk->next() == NULL &&
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   459
           chunk->prev() == NULL,
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   460
           "Was not removed from its list");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   461
    chunk = (Metachunk*) next;
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   462
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   463
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   464
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   465
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   466
uint VirtualSpaceNode::container_count_slow() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   467
  uint count = 0;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   468
  Metachunk* chunk = first_chunk();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   469
  Metachunk* invalid_chunk = (Metachunk*) top();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   470
  while (chunk < invalid_chunk ) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   471
    MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   472
    // Don't count the chunks on the free lists.  Those are
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   473
    // still part of the VirtualSpaceNode but not currently
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   474
    // counted.
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   475
    if (!chunk->is_tagged_free()) {
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   476
      count++;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   477
    }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   478
    chunk = (Metachunk*) next;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   479
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   480
  return count;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   481
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   482
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   483
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   484
// List of VirtualSpaces for metadata allocation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   485
class VirtualSpaceList : public CHeapObj<mtClass> {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   486
  friend class VirtualSpaceNode;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   487
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   488
  enum VirtualSpaceSizes {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   489
    VirtualSpaceSize = 256 * K
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   490
  };
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   491
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   492
  // Head of the list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   493
  VirtualSpaceNode* _virtual_space_list;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   494
  // virtual space currently being used for allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   495
  VirtualSpaceNode* _current_virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   496
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   497
  // 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
   498
  bool _is_class;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   499
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   500
  // 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
   501
  size_t _reserved_words;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   502
  size_t _committed_words;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   503
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   504
  // Number of virtual spaces
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   505
  size_t _virtual_space_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   506
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   507
  ~VirtualSpaceList();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   508
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   509
  VirtualSpaceNode* virtual_space_list() const { return _virtual_space_list; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   510
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   511
  void set_virtual_space_list(VirtualSpaceNode* v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   512
    _virtual_space_list = v;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   513
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   514
  void set_current_virtual_space(VirtualSpaceNode* v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   515
    _current_virtual_space = v;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   516
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   517
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   518
  void link_vs(VirtualSpaceNode* new_entry);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   519
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   520
  // 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
   521
  // 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
   522
  // 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
   523
  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
   524
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   525
  // 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
   526
  // 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
   527
  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
   528
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   529
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   530
  VirtualSpaceList(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   531
  VirtualSpaceList(ReservedSpace rs);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   532
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   533
  size_t free_bytes();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   534
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   535
  Metachunk* get_new_chunk(size_t word_size,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   536
                           size_t grow_chunks_by_words,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   537
                           size_t medium_chunk_bunch);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   538
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   539
  bool expand_node_by(VirtualSpaceNode* node,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   540
                      size_t min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   541
                      size_t preferred_words);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   542
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   543
  bool expand_by(size_t min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   544
                 size_t preferred_words);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   545
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   546
  VirtualSpaceNode* current_virtual_space() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   547
    return _current_virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   548
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   549
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   550
  bool is_class() const { return _is_class; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   551
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   552
  bool initialization_succeeded() { return _virtual_space_list != NULL; }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   553
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   554
  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
   555
  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
   556
  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
   557
  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
   558
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
   559
  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
   560
  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
   561
  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
   562
  void dec_committed_words(size_t v);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   563
  void inc_virtual_space_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   564
  void dec_virtual_space_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   565
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
   566
  bool contains(const void* ptr);
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
   567
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   568
  // Unlink empty VirtualSpaceNodes and free it.
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   569
  void purge(ChunkManager* chunk_manager);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   570
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   571
  void print_on(outputStream* st) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   572
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   573
  class VirtualSpaceListIterator : public StackObj {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   574
    VirtualSpaceNode* _virtual_spaces;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   575
   public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   576
    VirtualSpaceListIterator(VirtualSpaceNode* virtual_spaces) :
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   577
      _virtual_spaces(virtual_spaces) {}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   578
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   579
    bool repeat() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   580
      return _virtual_spaces != NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   581
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   582
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   583
    VirtualSpaceNode* get_next() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   584
      VirtualSpaceNode* result = _virtual_spaces;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   585
      if (_virtual_spaces != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   586
        _virtual_spaces = _virtual_spaces->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   587
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   588
      return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   589
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   590
  };
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   591
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   592
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   593
class Metadebug : AllStatic {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   594
  // Debugging support for Metaspaces
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   595
  static int _allocation_fail_alot_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   596
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   597
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   598
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   599
  static void init_allocation_fail_alot_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   600
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   601
  static bool test_metadata_failure();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   602
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   603
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   604
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   605
int Metadebug::_allocation_fail_alot_count = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   606
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   607
//  SpaceManager - used by Metaspace to handle allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   608
class SpaceManager : public CHeapObj<mtClass> {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   609
  friend class Metaspace;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   610
  friend class Metadebug;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   611
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   612
 private:
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   613
22201
9c2ccfa3a5fe 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 21569
diff changeset
   614
  // protects allocations
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   615
  Mutex* const _lock;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   616
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
   617
  // Type of metadata allocated.
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
   618
  Metaspace::MetadataType _mdtype;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
   619
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   620
  // List of chunks in use by this SpaceManager.  Allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   621
  // 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
   622
  // chunks when the SpaceManager is freed.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   623
  Metachunk* _chunks_in_use[NumberOfInUseLists];
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   624
  Metachunk* _current_chunk;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   625
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   626
  // Number of small chunks to allocate to a manager
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   627
  // If class space manager, small chunks are unlimited
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   628
  static uint const _small_chunk_limit;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   629
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   630
  // 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
   631
  size_t _allocated_blocks_words;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   632
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   633
  // Sum of all allocated chunks
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   634
  size_t _allocated_chunks_words;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   635
  size_t _allocated_chunks_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   636
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   637
  // Free lists of blocks are per SpaceManager since they
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   638
  // 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
   639
  // 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
   640
  // the class loader using the SpaceManager is collected.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   641
  BlockFreelist _block_freelists;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   642
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   643
  // protects virtualspace and chunk expansions
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   644
  static const char*  _expand_lock_name;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   645
  static const int    _expand_lock_rank;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   646
  static Mutex* const _expand_lock;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   647
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   648
 private:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   649
  // Accessors
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   650
  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
   651
  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
   652
    _chunks_in_use[index] = v;
9c2ccfa3a5fe 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 21569
diff changeset
   653
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   654
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   655
  BlockFreelist* block_freelists() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   656
    return (BlockFreelist*) &_block_freelists;
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
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
   659
  Metaspace::MetadataType mdtype() { return _mdtype; }
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   660
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   661
  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
   662
  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
   663
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   664
  Metachunk* current_chunk() const { return _current_chunk; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   665
  void set_current_chunk(Metachunk* v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   666
    _current_chunk = v;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   667
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   668
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   669
  Metachunk* find_current_chunk(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   670
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   671
  // Add chunk to the list of chunks in use
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   672
  void add_chunk(Metachunk* v, bool make_current);
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   673
  void retire_current_chunk();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   674
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   675
  Mutex* lock() const { return _lock; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   676
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   677
  const char* chunk_size_name(ChunkIndex index) const;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   678
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   679
 protected:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   680
  void initialize();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   681
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   682
 public:
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
   683
  SpaceManager(Metaspace::MetadataType mdtype,
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   684
               Mutex* lock);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   685
  ~SpaceManager();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   686
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   687
  enum ChunkMultiples {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   688
    MediumChunkMultiple = 4
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
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   691
  bool is_class() { return _mdtype == Metaspace::ClassType; }
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   692
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   693
  // Accessors
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   694
  size_t specialized_chunk_size() { return (size_t) is_class() ? ClassSpecializedChunk : SpecializedChunk; }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   695
  size_t small_chunk_size()       { return (size_t) is_class() ? ClassSmallChunk : SmallChunk; }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   696
  size_t medium_chunk_size()      { return (size_t) is_class() ? ClassMediumChunk : MediumChunk; }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   697
  size_t medium_chunk_bunch()     { return medium_chunk_size() * MediumChunkMultiple; }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   698
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
   699
  size_t smallest_chunk_size()  { return specialized_chunk_size(); }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   700
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   701
  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
   702
  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
   703
  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
   704
  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
   705
  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
   706
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   707
  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
   708
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   709
  static Mutex* expand_lock() { return _expand_lock; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   710
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   711
  // 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
   712
  // 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
   713
  // the in-use list.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   714
  void inc_size_metrics(size_t words);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   715
  // 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
   716
  // 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
   717
  void inc_used_metrics(size_t words);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   718
  // 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
   719
  // 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
   720
  // 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
   721
  void dec_total_from_size_metrics();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   722
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   723
  // Set the sizes for the initial chunks.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   724
  void get_initial_chunk_sizes(Metaspace::MetaspaceType type,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   725
                               size_t* chunk_word_size,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   726
                               size_t* class_chunk_word_size);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   727
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   728
  size_t sum_capacity_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   729
  size_t sum_used_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   730
  size_t sum_free_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   731
  size_t sum_waste_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   732
  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
   733
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   734
  size_t sum_count_in_chunks_in_use();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   735
  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
   736
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   737
  Metachunk* get_new_chunk(size_t word_size, size_t grow_chunks_by_words);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   738
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   739
  // Block allocation and deallocation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   740
  // Allocates a block from the current chunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   741
  MetaWord* allocate(size_t word_size);
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
  // Helper for allocations
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   744
  MetaWord* allocate_work(size_t word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   745
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   746
  // Returns a block to the per manager freelist
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   747
  void deallocate(MetaWord* p, size_t word_size);
13728
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
  // 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
   750
  // returned chunk size (for expanding space for chunk allocation).
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   751
  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
   752
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   753
  // Called when an allocation from the current chunk fails.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   754
  // 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
   755
  // and allocates from that chunk.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   756
  MetaWord* grow_and_allocate(size_t word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   757
20407
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
   758
  // Notify memory usage to MemoryService.
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
   759
  void track_metaspace_memory_usage();
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
   760
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   761
  // debugging support.
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
  void dump(outputStream* const out) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   764
  void print_on(outputStream* st) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   765
  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
   766
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   767
  void verify();
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
   768
  void verify_chunk_size(Metachunk* chunk);
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
   769
  NOT_PRODUCT(void mangle_freed_chunks();)
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   770
#ifdef ASSERT
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   771
  void verify_allocated_blocks_words();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   772
#endif
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   773
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   774
  size_t get_raw_word_size(size_t word_size) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   775
    size_t byte_size = word_size * BytesPerWord;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   776
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   777
    size_t raw_bytes_size = MAX2(byte_size, sizeof(Metablock));
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   778
    raw_bytes_size = align_size_up(raw_bytes_size, Metachunk::object_alignment());
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   779
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   780
    size_t raw_word_size = raw_bytes_size / BytesPerWord;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   781
    assert(raw_word_size * BytesPerWord == raw_bytes_size, "Size problem");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   782
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   783
    return raw_word_size;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   784
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   785
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   786
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   787
uint const SpaceManager::_small_chunk_limit = 4;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   788
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   789
const char* SpaceManager::_expand_lock_name =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   790
  "SpaceManager chunk allocation lock";
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   791
const int SpaceManager::_expand_lock_rank = Monitor::leaf - 1;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   792
Mutex* const SpaceManager::_expand_lock =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   793
  new Mutex(SpaceManager::_expand_lock_rank,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   794
            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
   795
            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
   796
            Monitor::_safepoint_check_never);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   797
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   798
void VirtualSpaceNode::inc_container_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   799
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   800
  _container_count++;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   801
  assert(_container_count == container_count_slow(),
22775
52bc5222f5f1 8026849: Fix typos in the GC code, part 2
jwilhelm
parents: 22551
diff changeset
   802
         err_msg("Inconsistency in container_count _container_count " SIZE_FORMAT
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   803
                 " container_count_slow() " SIZE_FORMAT,
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   804
                 _container_count, container_count_slow()));
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   805
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   806
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   807
void VirtualSpaceNode::dec_container_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   808
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   809
  _container_count--;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   810
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   811
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   812
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   813
void VirtualSpaceNode::verify_container_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   814
  assert(_container_count == container_count_slow(),
22775
52bc5222f5f1 8026849: Fix typos in the GC code, part 2
jwilhelm
parents: 22551
diff changeset
   815
    err_msg("Inconsistency in container_count _container_count " SIZE_FORMAT
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
   816
            " container_count_slow() " SIZE_FORMAT, _container_count, container_count_slow()));
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   817
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   818
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   819
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   820
// BlockFreelist methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   821
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   822
BlockFreelist::BlockFreelist() : _dictionary(NULL) {}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   823
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   824
BlockFreelist::~BlockFreelist() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   825
  if (_dictionary != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   826
    if (Verbose && TraceMetadataChunkAllocation) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   827
      _dictionary->print_free_lists(gclog_or_tty);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   828
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   829
    delete _dictionary;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   830
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   831
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   832
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   833
void BlockFreelist::return_block(MetaWord* p, size_t word_size) {
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
   834
  Metablock* free_chunk = ::new (p) Metablock(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   835
  if (dictionary() == NULL) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   836
   _dictionary = new BlockTreeDictionary();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   837
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   838
  dictionary()->return_chunk(free_chunk);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   839
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   840
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   841
MetaWord* BlockFreelist::get_block(size_t word_size) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   842
  if (dictionary() == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   843
    return NULL;
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
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   846
  if (word_size < TreeChunk<Metablock, FreeList<Metablock> >::min_size()) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   847
    // Dark matter.  Too small for dictionary.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   848
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   849
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   850
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   851
  Metablock* free_block =
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   852
    dictionary()->get_chunk(word_size, FreeBlockDictionary<Metablock>::atLeast);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   853
  if (free_block == NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   854
    return NULL;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   855
  }
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   856
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   857
  const size_t block_size = free_block->size();
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   858
  if (block_size > WasteMultiplier * word_size) {
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   859
    return_block((MetaWord*)free_block, block_size);
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   860
    return NULL;
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   861
  }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   862
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   863
  MetaWord* new_block = (MetaWord*)free_block;
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   864
  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
   865
  const size_t unused = block_size - word_size;
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   866
  if (unused >= TreeChunk<Metablock, FreeList<Metablock> >::min_size()) {
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   867
    return_block(new_block + word_size, unused);
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   868
  }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   869
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   870
  return new_block;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   871
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   872
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   873
void BlockFreelist::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   874
  if (dictionary() == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   875
    return;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   876
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   877
  dictionary()->print_free_lists(st);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   878
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   879
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   880
// VirtualSpaceNode methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   881
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   882
VirtualSpaceNode::~VirtualSpaceNode() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   883
  _rs.release();
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   884
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   885
  size_t word_size = sizeof(*this) / BytesPerWord;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   886
  Copy::fill_to_words((HeapWord*) this, word_size, 0xf1f1f1f1);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   887
#endif
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
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   890
size_t VirtualSpaceNode::used_words_in_vs() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   891
  return pointer_delta(top(), bottom(), sizeof(MetaWord));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   892
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   893
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   894
// Space committed in the VirtualSpace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   895
size_t VirtualSpaceNode::capacity_words_in_vs() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   896
  return pointer_delta(end(), bottom(), sizeof(MetaWord));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   897
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   898
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   899
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
   900
  return pointer_delta(end(), top(), sizeof(MetaWord));
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   901
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   902
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   903
// Allocates the chunk from the virtual space only.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   904
// 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
   905
// chunks removed here are necessarily used for allocation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   906
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
   907
  // Bottom of the new chunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   908
  MetaWord* chunk_limit = top();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   909
  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
   910
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   911
  // 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
   912
  // commit granularity to enforce the following condition.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   913
  // 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
   914
  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
   915
      "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
   916
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   917
  if (!is_available(chunk_word_size)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   918
    if (TraceMetadataChunkAllocation) {
19993
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19992
diff changeset
   919
      gclog_or_tty->print("VirtualSpaceNode::take_from_committed() not available %d words ", chunk_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   920
      // Dump some information about the virtual space that is nearly full
19993
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19992
diff changeset
   921
      print_on(gclog_or_tty);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   922
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   923
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   924
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   925
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   926
  // 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
   927
  inc_top(chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   928
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   929
  // Initialize the chunk
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   930
  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
   931
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   932
}
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
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   935
// 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
   936
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
   937
  size_t min_bytes = min_words * BytesPerWord;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   938
  size_t preferred_bytes = preferred_words * BytesPerWord;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   939
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   940
  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
   941
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   942
  if (uncommitted < min_bytes) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   943
    return false;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   944
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   945
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   946
  size_t commit = MIN2(preferred_bytes, uncommitted);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   947
  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
   948
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   949
  assert(result, "Failed to commit memory");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   950
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   951
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   952
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   953
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   954
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
   955
  assert_lock_strong(SpaceManager::expand_lock());
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   956
  Metachunk* result = take_from_committed(chunk_word_size);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   957
  if (result != NULL) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   958
    inc_container_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   959
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   960
  return result;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   961
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   962
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   963
bool VirtualSpaceNode::initialize() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   964
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   965
  if (!_rs.is_reserved()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   966
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   967
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   968
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   969
  // 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
   970
  // 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
   971
  // aligned only the middle alignment of the VirtualSpace is used.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   972
  assert_is_ptr_aligned(_rs.base(), Metaspace::commit_alignment());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   973
  assert_is_size_aligned(_rs.size(), Metaspace::commit_alignment());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   974
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   975
  // 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
   976
  // 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
   977
  // committed_size and actual_committed_size agrees.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   978
  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
   979
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   980
  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
   981
                                            Metaspace::commit_alignment());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   982
  if (result) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
   983
    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
   984
        "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
   985
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   986
    set_top((MetaWord*)virtual_space()->low());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   987
    set_reserved(MemRegion((HeapWord*)_rs.base(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   988
                 (HeapWord*)(_rs.base() + _rs.size())));
13729
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
   989
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
   990
    assert(reserved()->start() == (HeapWord*) _rs.base(),
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
   991
      err_msg("Reserved start was not set properly " PTR_FORMAT
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
   992
        " != " PTR_FORMAT, reserved()->start(), _rs.base()));
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
   993
    assert(reserved()->word_size() == _rs.size() / BytesPerWord,
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
   994
      err_msg("Reserved size was not set properly " SIZE_FORMAT
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
   995
        " != " SIZE_FORMAT, reserved()->word_size(),
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
   996
        _rs.size() / BytesPerWord));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   997
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   998
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   999
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1000
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1001
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1002
void VirtualSpaceNode::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1003
  size_t used = used_words_in_vs();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1004
  size_t capacity = capacity_words_in_vs();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1005
  VirtualSpace* vs = virtual_space();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1006
  st->print_cr("   space @ " PTR_FORMAT " " SIZE_FORMAT "K, %3d%% used "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1007
           "[" PTR_FORMAT ", " PTR_FORMAT ", "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1008
           PTR_FORMAT ", " PTR_FORMAT ")",
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1009
           vs, capacity / K,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1010
           capacity == 0 ? 0 : used * 100 / capacity,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1011
           bottom(), top(), end(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1012
           vs->high_boundary());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1013
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1014
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
  1015
#ifdef ASSERT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1016
void VirtualSpaceNode::mangle() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1017
  size_t word_size = capacity_words_in_vs();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1018
  Copy::fill_to_words((HeapWord*) low(), word_size, 0xf1f1f1f1);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1019
}
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
  1020
#endif // ASSERT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1021
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1022
// VirtualSpaceList methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1023
// Space allocated from the VirtualSpace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1024
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1025
VirtualSpaceList::~VirtualSpaceList() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1026
  VirtualSpaceListIterator iter(virtual_space_list());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1027
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1028
    VirtualSpaceNode* vsl = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1029
    delete vsl;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1030
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1031
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1032
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1033
void VirtualSpaceList::inc_reserved_words(size_t v) {
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1034
  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
  1035
  _reserved_words = _reserved_words + v;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1036
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1037
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
  1038
  assert_lock_strong(SpaceManager::expand_lock());
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1039
  _reserved_words = _reserved_words - v;
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1040
}
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1041
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1042
#define assert_committed_below_limit()                             \
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1043
  assert(MetaspaceAux::committed_bytes() <= MaxMetaspaceSize,      \
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1044
      err_msg("Too much committed memory. Committed: " SIZE_FORMAT \
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1045
              " limit (MaxMetaspaceSize): " SIZE_FORMAT,           \
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1046
          MetaspaceAux::committed_bytes(), MaxMetaspaceSize));
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1047
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1048
void VirtualSpaceList::inc_committed_words(size_t v) {
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1049
  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
  1050
  _committed_words = _committed_words + v;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1051
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1052
  assert_committed_below_limit();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1053
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1054
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
  1055
  assert_lock_strong(SpaceManager::expand_lock());
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1056
  _committed_words = _committed_words - v;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1057
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1058
  assert_committed_below_limit();
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1059
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1060
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1061
void VirtualSpaceList::inc_virtual_space_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1062
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1063
  _virtual_space_count++;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1064
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1065
void VirtualSpaceList::dec_virtual_space_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1066
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1067
  _virtual_space_count--;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1068
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1069
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1070
void ChunkManager::remove_chunk(Metachunk* chunk) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1071
  size_t word_size = chunk->word_size();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1072
  ChunkIndex index = list_index(word_size);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1073
  if (index != HumongousIndex) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1074
    free_chunks(index)->remove_chunk(chunk);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1075
  } else {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1076
    humongous_dictionary()->remove_chunk(chunk);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1077
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1078
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1079
  // Chunk is being removed from the chunks free list.
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  1080
  dec_free_chunks_total(chunk->word_size());
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1081
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1082
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1083
// Walk the list of VirtualSpaceNodes and delete
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1084
// nodes with a 0 container_count.  Remove Metachunks in
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1085
// the node from their respective freelists.
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1086
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
  1087
  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
  1088
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1089
  // Don't use a VirtualSpaceListIterator because this
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1090
  // 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
  1091
  VirtualSpaceNode* purged_vsl = NULL;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1092
  VirtualSpaceNode* prev_vsl = virtual_space_list();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1093
  VirtualSpaceNode* next_vsl = prev_vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1094
  while (next_vsl != NULL) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1095
    VirtualSpaceNode* vsl = next_vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1096
    next_vsl = vsl->next();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1097
    // Don't free the current virtual space since it will likely
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1098
    // be needed soon.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1099
    if (vsl->container_count() == 0 && vsl != current_virtual_space()) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1100
      // Unlink it from the list
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1101
      if (prev_vsl == vsl) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1102
        // 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
  1103
        assert(vsl == virtual_space_list(), "Expected to be the first node");
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1104
        set_virtual_space_list(vsl->next());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1105
      } else {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1106
        prev_vsl->set_next(vsl->next());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1107
      }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1108
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1109
      vsl->purge(chunk_manager);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1110
      dec_reserved_words(vsl->reserved_words());
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1111
      dec_committed_words(vsl->committed_words());
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1112
      dec_virtual_space_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1113
      purged_vsl = vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1114
      delete vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1115
    } else {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1116
      prev_vsl = vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1117
    }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1118
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1119
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1120
  if (purged_vsl != NULL) {
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1121
    // 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
  1122
    VirtualSpaceListIterator iter(virtual_space_list());
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1123
    while (iter.repeat()) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1124
      VirtualSpaceNode* vsl = iter.get_next();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1125
      assert(vsl != purged_vsl, "Purge of vsl failed");
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1126
    }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1127
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1128
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1129
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1130
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1131
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1132
// 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
  1133
// 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
  1134
// unloading time during a safepoint.
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1135
bool VirtualSpaceList::contains(const void* ptr) {
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1136
  // 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
  1137
  // 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
  1138
  VirtualSpaceListIterator iter(virtual_space_list());
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1139
  while (iter.repeat()) {
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1140
    VirtualSpaceNode* vsn = iter.get_next();
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1141
    if (vsn->contains(ptr)) {
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1142
      return true;
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1143
    }
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1144
  }
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1145
  return false;
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1146
}
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  1147
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1148
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
  1149
  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
  1150
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1151
  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
  1152
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1153
  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
  1154
                                  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
  1155
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1156
  vsn->retire(cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1157
}
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1158
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1159
void VirtualSpaceNode::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
  1160
  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
  1161
    ChunkIndex index = (ChunkIndex)i;
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1162
    size_t chunk_size = chunk_manager->free_chunks(index)->size();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1163
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1164
    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
  1165
      DEBUG_ONLY(verify_container_count();)
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1166
      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
  1167
      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
  1168
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1169
      chunk_manager->return_chunks(index, chunk);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1170
      chunk_manager->inc_free_chunks_total(chunk_size);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1171
      DEBUG_ONLY(verify_container_count();)
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1172
    }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1173
  }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1174
  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
  1175
}
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1176
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1177
VirtualSpaceList::VirtualSpaceList(size_t word_size) :
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1178
                                   _is_class(false),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1179
                                   _virtual_space_list(NULL),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1180
                                   _current_virtual_space(NULL),
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1181
                                   _reserved_words(0),
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1182
                                   _committed_words(0),
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1183
                                   _virtual_space_count(0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1184
  MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1185
                   Mutex::_no_safepoint_check_flag);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1186
  create_new_virtual_space(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1187
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1188
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1189
VirtualSpaceList::VirtualSpaceList(ReservedSpace rs) :
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1190
                                   _is_class(true),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1191
                                   _virtual_space_list(NULL),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1192
                                   _current_virtual_space(NULL),
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1193
                                   _reserved_words(0),
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1194
                                   _committed_words(0),
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1195
                                   _virtual_space_count(0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1196
  MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1197
                   Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1198
  VirtualSpaceNode* class_entry = new VirtualSpaceNode(rs);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1199
  bool succeeded = class_entry->initialize();
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1200
  if (succeeded) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1201
    link_vs(class_entry);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1202
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1203
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1204
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1205
size_t VirtualSpaceList::free_bytes() {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1206
  return virtual_space_list()->free_words_in_vs() * BytesPerWord;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1207
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1208
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1209
// 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
  1210
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
  1211
  assert_lock_strong(SpaceManager::expand_lock());
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1212
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1213
  if (is_class()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1214
    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
  1215
                  " 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
  1216
                  " 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
  1217
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1218
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1219
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1220
  if (vs_word_size == 0) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1221
    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
  1222
    return false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1223
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1224
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1225
  // Reserve the space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1226
  size_t vs_byte_size = vs_word_size * BytesPerWord;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1227
  assert_is_size_aligned(vs_byte_size, Metaspace::reserve_alignment());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1228
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1229
  // Allocate the meta virtual space and initialize it.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1230
  VirtualSpaceNode* new_entry = new VirtualSpaceNode(vs_byte_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1231
  if (!new_entry->initialize()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1232
    delete new_entry;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1233
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1234
  } else {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1235
    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
  1236
        "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
  1237
    // 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
  1238
    OrderAccess::storestore();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1239
    link_vs(new_entry);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1240
    return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1241
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1242
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1243
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1244
void VirtualSpaceList::link_vs(VirtualSpaceNode* new_entry) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1245
  if (virtual_space_list() == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1246
      set_virtual_space_list(new_entry);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1247
  } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1248
    current_virtual_space()->set_next(new_entry);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1249
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1250
  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
  1251
  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
  1252
  inc_committed_words(new_entry->committed_words());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1253
  inc_virtual_space_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1254
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1255
  new_entry->mangle();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1256
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1257
  if (TraceMetavirtualspaceAllocation && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1258
    VirtualSpaceNode* vsl = current_virtual_space();
19993
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19992
diff changeset
  1259
    vsl->print_on(gclog_or_tty);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1260
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1261
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1262
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1263
bool VirtualSpaceList::expand_node_by(VirtualSpaceNode* node,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1264
                                      size_t min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1265
                                      size_t preferred_words) {
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1266
  size_t before = node->committed_words();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1267
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1268
  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
  1269
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1270
  size_t after = node->committed_words();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1271
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1272
  // 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
  1273
  assert(after >= before, "Inconsistency");
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1274
  inc_committed_words(after - before);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1275
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1276
  return result;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1277
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  1278
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1279
bool VirtualSpaceList::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
  1280
  assert_is_size_aligned(min_words,       Metaspace::commit_alignment_words());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1281
  assert_is_size_aligned(preferred_words, Metaspace::commit_alignment_words());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1282
  assert(min_words <= preferred_words, "Invalid arguments");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1283
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1284
  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
  1285
    return  false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1286
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1287
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1288
  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
  1289
  if (allowed_expansion_words < min_words) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1290
    return false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1291
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1292
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1293
  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
  1294
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1295
  // 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
  1296
  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
  1297
                                    min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1298
                                    max_expansion_words);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1299
  if (vs_expanded) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1300
    return true;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1301
  }
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  1302
  retire_current_virtual_space();
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1303
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1304
  // Get another virtual space.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1305
  size_t grow_vs_words = MAX2((size_t)VirtualSpaceSize, preferred_words);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1306
  grow_vs_words = align_size_up(grow_vs_words, Metaspace::reserve_alignment_words());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1307
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1308
  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
  1309
    if (current_virtual_space()->is_pre_committed()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1310
      // 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
  1311
      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
  1312
          "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
  1313
          "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
  1314
      return true;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1315
    }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1316
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1317
    return expand_node_by(current_virtual_space(),
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1318
                          min_words,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1319
                          max_expansion_words);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1320
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1321
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1322
  return false;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1323
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1324
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1325
Metachunk* VirtualSpaceList::get_new_chunk(size_t word_size,
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1326
                                           size_t grow_chunks_by_words,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1327
                                           size_t medium_chunk_bunch) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1328
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1329
  // Allocate a chunk out of the current virtual space.
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1330
  Metachunk* next = current_virtual_space()->get_chunk_vs(grow_chunks_by_words);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1331
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1332
  if (next != NULL) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1333
    return next;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1334
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1335
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1336
  // 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
  1337
  // 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
  1338
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1339
  size_t min_word_size       = align_size_up(grow_chunks_by_words, Metaspace::commit_alignment_words());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1340
  size_t preferred_word_size = align_size_up(medium_chunk_bunch,   Metaspace::commit_alignment_words());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1341
  if (min_word_size >= preferred_word_size) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1342
    // Can happen when humongous chunks are allocated.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1343
    preferred_word_size = min_word_size;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1344
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1345
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1346
  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
  1347
  if (expanded) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1348
    next = current_virtual_space()->get_chunk_vs(grow_chunks_by_words);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1349
    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
  1350
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1351
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1352
   return next;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1353
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1354
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1355
void VirtualSpaceList::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1356
  if (TraceMetadataChunkAllocation && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1357
    VirtualSpaceListIterator iter(virtual_space_list());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1358
    while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1359
      VirtualSpaceNode* node = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1360
      node->print_on(st);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1361
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1362
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1363
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1364
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1365
// MetaspaceGC methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1366
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1367
// VM_CollectForMetadataAllocation is the vm operation used to GC.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1368
// 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
  1369
// 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
  1370
// 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
  1371
// 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
  1372
// gen had bounds, MinMetaspaceExpansion and MaxMetaspaceExpansion.  The
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1373
// 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
  1374
//
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1375
// 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
  1376
// 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
  1377
// 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
  1378
// 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
  1379
// 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
  1380
// 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
  1381
// 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
  1382
// 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
  1383
// the HWM.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1384
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1385
// 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
  1386
// Increase by a minimum amount (MinMetaspaceExpansion) so that
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1387
// 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
  1388
// 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
  1389
// 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
  1390
// plus some.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1391
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
  1392
  size_t min_delta = MinMetaspaceExpansion;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1393
  size_t max_delta = MaxMetaspaceExpansion;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1394
  size_t delta = align_size_up(bytes, Metaspace::commit_alignment());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1395
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1396
  if (delta <= min_delta) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1397
    delta = min_delta;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1398
  } else if (delta <= max_delta) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1399
    // 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
  1400
    // allocation so make the delta greater than just enough
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1401
    // for this allocation.
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1402
    delta = max_delta;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1403
  } else {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1404
    // 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
  1405
    // so increase by the minimum.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1406
    delta = delta + min_delta;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1407
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1408
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1409
  assert_is_size_aligned(delta, Metaspace::commit_alignment());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1410
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1411
  return delta;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1412
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1413
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1414
size_t MetaspaceGC::capacity_until_GC() {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1415
  size_t value = (size_t)OrderAccess::load_ptr_acquire(&_capacity_until_GC);
27693
3eee985a97e7 8059492: Wrong spelling in assert: "Not initialied properly?"
aharlap
parents: 27683
diff changeset
  1416
  assert(value >= MetaspaceSize, "Not initialized properly?");
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1417
  return value;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1418
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1419
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1420
bool MetaspaceGC::inc_capacity_until_GC(size_t v, size_t* new_cap_until_GC, size_t* old_cap_until_GC) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1421
  assert_is_size_aligned(v, Metaspace::commit_alignment());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1422
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1423
  size_t capacity_until_GC = (size_t) _capacity_until_GC;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1424
  size_t new_value = capacity_until_GC + v;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1425
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1426
  if (new_value < capacity_until_GC) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1427
    // The addition wrapped around, set new_value to aligned max value.
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1428
    new_value = align_size_down(max_uintx, Metaspace::commit_alignment());
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1429
  }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1430
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1431
  intptr_t expected = (intptr_t) capacity_until_GC;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1432
  intptr_t actual = Atomic::cmpxchg_ptr((intptr_t) new_value, &_capacity_until_GC, expected);
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1433
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1434
  if (expected != actual) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1435
    return false;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1436
  }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1437
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1438
  if (new_cap_until_GC != NULL) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1439
    *new_cap_until_GC = new_value;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1440
  }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1441
  if (old_cap_until_GC != NULL) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1442
    *old_cap_until_GC = capacity_until_GC;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1443
  }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1444
  return true;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1445
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1446
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1447
size_t MetaspaceGC::dec_capacity_until_GC(size_t v) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1448
  assert_is_size_aligned(v, Metaspace::commit_alignment());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1449
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1450
  return (size_t)Atomic::add_ptr(-(intptr_t)v, &_capacity_until_GC);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1451
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1452
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1453
void MetaspaceGC::initialize() {
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1454
  // 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
  1455
  // we can't do a GC during initialization.
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1456
  _capacity_until_GC = MaxMetaspaceSize;
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1457
}
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1458
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1459
void MetaspaceGC::post_initialize() {
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1460
  // 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
  1461
  _capacity_until_GC = MAX2(MetaspaceAux::committed_bytes(), MetaspaceSize);
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1462
}
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1463
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1464
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
  1465
  // 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
  1466
  if (is_class && Metaspace::using_class_space()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1467
    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
  1468
    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
  1469
      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
  1470
    }
16391
7bf8a7699f5f 8004241: NPG: Metaspace occupies more memory than specified by -XX:MaxMetaspaceSize option
mgerdin
parents: 16387
diff changeset
  1471
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1472
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1473
  // 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
  1474
  size_t committed_bytes = MetaspaceAux::committed_bytes();
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1475
  if (committed_bytes + word_size * BytesPerWord > MaxMetaspaceSize) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1476
    return false;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1477
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1478
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1479
  return true;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1480
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1481
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1482
size_t MetaspaceGC::allowed_expansion() {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1483
  size_t committed_bytes = MetaspaceAux::committed_bytes();
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1484
  size_t capacity_until_gc = capacity_until_GC();
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1485
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1486
  assert(capacity_until_gc >= committed_bytes,
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1487
        err_msg("capacity_until_gc: " SIZE_FORMAT " < committed_bytes: " SIZE_FORMAT,
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1488
                capacity_until_gc, committed_bytes));
20406
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 left_until_max  = MaxMetaspaceSize - committed_bytes;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1491
  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
  1492
  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
  1493
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1494
  return left_to_commit / BytesPerWord;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1495
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1496
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1497
void MetaspaceGC::compute_new_size() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1498
  assert(_shrink_factor <= 100, "invalid shrink factor");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1499
  uint current_shrink_factor = _shrink_factor;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1500
  _shrink_factor = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1501
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1502
  // 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
  1503
  // 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
  1504
  // un-fragmented chunk free list is available for future allocations.
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  1505
  // 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
  1506
  // 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
  1507
  // 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
  1508
  // 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
  1509
  // 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
  1510
  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
  1511
  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
  1512
15610
528d799702c7 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 15488
diff changeset
  1513
  const double minimum_free_percentage = MinMetaspaceFreeRatio / 100.0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1514
  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
  1515
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1516
  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
  1517
  size_t minimum_desired_capacity =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1518
    (size_t)MIN2(min_tmp, double(max_uintx));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1519
  // Don't shrink less than the initial generation size
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1520
  minimum_desired_capacity = MAX2(minimum_desired_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1521
                                  MetaspaceSize);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1522
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1523
  if (PrintGCDetails && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1524
    gclog_or_tty->print_cr("\nMetaspaceGC::compute_new_size: ");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1525
    gclog_or_tty->print_cr("  "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1526
                  "  minimum_free_percentage: %6.2f"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1527
                  "  maximum_used_percentage: %6.2f",
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1528
                  minimum_free_percentage,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1529
                  maximum_used_percentage);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1530
    gclog_or_tty->print_cr("  "
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1531
                  "   used_after_gc       : %6.1fKB",
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1532
                  used_after_gc / (double) K);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1533
  }
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
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1536
  size_t shrink_bytes = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1537
  if (capacity_until_GC < minimum_desired_capacity) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1538
    // 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
  1539
    // increment the HWM.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1540
    size_t expand_bytes = minimum_desired_capacity - capacity_until_GC;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1541
    expand_bytes = align_size_up(expand_bytes, Metaspace::commit_alignment());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1542
    // Don't expand unless it's significant
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1543
    if (expand_bytes >= MinMetaspaceExpansion) {
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1544
      size_t new_capacity_until_GC = 0;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1545
      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
  1546
      assert(succeeded, "Should always succesfully increment HWM when at safepoint");
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  1547
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1548
      Metaspace::tracer()->report_gc_threshold(capacity_until_GC,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1549
                                               new_capacity_until_GC,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1550
                                               MetaspaceGCThresholdUpdater::ComputeNewSize);
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1551
      if (PrintGCDetails && Verbose) {
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1552
        gclog_or_tty->print_cr("    expanding:"
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1553
                      "  minimum_desired_capacity: %6.1fKB"
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1554
                      "  expand_bytes: %6.1fKB"
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1555
                      "  MinMetaspaceExpansion: %6.1fKB"
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1556
                      "  new metaspace HWM:  %6.1fKB",
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1557
                      minimum_desired_capacity / (double) K,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1558
                      expand_bytes / (double) K,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1559
                      MinMetaspaceExpansion / (double) K,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1560
                      new_capacity_until_GC / (double) K);
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1561
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1562
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1563
    return;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1564
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1565
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1566
  // No expansion, now see if we want to shrink
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1567
  // We would never want to shrink more than this
22499
33777708d0fc 8031779: Assert in MetaspaceGC is always true
ehelin
parents: 22248
diff changeset
  1568
  assert(capacity_until_GC >= minimum_desired_capacity,
33777708d0fc 8031779: Assert in MetaspaceGC is always true
ehelin
parents: 22248
diff changeset
  1569
         err_msg(SIZE_FORMAT " >= " SIZE_FORMAT,
33777708d0fc 8031779: Assert in MetaspaceGC is always true
ehelin
parents: 22248
diff changeset
  1570
                 capacity_until_GC, minimum_desired_capacity));
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1571
  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
  1572
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1573
  // Should shrinking be considered?
15610
528d799702c7 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 15488
diff changeset
  1574
  if (MaxMetaspaceFreeRatio < 100) {
528d799702c7 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 15488
diff changeset
  1575
    const double maximum_free_percentage = MaxMetaspaceFreeRatio / 100.0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1576
    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
  1577
    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
  1578
    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
  1579
    maximum_desired_capacity = MAX2(maximum_desired_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1580
                                    MetaspaceSize);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1581
    if (PrintGCDetails && Verbose) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1582
      gclog_or_tty->print_cr("  "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1583
                             "  maximum_free_percentage: %6.2f"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1584
                             "  minimum_used_percentage: %6.2f",
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1585
                             maximum_free_percentage,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1586
                             minimum_used_percentage);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1587
      gclog_or_tty->print_cr("  "
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1588
                             "  minimum_desired_capacity: %6.1fKB"
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1589
                             "  maximum_desired_capacity: %6.1fKB",
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1590
                             minimum_desired_capacity / (double) K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1591
                             maximum_desired_capacity / (double) K);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1592
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1593
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1594
    assert(minimum_desired_capacity <= maximum_desired_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1595
           "sanity check");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1596
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1597
    if (capacity_until_GC > maximum_desired_capacity) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1598
      // Capacity too large, compute shrinking size
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1599
      shrink_bytes = capacity_until_GC - maximum_desired_capacity;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1600
      // 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
  1601
      // 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
  1602
      // 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
  1603
      // 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
  1604
      // 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
  1605
      // 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
  1606
      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
  1607
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1608
      shrink_bytes = align_size_down(shrink_bytes, Metaspace::commit_alignment());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1609
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1610
      assert(shrink_bytes <= max_shrink_bytes,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1611
        err_msg("invalid shrink size " SIZE_FORMAT " not <= " SIZE_FORMAT,
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1612
          shrink_bytes, max_shrink_bytes));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1613
      if (current_shrink_factor == 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1614
        _shrink_factor = 10;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1615
      } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1616
        _shrink_factor = MIN2(current_shrink_factor * 4, (uint) 100);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1617
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1618
      if (PrintGCDetails && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1619
        gclog_or_tty->print_cr("  "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1620
                      "  shrinking:"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1621
                      "  initSize: %.1fK"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1622
                      "  maximum_desired_capacity: %.1fK",
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1623
                      MetaspaceSize / (double) K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1624
                      maximum_desired_capacity / (double) K);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1625
        gclog_or_tty->print_cr("  "
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1626
                      "  shrink_bytes: %.1fK"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1627
                      "  current_shrink_factor: %d"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1628
                      "  new shrink factor: %d"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1629
                      "  MinMetaspaceExpansion: %.1fK",
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1630
                      shrink_bytes / (double) K,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1631
                      current_shrink_factor,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1632
                      _shrink_factor,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1633
                      MinMetaspaceExpansion / (double) K);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1634
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1635
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1636
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1637
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1638
  // 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
  1639
  if (shrink_bytes >= MinMetaspaceExpansion &&
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1640
      ((capacity_until_GC - shrink_bytes) >= MetaspaceSize)) {
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1641
    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
  1642
    Metaspace::tracer()->report_gc_threshold(capacity_until_GC,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1643
                                             new_capacity_until_GC,
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  1644
                                             MetaspaceGCThresholdUpdater::ComputeNewSize);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1645
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1646
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1647
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1648
// Metadebug methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1649
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1650
void Metadebug::init_allocation_fail_alot_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1651
  if (MetadataAllocationFailALot) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1652
    _allocation_fail_alot_count =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1653
      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
  1654
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1655
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1656
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1657
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1658
bool Metadebug::test_metadata_failure() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1659
  if (MetadataAllocationFailALot &&
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1660
      Threads::is_vm_complete()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1661
    if (_allocation_fail_alot_count > 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1662
      _allocation_fail_alot_count--;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1663
    } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1664
      if (TraceMetadataChunkAllocation && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1665
        gclog_or_tty->print_cr("Metadata allocation failing for "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1666
                               "MetadataAllocationFailALot");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1667
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1668
      init_allocation_fail_alot_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1669
      return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1670
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1671
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1672
  return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1673
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1674
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1675
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1676
// ChunkManager methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1677
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  1678
size_t ChunkManager::free_chunks_total_words() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1679
  return _free_chunks_total;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1680
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1681
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  1682
size_t ChunkManager::free_chunks_total_bytes() {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  1683
  return free_chunks_total_words() * BytesPerWord;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1684
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1685
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1686
size_t ChunkManager::free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1687
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1688
  if (!UseConcMarkSweepGC && !SpaceManager::expand_lock()->is_locked()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1689
    MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1690
                     Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1691
    // 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
  1692
    // 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
  1693
    slow_locked_verify_free_chunks_count();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1694
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1695
#endif
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1696
  return _free_chunks_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1697
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1698
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1699
void ChunkManager::locked_verify_free_chunks_total() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1700
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1701
  assert(sum_free_chunks() == _free_chunks_total,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1702
    err_msg("_free_chunks_total " SIZE_FORMAT " is not the"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1703
           " same as sum " SIZE_FORMAT, _free_chunks_total,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1704
           sum_free_chunks()));
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 ChunkManager::verify_free_chunks_total() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1708
  MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1709
                     Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1710
  locked_verify_free_chunks_total();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1711
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1712
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1713
void ChunkManager::locked_verify_free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1714
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1715
  assert(sum_free_chunks_count() == _free_chunks_count,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1716
    err_msg("_free_chunks_count " SIZE_FORMAT " is not the"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1717
           " same as sum " SIZE_FORMAT, _free_chunks_count,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1718
           sum_free_chunks_count()));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1719
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1720
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1721
void ChunkManager::verify_free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1722
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1723
  MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1724
                     Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1725
  locked_verify_free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1726
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1727
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1729
void ChunkManager::verify() {
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1730
  MutexLockerEx cl(SpaceManager::expand_lock(),
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1731
                     Mutex::_no_safepoint_check_flag);
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1732
  locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1733
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1734
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1735
void ChunkManager::locked_verify() {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1736
  locked_verify_free_chunks_count();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1737
  locked_verify_free_chunks_total();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1738
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1739
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1740
void ChunkManager::locked_print_free_chunks(outputStream* st) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1741
  assert_lock_strong(SpaceManager::expand_lock());
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1742
  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
  1743
                _free_chunks_total, _free_chunks_count);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1744
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1745
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1746
void ChunkManager::locked_print_sum_free_chunks(outputStream* st) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1747
  assert_lock_strong(SpaceManager::expand_lock());
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1748
  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
  1749
                sum_free_chunks(), sum_free_chunks_count());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1750
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1751
ChunkList* ChunkManager::free_chunks(ChunkIndex index) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1752
  return &_free_chunks[index];
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1753
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1754
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1755
// 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
  1756
// methods that are used in product builds.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1757
size_t ChunkManager::sum_free_chunks() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1758
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1759
  size_t result = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1760
  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
  1761
    ChunkList* list = free_chunks(i);
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
    if (list == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1764
      continue;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1765
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1766
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  1767
    result = result + list->count() * list->size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1768
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1769
  result = result + humongous_dictionary()->total_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1770
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1771
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1772
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1773
size_t ChunkManager::sum_free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1774
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1775
  size_t count = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1776
  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
  1777
    ChunkList* list = free_chunks(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1778
    if (list == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1779
      continue;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1780
    }
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  1781
    count = count + list->count();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1782
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1783
  count = count + humongous_dictionary()->total_free_blocks();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1784
  return count;
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
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1787
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
  1788
  ChunkIndex index = list_index(word_size);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1789
  assert(index < HumongousIndex, "No humongous list");
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1790
  return free_chunks(index);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1791
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1792
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1793
Metachunk* ChunkManager::free_chunks_get(size_t word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1794
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1795
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1796
  slow_locked_verify();
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1797
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1798
  Metachunk* chunk = NULL;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1799
  if (list_index(word_size) != HumongousIndex) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1800
    ChunkList* free_list = find_free_chunks_list(word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1801
    assert(free_list != NULL, "Sanity check");
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1802
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1803
    chunk = free_list->head();
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1804
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1805
    if (chunk == NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1806
      return NULL;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1807
    }
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1808
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1809
    // 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
  1810
    free_list->remove_chunk(chunk);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1811
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1812
    if (TraceMetadataChunkAllocation && Verbose) {
19993
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19992
diff changeset
  1813
      gclog_or_tty->print_cr("ChunkManager::free_chunks_get: free_list "
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19992
diff changeset
  1814
                             PTR_FORMAT " head " PTR_FORMAT " size " SIZE_FORMAT,
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19992
diff changeset
  1815
                             free_list, chunk, chunk->word_size());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1816
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1817
  } else {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1818
    chunk = humongous_dictionary()->get_chunk(
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1819
      word_size,
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1820
      FreeBlockDictionary<Metachunk>::atLeast);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1821
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1822
    if (chunk == NULL) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1823
      return NULL;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1824
    }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1825
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1826
    if (TraceMetadataHumongousAllocation) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1827
      size_t waste = chunk->word_size() - word_size;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1828
      gclog_or_tty->print_cr("Free list allocate humongous chunk size "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1829
                             SIZE_FORMAT " for requested size " SIZE_FORMAT
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1830
                             " waste " SIZE_FORMAT,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1831
                             chunk->word_size(), word_size, waste);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1832
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1833
  }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1834
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1835
  // Chunk is being removed from the chunks free list.
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  1836
  dec_free_chunks_total(chunk->word_size());
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  1837
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1838
  // 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
  1839
  chunk->set_next(NULL);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1840
  chunk->set_prev(NULL);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1841
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1842
  // 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
  1843
  // work.
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  1844
  chunk->set_is_tagged_free(false);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1845
#endif
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1846
  chunk->container()->inc_container_count();
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1847
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1848
  slow_locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1849
  return chunk;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1850
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1851
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1852
Metachunk* ChunkManager::chunk_freelist_allocate(size_t word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1853
  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
  1854
  slow_locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1855
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1856
  // Take from the beginning of the list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1857
  Metachunk* chunk = free_chunks_get(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1858
  if (chunk == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1859
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1860
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1861
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1862
  assert((word_size <= chunk->word_size()) ||
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1863
         list_index(chunk->word_size() == HumongousIndex),
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1864
         "Non-humongous variable sized chunk");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1865
  if (TraceMetadataChunkAllocation) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1866
    size_t list_count;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1867
    if (list_index(word_size) < HumongousIndex) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1868
      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
  1869
      list_count = list->count();
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1870
    } else {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1871
      list_count = humongous_dictionary()->total_count();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1872
    }
19993
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19992
diff changeset
  1873
    gclog_or_tty->print("ChunkManager::chunk_freelist_allocate: " PTR_FORMAT " chunk "
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19992
diff changeset
  1874
                        PTR_FORMAT "  size " SIZE_FORMAT " count " SIZE_FORMAT " ",
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19992
diff changeset
  1875
                        this, chunk, chunk->word_size(), list_count);
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19992
diff changeset
  1876
    locked_print_free_chunks(gclog_or_tty);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1877
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1878
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1879
  return chunk;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1880
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1881
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1882
void ChunkManager::print_on(outputStream* out) const {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1883
  if (PrintFLSStatistics != 0) {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  1884
    const_cast<ChunkManager *>(this)->humongous_dictionary()->report_statistics();
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1885
  }
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1886
}
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1887
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1888
// SpaceManager methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1889
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1890
void SpaceManager::get_initial_chunk_sizes(Metaspace::MetaspaceType type,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1891
                                           size_t* chunk_word_size,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1892
                                           size_t* class_chunk_word_size) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1893
  switch (type) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1894
  case Metaspace::BootMetaspaceType:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1895
    *chunk_word_size = Metaspace::first_chunk_word_size();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1896
    *class_chunk_word_size = Metaspace::first_class_chunk_word_size();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1897
    break;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1898
  case Metaspace::ROMetaspaceType:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1899
    *chunk_word_size = SharedReadOnlySize / wordSize;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1900
    *class_chunk_word_size = ClassSpecializedChunk;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1901
    break;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1902
  case Metaspace::ReadWriteMetaspaceType:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1903
    *chunk_word_size = SharedReadWriteSize / wordSize;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1904
    *class_chunk_word_size = ClassSpecializedChunk;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1905
    break;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1906
  case Metaspace::AnonymousMetaspaceType:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1907
  case Metaspace::ReflectionMetaspaceType:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1908
    *chunk_word_size = SpecializedChunk;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1909
    *class_chunk_word_size = ClassSpecializedChunk;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1910
    break;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1911
  default:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1912
    *chunk_word_size = SmallChunk;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1913
    *class_chunk_word_size = ClassSmallChunk;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1914
    break;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1915
  }
15488
6594bd32ea05 8007257: NPG: metaspace.cpp: Incorrect arguments in calls to err_msg
mikael
parents: 15087
diff changeset
  1916
  assert(*chunk_word_size != 0 && *class_chunk_word_size != 0,
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1917
    err_msg("Initial chunks sizes bad: data  " SIZE_FORMAT
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1918
            " class " SIZE_FORMAT,
15488
6594bd32ea05 8007257: NPG: metaspace.cpp: Incorrect arguments in calls to err_msg
mikael
parents: 15087
diff changeset
  1919
            *chunk_word_size, *class_chunk_word_size));
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1920
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1921
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1922
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
  1923
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1924
  size_t free = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1925
  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
  1926
    Metachunk* chunk = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1927
    while (chunk != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1928
      free += chunk->free_word_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1929
      chunk = chunk->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1930
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1931
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1932
  return free;
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
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1935
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
  1936
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1937
  size_t result = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1938
  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
  1939
   result += sum_waste_in_chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1940
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1941
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1942
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1943
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1944
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1945
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
  1946
  size_t result = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1947
  Metachunk* chunk = chunks_in_use(index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1948
  // 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
  1949
  // 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
  1950
  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
  1951
    if (chunk != current_chunk()) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1952
      result += chunk->free_word_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1953
    }
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
  1954
    chunk = chunk->next();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1955
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1956
  return result;
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
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
  1960
  // 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
  1961
  // 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
  1962
  // 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
  1963
  // 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
  1964
  // 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
  1965
  // 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
  1966
  // 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
  1967
  // answer.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1968
  if (UseConcMarkSweepGC) {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1969
    return allocated_chunks_words();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1970
  } else {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1971
    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
  1972
    size_t sum = 0;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1973
    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
  1974
      Metachunk* chunk = chunks_in_use(i);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1975
      while (chunk != NULL) {
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  1976
        sum += chunk->word_size();
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1977
        chunk = chunk->next();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1978
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1979
    }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1980
  return sum;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1981
  }
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
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1984
size_t SpaceManager::sum_count_in_chunks_in_use() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1985
  size_t count = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1986
  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
  1987
    count = count + sum_count_in_chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1988
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1989
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1990
  return count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1991
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1992
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1993
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
  1994
  size_t count = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1995
  Metachunk* chunk = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1996
  while (chunk != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1997
    count++;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1998
    chunk = chunk->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1999
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2000
  return count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2001
}
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
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
  2005
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2006
  size_t used = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2007
  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
  2008
    Metachunk* chunk = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2009
    while (chunk != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2010
      used += chunk->used_word_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2011
      chunk = chunk->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2012
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2013
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2014
  return used;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2015
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2016
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2017
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
  2018
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2019
  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
  2020
    Metachunk* chunk = chunks_in_use(i);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2021
    st->print("SpaceManager: %s " PTR_FORMAT,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2022
                 chunk_size_name(i), chunk);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2023
    if (chunk != NULL) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2024
      st->print_cr(" free " SIZE_FORMAT,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2025
                   chunk->free_word_size());
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2026
    } else {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24351
diff changeset
  2027
      st->cr();
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2028
    }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2029
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2030
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2031
  chunk_manager()->locked_print_free_chunks(st);
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2032
  chunk_manager()->locked_print_sum_free_chunks(st);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2033
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2034
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2035
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
  2036
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2037
  // Decide between a small chunk and a medium chunk.  Up to
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2038
  // _small_chunk_limit small chunks can be allocated but
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2039
  // once a medium chunk has been allocated, no more small
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2040
  // chunks will be allocated.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2041
  size_t chunk_word_size;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2042
  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
  2043
      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
  2044
    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
  2045
    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
  2046
      chunk_word_size = medium_chunk_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2047
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2048
  } else {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2049
    chunk_word_size = medium_chunk_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2050
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2051
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2052
  // 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
  2053
  // 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
  2054
  // the smallest chunk size.
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2055
  size_t if_humongous_sized_chunk =
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2056
    align_size_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
  2057
                  smallest_chunk_size());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2058
  chunk_word_size =
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2059
    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
  2060
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2061
  assert(!SpaceManager::is_humongous(word_size) ||
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2062
         chunk_word_size == if_humongous_sized_chunk,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2063
         err_msg("Size calculation is wrong, word_size " SIZE_FORMAT
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2064
                 " chunk_word_size " SIZE_FORMAT,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2065
                 word_size, chunk_word_size));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2066
  if (TraceMetadataHumongousAllocation &&
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2067
      SpaceManager::is_humongous(word_size)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2068
    gclog_or_tty->print_cr("Metadata humongous allocation:");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2069
    gclog_or_tty->print_cr("  word_size " PTR_FORMAT, word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2070
    gclog_or_tty->print_cr("  chunk_word_size " PTR_FORMAT,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2071
                           chunk_word_size);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2072
    gclog_or_tty->print_cr("    chunk overhead " PTR_FORMAT,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2073
                           Metachunk::overhead());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2074
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2075
  return chunk_word_size;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2076
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2077
20407
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2078
void SpaceManager::track_metaspace_memory_usage() {
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2079
  if (is_init_completed()) {
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2080
    if (is_class()) {
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2081
      MemoryService::track_compressed_class_memory_usage();
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2082
    }
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2083
    MemoryService::track_metaspace_memory_usage();
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2084
  }
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2085
}
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2086
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2087
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
  2088
  assert(vs_list()->current_virtual_space() != NULL,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2089
         "Should have been set");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2090
  assert(current_chunk() == NULL ||
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2091
         current_chunk()->allocate(word_size) == NULL,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2092
         "Don't need to expand");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2093
  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
  2094
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2095
  if (TraceMetadataChunkAllocation && Verbose) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2096
    size_t words_left = 0;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2097
    size_t words_used = 0;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2098
    if (current_chunk() != NULL) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2099
      words_left = current_chunk()->free_word_size();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2100
      words_used = current_chunk()->used_word_size();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2101
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2102
    gclog_or_tty->print_cr("SpaceManager::grow_and_allocate for " SIZE_FORMAT
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2103
                           " words " SIZE_FORMAT " words used " SIZE_FORMAT
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2104
                           " words left",
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2105
                            word_size, words_used, words_left);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2106
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2107
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2108
  // Get another chunk out of the virtual space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2109
  size_t grow_chunks_by_words = calc_chunk_size(word_size);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2110
  Metachunk* next = get_new_chunk(word_size, grow_chunks_by_words);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2111
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2112
  MetaWord* mem = NULL;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2113
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2114
  // 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
  2115
  // and do an allocation from it.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2116
  if (next != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2117
    // 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
  2118
    add_chunk(next, false);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2119
    mem = next->allocate(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2120
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2121
20407
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2122
  // Track metaspace memory usage statistic.
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2123
  track_metaspace_memory_usage();
68e215ce8944 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 20406
diff changeset
  2124
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2125
  return mem;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2126
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2127
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2128
void SpaceManager::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2129
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2130
  for (ChunkIndex i = ZeroIndex;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2131
       i < NumberOfInUseLists ;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2132
       i = next_chunk_index(i) ) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2133
    st->print_cr("  chunks_in_use " PTR_FORMAT " chunk size " PTR_FORMAT,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2134
                 chunks_in_use(i),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2135
                 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
  2136
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2137
  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
  2138
               " Humongous " SIZE_FORMAT,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2139
               sum_waste_in_chunks_in_use(SmallIndex),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2140
               sum_waste_in_chunks_in_use(MediumIndex),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2141
               sum_waste_in_chunks_in_use(HumongousIndex));
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2142
  // block free lists
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2143
  if (block_freelists() != NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2144
    st->print_cr("total in block free lists " SIZE_FORMAT,
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2145
      block_freelists()->total_size());
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2146
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2147
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2148
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2149
SpaceManager::SpaceManager(Metaspace::MetadataType mdtype,
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2150
                           Mutex* lock) :
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2151
  _mdtype(mdtype),
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2152
  _allocated_blocks_words(0),
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2153
  _allocated_chunks_words(0),
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2154
  _allocated_chunks_count(0),
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2155
  _lock(lock)
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2156
{
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2157
  initialize();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2158
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2159
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2160
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
  2161
  assert_lock_strong(SpaceManager::expand_lock());
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2162
  // 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
  2163
  // for each SpaceManager
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2164
  _allocated_chunks_words = _allocated_chunks_words + words;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2165
  _allocated_chunks_count++;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2166
  // Global total of capacity in allocated Metachunks
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2167
  MetaspaceAux::inc_capacity(mdtype(), words);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2168
  // Global total of allocated Metablocks.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2169
  // 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
  2170
  // 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
  2171
  // 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
  2172
  // Metachunk).
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2173
  MetaspaceAux::inc_used(mdtype(), Metachunk::overhead());
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2174
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2175
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2176
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
  2177
  // Add to the per SpaceManager total
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2178
  Atomic::add_ptr(words, &_allocated_blocks_words);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2179
  // Add to the global total
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2180
  MetaspaceAux::inc_used(mdtype(), words);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2181
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2182
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2183
void SpaceManager::dec_total_from_size_metrics() {
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2184
  MetaspaceAux::dec_capacity(mdtype(), allocated_chunks_words());
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2185
  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
  2186
  // Also deduct the overhead per Metachunk
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2187
  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
  2188
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2189
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2190
void SpaceManager::initialize() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2191
  Metadebug::init_allocation_fail_alot_count();
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2192
  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
  2193
    _chunks_in_use[i] = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2194
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2195
  _current_chunk = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2196
  if (TraceMetadataChunkAllocation && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2197
    gclog_or_tty->print_cr("SpaceManager(): " PTR_FORMAT, this);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2198
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2199
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2200
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2201
void ChunkManager::return_chunks(ChunkIndex index, Metachunk* chunks) {
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2202
  if (chunks == NULL) {
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2203
    return;
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2204
  }
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2205
  ChunkList* list = free_chunks(index);
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2206
  assert(list->size() == chunks->word_size(), "Mismatch in chunk sizes");
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2207
  assert_lock_strong(SpaceManager::expand_lock());
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2208
  Metachunk* cur = chunks;
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2209
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2210
  // This returns chunks one at a time.  If a new
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2211
  // class List can be created that is a base class
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2212
  // of FreeList then something like FreeList::prepend()
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2213
  // can be used in place of this loop
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2214
  while (cur != NULL) {
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2215
    assert(cur->container() != NULL, "Container should have been set");
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2216
    cur->container()->dec_container_count();
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2217
    // Capture the next link before it is changed
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2218
    // by the call to return_chunk_at_head();
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2219
    Metachunk* next = cur->next();
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  2220
    DEBUG_ONLY(cur->set_is_tagged_free(true);)
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2221
    list->return_chunk_at_head(cur);
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2222
    cur = next;
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2223
  }
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2224
}
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2225
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2226
SpaceManager::~SpaceManager() {
16385
4a05c6d94b04 8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents: 15954
diff changeset
  2227
  // 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
  2228
  assert(sum_capacity_in_chunks_in_use() == allocated_chunks_words(),
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2229
    err_msg("sum_capacity_in_chunks_in_use() " SIZE_FORMAT
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2230
            " allocated_chunks_words() " SIZE_FORMAT,
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2231
            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
  2232
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2233
  MutexLockerEx fcl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2234
                    Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2235
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2236
  chunk_manager()->slow_locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2237
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2238
  dec_total_from_size_metrics();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2239
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2240
  if (TraceMetadataChunkAllocation && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2241
    gclog_or_tty->print_cr("~SpaceManager(): " PTR_FORMAT, this);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2242
    locked_print_chunks_in_use_on(gclog_or_tty);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2243
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2244
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2245
  // Do not mangle freed Metachunks.  The chunk size inside Metachunks
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2246
  // is during the freeing of a VirtualSpaceNodes.
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
  2247
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2248
  // Have to update before the chunks_in_use lists are emptied
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2249
  // below.
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2250
  chunk_manager()->inc_free_chunks_total(allocated_chunks_words(),
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2251
                                         sum_count_in_chunks_in_use());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2252
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2253
  // 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
  2254
  // to the global list of free chunks.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2255
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2256
  // 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
  2257
  // free lists.  Each list is NULL terminated.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2258
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2259
  for (ChunkIndex i = ZeroIndex; i < HumongousIndex; i = next_chunk_index(i)) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2260
    if (TraceMetadataChunkAllocation && Verbose) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2261
      gclog_or_tty->print_cr("returned %d %s chunks to freelist",
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2262
                             sum_count_in_chunks_in_use(i),
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2263
                             chunk_size_name(i));
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2264
    }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2265
    Metachunk* chunks = chunks_in_use(i);
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2266
    chunk_manager()->return_chunks(i, chunks);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2267
    set_chunks_in_use(i, NULL);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2268
    if (TraceMetadataChunkAllocation && Verbose) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2269
      gclog_or_tty->print_cr("updated freelist count %d %s",
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2270
                             chunk_manager()->free_chunks(i)->count(),
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2271
                             chunk_size_name(i));
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2272
    }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2273
    assert(i != HumongousIndex, "Humongous chunks are handled explicitly later");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2274
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2275
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2276
  // The medium chunk case may be optimized by passing the head and
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2277
  // tail of the medium chunk list to add_at_head().  The tail is often
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2278
  // the current chunk but there are probably exceptions.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2279
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2280
  // Humongous chunks
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2281
  if (TraceMetadataChunkAllocation && Verbose) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2282
    gclog_or_tty->print_cr("returned %d %s humongous chunks to dictionary",
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2283
                            sum_count_in_chunks_in_use(HumongousIndex),
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2284
                            chunk_size_name(HumongousIndex));
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2285
    gclog_or_tty->print("Humongous chunk dictionary: ");
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2286
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2287
  // Humongous chunks are never the current chunk.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2288
  Metachunk* humongous_chunks = chunks_in_use(HumongousIndex);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2289
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2290
  while (humongous_chunks != NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2291
#ifdef ASSERT
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  2292
    humongous_chunks->set_is_tagged_free(true);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2293
#endif
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2294
    if (TraceMetadataChunkAllocation && Verbose) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2295
      gclog_or_tty->print(PTR_FORMAT " (" SIZE_FORMAT ") ",
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2296
                          humongous_chunks,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2297
                          humongous_chunks->word_size());
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2298
    }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2299
    assert(humongous_chunks->word_size() == (size_t)
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2300
           align_size_up(humongous_chunks->word_size(),
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2301
                             smallest_chunk_size()),
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2302
           err_msg("Humongous chunk size is wrong: word size " SIZE_FORMAT
15488
6594bd32ea05 8007257: NPG: metaspace.cpp: Incorrect arguments in calls to err_msg
mikael
parents: 15087
diff changeset
  2303
                   " granularity %d",
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  2304
                   humongous_chunks->word_size(), smallest_chunk_size()));
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2305
    Metachunk* next_humongous_chunks = humongous_chunks->next();
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2306
    humongous_chunks->container()->dec_container_count();
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2307
    chunk_manager()->humongous_dictionary()->return_chunk(humongous_chunks);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2308
    humongous_chunks = next_humongous_chunks;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2309
  }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2310
  if (TraceMetadataChunkAllocation && Verbose) {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24351
diff changeset
  2311
    gclog_or_tty->cr();
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2312
    gclog_or_tty->print_cr("updated dictionary count %d %s",
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2313
                     chunk_manager()->humongous_dictionary()->total_count(),
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2314
                     chunk_size_name(HumongousIndex));
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2315
  }
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2316
  chunk_manager()->slow_locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2317
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2318
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2319
const char* SpaceManager::chunk_size_name(ChunkIndex index) const {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2320
  switch (index) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2321
    case SpecializedIndex:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2322
      return "Specialized";
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2323
    case SmallIndex:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2324
      return "Small";
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2325
    case MediumIndex:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2326
      return "Medium";
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2327
    case HumongousIndex:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2328
      return "Humongous";
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2329
    default:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2330
      return NULL;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2331
  }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2332
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2333
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2334
ChunkIndex ChunkManager::list_index(size_t size) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2335
  switch (size) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2336
    case SpecializedChunk:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2337
      assert(SpecializedChunk == ClassSpecializedChunk,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2338
             "Need branch for ClassSpecializedChunk");
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2339
      return SpecializedIndex;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2340
    case SmallChunk:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2341
    case ClassSmallChunk:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2342
      return SmallIndex;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2343
    case MediumChunk:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2344
    case ClassMediumChunk:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2345
      return MediumIndex;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2346
    default:
15087
8849ea877278 8005486: NPG: Incorrect assertion in ChunkManager::list_index()
jmasa
parents: 15086
diff changeset
  2347
      assert(size > MediumChunk || size > ClassMediumChunk,
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2348
             "Not a humongous chunk");
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2349
      return HumongousIndex;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2350
  }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2351
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2352
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2353
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
  2354
  assert_lock_strong(_lock);
18987
a1b541fe1159 8019845: Memory leak during class redefinition
fparain
parents: 18492
diff changeset
  2355
  size_t raw_word_size = get_raw_word_size(word_size);
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
  2356
  size_t min_size = TreeChunk<Metablock, FreeList<Metablock> >::min_size();
18987
a1b541fe1159 8019845: Memory leak during class redefinition
fparain
parents: 18492
diff changeset
  2357
  assert(raw_word_size >= min_size,
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2358
         err_msg("Should not deallocate dark matter " SIZE_FORMAT "<" SIZE_FORMAT, word_size, min_size));
18987
a1b541fe1159 8019845: Memory leak during class redefinition
fparain
parents: 18492
diff changeset
  2359
  block_freelists()->return_block(p, raw_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2360
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2361
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2362
// 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
  2363
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
  2364
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2365
  assert(new_chunk != NULL, "Should not be NULL");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2366
  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
  2367
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2368
  new_chunk->reset_empty();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2369
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2370
  // Find the correct list and and set the current
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2371
  // chunk for that list.
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2372
  ChunkIndex index = ChunkManager::list_index(new_chunk->word_size());
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2373
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2374
  if (index != HumongousIndex) {
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2375
    retire_current_chunk();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2376
    set_current_chunk(new_chunk);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2377
    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
  2378
    set_chunks_in_use(index, new_chunk);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2379
  } else {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2380
    // 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
  2381
    // 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
  2382
    // chunk.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2383
    if (make_current) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2384
      // 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
  2385
      set_current_chunk(new_chunk);
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
    // 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
  2388
    // 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
  2389
    // 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
  2390
    // of the humongous chunks list.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2391
    new_chunk->set_next(chunks_in_use(HumongousIndex));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2392
    set_chunks_in_use(HumongousIndex, new_chunk);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2393
15087
8849ea877278 8005486: NPG: Incorrect assertion in ChunkManager::list_index()
jmasa
parents: 15086
diff changeset
  2394
    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
  2395
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2396
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2397
  // Add to the running sum of capacity
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2398
  inc_size_metrics(new_chunk->word_size());
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2399
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2400
  assert(new_chunk->is_empty(), "Not ready for reuse");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2401
  if (TraceMetadataChunkAllocation && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2402
    gclog_or_tty->print("SpaceManager::add_chunk: %d) ",
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2403
                        sum_count_in_chunks_in_use());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2404
    new_chunk->print_on(gclog_or_tty);
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2405
    chunk_manager()->locked_print_free_chunks(gclog_or_tty);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2406
  }
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
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2409
void SpaceManager::retire_current_chunk() {
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2410
  if (current_chunk() != NULL) {
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2411
    size_t remaining_words = current_chunk()->free_word_size();
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
  2412
    if (remaining_words >= TreeChunk<Metablock, FreeList<Metablock> >::min_size()) {
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2413
      block_freelists()->return_block(current_chunk()->allocate(remaining_words), remaining_words);
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2414
      inc_used_metrics(remaining_words);
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2415
    }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2416
  }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2417
}
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2418
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2419
Metachunk* SpaceManager::get_new_chunk(size_t word_size,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2420
                                       size_t grow_chunks_by_words) {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2421
  // Get a chunk from the chunk freelist
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2422
  Metachunk* next = chunk_manager()->chunk_freelist_allocate(grow_chunks_by_words);
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2423
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2424
  if (next == NULL) {
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2425
    next = vs_list()->get_new_chunk(word_size,
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2426
                                    grow_chunks_by_words,
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2427
                                    medium_chunk_bunch());
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2428
  }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2429
19992
ecae893d6947 8024751: Fix bugs in TraceMetadata
stefank
parents: 19990
diff changeset
  2430
  if (TraceMetadataHumongousAllocation && next != NULL &&
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2431
      SpaceManager::is_humongous(next->word_size())) {
19992
ecae893d6947 8024751: Fix bugs in TraceMetadata
stefank
parents: 19990
diff changeset
  2432
    gclog_or_tty->print_cr("  new humongous chunk word size "
ecae893d6947 8024751: Fix bugs in TraceMetadata
stefank
parents: 19990
diff changeset
  2433
                           PTR_FORMAT, next->word_size());
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2434
  }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2435
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2436
  return next;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2437
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2438
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2439
MetaWord* SpaceManager::allocate(size_t word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2440
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2441
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  2442
  size_t raw_word_size = get_raw_word_size(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2443
  BlockFreelist* fl =  block_freelists();
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2444
  MetaWord* p = NULL;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2445
  // 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
  2446
  // 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
  2447
  // 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
  2448
  // 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
  2449
  // for allocations.  Do some profiling.  JJJ
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2450
  if (fl->total_size() > allocation_from_dictionary_limit) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2451
    p = fl->get_block(raw_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2452
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2453
  if (p == NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2454
    p = allocate_work(raw_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2455
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2456
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2457
  return p;
13728
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
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2460
// Returns the address of spaced allocated for "word_size".
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2461
// This methods does not know about blocks (Metablocks)
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2462
MetaWord* SpaceManager::allocate_work(size_t word_size) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2463
  assert_lock_strong(_lock);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2464
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2465
  if (Metadebug::test_metadata_failure()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2466
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2467
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2468
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2469
  // Is there space in the current chunk?
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2470
  MetaWord* result = NULL;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2471
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2472
  // For DumpSharedSpaces, only allocate out of the current chunk which is
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2473
  // never null because we gave it the size we wanted.   Caller reports out
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2474
  // of memory if this returns null.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2475
  if (DumpSharedSpaces) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2476
    assert(current_chunk() != NULL, "should never happen");
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2477
    inc_used_metrics(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2478
    return current_chunk()->allocate(word_size); // caller handles null result
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2479
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2480
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2481
  if (current_chunk() != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2482
    result = current_chunk()->allocate(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2483
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2484
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2485
  if (result == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2486
    result = grow_and_allocate(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2487
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2488
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2489
  if (result != NULL) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2490
    inc_used_metrics(word_size);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2491
    assert(result != (MetaWord*) chunks_in_use(MediumIndex),
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2492
           "Head of the list is being allocated");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2493
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2494
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2495
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2496
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2497
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2498
void SpaceManager::verify() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2499
  // If there are blocks in the dictionary, then
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22499
diff changeset
  2500
  // verification of chunks does not work since
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2501
  // being in the dictionary alters a chunk.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2502
  if (block_freelists()->total_size() == 0) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2503
    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
  2504
      Metachunk* curr = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2505
      while (curr != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2506
        curr->verify();
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2507
        verify_chunk_size(curr);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2508
        curr = curr->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2509
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2510
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2511
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2512
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2513
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2514
void SpaceManager::verify_chunk_size(Metachunk* chunk) {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2515
  assert(is_humongous(chunk->word_size()) ||
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2516
         chunk->word_size() == medium_chunk_size() ||
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2517
         chunk->word_size() == small_chunk_size() ||
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2518
         chunk->word_size() == specialized_chunk_size(),
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2519
         "Chunk size is wrong");
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2520
  return;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2521
}
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2522
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2523
#ifdef ASSERT
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2524
void SpaceManager::verify_allocated_blocks_words() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2525
  // 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
  2526
  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
  2527
    "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
  2528
  assert(allocated_blocks_words() == sum_used_in_chunks_in_use(),
15488
6594bd32ea05 8007257: NPG: metaspace.cpp: Incorrect arguments in calls to err_msg
mikael
parents: 15087
diff changeset
  2529
    err_msg("allocation total is not consistent " SIZE_FORMAT
6594bd32ea05 8007257: NPG: metaspace.cpp: Incorrect arguments in calls to err_msg
mikael
parents: 15087
diff changeset
  2530
            " vs " SIZE_FORMAT,
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2531
            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
  2532
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2533
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2534
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2535
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2536
void SpaceManager::dump(outputStream* const out) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2537
  size_t curr_total = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2538
  size_t waste = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2539
  uint i = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2540
  size_t used = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2541
  size_t capacity = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2542
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2543
  // 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
  2544
  for (ChunkIndex index = ZeroIndex;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2545
       index < NumberOfInUseLists;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2546
       index = next_chunk_index(index)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2547
    for (Metachunk* curr = chunks_in_use(index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2548
         curr != NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2549
         curr = curr->next()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2550
      out->print("%d) ", i++);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2551
      curr->print_on(out);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2552
      curr_total += curr->word_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2553
      used += curr->used_word_size();
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  2554
      capacity += curr->word_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2555
      waste += curr->free_word_size() + curr->overhead();;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2556
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2557
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2558
19992
ecae893d6947 8024751: Fix bugs in TraceMetadata
stefank
parents: 19990
diff changeset
  2559
  if (TraceMetadataChunkAllocation && Verbose) {
ecae893d6947 8024751: Fix bugs in TraceMetadata
stefank
parents: 19990
diff changeset
  2560
    block_freelists()->print_on(out);
ecae893d6947 8024751: Fix bugs in TraceMetadata
stefank
parents: 19990
diff changeset
  2561
  }
ecae893d6947 8024751: Fix bugs in TraceMetadata
stefank
parents: 19990
diff changeset
  2562
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2563
  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
  2564
  // Free space isn't wasted.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2565
  waste -= free;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2566
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2567
  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
  2568
                " free " SIZE_FORMAT " capacity " SIZE_FORMAT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2569
                " waste " SIZE_FORMAT, curr_total, used, free, capacity, waste);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2570
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2571
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
  2572
#ifndef PRODUCT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2573
void SpaceManager::mangle_freed_chunks() {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2574
  for (ChunkIndex index = ZeroIndex;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2575
       index < NumberOfInUseLists;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2576
       index = next_chunk_index(index)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2577
    for (Metachunk* curr = chunks_in_use(index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2578
         curr != NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2579
         curr = curr->next()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2580
      curr->mangle();
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
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2583
}
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
  2584
#endif // PRODUCT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2585
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2586
// MetaspaceAux
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2587
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2588
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2589
size_t MetaspaceAux::_capacity_words[] = {0, 0};
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2590
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
  2591
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2592
size_t MetaspaceAux::free_bytes(Metaspace::MetadataType mdtype) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2593
  VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2594
  return list == NULL ? 0 : list->free_bytes();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2595
}
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2596
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2597
size_t MetaspaceAux::free_bytes() {
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2598
  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
  2599
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2600
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2601
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
  2602
  assert_lock_strong(SpaceManager::expand_lock());
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2603
  assert(words <= capacity_words(mdtype),
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2604
    err_msg("About to decrement below 0: words " SIZE_FORMAT
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2605
            " is greater than _capacity_words[%u] " SIZE_FORMAT,
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2606
            words, mdtype, capacity_words(mdtype)));
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2607
  _capacity_words[mdtype] -= words;
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2608
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2609
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2610
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
  2611
  assert_lock_strong(SpaceManager::expand_lock());
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2612
  // Needs to be atomic
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2613
  _capacity_words[mdtype] += words;
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2614
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2615
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2616
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
  2617
  assert(words <= used_words(mdtype),
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2618
    err_msg("About to decrement below 0: words " SIZE_FORMAT
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2619
            " is greater than _used_words[%u] " SIZE_FORMAT,
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2620
            words, mdtype, used_words(mdtype)));
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2621
  // 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
  2622
  // 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
  2623
  // 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
  2624
  // and protected by the Metaspace lock.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2625
  jlong minus_words = (jlong) - (jlong) words;
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2626
  Atomic::add_ptr(minus_words, &_used_words[mdtype]);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2627
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2628
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2629
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
  2630
  // _used_words tracks allocations for
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2631
  // each piece of metadata.  Those allocations are
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2632
  // generally done concurrently by different application
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2633
  // threads so must be done atomically.
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2634
  Atomic::add_ptr(words, &_used_words[mdtype]);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2635
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2636
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2637
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
  2638
  size_t used = 0;
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2639
  ClassLoaderDataGraphMetaspaceIterator iter;
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2640
  while (iter.repeat()) {
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2641
    Metaspace* msp = iter.get_next();
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2642
    // Sum allocated_blocks_words for each metaspace
13733
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2643
    if (msp != NULL) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2644
      used += msp->used_words_slow(mdtype);
13733
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2645
    }
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2646
  }
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2647
  return used * BytesPerWord;
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2648
}
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2649
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2650
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
  2651
  size_t free = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2652
  ClassLoaderDataGraphMetaspaceIterator iter;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2653
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2654
    Metaspace* msp = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2655
    if (msp != NULL) {
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2656
      free += msp->free_words_slow(mdtype);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2657
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2658
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2659
  return free * BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2660
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2661
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2662
size_t MetaspaceAux::capacity_bytes_slow(Metaspace::MetadataType mdtype) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2663
  if ((mdtype == Metaspace::ClassType) && !Metaspace::using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2664
    return 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2665
  }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2666
  // 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
  2667
  // added to the capacity calculation as needed.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2668
  size_t capacity = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2669
  ClassLoaderDataGraphMetaspaceIterator iter;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2670
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2671
    Metaspace* msp = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2672
    if (msp != NULL) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2673
      capacity += msp->capacity_words_slow(mdtype);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2674
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2675
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2676
  return capacity * BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2677
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2678
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2679
size_t MetaspaceAux::capacity_bytes_slow() {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2680
#ifdef PRODUCT
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2681
  // Use capacity_bytes() in PRODUCT instead of this function.
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2682
  guarantee(false, "Should not call capacity_bytes_slow() in the PRODUCT");
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2683
#endif
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2684
  size_t class_capacity = capacity_bytes_slow(Metaspace::ClassType);
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2685
  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
  2686
  assert(capacity_bytes() == class_capacity + non_class_capacity,
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2687
      err_msg("bad accounting: capacity_bytes() " SIZE_FORMAT
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2688
        " class_capacity + non_class_capacity " SIZE_FORMAT
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2689
        " class_capacity " SIZE_FORMAT " non_class_capacity " SIZE_FORMAT,
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2690
        capacity_bytes(), class_capacity + non_class_capacity,
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2691
        class_capacity, non_class_capacity));
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2692
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2693
  return class_capacity + non_class_capacity;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2694
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2695
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2696
size_t MetaspaceAux::reserved_bytes(Metaspace::MetadataType mdtype) {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2697
  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
  2698
  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
  2699
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2700
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  2701
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
  2702
  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
  2703
  return list == NULL ? 0 : list->committed_bytes();
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2704
}
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2705
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2706
size_t MetaspaceAux::min_chunk_size_words() { return Metaspace::first_chunk_word_size(); }
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2707
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2708
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
  2709
  ChunkManager* chunk_manager = Metaspace::get_chunk_manager(mdtype);
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2710
  if (chunk_manager == NULL) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2711
    return 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2712
  }
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2713
  chunk_manager->slow_verify();
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2714
  return chunk_manager->free_chunks_total_words();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2715
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2716
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2717
size_t MetaspaceAux::free_chunks_total_bytes(Metaspace::MetadataType mdtype) {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2718
  return free_chunks_total_words(mdtype) * BytesPerWord;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2719
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2720
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2721
size_t MetaspaceAux::free_chunks_total_words() {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2722
  return free_chunks_total_words(Metaspace::ClassType) +
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2723
         free_chunks_total_words(Metaspace::NonClassType);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2724
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2725
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2726
size_t MetaspaceAux::free_chunks_total_bytes() {
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2727
  return free_chunks_total_words() * BytesPerWord;
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2728
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2729
23470
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  2730
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
  2731
  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
  2732
}
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  2733
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  2734
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
  2735
  if (!has_chunk_free_list(mdtype)) {
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  2736
    return MetaspaceChunkFreeListSummary();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  2737
  }
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  2738
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  2739
  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
  2740
  return cm->chunk_free_list_summary();
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  2741
}
ff2a7ea4225d 8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents: 23469
diff changeset
  2742
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2743
void MetaspaceAux::print_metaspace_change(size_t prev_metadata_used) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2744
  gclog_or_tty->print(", [Metaspace:");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2745
  if (PrintGCDetails && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2746
    gclog_or_tty->print(" "  SIZE_FORMAT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2747
                        "->" SIZE_FORMAT
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2748
                        "("  SIZE_FORMAT ")",
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2749
                        prev_metadata_used,
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2750
                        used_bytes(),
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2751
                        reserved_bytes());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2752
  } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2753
    gclog_or_tty->print(" "  SIZE_FORMAT "K"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2754
                        "->" SIZE_FORMAT "K"
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2755
                        "("  SIZE_FORMAT "K)",
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2756
                        prev_metadata_used/K,
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2757
                        used_bytes()/K,
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2758
                        reserved_bytes()/K);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2759
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2760
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2761
  gclog_or_tty->print("]");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2762
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2763
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2764
// This is printed when PrintGCDetails
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2765
void MetaspaceAux::print_on(outputStream* out) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2766
  Metaspace::MetadataType nct = Metaspace::NonClassType;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2767
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2768
  out->print_cr(" Metaspace       "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2769
                "used "      SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2770
                "capacity "  SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2771
                "committed " SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2772
                "reserved "  SIZE_FORMAT "K",
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2773
                used_bytes()/K,
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2774
                capacity_bytes()/K,
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2775
                committed_bytes()/K,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2776
                reserved_bytes()/K);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2777
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2778
  if (Metaspace::using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2779
    Metaspace::MetadataType ct = Metaspace::ClassType;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2780
    out->print_cr("  class space    "
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2781
                  "used "      SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2782
                  "capacity "  SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2783
                  "committed " SIZE_FORMAT "K, "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2784
                  "reserved "  SIZE_FORMAT "K",
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2785
                  used_bytes(ct)/K,
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2786
                  capacity_bytes(ct)/K,
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2787
                  committed_bytes(ct)/K,
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2788
                  reserved_bytes(ct)/K);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2789
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2790
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2791
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2792
// Print information for class space and data space separately.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2793
// This is almost the same as above.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2794
void MetaspaceAux::print_on(outputStream* out, Metaspace::MetadataType mdtype) {
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2795
  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
  2796
  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
  2797
  size_t used_bytes = used_bytes_slow(mdtype);
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  2798
  size_t free_bytes = free_bytes_slow(mdtype);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2799
  size_t used_and_free = used_bytes + free_bytes +
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2800
                           free_chunks_capacity_bytes;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2801
  out->print_cr("  Chunk accounting: used in chunks " SIZE_FORMAT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2802
             "K + unused in chunks " SIZE_FORMAT "K  + "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2803
             " capacity in free chunks " SIZE_FORMAT "K = " SIZE_FORMAT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2804
             "K  capacity in allocated chunks " SIZE_FORMAT "K",
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2805
             used_bytes / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2806
             free_bytes / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2807
             free_chunks_capacity_bytes / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2808
             used_and_free / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2809
             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
  2810
  // 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
  2811
  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
  2812
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2813
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2814
// Print total fragmentation for class metaspaces
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2815
void MetaspaceAux::print_class_waste(outputStream* out) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2816
  assert(Metaspace::using_class_space(), "class metaspace not used");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2817
  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
  2818
  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
  2819
  ClassLoaderDataGraphMetaspaceIterator iter;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2820
  while (iter.repeat()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2821
    Metaspace* msp = iter.get_next();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2822
    if (msp != NULL) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2823
      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
  2824
      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
  2825
      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
  2826
      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
  2827
      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
  2828
      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
  2829
      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
  2830
    }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2831
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2832
  out->print_cr(" class: " SIZE_FORMAT " specialized(s) " SIZE_FORMAT ", "
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2833
                SIZE_FORMAT " small(s) " SIZE_FORMAT ", "
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2834
                SIZE_FORMAT " medium(s) " SIZE_FORMAT ", "
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2835
                "large count " SIZE_FORMAT,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2836
                cls_specialized_count, cls_specialized_waste,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2837
                cls_small_count, cls_small_waste,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2838
                cls_medium_count, cls_medium_waste, cls_humongous_count);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2839
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2840
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2841
// 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
  2842
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
  2843
  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
  2844
  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
  2845
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2846
  ClassLoaderDataGraphMetaspaceIterator iter;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2847
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2848
    Metaspace* msp = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2849
    if (msp != NULL) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2850
      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
  2851
      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
  2852
      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
  2853
      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
  2854
      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
  2855
      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
  2856
      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
  2857
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2858
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2859
  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
  2860
  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
  2861
                        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
  2862
                        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
  2863
                        "large count " SIZE_FORMAT,
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2864
             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
  2865
             small_waste, medium_count, medium_waste, humongous_count);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2866
  if (Metaspace::using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2867
    print_class_waste(out);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2868
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2869
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2870
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2871
// Dump global metaspace things from the end of ClassLoaderDataGraph
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2872
void MetaspaceAux::dump(outputStream* out) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2873
  out->print_cr("All Metaspace:");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2874
  out->print("data space: "); print_on(out, Metaspace::NonClassType);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2875
  out->print("class space: "); print_on(out, Metaspace::ClassType);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2876
  print_waste(out);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2877
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2878
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2879
void MetaspaceAux::verify_free_chunks() {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2880
  Metaspace::chunk_manager_metadata()->verify();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2881
  if (Metaspace::using_class_space()) {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2882
    Metaspace::chunk_manager_class()->verify();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2883
  }
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2884
}
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2885
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2886
void MetaspaceAux::verify_capacity() {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2887
#ifdef ASSERT
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2888
  size_t running_sum_capacity_bytes = capacity_bytes();
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2889
  // 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
  2890
  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
  2891
  assert(running_sum_capacity_bytes == capacity_in_use_bytes,
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2892
    err_msg("capacity_words() * BytesPerWord " SIZE_FORMAT
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2893
            " capacity_bytes_slow()" SIZE_FORMAT,
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2894
            running_sum_capacity_bytes, capacity_in_use_bytes));
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2895
  for (Metaspace::MetadataType i = Metaspace::ClassType;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2896
       i < Metaspace:: MetadataTypeCount;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2897
       i = (Metaspace::MetadataType)(i + 1)) {
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2898
    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
  2899
    assert(capacity_bytes(i) == capacity_in_use_bytes,
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2900
      err_msg("capacity_bytes(%u) " SIZE_FORMAT
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2901
              " capacity_bytes_slow(%u)" SIZE_FORMAT,
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2902
              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
  2903
  }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2904
#endif
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
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2907
void MetaspaceAux::verify_used() {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2908
#ifdef ASSERT
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2909
  size_t running_sum_used_bytes = used_bytes();
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2910
  // 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
  2911
  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
  2912
  assert(used_bytes() == used_in_use_bytes,
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2913
    err_msg("used_bytes() " SIZE_FORMAT
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2914
            " used_bytes_slow()" SIZE_FORMAT,
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2915
            used_bytes(), used_in_use_bytes));
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2916
  for (Metaspace::MetadataType i = Metaspace::ClassType;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2917
       i < Metaspace:: MetadataTypeCount;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2918
       i = (Metaspace::MetadataType)(i + 1)) {
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2919
    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
  2920
    assert(used_bytes(i) == used_in_use_bytes,
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2921
      err_msg("used_bytes(%u) " SIZE_FORMAT
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2922
              " used_bytes_slow(%u)" SIZE_FORMAT,
23854
50f7f89b34e0 8038934: Remove prefix allocated_ from methods and variables in Metaspace
ehelin
parents: 23503
diff changeset
  2923
              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
  2924
  }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2925
#endif
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
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2928
void MetaspaceAux::verify_metrics() {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2929
  verify_capacity();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2930
  verify_used();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2931
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2932
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2933
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2934
// Metaspace methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2935
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2936
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
  2937
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
  2938
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2939
size_t Metaspace::_commit_alignment = 0;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2940
size_t Metaspace::_reserve_alignment = 0;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  2941
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2942
Metaspace::Metaspace(Mutex* lock, MetaspaceType type) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2943
  initialize(lock, type);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2944
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2945
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2946
Metaspace::~Metaspace() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2947
  delete _vsm;
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2948
  if (using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2949
    delete _class_vsm;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2950
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2951
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2952
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2953
VirtualSpaceList* Metaspace::_space_list = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2954
VirtualSpaceList* Metaspace::_class_space_list = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2955
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2956
ChunkManager* Metaspace::_chunk_manager_metadata = NULL;
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2957
ChunkManager* Metaspace::_chunk_manager_class = NULL;
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  2958
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2959
#define VIRTUALSPACEMULTIPLIER 2
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2960
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2961
#ifdef _LP64
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  2962
static const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1);
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  2963
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2964
void Metaspace::set_narrow_klass_base_and_shift(address metaspace_base, address cds_base) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2965
  // 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
  2966
  // 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
  2967
  // (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
  2968
  // between the lower base and higher address.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2969
  address lower_base;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2970
  address higher_address;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  2971
#if INCLUDE_CDS
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2972
  if (UseSharedSpaces) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2973
    higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  2974
                          (address)(metaspace_base + compressed_class_space_size()));
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2975
    lower_base = MIN2(metaspace_base, cds_base);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  2976
  } else
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  2977
#endif
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  2978
  {
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  2979
    higher_address = metaspace_base + compressed_class_space_size();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2980
    lower_base = metaspace_base;
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  2981
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  2982
    uint64_t klass_encoding_max = UnscaledClassSpaceMax << LogKlassAlignmentInBytes;
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  2983
    // 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
  2984
    if (higher_address <= (address)klass_encoding_max) {
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22499
diff changeset
  2985
      lower_base = 0; // Effectively lower base is zero.
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  2986
    }
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2987
  }
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  2988
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2989
  Universe::set_narrow_klass_base(lower_base);
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  2990
21518
067dd7967128 8027616: Off by one error in putback for compressed oops nashorn performance improvement
coleenp
parents: 21189
diff changeset
  2991
  if ((uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2992
    Universe::set_narrow_klass_shift(0);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2993
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2994
    assert(!UseSharedSpaces, "Cannot shift with UseSharedSpaces");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2995
    Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2996
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2997
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2998
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  2999
#if INCLUDE_CDS
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3000
// 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
  3001
// to work with compressed klass pointers.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3002
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
  3003
  assert(cds_base != 0 && UseSharedSpaces, "Only use with CDS");
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3004
  assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3005
  address lower_base = MIN2((address)metaspace_base, cds_base);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3006
  address higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3007
                                (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
  3008
  return ((uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3009
}
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3010
#endif
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3011
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3012
// Try to allocate the metaspace at the requested addr.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3013
void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, address cds_base) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3014
  assert(using_class_space(), "called improperly");
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3015
  assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3016
  assert(compressed_class_space_size() < KlassEncodingMetaspaceMax,
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3017
         "Metaspace size is too big");
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3018
  assert_is_ptr_aligned(requested_addr, _reserve_alignment);
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3019
  assert_is_ptr_aligned(cds_base, _reserve_alignment);
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3020
  assert_is_size_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
  3021
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3022
  // 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
  3023
  bool large_pages = false;
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3024
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3025
#ifndef AARCH64
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3026
  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
  3027
                                             _reserve_alignment,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3028
                                             large_pages,
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28163
diff changeset
  3029
                                             requested_addr);
29180
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3030
#else // AARCH64
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3031
  ReservedSpace metaspace_rs;
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3032
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3033
  // Our compressed klass pointers may fit nicely into the lower 32
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3034
  // bits.
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3035
  if ((uint64_t)requested_addr + compressed_class_space_size() < 4*G) {
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3036
    metaspace_rs = ReservedSpace(compressed_class_space_size(),
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3037
                                             _reserve_alignment,
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3038
                                             large_pages,
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3039
                                             requested_addr, 0);
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3040
  }
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3041
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3042
  if (! metaspace_rs.is_reserved()) {
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3043
    // Try to align metaspace so that we can decode a compressed klass
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3044
    // with a single MOVK instruction.  We can do this iff the
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3045
    // compressed class base is a multiple of 4G.
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3046
    for (char *a = (char*)align_ptr_up(requested_addr, 4*G);
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3047
         a < (char*)(1024*G);
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3048
         a += 4*G) {
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3049
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3050
#if INCLUDE_CDS
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3051
      if (UseSharedSpaces
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3052
          && ! can_use_cds_with_metaspace_addr(a, cds_base)) {
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3053
        // We failed to find an aligned base that will reach.  Fall
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3054
        // back to using our requested addr.
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3055
        metaspace_rs = ReservedSpace(compressed_class_space_size(),
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3056
                                     _reserve_alignment,
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3057
                                     large_pages,
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3058
                                     requested_addr, 0);
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3059
        break;
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3060
      }
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3061
#endif
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3062
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3063
      metaspace_rs = ReservedSpace(compressed_class_space_size(),
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3064
                                   _reserve_alignment,
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3065
                                   large_pages,
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3066
                                   a, 0);
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3067
      if (metaspace_rs.is_reserved())
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3068
        break;
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3069
    }
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3070
  }
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3071
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3072
#endif // AARCH64
50369728b00e 8064611: AARCH64: Changes to HotSpot shared code
aph
parents: 27404
diff changeset
  3073
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3074
  if (!metaspace_rs.is_reserved()) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3075
#if INCLUDE_CDS
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3076
    if (UseSharedSpaces) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3077
      size_t increment = align_size_up(1*G, _reserve_alignment);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3078
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3079
      // Keep trying to allocate the metaspace, increasing the requested_addr
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3080
      // 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
  3081
      // use of CDS with compressed klass pointers.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3082
      char *addr = requested_addr;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3083
      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
  3084
             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
  3085
        addr = addr + increment;
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3086
        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
  3087
                                     _reserve_alignment, large_pages, addr);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3088
      }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3089
    }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3090
#endif
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3091
    // 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
  3092
    // 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
  3093
    // metaspace as if UseCompressedClassPointers is off because too much
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3094
    // initialization has happened that depends on UseCompressedClassPointers.
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3095
    // So, UseCompressedClassPointers cannot be turned off at this point.
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3096
    if (!metaspace_rs.is_reserved()) {
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3097
      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
  3098
                                   _reserve_alignment, large_pages);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3099
      if (!metaspace_rs.is_reserved()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3100
        vm_exit_during_initialization(err_msg("Could not allocate metaspace: %d bytes",
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3101
                                              compressed_class_space_size()));
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3102
      }
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
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3106
  // If we got here then the metaspace got allocated.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3107
  MemTracker::record_virtual_memory_type((address)metaspace_rs.base(), mtClass);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3108
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3109
#if INCLUDE_CDS
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3110
  // Verify that we can use shared spaces.  Otherwise, turn off CDS.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3111
  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
  3112
    FileMapInfo::stop_sharing_and_unmap(
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3113
        "Could not allocate metaspace at a compatible address");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3114
  }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3115
#endif
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3116
  set_narrow_klass_base_and_shift((address)metaspace_rs.base(),
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3117
                                  UseSharedSpaces ? (address)cds_base : 0);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3118
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3119
  initialize_class_space(metaspace_rs);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3120
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3121
  if (PrintCompressedOopsMode || (PrintMiscellaneous && Verbose)) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3122
    gclog_or_tty->print_cr("Narrow klass base: " PTR_FORMAT ", Narrow klass shift: " SIZE_FORMAT,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3123
                            Universe::narrow_klass_base(), Universe::narrow_klass_shift());
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3124
    gclog_or_tty->print_cr("Compressed class space size: " SIZE_FORMAT " Address: " PTR_FORMAT " Req Addr: " PTR_FORMAT,
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3125
                           compressed_class_space_size(), metaspace_rs.base(), requested_addr);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3126
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3127
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3128
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3129
// 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
  3130
// 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
  3131
void Metaspace::initialize_class_space(ReservedSpace rs) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3132
  // 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
  3133
  assert(rs.size() >= CompressedClassSpaceSize,
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3134
         err_msg(SIZE_FORMAT " != " UINTX_FORMAT, rs.size(), CompressedClassSpaceSize));
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3135
  assert(using_class_space(), "Must be using class space");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3136
  _class_space_list = new VirtualSpaceList(rs);
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3137
  _chunk_manager_class = new ChunkManager(SpecializedChunk, ClassSmallChunk, ClassMediumChunk);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3138
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3139
  if (!_class_space_list->initialization_succeeded()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3140
    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
  3141
  }
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3142
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3143
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3144
#endif
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3145
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3146
void Metaspace::ergo_initialize() {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3147
  if (DumpSharedSpaces) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3148
    // 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
  3149
    FLAG_SET_ERGO(bool, UseLargePagesInMetaspace, false);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3150
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3151
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3152
  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
  3153
  if (UseLargePages && UseLargePagesInMetaspace) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3154
    page_size = os::large_page_size();
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3155
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3156
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3157
  _commit_alignment  = page_size;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3158
  _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
  3159
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3160
  // 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
  3161
  // 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
  3162
  // 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
  3163
  // java.lang.management.MemoryUsage API.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3164
  //
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3165
  // 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
  3166
  // 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
  3167
  // alignment depends on other flags being parsed.
21559
c5421f5c6ffd 8026852: Use restricted_align_down in collector policy code
jwilhelm
parents: 21113
diff changeset
  3168
  MaxMetaspaceSize = align_size_down_bounded(MaxMetaspaceSize, _reserve_alignment);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3169
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3170
  if (MetaspaceSize > MaxMetaspaceSize) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3171
    MetaspaceSize = MaxMetaspaceSize;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3172
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3173
21559
c5421f5c6ffd 8026852: Use restricted_align_down in collector policy code
jwilhelm
parents: 21113
diff changeset
  3174
  MetaspaceSize = align_size_down_bounded(MetaspaceSize, _commit_alignment);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3175
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3176
  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
  3177
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3178
  if (MetaspaceSize < 256*K) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3179
    vm_exit_during_initialization("Too small initial Metaspace size");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3180
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3181
21559
c5421f5c6ffd 8026852: Use restricted_align_down in collector policy code
jwilhelm
parents: 21113
diff changeset
  3182
  MinMetaspaceExpansion = align_size_down_bounded(MinMetaspaceExpansion, _commit_alignment);
c5421f5c6ffd 8026852: Use restricted_align_down in collector policy code
jwilhelm
parents: 21113
diff changeset
  3183
  MaxMetaspaceExpansion = align_size_down_bounded(MaxMetaspaceExpansion, _commit_alignment);
c5421f5c6ffd 8026852: Use restricted_align_down in collector policy code
jwilhelm
parents: 21113
diff changeset
  3184
c5421f5c6ffd 8026852: Use restricted_align_down in collector policy code
jwilhelm
parents: 21113
diff changeset
  3185
  CompressedClassSpaceSize = align_size_down_bounded(CompressedClassSpaceSize, _reserve_alignment);
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3186
  set_compressed_class_space_size(CompressedClassSpaceSize);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3187
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3188
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3189
void Metaspace::global_initialize() {
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  3190
  MetaspaceGC::initialize();
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  3191
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3192
  // Initialize the alignment for shared spaces.
24665
51cb5579adb3 8038422: CDS test failed: assert((size % os::vm_allocation_granularity()) == 0) failed when limiting SharedMiscDataSize
minqi
parents: 24475
diff changeset
  3193
  int max_alignment = os::vm_allocation_granularity();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3194
  size_t cds_total = 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3195
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3196
  MetaspaceShared::set_max_alignment(max_alignment);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3197
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3198
  if (DumpSharedSpaces) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3199
#if INCLUDE_CDS
26304
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  3200
    MetaspaceShared::estimate_regions_size();
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  3201
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3202
    SharedReadOnlySize  = align_size_up(SharedReadOnlySize,  max_alignment);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3203
    SharedReadWriteSize = align_size_up(SharedReadWriteSize, max_alignment);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3204
    SharedMiscDataSize  = align_size_up(SharedMiscDataSize,  max_alignment);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3205
    SharedMiscCodeSize  = align_size_up(SharedMiscCodeSize,  max_alignment);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3206
28018
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3207
    // make sure SharedReadOnlySize and SharedReadWriteSize are not less than
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3208
    // the minimum values.
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3209
    if (SharedReadOnlySize < MetaspaceShared::min_ro_size){
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3210
      report_out_of_shared_space(SharedReadOnly);
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3211
    }
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3212
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3213
    if (SharedReadWriteSize < MetaspaceShared::min_rw_size){
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3214
      report_out_of_shared_space(SharedReadWrite);
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3215
    }
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3216
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3217
    // the min_misc_data_size and min_misc_code_size estimates are based on
28476
ae1ca3bf45ca 8067187: -XX:MaxMetaspaceSize=20m -Xshare:dump caused JVM to crash
ccheung
parents: 28372
diff changeset
  3218
    // MetaspaceShared::generate_vtable_methods().
ae1ca3bf45ca 8067187: -XX:MaxMetaspaceSize=20m -Xshare:dump caused JVM to crash
ccheung
parents: 28372
diff changeset
  3219
    // The minimum size only accounts for the vtable methods. Any size less than the
ae1ca3bf45ca 8067187: -XX:MaxMetaspaceSize=20m -Xshare:dump caused JVM to crash
ccheung
parents: 28372
diff changeset
  3220
    // minimum required size would cause vm crash when allocating the vtable methods.
28018
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3221
    uint min_misc_data_size = align_size_up(
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3222
      MetaspaceShared::num_virtuals * MetaspaceShared::vtbl_list_size * sizeof(void*), max_alignment);
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3223
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3224
    if (SharedMiscDataSize < min_misc_data_size) {
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3225
      report_out_of_shared_space(SharedMiscData);
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3226
    }
abc067cd68fd 8065050: vm crashes during CDS dump when very small SharedMiscDataSize is specified
ccheung
parents: 27404
diff changeset
  3227
27404
33c0f343cd5c 8038268: VM Crashes in MetaspaceShared::generate_vtable_methods while creating CDS archive with limiting SharedMiscCodeSize
ccheung
parents: 26938
diff changeset
  3228
    uintx min_misc_code_size = align_size_up(
33c0f343cd5c 8038268: VM Crashes in MetaspaceShared::generate_vtable_methods while creating CDS archive with limiting SharedMiscCodeSize
ccheung
parents: 26938
diff changeset
  3229
      (MetaspaceShared::num_virtuals * MetaspaceShared::vtbl_list_size) *
33c0f343cd5c 8038268: VM Crashes in MetaspaceShared::generate_vtable_methods while creating CDS archive with limiting SharedMiscCodeSize
ccheung
parents: 26938
diff changeset
  3230
        (sizeof(void*) + MetaspaceShared::vtbl_method_size) + MetaspaceShared::vtbl_common_code_size,
33c0f343cd5c 8038268: VM Crashes in MetaspaceShared::generate_vtable_methods while creating CDS archive with limiting SharedMiscCodeSize
ccheung
parents: 26938
diff changeset
  3231
          max_alignment);
33c0f343cd5c 8038268: VM Crashes in MetaspaceShared::generate_vtable_methods while creating CDS archive with limiting SharedMiscCodeSize
ccheung
parents: 26938
diff changeset
  3232
33c0f343cd5c 8038268: VM Crashes in MetaspaceShared::generate_vtable_methods while creating CDS archive with limiting SharedMiscCodeSize
ccheung
parents: 26938
diff changeset
  3233
    if (SharedMiscCodeSize < min_misc_code_size) {
33c0f343cd5c 8038268: VM Crashes in MetaspaceShared::generate_vtable_methods while creating CDS archive with limiting SharedMiscCodeSize
ccheung
parents: 26938
diff changeset
  3234
      report_out_of_shared_space(SharedMiscCode);
33c0f343cd5c 8038268: VM Crashes in MetaspaceShared::generate_vtable_methods while creating CDS archive with limiting SharedMiscCodeSize
ccheung
parents: 26938
diff changeset
  3235
    }
33c0f343cd5c 8038268: VM Crashes in MetaspaceShared::generate_vtable_methods while creating CDS archive with limiting SharedMiscCodeSize
ccheung
parents: 26938
diff changeset
  3236
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3237
    // Initialize with the sum of the shared space sizes.  The read-only
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3238
    // and read write metaspace chunks will be allocated out of this and the
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3239
    // remainder is the misc code and data chunks.
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3240
    cds_total = FileMapInfo::shared_spaces_size();
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3241
    cds_total = align_size_up(cds_total, _reserve_alignment);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3242
    _space_list = new VirtualSpaceList(cds_total/wordSize);
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3243
    _chunk_manager_metadata = new ChunkManager(SpecializedChunk, SmallChunk, MediumChunk);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3244
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3245
    if (!_space_list->initialization_succeeded()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3246
      vm_exit_during_initialization("Unable to dump shared archive.", NULL);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3247
    }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3248
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3249
#ifdef _LP64
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3250
    if (cds_total + compressed_class_space_size() > UnscaledClassSpaceMax) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3251
      vm_exit_during_initialization("Unable to dump shared archive.",
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3252
          err_msg("Size of archive (" SIZE_FORMAT ") + compressed class space ("
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3253
                  SIZE_FORMAT ") == total (" SIZE_FORMAT ") is larger than compressed "
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3254
                  "klass limit: " SIZE_FORMAT, cds_total, compressed_class_space_size(),
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3255
                  cds_total + compressed_class_space_size(), UnscaledClassSpaceMax));
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3256
    }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3257
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3258
    // Set the compressed klass pointer base so that decoding of these pointers works
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3259
    // properly when creating the shared archive.
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3260
    assert(UseCompressedOops && UseCompressedClassPointers,
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3261
      "UseCompressedOops and UseCompressedClassPointers must be set");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3262
    Universe::set_narrow_klass_base((address)_space_list->current_virtual_space()->bottom());
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3263
    if (TraceMetavirtualspaceAllocation && Verbose) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3264
      gclog_or_tty->print_cr("Setting_narrow_klass_base to Address: " PTR_FORMAT,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3265
                             _space_list->current_virtual_space()->bottom());
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3266
    }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3267
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3268
    Universe::set_narrow_klass_shift(0);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3269
#endif // _LP64
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3270
#endif // INCLUDE_CDS
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3271
  } else {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3272
#if INCLUDE_CDS
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3273
    // If using shared space, open the file that contains the shared space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3274
    // and map in the memory before initializing the rest of metaspace (so
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3275
    // the addresses don't conflict)
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3276
    address cds_address = NULL;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3277
    if (UseSharedSpaces) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3278
      FileMapInfo* mapinfo = new FileMapInfo();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3279
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3280
      // Open the shared archive file, read and validate the header. If
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3281
      // initialization fails, shared spaces [UseSharedSpaces] are
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3282
      // disabled and the file is closed.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3283
      // Map in spaces now also
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3284
      if (mapinfo->initialize() && MetaspaceShared::map_shared_spaces(mapinfo)) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3285
        cds_total = FileMapInfo::shared_spaces_size();
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3286
        cds_address = (address)mapinfo->region_base(0);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3287
      } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3288
        assert(!mapinfo->is_open() && !UseSharedSpaces,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3289
               "archive file not closed or shared spaces not disabled.");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3290
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3291
    }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3292
#endif // INCLUDE_CDS
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3293
#ifdef _LP64
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3294
    // If UseCompressedClassPointers is set then allocate the metaspace area
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3295
    // above the heap and above the CDS area (if it exists).
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3296
    if (using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3297
      if (UseSharedSpaces) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3298
#if INCLUDE_CDS
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3299
        char* cds_end = (char*)(cds_address + cds_total);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3300
        cds_end = (char *)align_ptr_up(cds_end, _reserve_alignment);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3301
        allocate_metaspace_compressed_klass_ptrs(cds_end, cds_address);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3302
#endif
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3303
      } else {
21188
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3304
        char* base = (char*)align_ptr_up(Universe::heap()->reserved_region().end(), _reserve_alignment);
d053e4e8f901 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 21186
diff changeset
  3305
        allocate_metaspace_compressed_klass_ptrs(base, 0);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3306
      }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3307
    }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3308
#endif // _LP64
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3309
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3310
    // Initialize these before initializing the VirtualSpaceList
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3311
    _first_chunk_word_size = InitialBootClassLoaderMetaspaceSize / BytesPerWord;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3312
    _first_chunk_word_size = align_word_size_up(_first_chunk_word_size);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3313
    // Make the first class chunk bigger than a medium chunk so it's not put
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3314
    // on the medium chunk list.   The next chunk will be small and progress
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3315
    // from there.  This size calculated by -version.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3316
    _first_class_chunk_word_size = MIN2((size_t)MediumChunk*6,
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3317
                                       (CompressedClassSpaceSize/BytesPerWord)*2);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3318
    _first_class_chunk_word_size = align_word_size_up(_first_class_chunk_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3319
    // Arbitrarily set the initial virtual space to a multiple
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3320
    // of the boot class loader size.
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3321
    size_t word_size = VIRTUALSPACEMULTIPLIER * _first_chunk_word_size;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3322
    word_size = align_size_up(word_size, Metaspace::reserve_alignment_words());
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3323
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3324
    // Initialize the list of virtual spaces.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3325
    _space_list = new VirtualSpaceList(word_size);
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3326
    _chunk_manager_metadata = new ChunkManager(SpecializedChunk, SmallChunk, MediumChunk);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3327
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3328
    if (!_space_list->initialization_succeeded()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3329
      vm_exit_during_initialization("Unable to setup metadata virtual space list.", NULL);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3330
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3331
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3332
23465
14790e4d53ec 8036698: Add trace event for updates to metaspace gc threshold
ehelin
parents: 22884
diff changeset
  3333
  _tracer = new MetaspaceTracer();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3334
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3335
24847
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  3336
void Metaspace::post_initialize() {
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  3337
  MetaspaceGC::post_initialize();
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  3338
}
37c354b113fe 8042933: assert(capacity_until_gc >= committed_bytes) failed
ehelin
parents: 24665
diff changeset
  3339
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3340
Metachunk* Metaspace::get_initialization_chunk(MetadataType mdtype,
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3341
                                               size_t chunk_word_size,
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3342
                                               size_t chunk_bunch) {
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3343
  // Get a chunk from the chunk freelist
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3344
  Metachunk* chunk = get_chunk_manager(mdtype)->chunk_freelist_allocate(chunk_word_size);
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3345
  if (chunk != NULL) {
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3346
    return chunk;
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3347
  }
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3348
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3349
  return get_space_list(mdtype)->get_new_chunk(chunk_word_size, chunk_word_size, chunk_bunch);
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3350
}
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3351
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3352
void Metaspace::initialize(Mutex* lock, MetaspaceType type) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3353
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3354
  assert(space_list() != NULL,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3355
    "Metadata VirtualSpaceList has not been initialized");
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3356
  assert(chunk_manager_metadata() != NULL,
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3357
    "Metadata ChunkManager has not been initialized");
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3358
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3359
  _vsm = new SpaceManager(NonClassType, lock);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3360
  if (_vsm == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3361
    return;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3362
  }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3363
  size_t word_size;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3364
  size_t class_word_size;
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3365
  vsm()->get_initial_chunk_sizes(type, &word_size, &class_word_size);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3366
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3367
  if (using_class_space()) {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3368
  assert(class_space_list() != NULL,
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3369
    "Class VirtualSpaceList has not been initialized");
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3370
  assert(chunk_manager_class() != NULL,
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3371
    "Class ChunkManager has not been initialized");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3372
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3373
    // Allocate SpaceManager for classes.
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3374
    _class_vsm = new SpaceManager(ClassType, lock);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3375
    if (_class_vsm == NULL) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3376
      return;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3377
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3378
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3379
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3380
  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
  3381
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3382
  // Allocate chunk for metadata objects
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3383
  Metachunk* new_chunk = get_initialization_chunk(NonClassType,
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3384
                                                  word_size,
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3385
                                                  vsm()->medium_chunk_bunch());
28476
ae1ca3bf45ca 8067187: -XX:MaxMetaspaceSize=20m -Xshare:dump caused JVM to crash
ccheung
parents: 28372
diff changeset
  3386
  // For dumping shared archive, report error if allocation has failed.
ae1ca3bf45ca 8067187: -XX:MaxMetaspaceSize=20m -Xshare:dump caused JVM to crash
ccheung
parents: 28372
diff changeset
  3387
  if (DumpSharedSpaces && new_chunk == NULL) {
ae1ca3bf45ca 8067187: -XX:MaxMetaspaceSize=20m -Xshare:dump caused JVM to crash
ccheung
parents: 28372
diff changeset
  3388
    report_insufficient_metaspace(MetaspaceAux::committed_bytes() + word_size * BytesPerWord);
ae1ca3bf45ca 8067187: -XX:MaxMetaspaceSize=20m -Xshare:dump caused JVM to crash
ccheung
parents: 28372
diff changeset
  3389
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3390
  assert(!DumpSharedSpaces || new_chunk != NULL, "should have enough space for both chunks");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3391
  if (new_chunk != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3392
    // Add to this manager's list of chunks in use and current_chunk().
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3393
    vsm()->add_chunk(new_chunk, true);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3394
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3395
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3396
  // Allocate chunk for class metadata objects
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3397
  if (using_class_space()) {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3398
    Metachunk* class_chunk = get_initialization_chunk(ClassType,
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3399
                                                      class_word_size,
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3400
                                                      class_vsm()->medium_chunk_bunch());
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3401
    if (class_chunk != NULL) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3402
      class_vsm()->add_chunk(class_chunk, true);
28476
ae1ca3bf45ca 8067187: -XX:MaxMetaspaceSize=20m -Xshare:dump caused JVM to crash
ccheung
parents: 28372
diff changeset
  3403
    } else {
ae1ca3bf45ca 8067187: -XX:MaxMetaspaceSize=20m -Xshare:dump caused JVM to crash
ccheung
parents: 28372
diff changeset
  3404
      // For dumping shared archive, report error if allocation has failed.
ae1ca3bf45ca 8067187: -XX:MaxMetaspaceSize=20m -Xshare:dump caused JVM to crash
ccheung
parents: 28372
diff changeset
  3405
      if (DumpSharedSpaces) {
ae1ca3bf45ca 8067187: -XX:MaxMetaspaceSize=20m -Xshare:dump caused JVM to crash
ccheung
parents: 28372
diff changeset
  3406
        report_insufficient_metaspace(MetaspaceAux::committed_bytes() + class_word_size * BytesPerWord);
ae1ca3bf45ca 8067187: -XX:MaxMetaspaceSize=20m -Xshare:dump caused JVM to crash
ccheung
parents: 28372
diff changeset
  3407
      }
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3408
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3409
  }
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3410
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3411
  _alloc_record_head = NULL;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3412
  _alloc_record_tail = NULL;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3413
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3414
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3415
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
  3416
  size_t byte_size = word_size * wordSize;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3417
  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
  3418
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3419
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3420
MetaWord* Metaspace::allocate(size_t word_size, MetadataType mdtype) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3421
  // DumpSharedSpaces doesn't use class metadata area (yet)
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3422
  // Also, 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
  3423
  if (is_class_space_allocation(mdtype)) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3424
    return  class_vsm()->allocate(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3425
  } else {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3426
    return  vsm()->allocate(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3427
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3428
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3429
13755
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3430
MetaWord* Metaspace::expand_and_allocate(size_t word_size, MetadataType mdtype) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3431
  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
  3432
  assert(delta_bytes > 0, "Must be");
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3433
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3434
  size_t before = 0;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3435
  size_t after = 0;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3436
  MetaWord* res;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3437
  bool incremented;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3438
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3439
  // 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
  3440
  // 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
  3441
  // have incremented the HWM and therefore the allocation might still succeed.
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3442
  do {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3443
    incremented = MetaspaceGC::inc_capacity_until_GC(delta_bytes, &after, &before);
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3444
    res = allocate(word_size, mdtype);
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3445
  } while (!incremented && res == NULL);
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3446
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3447
  if (incremented) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3448
    tracer()->report_gc_threshold(before, after,
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3449
                                  MetaspaceGCThresholdUpdater::ExpandAndAllocate);
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3450
    if (PrintGCDetails && Verbose) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3451
      gclog_or_tty->print_cr("Increase capacity to GC from " SIZE_FORMAT
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3452
          " to " SIZE_FORMAT, before, after);
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3453
    }
13755
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3454
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3455
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents: 26304
diff changeset
  3456
  return res;
13755
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3457
}
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3458
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3459
// Space allocated in the Metaspace.  This may
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3460
// be across several metadata virtual spaces.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3461
char* Metaspace::bottom() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3462
  assert(DumpSharedSpaces, "only useful and valid for dumping shared spaces");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3463
  return (char*)vsm()->current_chunk()->bottom();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3464
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3465
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3466
size_t Metaspace::used_words_slow(MetadataType mdtype) const {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3467
  if (mdtype == ClassType) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3468
    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
  3469
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3470
    return vsm()->sum_used_in_chunks_in_use();  // includes overhead!
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3471
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3472
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3473
19988
2b100c528806 8023476: Metaspace capacity > reserved
ehelin
parents: 19984
diff changeset
  3474
size_t Metaspace::free_words_slow(MetadataType mdtype) const {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3475
  if (mdtype == ClassType) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3476
    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
  3477
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3478
    return vsm()->sum_free_in_chunks_in_use();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3479
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3480
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3481
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3482
// Space capacity in the Metaspace.  It includes
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3483
// space in the list of chunks from which allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3484
// 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
  3485
// in the space available in the dictionary which
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3486
// is already counted in some chunk.
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3487
size_t Metaspace::capacity_words_slow(MetadataType mdtype) const {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3488
  if (mdtype == ClassType) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3489
    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
  3490
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3491
    return vsm()->sum_capacity_in_chunks_in_use();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3492
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3493
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3494
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3495
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
  3496
  return used_words_slow(mdtype) * BytesPerWord;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3497
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3498
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3499
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
  3500
  return capacity_words_slow(mdtype) * BytesPerWord;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3501
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3502
25051
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3503
size_t Metaspace::allocated_blocks_bytes() const {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3504
  return vsm()->allocated_blocks_bytes() +
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3505
      (using_class_space() ? class_vsm()->allocated_blocks_bytes() : 0);
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3506
}
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3507
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3508
size_t Metaspace::allocated_chunks_bytes() const {
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3509
  return vsm()->allocated_chunks_bytes() +
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3510
      (using_class_space() ? class_vsm()->allocated_chunks_bytes() : 0);
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3511
}
8110ec6e7340 8044107: Add Diagnostic Command to list all ClassLoaders
sla
parents: 24665
diff changeset
  3512
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3513
void Metaspace::deallocate(MetaWord* ptr, size_t word_size, bool is_class) {
23503
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3514
  assert(!SafepointSynchronize::is_at_safepoint()
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3515
         || Thread::current()->is_VM_thread(), "should be the VM thread");
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3516
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3517
  if (DumpSharedSpaces && PrintSharedSpaces) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3518
    record_deallocation(ptr, vsm()->get_raw_word_size(word_size));
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3519
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3520
23503
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3521
  MutexLockerEx ml(vsm()->lock(), Mutex::_no_safepoint_check_flag);
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3522
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3523
  if (word_size < TreeChunk<Metablock, FreeList<Metablock> >::min_size()) {
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3524
    // Dark matter.  Too small for dictionary.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3525
#ifdef ASSERT
23503
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3526
    Copy::fill_to_words((HeapWord*)ptr, word_size, 0xf5f5f5f5);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3527
#endif
23503
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3528
    return;
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3529
  }
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3530
  if (is_class && using_class_space()) {
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3531
    class_vsm()->deallocate(ptr, word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3532
  } else {
23503
84698692e4ef 8037952: Remove code duplication in Metaspace::deallocate
stefank
parents: 23470
diff changeset
  3533
    vsm()->deallocate(ptr, word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3534
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3535
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3536
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3537
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3538
MetaWord* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3539
                              bool read_only, MetaspaceObj::Type type, TRAPS) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3540
  if (HAS_PENDING_EXCEPTION) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3541
    assert(false, "Should not allocate with exception pending");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3542
    return NULL;  // caller does a CHECK_NULL too
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3543
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3544
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3545
  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
  3546
        "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
  3547
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3548
  // Allocate in metaspaces without taking out a lock, because it deadlocks
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3549
  // with the SymbolTable_lock.  Dumping is single threaded for now.  We'll have
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3550
  // to revisit this for application class data sharing.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3551
  if (DumpSharedSpaces) {
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3552
    assert(type > MetaspaceObj::UnknownType && type < MetaspaceObj::_number_of_types, "sanity");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3553
    Metaspace* space = read_only ? loader_data->ro_metaspace() : loader_data->rw_metaspace();
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3554
    MetaWord* result = space->allocate(word_size, NonClassType);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3555
    if (result == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3556
      report_out_of_shared_space(read_only ? SharedReadOnly : SharedReadWrite);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3557
    }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3558
    if (PrintSharedSpaces) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3559
      space->record_allocation(result, type, space->vsm()->get_raw_word_size(word_size));
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3560
    }
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3561
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3562
    // Zero initialize.
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3563
    Copy::fill_to_aligned_words((HeapWord*)result, word_size, 0);
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3564
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3565
    return result;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3566
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3567
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3568
  MetadataType mdtype = (type == MetaspaceObj::ClassType) ? ClassType : NonClassType;
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3569
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3570
  // Try to allocate metadata.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3571
  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
  3572
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3573
  if (result == NULL) {
23468
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  3574
    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
  3575
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3576
    // Allocation failed.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3577
    if (is_init_completed()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3578
      // 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
  3579
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3580
      // Try to clean out some memory and retry.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3581
      result = Universe::heap()->collector_policy()->satisfy_failed_metadata_allocation(
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3582
          loader_data, word_size, mdtype);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3583
    }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3584
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3585
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3586
  if (result == NULL) {
23469
0a4d02776968 8036701: Add trace event when a metaspace throws out of memory error
ehelin
parents: 23468
diff changeset
  3587
    report_metadata_oome(loader_data, word_size, type, mdtype, CHECK_NULL);
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3588
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3589
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3590
  // Zero initialize.
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3591
  Copy::fill_to_aligned_words((HeapWord*)result, word_size, 0);
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3592
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 20407
diff changeset
  3593
  return result;
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3594
}
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3595
21186
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  3596
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
  3597
  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
  3598
  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
  3599
}
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  3600
23469
0a4d02776968 8036701: Add trace event when a metaspace throws out of memory error
ehelin
parents: 23468
diff changeset
  3601
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
  3602
  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
  3603
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3604
  // If result is still null, we are out of memory.
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3605
  if (Verbose && TraceMetadataChunkAllocation) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3606
    gclog_or_tty->print_cr("Metaspace allocation failed for size "
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3607
        SIZE_FORMAT, word_size);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3608
    if (loader_data->metaspace_or_null() != NULL) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3609
      loader_data->dump(gclog_or_tty);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3610
    }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3611
    MetaspaceAux::dump(gclog_or_tty);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3612
  }
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3613
21186
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  3614
  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
  3615
  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
  3616
    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
  3617
    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
  3618
      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
  3619
      (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
  3620
      CompressedClassSpaceSize;
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  3621
  }
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  3622
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3623
  // -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
  3624
  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
  3625
    "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
  3626
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3627
  report_java_out_of_memory(space_string);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3628
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3629
  if (JvmtiExport::should_post_resource_exhausted()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3630
    JvmtiExport::post_resource_exhausted(
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3631
        JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3632
        space_string);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3633
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3634
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3635
  if (!is_init_completed()) {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3636
    vm_exit_during_initialization("OutOfMemoryError", space_string);
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3637
  }
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3638
21186
db851068711f 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 20733
diff changeset
  3639
  if (out_of_compressed_class_space) {
20406
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3640
    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
  3641
  } else {
934f0b12daa9 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 20306
diff changeset
  3642
    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
  3643
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3644
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3645
23468
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  3646
const char* Metaspace::metadata_type_name(Metaspace::MetadataType mdtype) {
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  3647
  switch (mdtype) {
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  3648
    case Metaspace::ClassType: return "Class";
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  3649
    case Metaspace::NonClassType: return "Metadata";
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  3650
    default:
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  3651
      assert(false, err_msg("Got bad mdtype: %d", (int) mdtype));
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  3652
      return NULL;
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  3653
  }
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  3654
}
6bb416a59349 8036699: Add trace event when a metaspace allocation fails
ehelin
parents: 23465
diff changeset
  3655
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3656
void Metaspace::record_allocation(void* ptr, MetaspaceObj::Type type, size_t word_size) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3657
  assert(DumpSharedSpaces, "sanity");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3658
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3659
  int byte_size = (int)word_size * HeapWordSize;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3660
  AllocRecord *rec = new AllocRecord((address)ptr, type, byte_size);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3661
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3662
  if (_alloc_record_head == NULL) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3663
    _alloc_record_head = _alloc_record_tail = rec;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3664
  } else if (_alloc_record_tail->_ptr + _alloc_record_tail->_byte_size == (address)ptr) {
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3665
    _alloc_record_tail->_next = rec;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3666
    _alloc_record_tail = rec;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3667
  } else {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3668
    // slow linear search, but this doesn't happen that often, and only when dumping
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3669
    for (AllocRecord *old = _alloc_record_head; old; old = old->_next) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3670
      if (old->_ptr == ptr) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3671
        assert(old->_type == MetaspaceObj::DeallocatedType, "sanity");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3672
        int remain_bytes = old->_byte_size - byte_size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3673
        assert(remain_bytes >= 0, "sanity");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3674
        old->_type = type;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3675
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3676
        if (remain_bytes == 0) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3677
          delete(rec);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3678
        } else {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3679
          address remain_ptr = address(ptr) + byte_size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3680
          rec->_ptr = remain_ptr;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3681
          rec->_byte_size = remain_bytes;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3682
          rec->_type = MetaspaceObj::DeallocatedType;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3683
          rec->_next = old->_next;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3684
          old->_byte_size = byte_size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3685
          old->_next = rec;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3686
        }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3687
        return;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3688
      }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3689
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3690
    assert(0, "reallocating a freed pointer that was not recorded");
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3691
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3692
}
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3693
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3694
void Metaspace::record_deallocation(void* ptr, size_t word_size) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3695
  assert(DumpSharedSpaces, "sanity");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3696
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3697
  for (AllocRecord *rec = _alloc_record_head; rec; rec = rec->_next) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3698
    if (rec->_ptr == ptr) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3699
      assert(rec->_byte_size == (int)word_size * HeapWordSize, "sanity");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3700
      rec->_type = MetaspaceObj::DeallocatedType;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3701
      return;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3702
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3703
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3704
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3705
  assert(0, "deallocating a pointer that was not recorded");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3706
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25055
diff changeset
  3707
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3708
void Metaspace::iterate(Metaspace::AllocRecordClosure *closure) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3709
  assert(DumpSharedSpaces, "unimplemented for !DumpSharedSpaces");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3710
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3711
  address last_addr = (address)bottom();
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3712
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3713
  for (AllocRecord *rec = _alloc_record_head; rec; rec = rec->_next) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3714
    address ptr = rec->_ptr;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3715
    if (last_addr < ptr) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3716
      closure->doit(last_addr, MetaspaceObj::UnknownType, ptr - last_addr);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3717
    }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3718
    closure->doit(ptr, rec->_type, rec->_byte_size);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3719
    last_addr = ptr + rec->_byte_size;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3720
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3721
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3722
  address top = ((address)bottom()) + used_bytes_slow(Metaspace::NonClassType);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3723
  if (last_addr < top) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3724
    closure->doit(last_addr, MetaspaceObj::UnknownType, top - last_addr);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3725
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3726
}
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3727
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3728
void Metaspace::purge(MetadataType mdtype) {
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3729
  get_space_list(mdtype)->purge(get_chunk_manager(mdtype));
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3730
}
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3731
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  3732
void Metaspace::purge() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  3733
  MutexLockerEx cl(SpaceManager::expand_lock(),
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  3734
                   Mutex::_no_safepoint_check_flag);
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3735
  purge(NonClassType);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3736
  if (using_class_space()) {
20081
e26536e86a5c 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 20080
diff changeset
  3737
    purge(ClassType);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3738
  }
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  3739
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  3740
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3741
void Metaspace::print_on(outputStream* out) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3742
  // Print both class virtual space counts and metaspace.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3743
  if (Verbose) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3744
    vsm()->print_on(out);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3745
    if (using_class_space()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3746
      class_vsm()->print_on(out);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3747
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3748
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3749
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3750
22201
9c2ccfa3a5fe 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 21569
diff changeset
  3751
bool Metaspace::contains(const void* ptr) {
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  3752
  if (UseSharedSpaces && MetaspaceShared::is_in_shared_space(ptr)) {
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  3753
    return true;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3754
  }
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  3755
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  3756
  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
  3757
     return true;
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  3758
  }
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  3759
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24424
diff changeset
  3760
  return get_space_list(NonClassType)->contains(ptr);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3761
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3762
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3763
void Metaspace::verify() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3764
  vsm()->verify();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3765
  if (using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3766
    class_vsm()->verify();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3767
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3768
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3769
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3770
void Metaspace::dump(outputStream* const out) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3771
  out->print_cr("\nVirtual space manager: " INTPTR_FORMAT, vsm());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3772
  vsm()->dump(out);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3773
  if (using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3774
    out->print_cr("\nClass space manager: " INTPTR_FORMAT, class_vsm());
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3775
    class_vsm()->dump(out);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3776
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3777
}
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3778
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3779
/////////////// Unit tests ///////////////
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3780
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3781
#ifndef PRODUCT
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3782
20084
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  3783
class TestMetaspaceAuxTest : AllStatic {
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3784
 public:
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3785
  static void test_reserved() {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3786
    size_t reserved = MetaspaceAux::reserved_bytes();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3787
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3788
    assert(reserved > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3789
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3790
    size_t committed  = MetaspaceAux::committed_bytes();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3791
    assert(committed <= reserved, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3792
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3793
    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
  3794
    assert(reserved_metadata > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3795
    assert(reserved_metadata <= reserved, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3796
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3797
    if (UseCompressedClassPointers) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3798
      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
  3799
      assert(reserved_class > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3800
      assert(reserved_class < reserved, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3801
    }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3802
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3803
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3804
  static void test_committed() {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3805
    size_t committed = MetaspaceAux::committed_bytes();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3806
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3807
    assert(committed > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3808
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3809
    size_t reserved  = MetaspaceAux::reserved_bytes();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3810
    assert(committed <= reserved, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3811
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3812
    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
  3813
    assert(committed_metadata > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3814
    assert(committed_metadata <= committed, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3815
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3816
    if (UseCompressedClassPointers) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3817
      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
  3818
      assert(committed_class > 0, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3819
      assert(committed_class < committed, "assert");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3820
    }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3821
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3822
20084
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  3823
  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
  3824
    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
  3825
    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
  3826
    // 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
  3827
    // vm_allocation_granularity aligned on Windows.
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  3828
    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
  3829
    large_size += (os::vm_page_size()/BytesPerWord);
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  3830
    vs_list->get_new_chunk(large_size, large_size, 0);
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  3831
  }
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  3832
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3833
  static void test() {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3834
    test_reserved();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3835
    test_committed();
20084
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  3836
    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
  3837
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3838
};
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3839
20084
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  3840
void TestMetaspaceAux_test() {
a61ec6d55abc 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 20081
diff changeset
  3841
  TestMetaspaceAuxTest::test();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3842
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  3843
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3844
class TestVirtualSpaceNodeTest {
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3845
  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
  3846
                                          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
  3847
                                          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
  3848
    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
  3849
    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
  3850
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3851
    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
  3852
    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
  3853
    // 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
  3854
    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
  3855
    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
  3856
  }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3857
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3858
 public:
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3859
  static void test() {
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3860
    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
  3861
    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
  3862
    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
  3863
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3864
    // 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
  3865
    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
  3866
    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
  3867
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3868
    { // 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
  3869
      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
  3870
      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
  3871
      vsn.initialize();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3872
      vsn.retire(&cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3873
      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
  3874
    }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3875
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3876
    { // 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
  3877
      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
  3878
      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
  3879
      vsn.initialize();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3880
      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
  3881
      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
  3882
      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
  3883
      vsn.retire(&cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3884
      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
  3885
      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
  3886
    }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3887
28497
a7aecf0ffb6b 8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents: 28372
diff changeset
  3888
    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
  3889
    // 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
  3890
    if (page_chunks < MediumChunk) {
a7aecf0ffb6b 8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents: 28372
diff changeset
  3891
      // 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
  3892
      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
  3893
      VirtualSpaceNode vsn(vsn_test_size_bytes);
28497
a7aecf0ffb6b 8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents: 28372
diff changeset
  3894
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3895
      vsn.initialize();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3896
      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
  3897
      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
  3898
      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
  3899
      vsn.retire(&cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3900
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3901
      // 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
  3902
      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
  3903
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3904
      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
  3905
      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
  3906
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3907
      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
  3908
      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
  3909
      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
  3910
    }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3911
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3912
    { // 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
  3913
      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
  3914
      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
  3915
      vsn.initialize();
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3916
      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
  3917
      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
  3918
      vsn.retire(&cm);
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3919
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3920
      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
  3921
      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
  3922
      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
  3923
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3924
      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
  3925
      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
  3926
      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
  3927
    }
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3928
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  3929
  }
22222
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3930
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3931
#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
  3932
  assert(vsn.is_available(word_size), \
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3933
    err_msg(#word_size ": " PTR_FORMAT " bytes were not available in " \
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3934
            "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3935
            (uintptr_t)(word_size * BytesPerWord), vsn.bottom(), vsn.end()));
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3936
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3937
#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
  3938
  assert(!vsn.is_available(word_size), \
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3939
    err_msg(#word_size ": " PTR_FORMAT " bytes should not be available in " \
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3940
            "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3941
            (uintptr_t)(word_size * BytesPerWord), vsn.bottom(), vsn.end()));
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3942
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3943
  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
  3944
    // Reserve some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3945
    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
  3946
    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
  3947
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3948
    // Commit some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3949
    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
  3950
    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
  3951
    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
  3952
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3953
    // 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
  3954
    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
  3955
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3956
    // 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
  3957
    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
  3958
    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
  3959
  }
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3960
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3961
  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
  3962
    // Reserve some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3963
    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
  3964
    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
  3965
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3966
    // Commit some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3967
    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
  3968
    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
  3969
    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
  3970
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3971
    // 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
  3972
    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
  3973
    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
  3974
  }
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3975
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3976
  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
  3977
    // Reserve some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3978
    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
  3979
    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
  3980
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3981
    // Commit some memory.
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3982
    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
  3983
    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
  3984
    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
  3985
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3986
    // 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
  3987
    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
  3988
    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
  3989
    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
  3990
    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
  3991
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3992
    // 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
  3993
    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
  3994
  }
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3995
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  3996
  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
  3997
    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
  3998
    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
  3999
    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
  4000
  }
21112
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4001
};
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4002
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4003
void TestVirtualSpaceNode_test() {
eb9c887bac49 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 20733
diff changeset
  4004
  TestVirtualSpaceNodeTest::test();
22222
45a293a4b895 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 21569
diff changeset
  4005
  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
  4006
}
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19988
diff changeset
  4007
#endif